提交
This commit is contained in:
+23
-23
@@ -1,23 +1,23 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddConversationHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IConversationService _cService;
|
||||
public FriendAddConversationHandler(IConversationService cService)
|
||||
{
|
||||
_cService = cService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
await _cService.MakeConversationAsync(@event.RequestUserId, @event.ResponseUserId, Models.ChatType.PRIVATE);
|
||||
await _cService.MakeConversationAsync(@event.ResponseUserId, @event.RequestUserId, Models.ChatType.PRIVATE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddConversationHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IConversationService _cService;
|
||||
public FriendAddConversationHandler(IConversationService cService)
|
||||
{
|
||||
_cService = cService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
await _cService.MakeConversationAsync(@event.RequestUserId, @event.ResponseUserId, Models.ChatType.PRIVATE);
|
||||
await _cService.MakeConversationAsync(@event.ResponseUserId, @event.RequestUserId, Models.ChatType.PRIVATE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddDBHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IFriendSerivce _friendService;
|
||||
private readonly ILogger<FriendAddDBHandler> _logger;
|
||||
public FriendAddDBHandler(IFriendSerivce friendService, ILogger<FriendAddDBHandler> logger)
|
||||
{
|
||||
_friendService = friendService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
|
||||
//为请求发起人添加好友记录
|
||||
await _friendService.MakeFriendshipAsync(
|
||||
@event.RequestUserId, @event.ResponseUserId, @event.RequestInfo.RemarkName);
|
||||
//为接收人添加好友记录
|
||||
await _friendService.MakeFriendshipAsync(
|
||||
@event.ResponseUserId, @event.RequestUserId, @event.requestUserRemarkname);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddDBHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IFriendSerivce _friendService;
|
||||
private readonly ILogger<FriendAddDBHandler> _logger;
|
||||
public FriendAddDBHandler(IFriendSerivce friendService, ILogger<FriendAddDBHandler> logger)
|
||||
{
|
||||
_friendService = friendService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
|
||||
//为请求发起人添加好友记录
|
||||
await _friendService.MakeFriendshipAsync(
|
||||
@event.RequestUserId, @event.ResponseUserId, @event.RequestInfo.RemarkName);
|
||||
//为接收人添加好友记录
|
||||
await _friendService.MakeFriendshipAsync(
|
||||
@event.ResponseUserId, @event.RequestUserId, @event.requestUserRemarkname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddSignalRHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _chathub;
|
||||
public FriendAddSignalRHandler(IHubContext<ChatHub> chathub)
|
||||
{
|
||||
_chathub = chathub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var usersList = new List<string> {
|
||||
@event.RequestUserId.ToString(), @event.ResponseUserId.ToString()
|
||||
};
|
||||
var res = new HubResponse<MessageBaseDto>("Event", new MessageBaseDto()
|
||||
{
|
||||
ChatType = ChatType.PRIVATE,
|
||||
Content = "您有新的好友关系已添加",
|
||||
//MsgId = @event.EventId.ToString(),
|
||||
ReceiverId = @event.ResponseUserId,
|
||||
SenderId = @event.RequestUserId,
|
||||
TimeStamp = DateTime.Now
|
||||
});
|
||||
await _chathub.Clients.Users(usersList).SendAsync("ReceiveMessage", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.FriendAddHandler
|
||||
{
|
||||
public class FriendAddSignalRHandler : IConsumer<FriendAddEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _chathub;
|
||||
public FriendAddSignalRHandler(IHubContext<ChatHub> chathub)
|
||||
{
|
||||
_chathub = chathub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<FriendAddEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var usersList = new List<string> {
|
||||
@event.RequestUserId.ToString(), @event.ResponseUserId.ToString()
|
||||
};
|
||||
var res = new HubResponse<MessageBaseDto>("Event", new MessageBaseDto()
|
||||
{
|
||||
ChatType = ChatType.PRIVATE,
|
||||
Content = "您有新的好友关系已添加",
|
||||
//MsgId = @event.EventId.ToString(),
|
||||
ReceiverId = @event.ResponseUserId,
|
||||
SenderId = @event.RequestUserId,
|
||||
TimeStamp = DateTime.Now
|
||||
});
|
||||
await _chathub.Clients.Users(usersList).SendAsync("ReceiveMessage", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+24
-24
@@ -1,24 +1,24 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteActionUpdateHandler
|
||||
{
|
||||
public class RequestDbHandler : IConsumer<GroupInviteActionUpdateEvent>
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
public RequestDbHandler(IGroupService groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteActionUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupInviteState.Passed)
|
||||
{
|
||||
await _groupService.MakeGroupRequestAsync(@event.UserId, @event.InviteUserId,@event.GroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteActionUpdateHandler
|
||||
{
|
||||
public class RequestDbHandler : IConsumer<GroupInviteActionUpdateEvent>
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
public RequestDbHandler(IGroupService groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteActionUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupInviteState.Passed)
|
||||
{
|
||||
await _groupService.MakeGroupRequestAsync(@event.UserId, @event.InviteUserId,@event.GroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -1,34 +1,34 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteActionUpdateHandler
|
||||
{
|
||||
public class SignalRHandler : IConsumer<GroupInviteActionUpdateEvent>
|
||||
{
|
||||
private IHubContext<ChatHub> _hub;
|
||||
public SignalRHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteActionUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var msg = new HubResponse<GroupInviteActionUpdateVo>("Event", new GroupInviteActionUpdateVo
|
||||
{
|
||||
Action = @event.Action,
|
||||
GroupId = @event.GroupId,
|
||||
InvitedUserId = @event.UserId,
|
||||
InviteUserId = @event.InviteUserId,
|
||||
InviteId = @event.InviteId
|
||||
});
|
||||
|
||||
await _hub.Clients.Users([@event.UserId.ToString(), @event.InviteUserId.ToString()])
|
||||
.SendAsync("ReceiveMessage",msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteActionUpdateHandler
|
||||
{
|
||||
public class SignalRHandler : IConsumer<GroupInviteActionUpdateEvent>
|
||||
{
|
||||
private IHubContext<ChatHub> _hub;
|
||||
public SignalRHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteActionUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var msg = new HubResponse<GroupInviteActionUpdateVo>("Event", new GroupInviteActionUpdateVo
|
||||
{
|
||||
Action = @event.Action,
|
||||
GroupId = @event.GroupId,
|
||||
InvitedUserId = @event.UserId,
|
||||
InviteUserId = @event.InviteUserId,
|
||||
InviteId = @event.InviteId
|
||||
});
|
||||
|
||||
await _hub.Clients.Users([@event.UserId.ToString(), @event.InviteUserId.ToString()])
|
||||
.SendAsync("ReceiveMessage",msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-26
@@ -1,26 +1,26 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteHandler
|
||||
{
|
||||
public class GroupInviteSignalRHandler : IConsumer<GroupInviteEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public GroupInviteSignalRHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var list = @event.Ids.Select(id => id.ToString()).ToArray();
|
||||
var msg = new HubResponse<GroupInviteVo>("Event", new GroupInviteVo { GroupId = @event.GroupId, UserId = @event.UserId });
|
||||
await _hub.Clients.Users(list).SendAsync("ReceiveMessage", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupInviteHandler
|
||||
{
|
||||
public class GroupInviteSignalRHandler : IConsumer<GroupInviteEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public GroupInviteSignalRHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupInviteEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var list = @event.Ids.Select(id => id.ToString()).ToArray();
|
||||
var msg = new HubResponse<GroupInviteVo>("Event", new GroupInviteVo { GroupId = @event.GroupId, UserId = @event.UserId });
|
||||
await _hub.Clients.Users(list).SendAsync("ReceiveMessage", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,21 +1,21 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinConversationHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private IConversationService _conversationService;
|
||||
public GroupJoinConversationHandler(IConversationService conversationService)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
await _conversationService.MakeConversationAsync(@event.UserId, @event.GroupId, Models.ChatType.GROUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinConversationHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private IConversationService _conversationService;
|
||||
public GroupJoinConversationHandler(IConversationService conversationService)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
await _conversationService.MakeConversationAsync(@event.UserId, @event.GroupId, Models.ChatType.GROUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinDbHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
public GroupJoinDbHandler(IGroupService groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
await _groupService.MakeGroupMemberAsync(context.Message.UserId,
|
||||
context.Message.GroupId, context.Message.IsCreated ?
|
||||
Models.GroupMemberRole.Master : Models.GroupMemberRole.Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinDbHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private readonly IGroupService _groupService;
|
||||
public GroupJoinDbHandler(IGroupService groupService)
|
||||
{
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
await _groupService.MakeGroupMemberAsync(context.Message.UserId,
|
||||
context.Message.GroupId, context.Message.IsCreated ?
|
||||
Models.GroupMemberRole.Master : Models.GroupMemberRole.Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+45
-45
@@ -1,45 +1,45 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Tools;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinSignalrHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IDatabase _redis;
|
||||
public GroupJoinSignalrHandler(IHubContext<ChatHub> hub, IConnectionMultiplexer connectionMultiplexer)
|
||||
{
|
||||
_hub = hub;
|
||||
_redis = connectionMultiplexer.GetDatabase();
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
string stramKey = StreamKeyBuilder.Group(@event.GroupId);
|
||||
//将用户加入群组通知
|
||||
var list = await _redis.SetMembersAsync(RedisKeys.GetConnectionIdKey(@event.UserId.ToString()));
|
||||
if(list != null && list.Length > 0)
|
||||
{
|
||||
var tasks = list.Select(connectionId =>
|
||||
_hub.Groups.AddToGroupAsync(connectionId!, stramKey)
|
||||
).ToList();
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
//发送通知给群成员
|
||||
var msg = new GroupJoinVo
|
||||
{
|
||||
GroupId = @event.GroupId,
|
||||
UserId = @event.UserId
|
||||
};
|
||||
await _hub.Clients.Group(stramKey).SendAsync("ReceiveMessage",new HubResponse<GroupJoinVo>("Event",msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Tools;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupJoinHandler
|
||||
{
|
||||
public class GroupJoinSignalrHandler : IConsumer<GroupJoinEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IDatabase _redis;
|
||||
public GroupJoinSignalrHandler(IHubContext<ChatHub> hub, IConnectionMultiplexer connectionMultiplexer)
|
||||
{
|
||||
_hub = hub;
|
||||
_redis = connectionMultiplexer.GetDatabase();
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupJoinEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
string stramKey = StreamKeyBuilder.Group(@event.GroupId);
|
||||
//将用户加入群组通知
|
||||
var list = await _redis.SetMembersAsync(RedisKeys.GetConnectionIdKey(@event.UserId.ToString()));
|
||||
if(list != null && list.Length > 0)
|
||||
{
|
||||
var tasks = list.Select(connectionId =>
|
||||
_hub.Groups.AddToGroupAsync(connectionId!, stramKey)
|
||||
).ToList();
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
//发送通知给群成员
|
||||
var msg = new GroupJoinVo
|
||||
{
|
||||
GroupId = @event.GroupId,
|
||||
UserId = @event.UserId
|
||||
};
|
||||
await _hub.Clients.Group(stramKey).SendAsync("ReceiveMessage",new HubResponse<GroupJoinVo>("Event",msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Hubs;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestHandler
|
||||
{
|
||||
public class GroupRequestSignalRHandler(IHubContext<ChatHub> hubContext) : IConsumer<GroupRequestEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub = hubContext;
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestEvent> context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Hubs;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestHandler
|
||||
{
|
||||
public class GroupRequestSignalRHandler(IHubContext<ChatHub> hubContext) : IConsumer<GroupRequestEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub = hubContext;
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestEvent> context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestHandler
|
||||
{
|
||||
public class NextEventHandler : IConsumer<GroupRequestEvent>
|
||||
{
|
||||
private readonly IPublishEndpoint _endpoint;
|
||||
public NextEventHandler(IPublishEndpoint endpoint)
|
||||
{
|
||||
_endpoint = endpoint;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupRequestState.Passed)
|
||||
{
|
||||
await _endpoint.Publish(new GroupJoinEvent
|
||||
{
|
||||
AggregateId = @event.AggregateId,
|
||||
OccurredAt = @event.OccurredAt,
|
||||
EventId = Guid.NewGuid(),
|
||||
GroupId = @event.GroupId,
|
||||
OperatorId = @event.OperatorId,
|
||||
UserId = @event.UserId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestHandler
|
||||
{
|
||||
public class NextEventHandler : IConsumer<GroupRequestEvent>
|
||||
{
|
||||
private readonly IPublishEndpoint _endpoint;
|
||||
public NextEventHandler(IPublishEndpoint endpoint)
|
||||
{
|
||||
_endpoint = endpoint;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupRequestState.Passed)
|
||||
{
|
||||
await _endpoint.Publish(new GroupJoinEvent
|
||||
{
|
||||
AggregateId = @event.AggregateId,
|
||||
OccurredAt = @event.OccurredAt,
|
||||
EventId = Guid.NewGuid(),
|
||||
GroupId = @event.GroupId,
|
||||
OperatorId = @event.OperatorId,
|
||||
UserId = @event.UserId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-31
@@ -1,31 +1,31 @@
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestUpdateHandler
|
||||
{
|
||||
public class NextEventHandler : IConsumer<GroupRequestUpdateEvent>
|
||||
{
|
||||
private readonly IPublishEndpoint _endpoint;
|
||||
public NextEventHandler(IPublishEndpoint endpoint)
|
||||
{
|
||||
_endpoint = endpoint;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupRequestState.Passed)
|
||||
{
|
||||
await _endpoint.Publish(new GroupJoinEvent
|
||||
{
|
||||
AggregateId = @event.AggregateId,
|
||||
OccurredAt = @event.OccurredAt,
|
||||
EventId = Guid.NewGuid(),
|
||||
GroupId = @event.GroupId,
|
||||
OperatorId = @event.OperatorId,
|
||||
UserId = @event.UserId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestUpdateHandler
|
||||
{
|
||||
public class NextEventHandler : IConsumer<GroupRequestUpdateEvent>
|
||||
{
|
||||
private readonly IPublishEndpoint _endpoint;
|
||||
public NextEventHandler(IPublishEndpoint endpoint)
|
||||
{
|
||||
_endpoint = endpoint;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestUpdateEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if(@event.Action == Models.GroupRequestState.Passed)
|
||||
{
|
||||
await _endpoint.Publish(new GroupJoinEvent
|
||||
{
|
||||
AggregateId = @event.AggregateId,
|
||||
OccurredAt = @event.OccurredAt,
|
||||
EventId = Guid.NewGuid(),
|
||||
GroupId = @event.GroupId,
|
||||
OperatorId = @event.OperatorId,
|
||||
UserId = @event.UserId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+29
-29
@@ -1,29 +1,29 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestUpdateHandler
|
||||
{
|
||||
public class RequestUpdateSignalrHandler : IConsumer<GroupRequestUpdateEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public RequestUpdateSignalrHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestUpdateEvent> context)
|
||||
{
|
||||
var msg = new HubResponse<GroupRequestUpdateVo>("Event", new GroupRequestUpdateVo
|
||||
{
|
||||
GroupId = context.Message.GroupId,
|
||||
RequestId = context.Message.RequestId,
|
||||
UserId = context.Message.UserId
|
||||
});
|
||||
await _hub.Clients.User(context.Message.UserId.ToString()).SendAsync("ReceiveMessage", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.VOs.Group;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.GroupRequestUpdateHandler
|
||||
{
|
||||
public class RequestUpdateSignalrHandler : IConsumer<GroupRequestUpdateEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
public RequestUpdateSignalrHandler(IHubContext<ChatHub> hub)
|
||||
{
|
||||
_hub = hub;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<GroupRequestUpdateEvent> context)
|
||||
{
|
||||
var msg = new HubResponse<GroupRequestUpdateVo>("Event", new GroupRequestUpdateVo
|
||||
{
|
||||
GroupId = context.Message.GroupId,
|
||||
RequestId = context.Message.RequestId,
|
||||
UserId = context.Message.UserId
|
||||
});
|
||||
await _hub.Clients.User(context.Message.UserId.ToString()).SendAsync("ReceiveMessage", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+66
-66
@@ -1,66 +1,66 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Services;
|
||||
using IM_API.Tools;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class ConversationEventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IConversationService _conversationService;
|
||||
private readonly ILogger<ConversationEventHandler> _logger;
|
||||
private readonly IUserService _userSerivce;
|
||||
private readonly IGroupService _groupService;
|
||||
public ConversationEventHandler(
|
||||
IConversationService conversationService,
|
||||
ILogger<ConversationEventHandler> logger,
|
||||
IUserService userService,
|
||||
IGroupService groupService
|
||||
)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
_logger = logger;
|
||||
_userSerivce = userService;
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if (@event.ChatType == ChatType.GROUP)
|
||||
{
|
||||
var userinfo = await _userSerivce.GetUserInfoAsync(@event.MsgSenderId);
|
||||
await _groupService.UpdateGroupConversationAsync(new Dtos.Group.GroupUpdateConversationDto
|
||||
{
|
||||
GroupId = @event.MsgRecipientId,
|
||||
LastMessage = @event.MessageContent,
|
||||
LastSenderName = userinfo.NickName,
|
||||
LastUpdateTime = @event.MessageCreated,
|
||||
MaxSequenceId = @event.SequenceId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _conversationService.UpdateConversationAfterSentAsync(new Dtos.Conversation.UpdateConversationDto
|
||||
{
|
||||
LastMessage = @event.MessageContent,
|
||||
LastSequenceId = @event.SequenceId,
|
||||
ReceiptId = @event.MsgRecipientId,
|
||||
SenderId = @event.MsgSenderId,
|
||||
StreamKey = @event.StreamKey,
|
||||
DateTime = @event.MessageCreated
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Services;
|
||||
using IM_API.Tools;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class ConversationEventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IConversationService _conversationService;
|
||||
private readonly ILogger<ConversationEventHandler> _logger;
|
||||
private readonly IUserService _userSerivce;
|
||||
private readonly IGroupService _groupService;
|
||||
public ConversationEventHandler(
|
||||
IConversationService conversationService,
|
||||
ILogger<ConversationEventHandler> logger,
|
||||
IUserService userService,
|
||||
IGroupService groupService
|
||||
)
|
||||
{
|
||||
_conversationService = conversationService;
|
||||
_logger = logger;
|
||||
_userSerivce = userService;
|
||||
_groupService = groupService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
if (@event.ChatType == ChatType.GROUP)
|
||||
{
|
||||
var userinfo = await _userSerivce.GetUserInfoAsync(@event.MsgSenderId);
|
||||
await _groupService.UpdateGroupConversationAsync(new Dtos.Group.GroupUpdateConversationDto
|
||||
{
|
||||
GroupId = @event.MsgRecipientId,
|
||||
LastMessage = @event.MessageContent,
|
||||
LastSenderName = userinfo.NickName,
|
||||
LastUpdateTime = @event.MessageCreated,
|
||||
MaxSequenceId = @event.SequenceId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await _conversationService.UpdateConversationAfterSentAsync(new Dtos.Conversation.UpdateConversationDto
|
||||
{
|
||||
LastMessage = @event.MessageContent,
|
||||
LastSequenceId = @event.SequenceId,
|
||||
ReceiptId = @event.MsgRecipientId,
|
||||
SenderId = @event.MsgSenderId,
|
||||
StreamKey = @event.StreamKey,
|
||||
DateTime = @event.MessageCreated
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+26
-26
@@ -1,26 +1,26 @@
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
using IM_API.Interface.Services;
|
||||
using AutoMapper;
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class MessageCreatedDbHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IMessageSevice _messageService;
|
||||
public readonly IMapper _mapper;
|
||||
public MessageCreatedDbHandler(IMessageSevice messageSevice, IMapper mapper)
|
||||
{
|
||||
_messageService = messageSevice;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var msg = _mapper.Map<Message>(@event);
|
||||
await _messageService.MakeMessageAsync(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using MassTransit;
|
||||
using IM_API.Interface.Services;
|
||||
using AutoMapper;
|
||||
using IM_API.Models;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class MessageCreatedDbHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IMessageSevice _messageService;
|
||||
public readonly IMapper _mapper;
|
||||
public MessageCreatedDbHandler(IMessageSevice messageSevice, IMapper mapper)
|
||||
{
|
||||
_messageService = messageSevice;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var msg = _mapper.Map<Message>(@event);
|
||||
await _messageService.MakeMessageAsync(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+48
-48
@@ -1,48 +1,48 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using IM_API.VOs.Message;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class SignalREventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IUserService _userService;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub, IMapper mapper,IUserService userService)
|
||||
{
|
||||
_hub = hub;
|
||||
_mapper = mapper;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
var @event = context.Message;
|
||||
try
|
||||
{
|
||||
var entity = _mapper.Map<Message>(@event);
|
||||
var messageBaseVo = _mapper.Map<MessageBaseVo>(entity);
|
||||
var senderinfo = await _userService.GetUserInfoAsync(@event.MsgSenderId);
|
||||
messageBaseVo.SenderName = senderinfo.NickName;
|
||||
messageBaseVo.SenderAvatar = senderinfo.Avatar ?? "";
|
||||
await _hub.Clients.Group(@event.StreamKey).SendAsync("ReceiveMessage", new HubResponse<MessageBaseVo>("Event", messageBaseVo));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[SignalR] 发送失败: {ex.Message}");
|
||||
Console.ResetColor();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using AutoMapper;
|
||||
using IM_API.Application.Interfaces;
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
using IM_API.Tools;
|
||||
using IM_API.VOs.Message;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.MessageCreatedHandler
|
||||
{
|
||||
public class SignalREventHandler : IConsumer<MessageCreatedEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IUserService _userService;
|
||||
public SignalREventHandler(IHubContext<ChatHub> hub, IMapper mapper,IUserService userService)
|
||||
{
|
||||
_hub = hub;
|
||||
_mapper = mapper;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<MessageCreatedEvent> context)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
var @event = context.Message;
|
||||
try
|
||||
{
|
||||
var entity = _mapper.Map<Message>(@event);
|
||||
var messageBaseVo = _mapper.Map<MessageBaseVo>(entity);
|
||||
var senderinfo = await _userService.GetUserInfoAsync(@event.MsgSenderId);
|
||||
messageBaseVo.SenderName = senderinfo.NickName;
|
||||
messageBaseVo.SenderAvatar = senderinfo.Avatar ?? "";
|
||||
await _hub.Clients.Group(@event.StreamKey).SendAsync("ReceiveMessage", new HubResponse<MessageBaseVo>("Event", messageBaseVo));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[SignalR] 发送失败: {ex.Message}");
|
||||
Console.ResetColor();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Dtos.Friend;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.RequestFriendHandler
|
||||
{
|
||||
public class RequestFriendSignalRHandler:IConsumer<RequestFriendEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IUserService _userService;
|
||||
public RequestFriendSignalRHandler(IHubContext<ChatHub> hubContext, IUserService userService)
|
||||
{
|
||||
_hub = hubContext;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<RequestFriendEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var userInfo = await _userService.GetUserInfoAsync(@event.FromUserId);
|
||||
var res = new HubResponse<FriendRequestResDto>("Event", new FriendRequestResDto()
|
||||
{
|
||||
RequestUser = @event.FromUserId,
|
||||
ResponseUser = @event.ToUserId,
|
||||
Created = DateTime.UtcNow,
|
||||
Description = @event.Description,
|
||||
Avatar = userInfo.Avatar,
|
||||
NickName = userInfo.NickName
|
||||
});
|
||||
await _hub.Clients.User(@event.ToUserId.ToString()).SendAsync("ReceiveMessage", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
using IM_API.Domain.Events;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Dtos.Friend;
|
||||
using IM_API.Hubs;
|
||||
using IM_API.Interface.Services;
|
||||
using MassTransit;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace IM_API.Application.EventHandlers.RequestFriendHandler
|
||||
{
|
||||
public class RequestFriendSignalRHandler:IConsumer<RequestFriendEvent>
|
||||
{
|
||||
private readonly IHubContext<ChatHub> _hub;
|
||||
private readonly IUserService _userService;
|
||||
public RequestFriendSignalRHandler(IHubContext<ChatHub> hubContext, IUserService userService)
|
||||
{
|
||||
_hub = hubContext;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task Consume(ConsumeContext<RequestFriendEvent> context)
|
||||
{
|
||||
var @event = context.Message;
|
||||
var userInfo = await _userService.GetUserInfoAsync(@event.FromUserId);
|
||||
var res = new HubResponse<FriendRequestResDto>("Event", new FriendRequestResDto()
|
||||
{
|
||||
RequestUser = @event.FromUserId,
|
||||
ResponseUser = @event.ToUserId,
|
||||
Created = DateTime.UtcNow,
|
||||
Description = @event.Description,
|
||||
Avatar = userInfo.Avatar,
|
||||
NickName = userInfo.NickName
|
||||
});
|
||||
await _hub.Clients.User(@event.ToUserId.ToString()).SendAsync("ReceiveMessage", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user