Add test for adding a friend whilst online

iar_mods
Justin Clark-Casey (justincc) 2011-11-14 18:08:02 +00:00
parent de895ee54a
commit 348d15707d
4 changed files with 53 additions and 7 deletions

View File

@ -56,13 +56,21 @@ namespace OpenSim.Data.Null
/// <returns></returns>
public FriendsData[] GetFriends(string userID)
{
List<FriendsData> lst = m_Data.FindAll(delegate (FriendsData fdata)
List<FriendsData> 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];
}

View File

@ -576,9 +576,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> 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
}
/// <summary>
/// Update loca cache only
/// Update local cache only
/// </summary>
/// <param name="userID"></param>
/// <param name="friendID"></param>

View File

@ -74,5 +74,24 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
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));
}
}
}

View File

@ -33,6 +33,20 @@ namespace OpenSim.Region.Framework.Interfaces
{
public interface IFriendsModule
{
/// <summary>
/// Add a friend for the given user.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <param name="client"></param>
/// <param name="friendID"></param>
void AddFriend(IClientAPI client, UUID friendID);
uint GetFriendPerms(UUID PrincipalID, UUID FriendID);
bool SendFriendsOnlineIfNeeded(IClientAPI client);
}