From 86706f45af8be26671ff3a606a3c8be5a4d35f9e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 26 Jan 2023 18:53:33 +0000 Subject: [PATCH] a few changes to friends module --- .../Avatar/Friends/HGFriendsModule.cs | 27 ++++++----- .../Avatar/Friends/HGStatusNotifier.cs | 48 +++++++++---------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs index 031c12647d..13a3d7a27c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs @@ -256,15 +256,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends //m_log.DebugFormat("[HGFRIENDS MODULE]: Entering StatusNotify for {0}", userID); // First, let's divide the friends on a per-domain basis + List locallst = new(friendList.Count); + Dictionary> friendsPerDomain = new Dictionary>(); foreach (FriendInfo friend in friendList) { - UUID friendID; - if (UUID.TryParse(friend.Friend, out friendID)) + if (UUID.TryParse(friend.Friend, out UUID friendID)) { - if (!friendsPerDomain.ContainsKey("local")) - friendsPerDomain["local"] = new List(); - friendsPerDomain["local"].Add(friend); + if (LocalStatusNotification(userID, friendID, online)) + continue; + locallst.Add(friend); } else { @@ -275,19 +276,23 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends if (LocalStatusNotification(userID, friendID, online)) continue; - if (!friendsPerDomain.ContainsKey(url)) - friendsPerDomain[url] = new List(); - friendsPerDomain[url].Add(friend); + if (!friendsPerDomain.TryGetValue(url, out List lst)) + { + lst = new List(); + friendsPerDomain[url] = lst; + } + lst.Add(friend); } } } // For the local friends, just call the base method // Let's do this first of all - if (friendsPerDomain.ContainsKey("local")) - base.StatusNotify(friendsPerDomain["local"], userID, online); + if (locallst.Count > 0) + base.StatusNotify(locallst, userID, online); - m_StatusNotifier.Notify(userID, friendsPerDomain, online); + if(friendsPerDomain.Count > 0) + m_StatusNotifier.Notify(userID, friendsPerDomain, online); // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting StatusNotify for {0}", userID); } diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs index 88598abd12..542a7c1e4d 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGStatusNotifier.cs @@ -30,35 +30,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends { foreach (KeyValuePair> kvp in friendsPerDomain) { - if (kvp.Key != "local") + // For the others, call the user agent service + List ids = new(kvp.Value.Count); + foreach (FriendInfo f in kvp.Value) + ids.Add(f.Friend); + + if (ids.Count == 0) + continue; // no one to notify. caller don't do this + + //m_log.DebugFormat("[HG STATUS NOTIFIER]: Notifying {0} friends in {1}", ids.Count, kvp.Key); + // ASSUMPTION: we assume that all users for one home domain + // have exactly the same set of service URLs. + // If this is ever not true, we need to change this. + if (Util.ParseUniversalUserIdentifier(ids[0], out UUID friendID)) { - // For the others, call the user agent service - List ids = new List(); - foreach (FriendInfo f in kvp.Value) - ids.Add(f.Friend); - - if (ids.Count == 0) - continue; // no one to notify. caller don't do this - - //m_log.DebugFormat("[HG STATUS NOTIFIER]: Notifying {0} friends in {1}", ids.Count, kvp.Key); - // ASSUMPTION: we assume that all users for one home domain - // have exactly the same set of service URLs. - // If this is ever not true, we need to change this. - if (Util.ParseUniversalUserIdentifier(ids[0], out UUID friendID)) + string friendsServerURI = m_FriendsModule.UserManagementModule.GetUserServerURL(friendID, "FriendsServerURI"); + if (!string.IsNullOrEmpty(friendsServerURI)) { - string friendsServerURI = m_FriendsModule.UserManagementModule.GetUserServerURL(friendID, "FriendsServerURI"); - if (friendsServerURI != string.Empty) + HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI); + + List friendsOnline = fConn.StatusNotification(ids, userID, online); + + if (online && friendsOnline.Count > 0) { - HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI); - - List friendsOnline = fConn.StatusNotification(ids, userID, online); - - if (online && friendsOnline.Count > 0) - { - IClientAPI client = m_FriendsModule.LocateClientObject(userID); - if (client != null) - client.SendAgentOnline(friendsOnline.ToArray()); - } + IClientAPI client = m_FriendsModule.LocateClientObject(userID); + client?.SendAgentOnline(friendsOnline.ToArray()); } } }