revert Merge pull request 'add capability to disable chat feature for groups/syncshells' (#43) from disable-chat-groups into master

Reviewed-on: #43
This commit is contained in:
2025-12-22 02:25:40 +00:00
parent ce9b94a534
commit f4753505aa
6 changed files with 9 additions and 105 deletions

View File

@@ -41,10 +41,8 @@ public partial class LightlessHub
var groupInfos = await DbContext.Groups var groupInfos = await DbContext.Groups
.AsNoTracking() .AsNoTracking()
.Where(g => g.ChatEnabled .Where(g => g.OwnerUID == userUid
&& (g.OwnerUID == userUid
|| DbContext.GroupPairs.Any(p => p.GroupGID == g.GID && p.GroupUserUID == userUid)) || DbContext.GroupPairs.Any(p => p.GroupGID == g.GID && p.GroupUserUID == userUid))
)
.ToListAsync() .ToListAsync()
.ConfigureAwait(false); .ConfigureAwait(false);
@@ -164,13 +162,6 @@ public partial class LightlessHub
throw new HubException("Unsupported chat channel."); throw new HubException("Unsupported chat channel.");
} }
if (!group.ChatEnabled)
{
TryInvokeChatService(() => _chatChannelService.RemovePresence(UserUID, channel), "removing chat presence", channel);
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Warning, "This Syncshell chat is disabled.").ConfigureAwait(false);
return;
}
var isMember = string.Equals(group.OwnerUID, UserUID, StringComparison.Ordinal) var isMember = string.Equals(group.OwnerUID, UserUID, StringComparison.Ordinal)
|| await DbContext.GroupPairs || await DbContext.GroupPairs
.AsNoTracking() .AsNoTracking()
@@ -216,23 +207,6 @@ public partial class LightlessHub
var channel = request.Channel.WithNormalizedCustomKey(); var channel = request.Channel.WithNormalizedCustomKey();
if (channel.Type == ChatChannelType.Group)
{
var groupId = channel.CustomKey ?? string.Empty;
var chatEnabled = !string.IsNullOrEmpty(groupId) && await DbContext.Groups
.AsNoTracking()
.Where(g => g.GID == groupId)
.Select(g => g.ChatEnabled)
.SingleOrDefaultAsync(RequestAbortedToken)
.ConfigureAwait(false);
if (!chatEnabled)
{
await Clients.Caller.Client_ReceiveServerMessage(MessageSeverity.Warning, "This Syncshell chat is disabled.").ConfigureAwait(false);
return;
}
}
if (await HandleIfChatBannedAsync(UserUID).ConfigureAwait(false)) if (await HandleIfChatBannedAsync(UserUID).ConfigureAwait(false))
{ {
throw new HubException("Chat access has been revoked."); throw new HubException("Chat access has been revoked.");

View File

@@ -1,7 +1,6 @@
using LightlessSync.API.Data; using LightlessSync.API.Data;
using LightlessSync.API.Data.Enum; using LightlessSync.API.Data.Enum;
using LightlessSync.API.Data.Extensions; using LightlessSync.API.Data.Extensions;
using LightlessSync.API.Dto.Chat;
using LightlessSync.API.Dto.Group; using LightlessSync.API.Dto.Group;
using LightlessSync.API.Dto.User; using LightlessSync.API.Dto.User;
using LightlessSyncServer.Models; using LightlessSyncServer.Models;
@@ -12,8 +11,10 @@ using LightlessSyncShared.Utils;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using System.Collections.Concurrent; using SixLabors.ImageSharp.PixelFormats;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace LightlessSyncServer.Hubs; namespace LightlessSyncServer.Hubs;
@@ -51,8 +52,6 @@ public partial class LightlessHub
_logger.LogCallInfo(LightlessHubLogger.Args(dto, "Success")); _logger.LogCallInfo(LightlessHubLogger.Args(dto, "Success"));
} }
private static readonly ConcurrentDictionary<string, DateTime> GroupChatToggleCooldowns = new(StringComparer.Ordinal);
[Authorize(Policy = "Identified")] [Authorize(Policy = "Identified")]
public async Task GroupChangeGroupPermissionState(GroupPermissionDto dto) public async Task GroupChangeGroupPermissionState(GroupPermissionDto dto)
{ {
@@ -61,73 +60,15 @@ public partial class LightlessHub
var (hasRights, group) = await TryValidateGroupModeratorOrOwner(dto.Group.GID).ConfigureAwait(false); var (hasRights, group) = await TryValidateGroupModeratorOrOwner(dto.Group.GID).ConfigureAwait(false);
if (!hasRights) return; if (!hasRights) return;
var permissions = dto.Permissions; group.InvitesEnabled = !dto.Permissions.HasFlag(GroupPermissions.DisableInvites);
var isOwner = string.Equals(group.OwnerUID, UserUID, StringComparison.Ordinal); group.PreferDisableSounds = dto.Permissions.HasFlag(GroupPermissions.PreferDisableSounds);
var chatEnabled = group.ChatEnabled; group.PreferDisableAnimations = dto.Permissions.HasFlag(GroupPermissions.PreferDisableAnimations);
var chatChanged = false; group.PreferDisableVFX = dto.Permissions.HasFlag(GroupPermissions.PreferDisableVFX);
if (!isOwner)
{
permissions.SetDisableChat(!group.ChatEnabled);
}
else
{
var requestedChatEnabled = !permissions.IsDisableChat();
if (requestedChatEnabled != group.ChatEnabled)
{
var now = DateTime.UtcNow;
if (GroupChatToggleCooldowns.TryGetValue(group.GID, out var lockedUntil) && lockedUntil > now)
{
var remaining = lockedUntil - now;
var minutes = Math.Max(1, (int)Math.Ceiling(remaining.TotalMinutes));
await Clients.Caller.Client_ReceiveServerMessage(
MessageSeverity.Warning,
$"Syncshell chat can be toggled again in {minutes} minute{(minutes == 1 ? string.Empty : "s")}."
).ConfigureAwait(false);
permissions.SetDisableChat(!group.ChatEnabled);
}
else
{
chatEnabled = requestedChatEnabled;
group.ChatEnabled = chatEnabled;
GroupChatToggleCooldowns[group.GID] = now.AddMinutes(5);
chatChanged = true;
}
}
}
group.InvitesEnabled = !permissions.HasFlag(GroupPermissions.DisableInvites);
group.PreferDisableSounds = permissions.HasFlag(GroupPermissions.PreferDisableSounds);
group.PreferDisableAnimations = permissions.HasFlag(GroupPermissions.PreferDisableAnimations);
group.PreferDisableVFX = permissions.HasFlag(GroupPermissions.PreferDisableVFX);
await DbContext.SaveChangesAsync(RequestAbortedToken).ConfigureAwait(false); await DbContext.SaveChangesAsync(RequestAbortedToken).ConfigureAwait(false);
var groupPairs = DbContext.GroupPairs.Where(p => p.GroupGID == dto.Group.GID).Select(p => p.GroupUserUID).ToList(); var groupPairs = DbContext.GroupPairs.Where(p => p.GroupGID == dto.Group.GID).Select(p => p.GroupUserUID).ToList();
await Clients.Users(groupPairs).Client_GroupChangePermissions(new GroupPermissionDto(dto.Group, permissions)).ConfigureAwait(false); await Clients.Users(groupPairs).Client_GroupChangePermissions(new GroupPermissionDto(dto.Group, dto.Permissions)).ConfigureAwait(false);
if (isOwner && chatChanged && !chatEnabled)
{
var groupDisplayName = string.IsNullOrWhiteSpace(group.Alias) ? group.GID : group.Alias;
var descriptor = new ChatChannelDescriptor
{
Type = ChatChannelType.Group,
WorldId = 0,
ZoneId = 0,
CustomKey = group.GID
};
foreach (var uid in groupPairs)
{
TryInvokeChatService(() => _chatChannelService.RemovePresence(uid, descriptor), "removing group chat presence", descriptor, uid);
}
await Clients.Users(groupPairs)
.Client_ReceiveServerMessage(
MessageSeverity.Information,
$"Syncshell chat for '{groupDisplayName}' has been disabled.")
.ConfigureAwait(false);
}
} }
[Authorize(Policy = "Identified")] [Authorize(Policy = "Identified")]
@@ -294,7 +235,6 @@ public partial class LightlessHub
PreferDisableAnimations = defaultPermissions.DisableGroupAnimations, PreferDisableAnimations = defaultPermissions.DisableGroupAnimations,
PreferDisableSounds = defaultPermissions.DisableGroupSounds, PreferDisableSounds = defaultPermissions.DisableGroupSounds,
PreferDisableVFX = defaultPermissions.DisableGroupVFX, PreferDisableVFX = defaultPermissions.DisableGroupVFX,
ChatEnabled = true,
CreatedDate = currentTime, CreatedDate = currentTime,
}; };

View File

@@ -118,7 +118,6 @@ public static class Extensions
permissions.SetPreferDisableSounds(group.PreferDisableSounds); permissions.SetPreferDisableSounds(group.PreferDisableSounds);
permissions.SetPreferDisableVFX(group.PreferDisableVFX); permissions.SetPreferDisableVFX(group.PreferDisableVFX);
permissions.SetDisableInvites(!group.InvitesEnabled); permissions.SetDisableInvites(!group.InvitesEnabled);
permissions.SetDisableChat(!group.ChatEnabled);
return permissions; return permissions;
} }

View File

@@ -80,9 +80,6 @@ public class LightlessDbContext : DbContext
.WithOne(p => p.Group) .WithOne(p => p.Group)
.HasForeignKey<GroupProfile>(p => p.GroupGID) .HasForeignKey<GroupProfile>(p => p.GroupGID)
.IsRequired(false); .IsRequired(false);
mb.Entity<Group>()
.Property(g => g.ChatEnabled)
.HasDefaultValue(true);
mb.Entity<GroupPair>().ToTable("group_pairs"); mb.Entity<GroupPair>().ToTable("group_pairs");
mb.Entity<GroupPair>().HasKey(u => new { u.GroupGID, u.GroupUserUID }); mb.Entity<GroupPair>().HasKey(u => new { u.GroupGID, u.GroupUserUID });
mb.Entity<GroupPair>().HasIndex(c => c.GroupUserUID); mb.Entity<GroupPair>().HasIndex(c => c.GroupUserUID);

View File

@@ -468,11 +468,6 @@ namespace LightlessSyncServer.Migrations
.HasColumnType("boolean") .HasColumnType("boolean")
.HasColumnName("prefer_disable_vfx"); .HasColumnName("prefer_disable_vfx");
b.Property<bool>("ChatEnabled")
.HasColumnType("boolean")
.HasColumnName("chat_enabled")
.HasDefaultValue(true);
b.HasKey("GID") b.HasKey("GID")
.HasName("pk_groups"); .HasName("pk_groups");

View File

@@ -19,6 +19,5 @@ public class Group
public bool PreferDisableSounds { get; set; } public bool PreferDisableSounds { get; set; }
public bool PreferDisableAnimations { get; set; } public bool PreferDisableAnimations { get; set; }
public bool PreferDisableVFX { get; set; } public bool PreferDisableVFX { get; set; }
public bool ChatEnabled { get; set; } = true;
public DateTime CreatedDate { get; set; } = DateTime.UtcNow; public DateTime CreatedDate { get; set; } = DateTime.UtcNow;
} }