Code cleanup

This commit is contained in:
Stone_Red
2026-07-18 17:21:36 +02:00
parent 59f6f1d1bd
commit 92cd2bf332
17 changed files with 47 additions and 31 deletions
+9
View File
@@ -32,14 +32,23 @@ public sealed class ChannelJoinResult
public sealed class ConnectionService : IConnectionService public sealed class ConnectionService : IConnectionService
{ {
public event Action<ServerModel>? ServerAdded; public event Action<ServerModel>? ServerAdded;
public event Action<string>? ServerRemoved; public event Action<string>? ServerRemoved;
public event Action<ServerModel>? ServerStateChanged; public event Action<ServerModel>? ServerStateChanged;
public event Action<string, ChannelModel>? ChannelAdded; public event Action<string, ChannelModel>? ChannelAdded;
public event Action<string, string>? ChannelRemoved; public event Action<string, string>? ChannelRemoved;
public event Action<string, MessageModel>? MessageReceived; public event Action<string, MessageModel>? MessageReceived;
public event Action<string, string, string?>? UserJoined; public event Action<string, string, string?>? UserJoined;
public event Action<string, string>? UserLeft; public event Action<string, string>? UserLeft;
public event Action<string, string>? ErrorOccurred; public event Action<string, string>? ErrorOccurred;
public event Action<string, string>? ChannelDeleted; public event Action<string, string>? ChannelDeleted;
private readonly Dictionary<string, ServerConnection> _connections = new(StringComparer.OrdinalIgnoreCase); private readonly Dictionary<string, ServerConnection> _connections = new(StringComparer.OrdinalIgnoreCase);
+1
View File
@@ -3,5 +3,6 @@ namespace Decho.Services;
public interface IAttachmentService public interface IAttachmentService
{ {
Task<string?> DownloadAttachmentAsync(string serverUrl, string channelName, string relativeUrl, string fileName); Task<string?> DownloadAttachmentAsync(string serverUrl, string channelName, string relativeUrl, string fileName);
Task<byte[]?> DownloadImageBytesAsync(string serverUrl, string channelName, string relativeUrl); Task<byte[]?> DownloadImageBytesAsync(string serverUrl, string channelName, string relativeUrl);
} }
@@ -3,7 +3,10 @@ namespace Decho.Services;
public interface IConfigPersistenceService public interface IConfigPersistenceService
{ {
void SaveRefreshToken(string serverUrl, string token, string userId); void SaveRefreshToken(string serverUrl, string token, string userId);
void RemoveServerFromConfig(string serverUrl); void RemoveServerFromConfig(string serverUrl);
void RemoveFromLeftChannels(string serverUrl, string channelName); void RemoveFromLeftChannels(string serverUrl, string channelName);
void AddLeftChannel(string serverUrl, string channelName); void AddLeftChannel(string serverUrl, string channelName);
} }
+2
View File
@@ -3,6 +3,8 @@ namespace Decho.Services;
public interface ICryptoService public interface ICryptoService
{ {
void MarkChannelEncrypted(string serverUrl, string channelName, bool isEncrypted); void MarkChannelEncrypted(string serverUrl, string channelName, bool isEncrypted);
bool HasChannelKey(string serverUrl, string channelName); bool HasChannelKey(string serverUrl, string channelName);
bool TryGetRoomKey(string serverUrl, string channelName, out byte[]? key); bool TryGetRoomKey(string serverUrl, string channelName, out byte[]? key);
} }
@@ -86,7 +86,8 @@ public sealed class MessageComposerViewModel : ViewModelBase
IObservable<bool> canSend = this.WhenAnyValue( IObservable<bool> canSend = this.WhenAnyValue(
x => x.Draft, x => x.Draft,
x => x.HasStagedFiles, x => x.HasStagedFiles,
(draft, hasFiles) => !string.IsNullOrWhiteSpace(draft) || hasFiles); (draft, hasFiles) =>
!string.IsNullOrWhiteSpace(draft) || hasFiles);
SendCommand = ReactiveCommand.Create(Send, canSend); SendCommand = ReactiveCommand.Create(Send, canSend);
_ = this.WhenAnyValue(x => x.Draft).Subscribe(OnDraftChanged); _ = this.WhenAnyValue(x => x.Draft).Subscribe(OnDraftChanged);
@@ -179,20 +180,7 @@ public sealed class MessageComposerViewModel : ViewModelBase
ReplyTarget = null; ReplyTarget = null;
} }
private void UpdateStagedSummary() internal void Send()
{
this.RaisePropertyChanged(nameof(HasStagedFiles));
StagedFilesSummary = StagedFiles.Count > 0
? $"{StagedFiles.Count} file(s) staged"
: string.Empty;
}
private void OnDraftChanged(string? draft)
{
Autocomplete.Update(draft ?? string.Empty);
}
private void Send()
{ {
string text = Draft.Trim(); string text = Draft.Trim();
Draft = string.Empty; Draft = string.Empty;
@@ -212,4 +200,17 @@ public sealed class MessageComposerViewModel : ViewModelBase
SendRequested?.Invoke(ServerUrl, text, filePaths, replyToId); SendRequested?.Invoke(ServerUrl, text, filePaths, replyToId);
} }
private void UpdateStagedSummary()
{
this.RaisePropertyChanged(nameof(HasStagedFiles));
StagedFilesSummary = StagedFiles.Count > 0
? $"{StagedFiles.Count} file(s) staged"
: string.Empty;
}
private void OnDraftChanged(string? draft)
{
Autocomplete.Update(draft ?? string.Empty);
}
} }