mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 00:56:05 +02:00
feat: add force disconnect handling and improve user ban notifications
This commit is contained in:
@@ -830,25 +830,33 @@ public sealed class AppOrchestrator : IDisposable
|
||||
InvokeUI(() =>
|
||||
{
|
||||
_mainWindow.AddSystemMessage(channelName, $"{username} was kicked{reasonText}");
|
||||
if (username.Equals(_currentUsername, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_mainWindow.AddSystemMessage(channelName, "You were kicked from this channel.");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
connection.OnUserBanned += (username, reason) =>
|
||||
{
|
||||
var reasonText = reason is not null ? $" ({reason})" : "";
|
||||
InvokeUI(() =>
|
||||
{
|
||||
if (username.Equals(_currentUsername, StringComparison.OrdinalIgnoreCase))
|
||||
// Show ban notification for other users in the channel
|
||||
if (!username.Equals(_currentUsername, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_mainWindow.ShowError("You have been banned from this server.");
|
||||
HandleDisconnect();
|
||||
var channel = _mainWindow.CurrentChannel;
|
||||
if (!string.IsNullOrEmpty(channel))
|
||||
_mainWindow.AddSystemMessage(channel, $"{username} was banned{reasonText}");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
connection.OnForceDisconnect += reason =>
|
||||
{
|
||||
InvokeUI(() =>
|
||||
{
|
||||
_mainWindow.ShowError(reason);
|
||||
HandleDisconnect();
|
||||
});
|
||||
};
|
||||
|
||||
connection.OnMessageDeleted += (channelName, messageId) =>
|
||||
{
|
||||
InvokeUI(() =>
|
||||
|
||||
@@ -18,6 +18,7 @@ public sealed class EchoHubConnection : IAsyncDisposable
|
||||
public event Action<string, string?>? OnUserBanned;
|
||||
public event Action<string, Guid>? OnMessageDeleted;
|
||||
public event Action<string>? OnChannelNuked;
|
||||
public event Action<string>? OnForceDisconnect;
|
||||
public event Action<string>? OnError;
|
||||
public event Action<string>? OnConnectionStateChanged;
|
||||
public event Action? OnReconnected;
|
||||
@@ -105,6 +106,11 @@ public sealed class EchoHubConnection : IAsyncDisposable
|
||||
OnChannelNuked?.Invoke(channelName);
|
||||
});
|
||||
|
||||
_connection.On<string>(nameof(Core.Contracts.IEchoHubClient.ForceDisconnect), reason =>
|
||||
{
|
||||
OnForceDisconnect?.Invoke(reason);
|
||||
});
|
||||
|
||||
_connection.On<string>(nameof(Core.Contracts.IEchoHubClient.Error), message =>
|
||||
{
|
||||
OnError?.Invoke(message);
|
||||
|
||||
@@ -197,6 +197,7 @@ public sealed class MainWindow : Runnable
|
||||
WordWrap = true
|
||||
};
|
||||
_inputField.KeyDown += OnInputKeyDown;
|
||||
_inputField.ContentsChanged += OnInputContentsChanged;
|
||||
_inputFrame.Add(_inputField);
|
||||
Add(_inputFrame);
|
||||
|
||||
@@ -388,6 +389,31 @@ public sealed class MainWindow : Runnable
|
||||
}
|
||||
}
|
||||
|
||||
private bool _suppressEmojiReplace;
|
||||
|
||||
private void OnInputContentsChanged(object? sender, ContentsChangedEventArgs e)
|
||||
{
|
||||
if (_suppressEmojiReplace)
|
||||
return;
|
||||
|
||||
var text = _inputField.Text;
|
||||
if (string.IsNullOrEmpty(text))
|
||||
return;
|
||||
|
||||
var replaced = EmojiHelper.ReplaceEmoji(text);
|
||||
if (replaced == text)
|
||||
return;
|
||||
|
||||
// Calculate where cursor should land after replacement
|
||||
var lengthDelta = replaced.Length - text.Length;
|
||||
var newCol = Math.Max(0, _inputField.CurrentColumn + lengthDelta);
|
||||
|
||||
_suppressEmojiReplace = true;
|
||||
_inputField.Text = replaced;
|
||||
_inputField.InsertionPoint = new System.Drawing.Point(newCol, _inputField.CurrentRow);
|
||||
_suppressEmojiReplace = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tab-complete slash commands in the input field.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user