a few changes to friends module

This commit is contained in:
UbitUmarov
2023-01-26 18:53:33 +00:00
parent 4358ab54b0
commit 86706f45af
2 changed files with 38 additions and 37 deletions

View File

@@ -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<FriendInfo> locallst = new(friendList.Count);
Dictionary<string, List<FriendInfo>> friendsPerDomain = new Dictionary<string, List<FriendInfo>>();
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<FriendInfo>();
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<FriendInfo>();
friendsPerDomain[url].Add(friend);
if (!friendsPerDomain.TryGetValue(url, out List<FriendInfo> lst))
{
lst = new List<FriendInfo>();
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);
}

View File

@@ -30,35 +30,31 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
{
foreach (KeyValuePair<string, List<FriendInfo>> kvp in friendsPerDomain)
{
if (kvp.Key != "local")
// For the others, call the user agent service
List<string> 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<string> ids = new List<string>();
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<UUID> friendsOnline = fConn.StatusNotification(ids, userID, online);
if (online && friendsOnline.Count > 0)
{
HGFriendsServicesConnector fConn = new HGFriendsServicesConnector(friendsServerURI);
List<UUID> 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());
}
}
}