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
---
OpenSim/Data/Null/NullFriendsData.cs | 10 +++++++++-
.../CoreModules/Avatar/Friends/FriendsModule.cs | 15 ++++++++++-----
.../Avatar/Friends/Tests/FriendModuleTests.cs | 21 ++++++++++++++++++++-
.../Region/Framework/Interfaces/IFriendsModule.cs | 14 ++++++++++++++
4 files changed, 53 insertions(+), 7 deletions(-)
diff --git a/OpenSim/Data/Null/NullFriendsData.cs b/OpenSim/Data/Null/NullFriendsData.cs
index d90788a..0a4b242 100644
--- a/OpenSim/Data/Null/NullFriendsData.cs
+++ b/OpenSim/Data/Null/NullFriendsData.cs
@@ -56,13 +56,21 @@ namespace OpenSim.Data.Null
///
public FriendsData[] GetFriends(string userID)
{
- List lst = m_Data.FindAll(delegate (FriendsData fdata)
+ List lst = m_Data.FindAll(fdata =>
{
return fdata.PrincipalID == userID.ToString();
});
if (lst != null)
+ {
+ lst.ForEach(f =>
+ {
+ FriendsData f2 = m_Data.Find(candidateF2 => f.Friend == candidateF2.PrincipalID);
+ if (f2 != null) { f.Data["TheirFlags"] = f2.Data["Flags"]; }
+ });
+
return lst.ToArray();
+ }
return new FriendsData[0];
}
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