From 348d15707d129c99bc79cd35d544bc62b9a6f1b2 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 14 Nov 2011 18:08:02 +0000 Subject: Add test for adding a friend whilst online --- .../CoreModules/Avatar/Friends/FriendsModule.cs | 15 ++++++++++----- .../Avatar/Friends/Tests/FriendModuleTests.cs | 21 ++++++++++++++++++++- .../Region/Framework/Interfaces/IFriendsModule.cs | 14 ++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 28a2f73..f4281e5 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -576,9 +576,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List callingCardFolders) { - m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); + m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID); - StoreFriendships(agentID, friendID); + AddFriend(client, friendID); + } + + public void AddFriend(IClientAPI client, UUID friendID) + { + StoreFriendships(client.AgentId, friendID); // Update the local cache RefetchFriends(client); @@ -588,7 +593,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends // // Try Local - if (LocalFriendshipApproved(agentID, client.Name, friendID)) + if (LocalFriendshipApproved(client.AgentId, client.Name, friendID)) { client.SendAgentOnline(new UUID[] { friendID }); return; @@ -602,7 +607,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); - m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); + m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID); client.SendAgentOnline(new UUID[] { friendID }); } } @@ -869,7 +874,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } /// - /// Update loca cache only + /// Update local cache only /// /// /// diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs index b52093a..3ad691a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs @@ -70,9 +70,28 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests UUID userId = TestHelpers.ParseTail(0x1); ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); - + Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0)); Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(0)); } + + [Test] + public void TestAddFriendWhileOnline() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + UUID userId = TestHelpers.ParseTail(0x1); + UUID user2Id = TestHelpers.ParseTail(0x2); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); + ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, user2Id); + + // This friendship is currently only one-way, which might be pathalogical in Second Life. + m_fm.AddFriend(sp.ControllingClient, user2Id); + + Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0)); + Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(1)); + } } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs index d4a6857..8143164 100644 --- a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs @@ -33,6 +33,20 @@ namespace OpenSim.Region.Framework.Interfaces { public interface IFriendsModule { + /// + /// Add a friend for the given user. + /// + /// + /// This is a one-way friendship. To make a two way friendship you will need to call this again with the + /// client and friend reversed. + /// + /// Ultimately, it would be more useful to take in a user account here rather than having to have a user + /// present in the scene. + /// + /// + /// + void AddFriend(IClientAPI client, UUID friendID); + uint GetFriendPerms(UUID PrincipalID, UUID FriendID); bool SendFriendsOnlineIfNeeded(IClientAPI client); } -- cgit v1.1