Add new channels to UI when created and update connecting status logic

This commit is contained in:
Stone_Red
2026-07-17 03:01:05 +02:00
parent 9f1ffa7802
commit e1366c0aea
4 changed files with 31 additions and 3 deletions
+17 -2
View File
@@ -778,7 +778,22 @@ public sealed class ConnectionService : IDisposable
{
ChannelModel? existing = entry.Server.Channels.FirstOrDefault(c =>
string.Equals(c.Name, channel.Name, StringComparison.OrdinalIgnoreCase));
_ = existing?.Topic = channel.Topic;
if (existing is not null)
{
_ = existing.Topic = channel.Topic;
}
else
{
var model = new ChannelModel(
channel.Id.ToString(),
channel.Name,
[],
channel.Topic,
channel.IsPublic,
channel.IsProtected);
entry.Server.Channels.Add(model);
ChannelAdded?.Invoke(entry.Server.ServerUrl, model);
}
};
conn.ForceDisconnected += reason =>
@@ -796,7 +811,7 @@ public sealed class ConnectionService : IDisposable
conn.ConnectionStatusChanged += status =>
{
entry.Server.IsConnected = status == "Connected";
entry.Server.IsConnecting = status is "Connecting..." or "Authenticating...";
entry.Server.IsConnecting = status is "Connecting..." or "Authenticating..." or "Reconnecting...";
ServerStateChanged?.Invoke(entry.Server);
};
}
@@ -625,6 +625,18 @@ public sealed class MainWindowViewModel : ViewModelBase
StatusText = $"Error: {error}";
});
};
ConnectionService.ChannelAdded += (serverUrl, channel) =>
{
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
{
ServerViewModel? serverVm = Sidebar.GetServer(serverUrl);
if (serverVm is not null && serverVm.Channels.All(c => c.Name != channel.Name))
{
serverVm.Channels.Add(new ChannelViewModel(channel));
}
});
};
}
private async Task RefreshOnlineUsersAsync(string serverUrl, string channelName)
+1
View File
@@ -100,6 +100,7 @@ public sealed class ServerViewModel : ViewModelBase
{
_ = this.RaiseAndSetIfChanged(ref _isConnecting, value);
this.RaisePropertyChanged(nameof(ConnectionStatusText));
this.RaisePropertyChanged(nameof(ConnectionStatusColor));
this.RaisePropertyChanged(nameof(ShowConnectionControls));
}
}
+1 -1
View File
@@ -11,7 +11,7 @@
<TextBlock FontWeight="Bold"
FontSize="13"
Margin="8 6"
Text="{Binding OnlineUserCount, StringFormat='Online — {0}'}" />
Text="{Binding OnlineUserCount, StringFormat='Users - {0}'}" />
<ItemsControl ItemsSource="{Binding OnlineUsers}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:UserViewModel">