Merge branch 'feature-nxdev' of https://gitea.nxsir.cn/code/IM into feature-nxdev
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using AutoMapper;
|
||||
using IM_API.Dtos;
|
||||
using IM_API.Dtos.Conversation;
|
||||
using IM_API.Exceptions;
|
||||
using IM_API.Interface.Services;
|
||||
using IM_API.Models;
|
||||
@@ -134,5 +134,27 @@ namespace IM_API.Services
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public async Task MakeConversationAsync(int userAId, int userBId, ChatType chatType)
|
||||
{
|
||||
var userAcExist = await _context.Conversations.AnyAsync(x => x.UserId == userAId && x.TargetId == userBId);
|
||||
if (userAcExist) return;
|
||||
var streamKey = chatType == ChatType.PRIVATE ?
|
||||
StreamKeyBuilder.Private(userAId, userBId) : StreamKeyBuilder.Group(userBId);
|
||||
var conversation = new Conversation()
|
||||
{
|
||||
ChatType = (int)chatType,
|
||||
LastMessage = "",
|
||||
LastMessageTime = DateTime.UtcNow,
|
||||
LastReadMessageId = -1,
|
||||
StreamKey = streamKey,
|
||||
TargetId = userBId,
|
||||
UnreadCount = 0,
|
||||
UserId = userAId
|
||||
|
||||
};
|
||||
_context.Conversations.Add(conversation);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user