mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-05 15:46:01 +02:00
feat: enhance profile editing with avatar support and UI adjustments
- Added AvatarPath to ProfileEditResult for user profile updates. - Updated ProfileEditDialog to include avatar selection with a browse button. - Increased dialog height to accommodate new avatar input fields. - Implemented avatar file path handling in the profile edit dialog. feat: introduce moderation features and user roles - Added ServerRole enum to define user roles (Member, Mod, Admin, Owner). - Extended User model to include role, mute, and ban status. - Created ModerationController for user role assignment, kicking, banning, and muting. - Implemented methods in IChatBroadcaster and SignalRBroadcaster for user moderation actions. - Updated database schema with new columns for user roles and moderation states. fix: ensure muted users cannot send messages - Added mute status checks in ChatService to prevent message sending for muted users. - Updated user presence and status handling to reflect role changes and moderation actions. chore: update constants for ASCII art rendering - Introduced AsciiArtHeightHalfBlock constant for improved ASCII art rendering.
This commit is contained in:
@@ -72,7 +72,8 @@ public class ChatService : IChatService
|
||||
user.DisplayName,
|
||||
user.NicknameColor,
|
||||
UserStatus.Invisible,
|
||||
user.StatusMessage);
|
||||
user.StatusMessage,
|
||||
user.Role);
|
||||
|
||||
await BroadcastToAllAsync(b => b.SendUserStatusChangedAsync(channelsBeforeDisconnect, presence));
|
||||
}
|
||||
@@ -139,6 +140,21 @@ public class ChatService : IChatService
|
||||
|
||||
var sender = await db.Users.FindAsync(userId);
|
||||
|
||||
// Check mute status
|
||||
if (sender is not null && sender.IsMuted)
|
||||
{
|
||||
if (sender.MutedUntil.HasValue && sender.MutedUntil.Value <= DateTimeOffset.UtcNow)
|
||||
{
|
||||
sender.IsMuted = false;
|
||||
sender.MutedUntil = null;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "You are muted and cannot send messages.";
|
||||
}
|
||||
}
|
||||
|
||||
var message = new Message
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
@@ -203,7 +219,8 @@ public class ChatService : IChatService
|
||||
user.DisplayName,
|
||||
user.NicknameColor,
|
||||
status,
|
||||
statusMessage);
|
||||
statusMessage,
|
||||
user.Role);
|
||||
|
||||
var channels = _presenceTracker.GetChannelsForUser(username);
|
||||
await BroadcastToAllAsync(b => b.SendUserStatusChangedAsync(channels, presence));
|
||||
@@ -226,7 +243,8 @@ public class ChatService : IChatService
|
||||
u.DisplayName,
|
||||
u.NicknameColor,
|
||||
u.Status,
|
||||
u.StatusMessage))
|
||||
u.StatusMessage,
|
||||
u.Role))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
@@ -264,7 +282,7 @@ public class ChatService : IChatService
|
||||
return new UserProfileDto(
|
||||
user.Id, user.Username, user.DisplayName, user.Bio,
|
||||
user.NicknameColor, user.AvatarAscii, user.Status,
|
||||
user.StatusMessage, user.CreatedAt, user.LastSeenAt);
|
||||
user.StatusMessage, user.Role, user.CreatedAt, user.LastSeenAt);
|
||||
}
|
||||
|
||||
public async Task<(string? Topic, bool Exists)> GetChannelTopicAsync(string channelName)
|
||||
|
||||
@@ -8,47 +8,72 @@ namespace EchoHub.Server.Services;
|
||||
|
||||
public class ImageToAsciiService
|
||||
{
|
||||
private static readonly char[] AsciiChars = " .:-=+*#%@".ToCharArray();
|
||||
|
||||
public string ConvertToAscii(Stream imageStream, int width = HubConstants.AsciiArtWidth, int height = HubConstants.AsciiArtHeight)
|
||||
/// <summary>
|
||||
/// Converts an image to ASCII art using half-block characters (▀▄█) with
|
||||
/// 24-bit ANSI foreground and background colors for 2x vertical resolution.
|
||||
/// Each character cell represents two vertical pixels.
|
||||
/// </summary>
|
||||
public string ConvertToAscii(Stream imageStream, int width = HubConstants.AsciiArtWidth, int height = HubConstants.AsciiArtHeightHalfBlock)
|
||||
{
|
||||
using var image = Image.Load<Rgba32>(imageStream);
|
||||
|
||||
// Ensure height is even for pair processing
|
||||
if (height % 2 != 0) height++;
|
||||
|
||||
image.Mutate(x => x.Resize(width, height));
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
byte lastR = 0, lastG = 0, lastB = 0;
|
||||
bool hasLastColor = false;
|
||||
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
for (int y = 0; y < image.Height; y += 2)
|
||||
{
|
||||
byte lastFgR = 0, lastFgG = 0, lastFgB = 0;
|
||||
byte lastBgR = 0, lastBgG = 0, lastBgB = 0;
|
||||
bool hasLastColor = false;
|
||||
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
{
|
||||
var pixel = image[x, y];
|
||||
var brightness = 0.299 * pixel.R + 0.587 * pixel.G + 0.114 * pixel.B;
|
||||
var topPixel = image[x, y];
|
||||
var bottomPixel = (y + 1 < image.Height) ? image[x, y + 1] : topPixel;
|
||||
|
||||
// Map brightness (0-255) to ASCII char index
|
||||
var index = (int)((brightness / 255.0) * (AsciiChars.Length - 1));
|
||||
byte fgR, fgG, fgB, bgR, bgG, bgB;
|
||||
char blockChar;
|
||||
|
||||
// Emit ANSI 24-bit color only when it changes
|
||||
if (!hasLastColor || pixel.R != lastR || pixel.G != lastG || pixel.B != lastB)
|
||||
if (topPixel.R == bottomPixel.R && topPixel.G == bottomPixel.G && topPixel.B == bottomPixel.B)
|
||||
{
|
||||
sb.Append($"\x1b[38;2;{pixel.R};{pixel.G};{pixel.B}m");
|
||||
lastR = pixel.R;
|
||||
lastG = pixel.G;
|
||||
lastB = pixel.B;
|
||||
hasLastColor = true;
|
||||
// Both pixels same color — full block
|
||||
fgR = topPixel.R; fgG = topPixel.G; fgB = topPixel.B;
|
||||
bgR = topPixel.R; bgG = topPixel.G; bgB = topPixel.B;
|
||||
blockChar = '\u2588'; // █
|
||||
}
|
||||
else
|
||||
{
|
||||
// Top pixel = foreground, bottom pixel = background, upper half block
|
||||
fgR = topPixel.R; fgG = topPixel.G; fgB = topPixel.B;
|
||||
bgR = bottomPixel.R; bgG = bottomPixel.G; bgB = bottomPixel.B;
|
||||
blockChar = '\u2580'; // ▀
|
||||
}
|
||||
|
||||
sb.Append(AsciiChars[index]);
|
||||
// Emit color codes only when they change
|
||||
bool fgChanged = !hasLastColor || fgR != lastFgR || fgG != lastFgG || fgB != lastFgB;
|
||||
bool bgChanged = !hasLastColor || bgR != lastBgR || bgG != lastBgG || bgB != lastBgB;
|
||||
|
||||
if (fgChanged)
|
||||
sb.Append($"\x1b[38;2;{fgR};{fgG};{fgB}m");
|
||||
if (bgChanged)
|
||||
sb.Append($"\x1b[48;2;{bgR};{bgG};{bgB}m");
|
||||
|
||||
sb.Append(blockChar);
|
||||
|
||||
lastFgR = fgR; lastFgG = fgG; lastFgB = fgB;
|
||||
lastBgR = bgR; lastBgG = bgG; lastBgB = bgB;
|
||||
hasLastColor = true;
|
||||
}
|
||||
|
||||
// Reset color at end of line
|
||||
sb.Append("\x1b[0m");
|
||||
hasLastColor = false;
|
||||
|
||||
if (y < image.Height - 1)
|
||||
if (y + 2 < image.Height)
|
||||
{
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
@@ -54,6 +54,18 @@ public class SignalRBroadcaster : IChatBroadcaster
|
||||
return HubContext.Clients.Clients(connections).UserStatusChanged(presence);
|
||||
}
|
||||
|
||||
public Task SendUserKickedAsync(string channelName, string username, string? reason)
|
||||
=> HubContext.Clients.Group(channelName).UserKicked(channelName, username, reason);
|
||||
|
||||
public Task SendUserBannedAsync(string username, string? reason)
|
||||
=> HubContext.Clients.All.UserBanned(username, reason);
|
||||
|
||||
public Task SendMessageDeletedAsync(string channelName, Guid messageId)
|
||||
=> HubContext.Clients.Group(channelName).MessageDeleted(channelName, messageId);
|
||||
|
||||
public Task SendChannelNukedAsync(string channelName)
|
||||
=> HubContext.Clients.Group(channelName).ChannelNuked(channelName);
|
||||
|
||||
public Task SendErrorAsync(string connectionId, string message)
|
||||
{
|
||||
if (connectionId.StartsWith("irc-"))
|
||||
|
||||
Reference in New Issue
Block a user