diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 6c207bdb22..2a1a1d5ec4 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs @@ -241,7 +241,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApproveFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; - client.OnTerminateFriendship += OnTerminateFriendship; + client.OnTerminateFriendship += (thisClient, agentID, exfriendID) => RemoveFriendship(thisClient, exfriendID); client.OnGrantUserRights += OnGrantUserRights; Util.FireAndForget(delegate { FetchFriendslist(client); }); @@ -643,10 +643,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends } } } - - private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) + + public void RemoveFriendship(IClientAPI client, UUID exfriendID) { - if (!DeleteFriendship(agentID, exfriendID)) + if (!DeleteFriendship(client.AgentId, exfriendID)) client.SendAlertMessage("Unable to terminate friendship on this sim."); // Update local cache @@ -669,9 +669,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (friendSession != null) { GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); - m_FriendsSimConnector.FriendshipTerminated(region, agentID, exfriendID); + m_FriendsSimConnector.FriendshipTerminated(region, client.AgentId, exfriendID); } - } + } } private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs index 1e97c23454..b5525207cd 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs @@ -71,12 +71,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests 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)); + Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0)); + Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0)); } [Test] - public void TestAddFriendWhileOnline() + public void TestAddFriendshipWhileOnline() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); @@ -91,8 +91,28 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests // notification. m_fm.AddFriendship(sp.ControllingClient, user2Id); - Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0)); - Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(1)); + Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0)); + Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1)); + } + + [Test] + public void TestRemoveFriendshipWhileOnline() + { + TestHelpers.InMethod(); +// log4net.Config.XmlConfigurator.Configure(); + + UUID user1Id = TestHelpers.ParseTail(0x1); + UUID user2Id = TestHelpers.ParseTail(0x2); + + ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, user1Id); + SceneHelpers.AddScenePresence(m_scene, user2Id); + + m_fm.AddFriendship(sp.ControllingClient, user2Id); + m_fm.RemoveFriendship(sp.ControllingClient, user2Id); + + TestClient user1Client = sp.ControllingClient as TestClient; + Assert.That(user1Client.ReceivedFriendshipTerminations.Count, Is.EqualTo(1)); + Assert.That(user1Client.ReceivedFriendshipTerminations[0], Is.EqualTo(user2Id)); } } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs index fdede340fc..061799e394 100644 --- a/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IFriendsModule.cs @@ -44,6 +44,17 @@ namespace OpenSim.Region.Framework.Interfaces /// void AddFriendship(IClientAPI client, UUID friendID); + /// + /// Remove a friendship between two users. + /// + /// + /// 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 RemoveFriendship(IClientAPI client, UUID exFriendID); + uint GetFriendPerms(UUID PrincipalID, UUID FriendID); bool SendFriendsOnlineIfNeeded(IClientAPI client); } diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index 80ed13e3ba..54b88eeab5 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -57,8 +57,9 @@ namespace OpenSim.Tests.Common.Mock private IScene m_scene; // Properties so that we can get at received data for test purposes - public List OfflineNotificationsReceived { get; private set; } - public List OnlineNotificationsReceived { get; private set; } + public List ReceivedOfflineNotifications { get; private set; } + public List ReceivedOnlineNotifications { get; private set; } + public List ReceivedFriendshipTerminations { get; private set; } // disable warning: public events, part of the public API #pragma warning disable 67 @@ -445,8 +446,9 @@ namespace OpenSim.Tests.Common.Mock m_scene = scene; CapsSeedUrl = agentData.CapsPath; - OfflineNotificationsReceived = new List(); - OnlineNotificationsReceived = new List(); + ReceivedOfflineNotifications = new List(); + ReceivedOnlineNotifications = new List(); + ReceivedFriendshipTerminations = new List(); } /// @@ -834,12 +836,12 @@ namespace OpenSim.Tests.Common.Mock public void SendAgentOffline(UUID[] agentIDs) { - OfflineNotificationsReceived.AddRange(agentIDs); + ReceivedOfflineNotifications.AddRange(agentIDs); } public void SendAgentOnline(UUID[] agentIDs) { - OnlineNotificationsReceived.AddRange(agentIDs); + ReceivedOnlineNotifications.AddRange(agentIDs); } public void SendSitResponse(UUID TargetID, Vector3 OffsetPos, Quaternion SitOrientation, bool autopilot, @@ -1109,6 +1111,7 @@ namespace OpenSim.Tests.Common.Mock public void SendTerminateFriend(UUID exFriendID) { + ReceivedFriendshipTerminations.Add(exFriendID); } public bool AddGenericPacketHandler(string MethodName, GenericMessage handler)