mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 07:36:01 +02:00
feat: load more message history when scrolling to top
This commit is contained in:
@@ -30,6 +30,7 @@ public sealed class AppOrchestrator : IDisposable
|
||||
private readonly ConnectionManager _conn = new();
|
||||
private readonly Dictionary<string, List<UserPresenceDto>> _channelUsers = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly Lock _channelUsersLock = new();
|
||||
private readonly HashSet<string> _channelsLoadingMore = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private ClientConfig _config;
|
||||
private readonly UserSession _session = new();
|
||||
@@ -92,6 +93,7 @@ public sealed class AppOrchestrator : IDisposable
|
||||
_mainWindow.OnUserProfileRequested += HandleViewProfile;
|
||||
_mainWindow.OnChannelJoinRequested += HandleChannelJoinFromMessage;
|
||||
_mainWindow.OnSearchRequested += HandleSearchRequested;
|
||||
_mainWindow.OnLoadMoreRequested += HandleLoadMoreRequested;
|
||||
}
|
||||
|
||||
// ── Command Handler Wiring ─────────────────────────────────────────────
|
||||
@@ -721,6 +723,31 @@ public sealed class AppOrchestrator : IDisposable
|
||||
}, "Failed to join channel");
|
||||
}
|
||||
|
||||
private void HandleLoadMoreRequested()
|
||||
{
|
||||
if (!_conn.IsConnected) return;
|
||||
|
||||
var channel = _mainWindow.CurrentChannel;
|
||||
if (string.IsNullOrEmpty(channel)) return;
|
||||
|
||||
if (!_channelsLoadingMore.Add(channel)) return;
|
||||
|
||||
var offset = _messageManager.GetMessages(channel)?.Count ?? 0;
|
||||
|
||||
RunAsync(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var history = await _conn.GetHistoryAsync(channel, HubConstants.DefaultHistoryCount, offset);
|
||||
InvokeUI(() => _messageManager.PrependHistory(channel, history));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_channelsLoadingMore.Remove(channel);
|
||||
}
|
||||
}, "Failed to load more messages");
|
||||
}
|
||||
|
||||
private void HandleChannelJoinFromMessage(string channelName)
|
||||
{
|
||||
if (!_conn.IsConnected) return;
|
||||
|
||||
Reference in New Issue
Block a user