mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-17 04:58:46 +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:
@@ -65,6 +65,8 @@ public static class ConfigurationProgramExtensions
|
||||
services.AddScoped<IPingHandlerService, PingHandlerService>();
|
||||
|
||||
services.AddScoped<IUserGroupsGetterService, UserGroupsGetterService>();
|
||||
services.AddScoped<IGroupManagementService, GroupManagementService>();
|
||||
services.AddScoped<IGroupAvatarService, GroupAvatarService>();
|
||||
|
||||
//services.AddScoped<IMessageCommandService, MessageCommandService>();
|
||||
services.AddScoped<IMessageSendingService, MessageSendingService>();
|
||||
|
||||
@@ -9,6 +9,7 @@ using Govor.Application.Messages.Parameters;
|
||||
using Govor.Contracts.Responses.SignalR;
|
||||
using Govor.Application.Reactions;
|
||||
using Govor.Domain.Models.Reactions;
|
||||
using Govor.Application.Groups;
|
||||
|
||||
namespace Govor.API.Common.Mapping;
|
||||
|
||||
@@ -22,6 +23,11 @@ public class MappingProfile : Profile
|
||||
CreateMap<ReactionCount, ReactionCountResponse>();
|
||||
CreateMap<MessageReactionState, MessageReactionsChangedResponse>();
|
||||
CreateMap<ChannelReactionPolicy, ChannelReactionPolicyResponse>();
|
||||
CreateMap<GroupSummary, GroupResponse>()
|
||||
.IncludeMembers(s => s.Group);
|
||||
CreateMap<ChatGroup, GroupResponse>();
|
||||
CreateMap<GroupMember, GroupMemberResponse>();
|
||||
CreateMap<GroupInvitation, GroupInvitationResponse>();
|
||||
CreateMap<Message, MessageResponse>();
|
||||
CreateMap<MediaAttachments, MediaAttachmentResponse>();
|
||||
CreateMap<MessageReaction, MessageReactionResponse>();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Govor.API.Common.Extensions;
|
||||
using Govor.API.Hubs.Infrastructure;
|
||||
using Govor.Application.Groups;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Contracts.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers.AdminStuff;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Roles = "Admin")]
|
||||
[Route("api/admin/required-channel")]
|
||||
public class RequiredChannelController(IGroupManagementService groups, ICurrentUserService currentUser,
|
||||
IChatNotificationService notifier) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get() => (await groups.GetRequiredChannelAsync(currentUser.GetCurrentUserId()))
|
||||
.Map(s => new { channelId = s.RequiredChannelId, allowLeave = s.AllowLeave }).ToActionResult();
|
||||
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> Set([FromBody] RequiredChannelRequest request)
|
||||
{
|
||||
var actorId = currentUser.GetCurrentUserId();
|
||||
var previous = await groups.GetRequiredChannelAsync(actorId);
|
||||
if (previous.IsFailure) return previous.ToActionResult();
|
||||
var result = await groups.SetRequiredChannelAsync(actorId, request.ChannelId, request.AllowLeave);
|
||||
if (result.IsSuccess)
|
||||
foreach (var channelId in new[] { previous.Value.RequiredChannelId, result.Value.RequiredChannelId }.OfType<Guid>().Distinct())
|
||||
await notifier.NotifyGroupProfileChangedAsync(channelId);
|
||||
return result.Map(s => new { channelId = s.RequiredChannelId, allowLeave = s.AllowLeave }).ToActionResult();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Govor.API.Common.Extensions;
|
||||
using Govor.API.Hubs.Infrastructure;
|
||||
using Govor.Application.Authentication;
|
||||
using Govor.Application.Users.UserSessions;
|
||||
using Govor.Contracts.Requests;
|
||||
@@ -17,17 +18,20 @@ public class AuthController : Controller
|
||||
private IInvitesService _invitesService;
|
||||
private IAccountService _accountService;
|
||||
private ILogger<AuthController> _logger;
|
||||
private readonly IChatNotificationService _notifier;
|
||||
|
||||
public AuthController(
|
||||
IAccountService accountService,
|
||||
IInvitesService invitesService,
|
||||
IUserSessionOpener userSessionOpener,
|
||||
ILogger<AuthController> logger)
|
||||
ILogger<AuthController> logger,
|
||||
IChatNotificationService notifier)
|
||||
{
|
||||
_userSession = userSessionOpener;
|
||||
_accountService = accountService;
|
||||
_invitesService = invitesService;
|
||||
_logger = logger;
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
[HttpPost("register")] // api/auth/register
|
||||
@@ -38,7 +42,12 @@ public class AuthController : Controller
|
||||
var result = await _invitesService.ValidateAsync(request.InviteLink)
|
||||
.BindAsync(invite => _accountService.RegistrationAsync(request.Name, request.Password, invite))
|
||||
.TapAsync(user => _logger.LogInformation("User {Username} ({Id}) registered successfully", user.Username, user.Id))
|
||||
.BindAsync(user => _userSession.OpenSessionAsync(user, request.DeviceInfo));
|
||||
.BindAsync(async user =>
|
||||
{
|
||||
// Registration has committed the required-channel membership at this point.
|
||||
await _notifier.NotifyUserJoinedGroupsAsync(user.Id);
|
||||
return await _userSession.OpenSessionAsync(user, request.DeviceInfo);
|
||||
});
|
||||
|
||||
if (result.IsFailure)
|
||||
{
|
||||
@@ -74,4 +83,4 @@ public class AuthController : Controller
|
||||
|
||||
return result.ToActionResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using Govor.API.Common.Extensions;
|
||||
using Govor.API.Hubs.Infrastructure;
|
||||
using Govor.Application.Groups;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Application.Messages;
|
||||
using Govor.Application.Messages.Parameters;
|
||||
using Govor.Application.Reactions;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Contracts.Responses;
|
||||
using Govor.Contracts.Responses.SignalR;
|
||||
using Govor.Domain;
|
||||
using Govor.Domain.Common;
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmartRes;
|
||||
|
||||
namespace Govor.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize(Roles = "Admin,User")]
|
||||
[Route("api/groups")]
|
||||
public class GroupsController(IGroupManagementService groups, ICurrentUserService currentUser, IMapper mapper,
|
||||
GovorDbContext context, IMessageRemovingService remover, IChatNotificationService notifier, IGroupAvatarService avatars) : ControllerBase
|
||||
{
|
||||
private Guid ActorId => currentUser.GetCurrentUserId();
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateGroupRequest request)
|
||||
{
|
||||
var result = await groups.CreateAsync(ActorId, request.Name, request.Description, request.IsPrivate, request.IsChannel);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupMemberChangedAsync(result.Value.Group.Id, ActorId);
|
||||
return result.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
}
|
||||
|
||||
[HttpGet("search")]
|
||||
public async Task<IActionResult> Search([FromQuery, MaxLength(100)] string q = "",
|
||||
[FromQuery, Range(0, int.MaxValue)] int skip = 0, [FromQuery, Range(1, 100)] int take = 50) =>
|
||||
Ok(mapper.Map<List<GroupResponse>>(await groups.SearchAsync(ActorId, q, skip, take)));
|
||||
|
||||
[HttpGet("mine")]
|
||||
public async Task<IActionResult> Mine([FromQuery, Range(0, int.MaxValue)] int skip = 0,
|
||||
[FromQuery, Range(1, 100)] int take = 50) => Ok(mapper.Map<List<GroupResponse>>(await groups.MineAsync(ActorId, skip, take)));
|
||||
|
||||
[HttpGet("{groupId:guid}")]
|
||||
public async Task<IActionResult> Get(Guid groupId) => (await groups.GetAsync(ActorId, groupId))
|
||||
.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
|
||||
[HttpPut("{groupId:guid}")]
|
||||
public async Task<IActionResult> Update(Guid groupId, [FromBody] UpdateGroupRequest request)
|
||||
{
|
||||
var result = await groups.UpdateAsync(ActorId, groupId, request.Name, request.Description, request.IsPrivate);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupProfileChangedAsync(groupId);
|
||||
return result.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
}
|
||||
|
||||
[HttpPost("{groupId:guid}/join")]
|
||||
public async Task<IActionResult> Join(Guid groupId)
|
||||
{
|
||||
var result = await groups.JoinPublicAsync(ActorId, groupId);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupMemberChangedAsync(groupId, ActorId);
|
||||
return result.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
}
|
||||
|
||||
[HttpPost("{groupId:guid}/avatar")]
|
||||
[RequestSizeLimit(2_200_000)]
|
||||
public async Task<IActionResult> UploadAvatar(Guid groupId, [FromForm] GroupAvatarUploadRequest request)
|
||||
{
|
||||
if (request.File.Length == 0 || request.File.Length > ReactionMediaLimits.MaxUploadBytes)
|
||||
return BadRequest("Upload must contain at most 2 MiB.");
|
||||
using var buffer = new MemoryStream();
|
||||
await request.File.CopyToAsync(buffer, HttpContext.RequestAborted);
|
||||
var result = await avatars.UploadAsync(ActorId, groupId, buffer.ToArray(), HttpContext.RequestAborted);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupProfileChangedAsync(groupId);
|
||||
return result.Map(id => new { imageId = id, mediaUrl = $"/api/media/download/{id}" }).ToActionResult();
|
||||
}
|
||||
|
||||
[HttpDelete("{groupId:guid}/avatar")]
|
||||
public async Task<IActionResult> RemoveAvatar(Guid groupId)
|
||||
{
|
||||
var result = await avatars.RemoveAsync(ActorId, groupId);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupProfileChangedAsync(groupId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
[HttpDelete("{groupId:guid}/members/me")]
|
||||
public Task<IActionResult> Leave(Guid groupId) => ChangeMemberAsync(groupId, ActorId, groups.LeaveAsync(ActorId, groupId));
|
||||
|
||||
[HttpGet("{groupId:guid}/members")]
|
||||
public async Task<IActionResult> Members(Guid groupId, [FromQuery] bool bannedOnly = false,
|
||||
[FromQuery, Range(0, int.MaxValue)] int skip = 0, [FromQuery, Range(1, 100)] int take = 50) =>
|
||||
(await groups.MembersAsync(ActorId, groupId, bannedOnly, skip, take))
|
||||
.Map(m => mapper.Map<List<GroupMemberResponse>>(m)).ToActionResult();
|
||||
|
||||
[HttpPut("{groupId:guid}/members/{userId:guid}/administrator")]
|
||||
public Task<IActionResult> Promote(Guid groupId, Guid userId) => ChangeMemberAsync(groupId, userId, groups.SetAdministratorAsync(ActorId, groupId, userId, true));
|
||||
|
||||
[HttpDelete("{groupId:guid}/members/{userId:guid}/administrator")]
|
||||
public Task<IActionResult> Demote(Guid groupId, Guid userId) => ChangeMemberAsync(groupId, userId, groups.SetAdministratorAsync(ActorId, groupId, userId, false));
|
||||
|
||||
[HttpPut("{groupId:guid}/members/{userId:guid}/ban")]
|
||||
public Task<IActionResult> Ban(Guid groupId, Guid userId) => ChangeMemberAsync(groupId, userId, groups.SetBanAsync(ActorId, groupId, userId, true));
|
||||
|
||||
[HttpDelete("{groupId:guid}/members/{userId:guid}/ban")]
|
||||
public Task<IActionResult> Unban(Guid groupId, Guid userId) => ChangeMemberAsync(groupId, userId, groups.SetBanAsync(ActorId, groupId, userId, false));
|
||||
|
||||
[HttpPost("{groupId:guid}/ownership/{userId:guid}")]
|
||||
public async Task<IActionResult> Transfer(Guid groupId, Guid userId)
|
||||
{
|
||||
var result = await groups.TransferOwnershipAsync(ActorId, groupId, userId);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
await notifier.NotifyGroupProfileChangedAsync(groupId);
|
||||
await notifier.NotifyGroupMemberChangedAsync(groupId, ActorId);
|
||||
await notifier.NotifyGroupMemberChangedAsync(groupId, userId);
|
||||
}
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
private async Task<IActionResult> ChangeMemberAsync(Guid groupId, Guid userId, Task<Result<Unit, Error>> mutation)
|
||||
{
|
||||
var result = await mutation;
|
||||
if (result.IsSuccess) await notifier.NotifyGroupMemberChangedAsync(groupId, userId);
|
||||
return result.ToActionResult();
|
||||
}
|
||||
|
||||
[HttpPost("{groupId:guid}/invitations")]
|
||||
public async Task<IActionResult> CreateInvitation(Guid groupId, [FromBody] CreateGroupInvitationRequest request) =>
|
||||
(await groups.CreateInvitationAsync(ActorId, groupId, request.ValidForDays, request.MaxParticipants, request.Description))
|
||||
.Map(i => mapper.Map<GroupInvitationResponse>(i)).ToActionResult();
|
||||
|
||||
[HttpGet("{groupId:guid}/invitations")]
|
||||
public async Task<IActionResult> Invitations(Guid groupId) => (await groups.InvitationsAsync(ActorId, groupId))
|
||||
.Map(i => mapper.Map<List<GroupInvitationResponse>>(i)).ToActionResult();
|
||||
|
||||
[HttpDelete("{groupId:guid}/invitations/{invitationId:guid}")]
|
||||
public async Task<IActionResult> RevokeInvitation(Guid groupId, Guid invitationId) =>
|
||||
(await groups.RevokeInvitationAsync(ActorId, groupId, invitationId)).ToActionResult();
|
||||
|
||||
[HttpDelete("{groupId:guid}/messages/{messageId:guid}")]
|
||||
public async Task<IActionResult> RemoveMessage(Guid groupId, Guid messageId)
|
||||
{
|
||||
if (!await context.Messages.AnyAsync(m => m.Id == messageId && m.RecipientId == groupId && m.RecipientType == RecipientType.Group))
|
||||
return NotFound();
|
||||
var result = await remover.DeleteMessageAsync(new DeleteMessage(ActorId, messageId, ForceRemove: true));
|
||||
if (result.IsFailure) return result.ToActionResult();
|
||||
var message = result.Value;
|
||||
await notifier.NotifyMessageRemovedAsync(new MessageRemovedResponse
|
||||
{
|
||||
MessageId = message.Id, SenderId = message.SenderId, RecipientId = groupId,
|
||||
RecipientType = RecipientType.Group, RequestType = Govor.Contracts.Requests.SignalR.RemoveMessageRequestType.ForceRemove
|
||||
});
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupAvatarUploadRequest
|
||||
{
|
||||
[Required] public IFormFile File { get; set; }
|
||||
}
|
||||
@@ -1,45 +1,33 @@
|
||||
using AutoMapper;
|
||||
using Govor.API.Common.Extensions;
|
||||
using Govor.API.Hubs.Infrastructure;
|
||||
using Govor.Application.Groups;
|
||||
using Govor.Application.Infrastructure.Extensions;
|
||||
using Govor.Contracts.Responses;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("invite")]
|
||||
public class InviteController : ControllerBase
|
||||
[Authorize(Roles = "Admin,User")]
|
||||
[Route("api/group-invites")]
|
||||
public class InviteController(IGroupManagementService groups, ICurrentUserService currentUser, IMapper mapper,
|
||||
IChatNotificationService notifier) : ControllerBase
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
private readonly ILogger<InviteController> _logger;
|
||||
private readonly ICurrentUserService _currentUser;
|
||||
public InviteController(IGroupService groupService,
|
||||
ILogger<InviteController> logger)
|
||||
{
|
||||
_groupService = groupService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
// GET only previews: link scanners/prefetch must not join an account to a group.
|
||||
[HttpGet("{code}")]
|
||||
public async Task<IActionResult> JoinGroup(string code)
|
||||
{
|
||||
try
|
||||
{
|
||||
var groupRes = await _groupService.AddUserToGroupByInvitationAsync(_currentUser.GetCurrentUserId(), code);
|
||||
|
||||
var group = _groupService.GetGroupByInviteCode(code);
|
||||
[HttpGet("/invite/{code}")]
|
||||
public async Task<IActionResult> Preview(string code) => (await groups.PreviewInvitationAsync(currentUser.GetCurrentUserId(), code))
|
||||
.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
groupId = group.Id,
|
||||
name = group.Name,
|
||||
isChannel = group.IsChannel
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return StatusCode(500, ex.Message);
|
||||
}
|
||||
[HttpPost("{code}/join")]
|
||||
[HttpPost("/invite/{code}/join")]
|
||||
public async Task<IActionResult> Join(string code)
|
||||
{
|
||||
var actorId = currentUser.GetCurrentUserId();
|
||||
var result = await groups.JoinByInvitationAsync(actorId, code);
|
||||
if (result.IsSuccess) await notifier.NotifyGroupMemberChangedAsync(result.Value.Group.Id, actorId);
|
||||
return result.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ public static class ChatHubConstants
|
||||
public const string ChatRead = "ChatRead";
|
||||
public const string MessageReactionsChanged = "MessageReactionsChanged";
|
||||
public const string ChannelReactionPolicyChanged = "ChannelReactionPolicyChanged";
|
||||
public const string GroupProfileChanged = "GroupProfileChanged";
|
||||
public const string GroupMemberChanged = "GroupMemberChanged";
|
||||
|
||||
public static string GetUserGroup(Guid userId) => userId.ToString();
|
||||
public static string GetSessionGroup(Guid sessionId) => $"session_{sessionId}";
|
||||
|
||||
@@ -5,6 +5,7 @@ using Govor.Contracts.Responses.SignalR;
|
||||
using Govor.Domain;
|
||||
using Govor.Domain.Common;
|
||||
using Govor.Domain.Models.Messages;
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -117,7 +118,40 @@ public class ChatNotificationService : IChatNotificationService
|
||||
TryNotifyAsync(() => NotifyParticipantsAsync(response.RecipientId,
|
||||
response.RecipientType, ChatHubConstants.MessageEdited, response));
|
||||
|
||||
private async Task NotifyParticipantsAsync(Guid chatId, RecipientType type, string method, object payload)
|
||||
public Task NotifyGroupProfileChangedAsync(Guid groupId) =>
|
||||
TryNotifyAsync(() => NotifyParticipantsAsync(groupId, RecipientType.Group,
|
||||
ChatHubConstants.GroupProfileChanged, new GroupProfileChangedResponse { GroupId = groupId }));
|
||||
|
||||
public Task NotifyGroupMemberChangedAsync(Guid groupId, Guid userId) => TryNotifyAsync(async () =>
|
||||
{
|
||||
var member = await _context.GroupMemberships.AsNoTracking()
|
||||
.Where(m => m.GroupId == groupId && m.UserId == userId)
|
||||
.Select(m => new
|
||||
{
|
||||
m.IsBanned,
|
||||
IsOwner = _context.ChatGroups.Any(g => g.Id == groupId && g.OwnerUserId == userId),
|
||||
IsAdmin = _context.GroupAdmins.Any(a => a.GroupId == groupId && a.UserId == userId)
|
||||
}).FirstOrDefaultAsync();
|
||||
var response = new GroupMemberChangedResponse
|
||||
{
|
||||
GroupId = groupId, UserId = userId,
|
||||
Status = member is null ? GroupMemberStatus.Left : member.IsBanned ? GroupMemberStatus.Banned : GroupMemberStatus.Active,
|
||||
Role = member is null || member.IsBanned ? null : member.IsOwner ? GroupRole.Owner : member.IsAdmin ? GroupRole.Admin : GroupRole.Member
|
||||
};
|
||||
// The affected user must learn about a ban/leave even after losing membership.
|
||||
// Only this membership event includes them; profile and chat events do not.
|
||||
await NotifyParticipantsAsync(groupId, RecipientType.Group, ChatHubConstants.GroupMemberChanged, response, userId);
|
||||
});
|
||||
|
||||
public Task NotifyUserJoinedGroupsAsync(Guid userId) => TryNotifyAsync(async () =>
|
||||
{
|
||||
var groupIds = await _context.GroupMemberships.AsNoTracking()
|
||||
.Where(m => m.UserId == userId && !m.IsBanned).Select(m => m.GroupId).ToListAsync();
|
||||
foreach (var groupId in groupIds)
|
||||
await NotifyGroupMemberChangedAsync(groupId, userId);
|
||||
});
|
||||
|
||||
private async Task NotifyParticipantsAsync(Guid chatId, RecipientType type, string method, object payload, Guid? affectedUserId = null)
|
||||
{
|
||||
// Resolve current participants instead of treating a chat ID as a user ID.
|
||||
// Deliver only to active sessions, including all of a participant's devices.
|
||||
@@ -133,6 +167,8 @@ public class ChatNotificationService : IChatNotificationService
|
||||
participants = await _context.GroupMemberships.AsNoTracking()
|
||||
.Where(m => m.GroupId == chatId && !m.IsBanned).Select(m => m.UserId).Distinct().ToListAsync();
|
||||
|
||||
if (affectedUserId.HasValue)
|
||||
participants.Add(affectedUserId.Value);
|
||||
if (participants.Count > 0)
|
||||
await NotifyUsersAsync(participants, method, payload);
|
||||
}
|
||||
@@ -142,7 +178,7 @@ public class ChatNotificationService : IChatNotificationService
|
||||
var now = DateTime.UtcNow;
|
||||
var sessions = await _context.UserSessions.AsNoTracking()
|
||||
.Where(s => users.Contains(s.UserId) && !s.IsRevoked && s.ExpiresAt > now)
|
||||
.Select(s => s.Id).ToListAsync();
|
||||
.Select(s => s.Id).Distinct().ToListAsync();
|
||||
if (sessions.Count > 0)
|
||||
await _hubContext.Clients.Groups(sessions.Select(ChatHubConstants.GetSessionGroup).ToList())
|
||||
.SendAsync(method, payload);
|
||||
@@ -156,7 +192,7 @@ public class ChatNotificationService : IChatNotificationService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to deliver chat notification; clients can resync from history.");
|
||||
_logger.LogError(ex, "Failed to deliver chat notification; clients can resync through HTTP.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,7 @@ public interface IChatNotificationService
|
||||
Task NotifyChannelReactionPolicyChangedAsync(ChannelReactionPolicyResponse response);
|
||||
Task NotifyMessageRemovedAsync(MessageRemovedResponse response);
|
||||
Task NotifyMessageEditedAsync(MessageEditResponse response);
|
||||
Task NotifyGroupProfileChangedAsync(Guid groupId);
|
||||
Task NotifyGroupMemberChangedAsync(Guid groupId, Guid userId);
|
||||
Task NotifyUserJoinedGroupsAsync(Guid userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user