feat: Manage joined channels in AppOrchestrator and update channel history handling

This commit is contained in:
HueByte
2026-02-19 08:03:30 +01:00
parent eef9059b6a
commit 96b31ec568
4 changed files with 62 additions and 22 deletions
+33 -2
View File
@@ -50,7 +50,10 @@ public class PresenceTracker
return username;
}
public void JoinChannel(string username, string channelName)
/// <summary>
/// Returns true if this is a new join, false if the user was already in the channel.
/// </summary>
public bool JoinChannel(string username, string channelName)
{
lock (_lock)
{
@@ -60,7 +63,7 @@ public class PresenceTracker
_userChannels[username] = channels;
}
channels.Add(channelName);
return channels.Add(channelName);
}
}
@@ -106,6 +109,34 @@ public class PresenceTracker
return [];
}
/// <summary>
/// Get all unique connection IDs for users who share any of the given channels.
/// </summary>
public List<string> GetConnectionsInChannels(List<string> channels)
{
lock (_lock)
{
var usernames = new HashSet<string>();
foreach (var channel in channels)
{
foreach (var (username, userChannels) in _userChannels)
{
if (userChannels.Contains(channel))
usernames.Add(username);
}
}
var connections = new List<string>();
foreach (var username in usernames)
{
if (_userConnections.TryGetValue(username, out var conns))
connections.AddRange(conns);
}
return connections;
}
}
public bool IsOnline(string username)
{
return _userConnections.TryGetValue(username, out var connections) && connections.Count > 0;