mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-17 12:59:25 +00:00
Add primitive groups and required channel
Adds server-side group and channel management, private invitations, member moderation, avatar handling, and required-channel configuration. This change also introduces SignalR group profile/member notifications, updates registration to atomically join required channels, and adds EF migration and test coverage for group membership, permissions, and invitation expiry rules.
This commit is contained in:
@@ -2,6 +2,7 @@ using Govor.Application.Messages.Parameters;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Govor.Domain;
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Govor.Application.Groups;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@@ -24,6 +25,25 @@ public class MessageEditingService : IMessageEditingService
|
||||
}
|
||||
|
||||
public async Task<EditMessageResult> EditMessageAsync(EditMessage editParams)
|
||||
{
|
||||
var target = await _dbContext.Messages.AsNoTracking().FirstOrDefaultAsync(m => m.Id == editParams.MessageId);
|
||||
if (target?.RecipientType != RecipientType.Group) return await EditCoreAsync(editParams);
|
||||
return await _dbContext.Database.CreateExecutionStrategy().ExecuteAsync(async () =>
|
||||
{
|
||||
await using var transaction = await _dbContext.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
await _dbContext.ChatGroups.Where(g => g.Id == target.RecipientId)
|
||||
.ExecuteUpdateAsync(s => s.SetProperty(g => g.Name, g => g.Name));
|
||||
var result = await EditCoreAsync(editParams);
|
||||
if (result.IsSuccess) await transaction.CommitAsync();
|
||||
return result;
|
||||
}
|
||||
catch { _dbContext.ChangeTracker.Clear(); throw; }
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<EditMessageResult> EditCoreAsync(EditMessage editParams)
|
||||
{
|
||||
var message = await _dbContext.Messages
|
||||
.Include(m => m.MediaAttachments)
|
||||
@@ -38,7 +58,10 @@ public class MessageEditingService : IMessageEditingService
|
||||
}
|
||||
|
||||
if (message.SenderId != editParams.EditorId || !await _dbContext.HasChatAccessAsync(
|
||||
editParams.EditorId, message.RecipientId, message.RecipientType))
|
||||
editParams.EditorId, message.RecipientId, message.RecipientType) ||
|
||||
(message.RecipientType == RecipientType.Group &&
|
||||
await _dbContext.ChatGroups.AnyAsync(g => g.Id == message.RecipientId && g.IsChannel) &&
|
||||
!await _dbContext.IsGroupAdministratorAsync(message.RecipientId, editParams.EditorId)))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"User {EditorId} unauthorized to edit message {MessageId}",
|
||||
|
||||
Reference in New Issue
Block a user