committed by
GitHub
69 changed files with 5580 additions and 5238 deletions
File diff suppressed because it is too large
@ -1,19 +1,19 @@ |
|||
namespace LINGYUN.Abp.IM.SignalR |
|||
{ |
|||
public class AbpIMSignalROptions |
|||
{ |
|||
/// <summary>
|
|||
/// 自定义的客户端接收消息方法名称
|
|||
/// </summary>
|
|||
public string GetChatMessageMethod { get; set; } |
|||
/// <summary>
|
|||
/// 用户上线接收方法名称
|
|||
/// </summary>
|
|||
public string UserOnlineMethod { get; set; } |
|||
public AbpIMSignalROptions() |
|||
{ |
|||
GetChatMessageMethod = "getChatMessage"; |
|||
UserOnlineMethod = "onUserOnlined"; |
|||
} |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.IM.SignalR |
|||
{ |
|||
public class AbpIMSignalROptions |
|||
{ |
|||
/// <summary>
|
|||
/// 自定义的客户端接收消息方法名称
|
|||
/// </summary>
|
|||
public string GetChatMessageMethod { get; set; } |
|||
/// <summary>
|
|||
/// 用户上线接收方法名称
|
|||
/// </summary>
|
|||
public string UserOnlineMethod { get; set; } |
|||
public AbpIMSignalROptions() |
|||
{ |
|||
GetChatMessageMethod = "get-chat-message"; |
|||
UserOnlineMethod = "on-user-onlined"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,124 +1,139 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.RealTime.Client; |
|||
using LINGYUN.Abp.RealTime.SignalR; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Immutable; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.SignalR.Hubs |
|||
{ |
|||
[Authorize] |
|||
public class MessagesHub : OnlineClientHubBase |
|||
{ |
|||
protected AbpIMSignalROptions Options { get; } |
|||
protected IFriendStore FriendStore { get; } |
|||
protected IMessageStore MessageStore { get; } |
|||
protected IUserGroupStore UserGroupStore { get; } |
|||
|
|||
public MessagesHub( |
|||
IFriendStore friendStore, |
|||
IMessageStore messageStore, |
|||
IUserGroupStore userGroupStore, |
|||
IOptions<AbpIMSignalROptions> options) |
|||
{ |
|||
FriendStore = friendStore; |
|||
MessageStore = messageStore; |
|||
UserGroupStore = userGroupStore; |
|||
Options = options.Value; |
|||
} |
|||
|
|||
protected override async Task OnClientConnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientConnectedAsync(client); |
|||
// 加入通讯组
|
|||
var userGroups = await UserGroupStore.GetUserGroupsAsync(client.TenantId, client.UserId.Value); |
|||
foreach (var group in userGroups) |
|||
{ |
|||
await Groups.AddToGroupAsync(client.ConnectionId, group.Name); |
|||
var groupClient = Clients.Group(group.Name); |
|||
if (groupClient != null) |
|||
{ |
|||
// 发送用户上线通知
|
|||
await groupClient.SendAsync(Options.UserOnlineMethod, client.TenantId, client.UserId.Value); |
|||
} |
|||
} |
|||
|
|||
// 发送好友上线通知
|
|||
var userFriends = await FriendStore.GetListAsync(client.TenantId, client.UserId.Value); |
|||
if (userFriends.Count > 0) |
|||
{ |
|||
var friendClientIds = userFriends.Select(friend => friend.FriendId.ToString()).ToImmutableArray(); |
|||
var userClients = Clients.Users(friendClientIds); |
|||
if (userClients != null) |
|||
{ |
|||
await userClients.SendAsync(Options.UserOnlineMethod, client.TenantId, client.UserId.Value); |
|||
} |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 客户端调用发送消息方法
|
|||
/// </summary>
|
|||
/// <param name="chatMessage"></param>
|
|||
/// <returns></returns>
|
|||
[HubMethodName("SendMessage")] |
|||
public virtual async Task SendMessageAsync(ChatMessage chatMessage) |
|||
{ |
|||
// 持久化
|
|||
await MessageStore.StoreMessageAsync(chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
|
|||
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
await SendMessageToGroupAsync(chatMessage); |
|||
} |
|||
else |
|||
{ |
|||
await SendMessageToUserAsync(chatMessage); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task SendMessageToGroupAsync(ChatMessage chatMessage) |
|||
{ |
|||
var signalRClient = Clients.Group(chatMessage.GroupId); |
|||
if (signalRClient == null) |
|||
{ |
|||
Logger.LogDebug("Can not get group " + chatMessage.GroupId + " from SignalR hub!"); |
|||
return; |
|||
} |
|||
|
|||
await signalRClient.SendAsync(Options.GetChatMessageMethod, chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
} |
|||
|
|||
protected virtual async Task SendMessageToUserAsync(ChatMessage chatMessage) |
|||
{ |
|||
var onlineClientContext = new OnlineClientContext(chatMessage.TenantId, chatMessage.ToUserId.GetValueOrDefault()); |
|||
var onlineClients = OnlineClientManager.GetAllByContext(onlineClientContext); |
|||
|
|||
foreach (var onlineClient in onlineClients) |
|||
{ |
|||
try |
|||
{ |
|||
var signalRClient = Clients.Client(onlineClient.ConnectionId); |
|||
if (signalRClient == null) |
|||
{ |
|||
Logger.LogDebug("Can not get user " + onlineClientContext.UserId + " with connectionId " + onlineClient.ConnectionId + " from SignalR hub!"); |
|||
continue; |
|||
} |
|||
await signalRClient.SendAsync(Options.GetChatMessageMethod, chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
// 发送异常记录就行了,因为消息已经持久化
|
|||
Logger.LogWarning("Could not send message to user: {0}", chatMessage.ToUserId); |
|||
Logger.LogWarning("Send to user message error: {0}", ex.Message); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.RealTime.Client; |
|||
using LINGYUN.Abp.RealTime.SignalR; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using Microsoft.Extensions.Logging; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Collections.Immutable; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.SignalR.Hubs |
|||
{ |
|||
[Authorize] |
|||
public class MessagesHub : OnlineClientHubBase |
|||
{ |
|||
protected IMessageProcessor Processor => LazyServiceProvider.LazyGetRequiredService<IMessageProcessor>(); |
|||
|
|||
protected AbpIMSignalROptions Options { get; } |
|||
protected IFriendStore FriendStore { get; } |
|||
protected IMessageStore MessageStore { get; } |
|||
protected IUserGroupStore UserGroupStore { get; } |
|||
|
|||
public MessagesHub( |
|||
IFriendStore friendStore, |
|||
IMessageStore messageStore, |
|||
IUserGroupStore userGroupStore, |
|||
IOptions<AbpIMSignalROptions> options) |
|||
{ |
|||
FriendStore = friendStore; |
|||
MessageStore = messageStore; |
|||
UserGroupStore = userGroupStore; |
|||
Options = options.Value; |
|||
} |
|||
|
|||
protected override async Task OnClientConnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientConnectedAsync(client); |
|||
// 加入通讯组
|
|||
var userGroups = await UserGroupStore.GetUserGroupsAsync(client.TenantId, client.UserId.Value); |
|||
foreach (var group in userGroups) |
|||
{ |
|||
await Groups.AddToGroupAsync(client.ConnectionId, group.Name); |
|||
var groupClient = Clients.Group(group.Name); |
|||
if (groupClient != null) |
|||
{ |
|||
// 发送用户上线通知
|
|||
await groupClient.SendAsync(Options.UserOnlineMethod, client.TenantId, client.UserId.Value); |
|||
} |
|||
} |
|||
|
|||
// 发送好友上线通知
|
|||
var userFriends = await FriendStore.GetListAsync(client.TenantId, client.UserId.Value); |
|||
if (userFriends.Count > 0) |
|||
{ |
|||
var friendClientIds = userFriends.Select(friend => friend.FriendId.ToString()).ToImmutableArray(); |
|||
var userClients = Clients.Users(friendClientIds); |
|||
if (userClients != null) |
|||
{ |
|||
await userClients.SendAsync(Options.UserOnlineMethod, client.TenantId, client.UserId.Value); |
|||
} |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// 客户端调用发送消息方法
|
|||
/// </summary>
|
|||
/// <param name="chatMessage"></param>
|
|||
/// <returns></returns>
|
|||
// [HubMethodName("SendMessage")]
|
|||
[HubMethodName("send")] |
|||
public virtual async Task SendAsync(ChatMessage chatMessage) |
|||
{ |
|||
// 持久化
|
|||
await MessageStore.StoreMessageAsync(chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
|
|||
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
await SendMessageToGroupAsync(chatMessage); |
|||
} |
|||
else |
|||
{ |
|||
await SendMessageToUserAsync(chatMessage); |
|||
} |
|||
} |
|||
|
|||
[HubMethodName("recall")] |
|||
public virtual async Task ReCallAsync(ChatMessage chatMessage) |
|||
{ |
|||
await Processor.ReCallAsync(chatMessage); |
|||
} |
|||
|
|||
[HubMethodName("read")] |
|||
public virtual async Task ReadAsync(ChatMessage chatMessage) |
|||
{ |
|||
await Processor.ReadAsync(chatMessage); |
|||
} |
|||
|
|||
protected virtual async Task SendMessageToGroupAsync(ChatMessage chatMessage) |
|||
{ |
|||
var signalRClient = Clients.Group(chatMessage.GroupId); |
|||
if (signalRClient == null) |
|||
{ |
|||
Logger.LogDebug("Can not get group " + chatMessage.GroupId + " from SignalR hub!"); |
|||
return; |
|||
} |
|||
|
|||
await signalRClient.SendAsync(Options.GetChatMessageMethod, chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
} |
|||
|
|||
protected virtual async Task SendMessageToUserAsync(ChatMessage chatMessage) |
|||
{ |
|||
var onlineClientContext = new OnlineClientContext(chatMessage.TenantId, chatMessage.ToUserId.GetValueOrDefault()); |
|||
var onlineClients = OnlineClientManager.GetAllByContext(onlineClientContext); |
|||
|
|||
foreach (var onlineClient in onlineClients) |
|||
{ |
|||
try |
|||
{ |
|||
var signalRClient = Clients.Client(onlineClient.ConnectionId); |
|||
if (signalRClient == null) |
|||
{ |
|||
Logger.LogDebug("Can not get user " + onlineClientContext.UserId + " with connectionId " + onlineClient.ConnectionId + " from SignalR hub!"); |
|||
continue; |
|||
} |
|||
await signalRClient.SendAsync(Options.GetChatMessageMethod, chatMessage, cancellationToken: Context.ConnectionAborted); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
// 发送异常记录就行了,因为消息已经持久化
|
|||
Logger.LogWarning("Could not send message to user: {0}", chatMessage.ToUserId); |
|||
Logger.LogWarning("Send to user message error: {0}", ex.Message); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,161 +1,157 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Contract |
|||
{ |
|||
public interface IFriendStore |
|||
{ |
|||
/// <summary>
|
|||
/// 是否是好友关系
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> IsFriendAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 查询好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="reverse"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
bool reverse = false, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 获取好友数量
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="reverse"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetPagedListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserFriend.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取最近联系好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetLastContactListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取好友信息
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserFriend> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加好友
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加好友请求
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <param name="remarkName"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserAddFriendResult> AddRequestAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
string description = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 移除好友
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加黑名单
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 移除黑名单
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Contract |
|||
{ |
|||
public interface IFriendStore |
|||
{ |
|||
/// <summary>
|
|||
/// 是否是好友关系
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> IsFriendAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 查询好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 获取好友数量
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetPagedListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserFriend.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取最近联系好友列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserFriend>> GetLastContactListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取好友信息
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserFriend> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加好友
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加好友请求
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <param name="remarkName"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserAddFriendResult> AddRequestAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
string description = "", |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 移除好友
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 添加黑名单
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 移除黑名单
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="friendId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,108 +1,106 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Group |
|||
{ |
|||
public interface IUserGroupStore |
|||
{ |
|||
/// <summary>
|
|||
/// 成员是否在群组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> MemberHasInGroupAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组用户身份
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<GroupUserCard> GetUserGroupCardAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取用户所在通讯组列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<IEnumerable<Group>> GetUserGroupsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task<IEnumerable<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetMembersCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取通讯组用户
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 用户加入通讯组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddUserToGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
Guid acceptUserId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 用户退出通讯组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveUserFormGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Group |
|||
{ |
|||
public interface IUserGroupStore |
|||
{ |
|||
/// <summary>
|
|||
/// 成员是否在群组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> MemberHasInGroupAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组用户身份
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<GroupUserCard> GetUserGroupCardAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取用户所在通讯组列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<IEnumerable<Group>> GetUserGroupsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task<IEnumerable<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetMembersCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取通讯组用户
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 用户加入通讯组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task AddUserToGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
Guid acceptUserId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 用户退出通讯组
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveUserFormGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,60 +1,58 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM |
|||
{ |
|||
/// <summary>
|
|||
/// IM用户资料查找接口
|
|||
/// </summary>
|
|||
public interface IUserCardFinder |
|||
{ |
|||
/// <summary>
|
|||
/// 查询IM用户数量
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserName">用户名称</param>
|
|||
/// <param name="startAge">起止年龄</param>
|
|||
/// <param name="endAge">起止年龄</param>
|
|||
/// <param name="sex">性别</param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null); |
|||
/// <summary>
|
|||
/// 查询IM用户列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserName">用户名称</param>
|
|||
/// <param name="startAge">起止年龄</param>
|
|||
/// <param name="endAge">起止年龄</param>
|
|||
/// <param name="sex">性别</param>
|
|||
/// <param name="sorting">排序字段</param>
|
|||
/// <param name="reverse">是否倒序</param>
|
|||
/// <param name="skipCount">起始记录位置</param>
|
|||
/// <param name="maxResultCount">最大返回数量</param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserCard>> GetListAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10); |
|||
/// <summary>
|
|||
/// 获取IM用户信息
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserId"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserCard> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid findUserId); |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM |
|||
{ |
|||
/// <summary>
|
|||
/// IM用户资料查找接口
|
|||
/// </summary>
|
|||
public interface IUserCardFinder |
|||
{ |
|||
/// <summary>
|
|||
/// 查询IM用户数量
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserName">用户名称</param>
|
|||
/// <param name="startAge">起止年龄</param>
|
|||
/// <param name="endAge">起止年龄</param>
|
|||
/// <param name="sex">性别</param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null); |
|||
/// <summary>
|
|||
/// 查询IM用户列表
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserName">用户名称</param>
|
|||
/// <param name="startAge">起止年龄</param>
|
|||
/// <param name="endAge">起止年龄</param>
|
|||
/// <param name="sex">性别</param>
|
|||
/// <param name="sorting">排序字段</param>
|
|||
/// <param name="skipCount">起始记录位置</param>
|
|||
/// <param name="maxResultCount">最大返回数量</param>
|
|||
/// <returns></returns>
|
|||
Task<List<UserCard>> GetListAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10); |
|||
/// <summary>
|
|||
/// 获取IM用户信息
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="findUserId"></param>
|
|||
/// <returns></returns>
|
|||
Task<UserCard> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid findUserId); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,23 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
/// <summary>
|
|||
/// 消息处理器
|
|||
/// </summary>
|
|||
public interface IMessageProcessor |
|||
{ |
|||
/// <summary>
|
|||
/// 撤回
|
|||
/// </summary>
|
|||
/// <param name="message"></param>
|
|||
/// <returns></returns>
|
|||
Task ReCallAsync(ChatMessage message); |
|||
/// <summary>
|
|||
/// 消息已读
|
|||
/// </summary>
|
|||
/// <param name="message"></param>
|
|||
/// <returns></returns>
|
|||
Task ReadAsync(ChatMessage message); |
|||
} |
|||
} |
|||
@ -1,108 +1,103 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
public interface IMessageStore |
|||
{ |
|||
/// <summary>
|
|||
/// 存储聊天记录
|
|||
/// </summary>
|
|||
/// <param name="chatMessage"></param>
|
|||
/// <param name="formUserId"></param>
|
|||
/// <param name="toUserId"></param>
|
|||
/// <returns></returns>
|
|||
Task StoreMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组聊天记录总数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns></returns>
|
|||
Task<long> GetGroupMessageCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组聊天记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="reverse"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<ChatMessage>> GetGroupMessageAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取上一次通讯消息记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="reverse"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<LastChatMessage>> GetLastChatMessagesAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
bool reverse = true, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 获取与某个用户的聊天记录总数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="sendUserId"></param>
|
|||
/// <param name="receiveUserId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns></returns>
|
|||
Task<long> GetChatMessageCountAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取与某个用户的聊天记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<ChatMessage>> GetChatMessageAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
public interface IMessageStore |
|||
{ |
|||
/// <summary>
|
|||
/// 存储聊天记录
|
|||
/// </summary>
|
|||
/// <param name="chatMessage"></param>
|
|||
/// <param name="formUserId"></param>
|
|||
/// <param name="toUserId"></param>
|
|||
/// <returns></returns>
|
|||
Task StoreMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组聊天记录总数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns></returns>
|
|||
Task<long> GetGroupMessageCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组聊天记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<ChatMessage>> GetGroupMessageAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取上一次通讯消息记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<LastChatMessage>> GetLastChatMessagesAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default |
|||
); |
|||
/// <summary>
|
|||
/// 获取与某个用户的聊天记录总数
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="sendUserId"></param>
|
|||
/// <param name="receiveUserId"></param>
|
|||
/// <param name="filter"></param>
|
|||
/// <param name="type"></param>
|
|||
/// <returns></returns>
|
|||
Task<long> GetChatMessageCountAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取与某个用户的聊天记录
|
|||
/// </summary>
|
|||
/// <param name="tenantId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<ChatMessage>> GetChatMessageAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,25 +1,29 @@ |
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
/// <summary>
|
|||
/// 消息状态
|
|||
/// </summary>
|
|||
public enum MessageSendState : sbyte |
|||
{ |
|||
/// <summary>
|
|||
/// 已发送
|
|||
/// </summary>
|
|||
Send = 0, |
|||
/// <summary>
|
|||
/// 撤回
|
|||
/// </summary>
|
|||
ReCall = 10, |
|||
/// <summary>
|
|||
/// 发送失败
|
|||
/// </summary>
|
|||
Failed = 50, |
|||
/// <summary>
|
|||
/// 退回
|
|||
/// </summary>
|
|||
BackTo = 100 |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
/// <summary>
|
|||
/// 消息状态
|
|||
/// </summary>
|
|||
public enum MessageState : sbyte |
|||
{ |
|||
/// <summary>
|
|||
/// 已发送
|
|||
/// </summary>
|
|||
Send = 0, |
|||
/// <summary>
|
|||
/// 已读
|
|||
/// </summary>
|
|||
Read = 1, |
|||
/// <summary>
|
|||
/// 撤回
|
|||
/// </summary>
|
|||
ReCall = 10, |
|||
/// <summary>
|
|||
/// 发送失败
|
|||
/// </summary>
|
|||
Failed = 50, |
|||
/// <summary>
|
|||
/// 退回
|
|||
/// </summary>
|
|||
BackTo = 100 |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.IM.Messages |
|||
{ |
|||
[Dependency(TryRegister = true)] |
|||
public class NullMessageProcessor : IMessageProcessor, ISingletonDependency |
|||
{ |
|||
public Task ReadAsync(ChatMessage message) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task ReCallAsync(ChatMessage message) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace LINGYUN.Abp.IM.Settings |
|||
{ |
|||
public static class AbpIMSettingNames |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,15 +1,15 @@ |
|||
namespace LINGYUN.Abp.Notifications.SignalR |
|||
{ |
|||
public class AbpNotificationsSignalROptions |
|||
{ |
|||
/// <summary>
|
|||
/// 自定义的客户端订阅通知方法名称
|
|||
/// </summary>
|
|||
public string MethodName { get; set; } |
|||
|
|||
public AbpNotificationsSignalROptions() |
|||
{ |
|||
MethodName = "getNotification"; |
|||
} |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.Notifications.SignalR |
|||
{ |
|||
public class AbpNotificationsSignalROptions |
|||
{ |
|||
/// <summary>
|
|||
/// 自定义的客户端订阅通知方法名称
|
|||
/// </summary>
|
|||
public string MethodName { get; set; } |
|||
|
|||
public AbpNotificationsSignalROptions() |
|||
{ |
|||
MethodName = "get-notification"; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,78 +1,81 @@ |
|||
using LINGYUN.Abp.RealTime.Client; |
|||
using LINGYUN.Abp.RealTime.SignalR; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Uow; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.Notifications.SignalR.Hubs |
|||
{ |
|||
[Authorize] |
|||
public class NotificationsHub : OnlineClientHubBase |
|||
{ |
|||
protected INotificationStore NotificationStore => LazyServiceProvider.LazyGetRequiredService<INotificationStore>(); |
|||
|
|||
protected override async Task OnClientConnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientConnectedAsync(client); |
|||
|
|||
if (client.TenantId.HasValue) |
|||
{ |
|||
// 以租户为分组,将用户加入租户通讯组
|
|||
await Groups.AddToGroupAsync(client.ConnectionId, client.TenantId.Value.ToString(), Context.ConnectionAborted); |
|||
} |
|||
else |
|||
{ |
|||
await Groups.AddToGroupAsync(client.ConnectionId, "Global", Context.ConnectionAborted); |
|||
} |
|||
} |
|||
|
|||
protected override async Task OnClientDisconnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientDisconnectedAsync(client); |
|||
|
|||
if (client.TenantId.HasValue) |
|||
{ |
|||
// 以租户为分组,将移除租户通讯组
|
|||
await Groups.RemoveFromGroupAsync(client.ConnectionId, client.TenantId.Value.ToString(), Context.ConnectionAborted); |
|||
} |
|||
else |
|||
{ |
|||
await Groups.RemoveFromGroupAsync(client.ConnectionId, "Global", Context.ConnectionAborted); |
|||
} |
|||
} |
|||
|
|||
[HubMethodName("MySubscriptions")] |
|||
public virtual async Task<ListResultDto<NotificationSubscriptionInfo>> GetMySubscriptionsAsync() |
|||
{ |
|||
var subscriptions = await NotificationStore |
|||
.GetUserSubscriptionsAsync(CurrentTenant.Id, CurrentUser.GetId()); |
|||
|
|||
return new ListResultDto<NotificationSubscriptionInfo>(subscriptions); |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
[HubMethodName("GetNotification")] |
|||
public virtual async Task<ListResultDto<NotificationInfo>> GetNotificationAsync() |
|||
{ |
|||
var userNotifications = await NotificationStore |
|||
.GetUserNotificationsAsync(CurrentTenant.Id, CurrentUser.GetId(), NotificationReadState.UnRead, 10); |
|||
|
|||
return new ListResultDto<NotificationInfo>(userNotifications); |
|||
} |
|||
|
|||
[HubMethodName("ChangeState")] |
|||
public virtual async Task ChangeStateAsync(string id, NotificationReadState readState = NotificationReadState.Read) |
|||
{ |
|||
await NotificationStore |
|||
.ChangeUserNotificationReadStateAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
long.Parse(id), |
|||
readState, |
|||
Context.ConnectionAborted); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.RealTime.Client; |
|||
using LINGYUN.Abp.RealTime.SignalR; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.SignalR; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Uow; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.Notifications.SignalR.Hubs |
|||
{ |
|||
[Authorize] |
|||
public class NotificationsHub : OnlineClientHubBase |
|||
{ |
|||
protected INotificationStore NotificationStore => LazyServiceProvider.LazyGetRequiredService<INotificationStore>(); |
|||
|
|||
protected override async Task OnClientConnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientConnectedAsync(client); |
|||
|
|||
if (client.TenantId.HasValue) |
|||
{ |
|||
// 以租户为分组,将用户加入租户通讯组
|
|||
await Groups.AddToGroupAsync(client.ConnectionId, client.TenantId.Value.ToString(), Context.ConnectionAborted); |
|||
} |
|||
else |
|||
{ |
|||
await Groups.AddToGroupAsync(client.ConnectionId, "Global", Context.ConnectionAborted); |
|||
} |
|||
} |
|||
|
|||
protected override async Task OnClientDisconnectedAsync(IOnlineClient client) |
|||
{ |
|||
await base.OnClientDisconnectedAsync(client); |
|||
|
|||
if (client.TenantId.HasValue) |
|||
{ |
|||
// 以租户为分组,将移除租户通讯组
|
|||
await Groups.RemoveFromGroupAsync(client.ConnectionId, client.TenantId.Value.ToString(), Context.ConnectionAborted); |
|||
} |
|||
else |
|||
{ |
|||
await Groups.RemoveFromGroupAsync(client.ConnectionId, "Global", Context.ConnectionAborted); |
|||
} |
|||
} |
|||
|
|||
// [HubMethodName("MySubscriptions")]
|
|||
[HubMethodName("my-subscriptions")] |
|||
public virtual async Task<ListResultDto<NotificationSubscriptionInfo>> GetMySubscriptionsAsync() |
|||
{ |
|||
var subscriptions = await NotificationStore |
|||
.GetUserSubscriptionsAsync(CurrentTenant.Id, CurrentUser.GetId()); |
|||
|
|||
return new ListResultDto<NotificationSubscriptionInfo>(subscriptions); |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
// [HubMethodName("GetNotification")]
|
|||
[HubMethodName("get-notifications")] |
|||
public virtual async Task<ListResultDto<NotificationInfo>> GetNotificationAsync() |
|||
{ |
|||
var userNotifications = await NotificationStore |
|||
.GetUserNotificationsAsync(CurrentTenant.Id, CurrentUser.GetId(), NotificationReadState.UnRead, 10); |
|||
|
|||
return new ListResultDto<NotificationInfo>(userNotifications); |
|||
} |
|||
|
|||
// [HubMethodName("ChangeState")]
|
|||
[HubMethodName("change-state")] |
|||
public virtual async Task ChangeStateAsync(string id, NotificationReadState readState = NotificationReadState.Read) |
|||
{ |
|||
await NotificationStore |
|||
.ChangeUserNotificationReadStateAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
long.Parse(id), |
|||
readState, |
|||
Context.ConnectionAborted); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,126 +1,125 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
public interface INotificationStore |
|||
{ |
|||
Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
bool reverse = true, |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
public interface INotificationStore |
|||
{ |
|||
Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,188 +1,187 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
[Dependency(TryRegister = true)] |
|||
public class NullNotificationStore : INotificationStore, ISingletonDependency |
|||
{ |
|||
public Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new NotificationInfo()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationInfo>()); |
|||
} |
|||
|
|||
public Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(0); |
|||
} |
|||
|
|||
public Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
bool reverse = true, |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(false); |
|||
} |
|||
} |
|||
} |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.Notifications |
|||
{ |
|||
[Dependency(TryRegister = true)] |
|||
public class NullNotificationStore : INotificationStore, ISingletonDependency |
|||
{ |
|||
public Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new NotificationInfo()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationInfo>()); |
|||
} |
|||
|
|||
public Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(0); |
|||
} |
|||
|
|||
public Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(new List<NotificationSubscriptionInfo>()); |
|||
} |
|||
|
|||
public Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.CompletedTask; |
|||
} |
|||
|
|||
public Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return Task.FromResult(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,10 +1,9 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GetMyFriendsDto : ISortedResultRequest |
|||
{ |
|||
public string Sorting { get; set; } |
|||
public bool Reverse { get; set; } |
|||
} |
|||
} |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GetMyFriendsDto : ISortedResultRequest |
|||
{ |
|||
public string Sorting { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,11 +1,10 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GetUserLastMessageDto : ILimitedResultRequest, ISortedResultRequest |
|||
{ |
|||
public int MaxResultCount { get; set; } |
|||
public string Sorting { get; set; } |
|||
public bool Reverse { get; set; } |
|||
} |
|||
} |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GetUserLastMessageDto : ILimitedResultRequest, ISortedResultRequest |
|||
{ |
|||
public int MaxResultCount { get; set; } |
|||
public string Sorting { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,15 +1,14 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GroupMessageGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public long GroupId { get; set; } |
|||
public bool Reverse { get; set; } |
|||
public string Filter { get; set; } |
|||
public MessageType? MessageType { get; set; } |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GroupMessageGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public long GroupId { get; set; } |
|||
public string Filter { get; set; } |
|||
public MessageType? MessageType { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,15 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GroupUserGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public long GroupId { get; set; } |
|||
|
|||
public bool Reverse { get; set; } |
|||
|
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class GroupUserGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public long GroupId { get; set; } |
|||
|
|||
public string Filter { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,15 +1,13 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class MyFriendGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public bool Reverse { get; set; } |
|||
} |
|||
|
|||
public class MyLastContractFriendGetByPagedDto : PagedResultRequestDto |
|||
{ |
|||
} |
|||
} |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class MyFriendGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
} |
|||
|
|||
public class MyLastContractFriendGetByPagedDto : PagedResultRequestDto |
|||
{ |
|||
} |
|||
} |
|||
|
|||
@ -1,16 +1,15 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class UserMessageGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public Guid ReceiveUserId { get; set; } |
|||
public bool Reverse { get; set; } |
|||
public string Filter { get; set; } |
|||
public MessageType? MessageType { get; set; } |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class UserMessageGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
[Required] |
|||
public Guid ReceiveUserId { get; set; } |
|||
public string Filter { get; set; } |
|||
public MessageType? MessageType { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,14 +1,12 @@ |
|||
using LINGYUN.Abp.Notifications; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public class UserNotificationGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public bool Reverse { get; set; } |
|||
|
|||
public NotificationReadState? ReadState { get; set; } |
|||
} |
|||
} |
|||
using LINGYUN.Abp.Notifications; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public class UserNotificationGetByPagedDto : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public NotificationReadState? ReadState { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,136 +1,136 @@ |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
[Authorize] |
|||
public class ChatAppService : ApplicationService, IChatAppService |
|||
{ |
|||
protected IMessageSender MessageSender => LazyServiceProvider.LazyGetRequiredService<IMessageSender>(); |
|||
|
|||
private readonly IUserGroupStore _userGroupStore; |
|||
private readonly IMessageStore _messageStore; |
|||
|
|||
public ChatAppService( |
|||
IMessageStore messageStore, |
|||
IUserGroupStore userGroupStore) |
|||
{ |
|||
_messageStore = messageStore; |
|||
_userGroupStore = userGroupStore; |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto input) |
|||
{ |
|||
var chatMessageCount = await _messageStore |
|||
.GetChatMessageCountAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId, |
|||
input.Filter, input.MessageType); |
|||
|
|||
var chatMessages = await _messageStore |
|||
.GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId, |
|||
input.Filter, input.Sorting, input.Reverse, |
|||
input.MessageType, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<ChatMessage>(chatMessageCount, chatMessages); |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<LastChatMessage>> GetMyLastChatMessageAsync(GetUserLastMessageDto input) |
|||
{ |
|||
var chatMessages = await _messageStore |
|||
.GetLastChatMessagesAsync(CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Sorting, input.Reverse, input.MaxResultCount); |
|||
|
|||
return new ListResultDto<LastChatMessage>(chatMessages); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<ChatMessage>> GetMyGroupMessageAsync(GroupMessageGetByPagedDto input) |
|||
{ |
|||
if (! await _userGroupStore.MemberHasInGroupAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId())) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.YouHaveNotJoinedGroup); |
|||
} |
|||
|
|||
var groupMessageCount = await _messageStore |
|||
.GetGroupMessageCountAsync(CurrentTenant.Id, input.GroupId, |
|||
input.Filter, input.MessageType); |
|||
|
|||
var groupMessages = await _messageStore |
|||
.GetGroupMessageAsync(CurrentTenant.Id, input.GroupId, |
|||
input.Filter, input.Sorting, input.Reverse, |
|||
input.MessageType, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<ChatMessage>(groupMessageCount, groupMessages); |
|||
} |
|||
|
|||
//public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto input)
|
|||
//{
|
|||
// var groupUserCardCount = await _userGroupStore
|
|||
// .GetMembersCountAsync(CurrentTenant.Id, input.GroupId);
|
|||
|
|||
// var groupUserCards = await _userGroupStore.GetMembersAsync(CurrentTenant.Id,
|
|||
// input.GroupId, input.Sorting, input.Reverse,
|
|||
// input.SkipCount, input.MaxResultCount);
|
|||
|
|||
// return new PagedResultDto<GroupUserCard>(groupUserCardCount, groupUserCards);
|
|||
//}
|
|||
|
|||
//[Authorize]
|
|||
//public virtual async Task<ListResultDto<Group>> GetMyGroupsAsync()
|
|||
//{
|
|||
// var myGroups = await _userGroupStore.GetUserGroupsAsync(CurrentTenant.Id, CurrentUser.GetId());
|
|||
|
|||
// return new ListResultDto<Group>(myGroups.ToImmutableList());
|
|||
//}
|
|||
|
|||
//public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto input)
|
|||
//{
|
|||
// var myGroupCard = await _userGroupStore
|
|||
// .GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
|
|||
// if (myGroupCard == null)
|
|||
// {
|
|||
// // 当前登录用户不再用户组
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// if (!myGroupCard.IsAdmin)
|
|||
// {
|
|||
// // 当前登录用户没有加人权限
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// await _userGroupStore
|
|||
// .AddUserToGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId, CurrentUser.GetId());
|
|||
//}
|
|||
|
|||
//public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto input)
|
|||
//{
|
|||
// var myGroupCard = await _userGroupStore
|
|||
// .GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
|
|||
// if (myGroupCard == null)
|
|||
// {
|
|||
// // 当前登录用户不再用户组
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// if (!myGroupCard.IsAdmin)
|
|||
// {
|
|||
// // 当前登录用户没有踢人权限
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// await _userGroupStore
|
|||
// .RemoveUserFormGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId);
|
|||
//}
|
|||
|
|||
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage input) |
|||
{ |
|||
// TODO:向其他租户发送消息?
|
|||
input.TenantId ??= CurrentTenant.Id; |
|||
|
|||
var messageId = await MessageSender.SendMessageAsync(input); |
|||
|
|||
return new ChatMessageSendResultDto(messageId); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
[Authorize] |
|||
public class ChatAppService : ApplicationService, IChatAppService |
|||
{ |
|||
protected IMessageSender MessageSender => LazyServiceProvider.LazyGetRequiredService<IMessageSender>(); |
|||
|
|||
private readonly IUserGroupStore _userGroupStore; |
|||
private readonly IMessageStore _messageStore; |
|||
|
|||
public ChatAppService( |
|||
IMessageStore messageStore, |
|||
IUserGroupStore userGroupStore) |
|||
{ |
|||
_messageStore = messageStore; |
|||
_userGroupStore = userGroupStore; |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto input) |
|||
{ |
|||
var chatMessageCount = await _messageStore |
|||
.GetChatMessageCountAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId, |
|||
input.Filter, input.MessageType); |
|||
|
|||
var chatMessages = await _messageStore |
|||
.GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId, |
|||
input.Filter, input.Sorting, |
|||
input.MessageType, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<ChatMessage>(chatMessageCount, chatMessages); |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<LastChatMessage>> GetMyLastChatMessageAsync(GetUserLastMessageDto input) |
|||
{ |
|||
var chatMessages = await _messageStore |
|||
.GetLastChatMessagesAsync(CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Sorting, input.MaxResultCount); |
|||
|
|||
return new ListResultDto<LastChatMessage>(chatMessages); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<ChatMessage>> GetMyGroupMessageAsync(GroupMessageGetByPagedDto input) |
|||
{ |
|||
if (! await _userGroupStore.MemberHasInGroupAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId())) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.YouHaveNotJoinedGroup); |
|||
} |
|||
|
|||
var groupMessageCount = await _messageStore |
|||
.GetGroupMessageCountAsync(CurrentTenant.Id, input.GroupId, |
|||
input.Filter, input.MessageType); |
|||
|
|||
var groupMessages = await _messageStore |
|||
.GetGroupMessageAsync(CurrentTenant.Id, input.GroupId, |
|||
input.Filter, input.Sorting, |
|||
input.MessageType, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<ChatMessage>(groupMessageCount, groupMessages); |
|||
} |
|||
|
|||
//public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto input)
|
|||
//{
|
|||
// var groupUserCardCount = await _userGroupStore
|
|||
// .GetMembersCountAsync(CurrentTenant.Id, input.GroupId);
|
|||
|
|||
// var groupUserCards = await _userGroupStore.GetMembersAsync(CurrentTenant.Id,
|
|||
// input.GroupId, input.Sorting, input.Reverse,
|
|||
// input.SkipCount, input.MaxResultCount);
|
|||
|
|||
// return new PagedResultDto<GroupUserCard>(groupUserCardCount, groupUserCards);
|
|||
//}
|
|||
|
|||
//[Authorize]
|
|||
//public virtual async Task<ListResultDto<Group>> GetMyGroupsAsync()
|
|||
//{
|
|||
// var myGroups = await _userGroupStore.GetUserGroupsAsync(CurrentTenant.Id, CurrentUser.GetId());
|
|||
|
|||
// return new ListResultDto<Group>(myGroups.ToImmutableList());
|
|||
//}
|
|||
|
|||
//public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto input)
|
|||
//{
|
|||
// var myGroupCard = await _userGroupStore
|
|||
// .GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
|
|||
// if (myGroupCard == null)
|
|||
// {
|
|||
// // 当前登录用户不再用户组
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// if (!myGroupCard.IsAdmin)
|
|||
// {
|
|||
// // 当前登录用户没有加人权限
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// await _userGroupStore
|
|||
// .AddUserToGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId, CurrentUser.GetId());
|
|||
//}
|
|||
|
|||
//public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto input)
|
|||
//{
|
|||
// var myGroupCard = await _userGroupStore
|
|||
// .GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
|
|||
// if (myGroupCard == null)
|
|||
// {
|
|||
// // 当前登录用户不再用户组
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// if (!myGroupCard.IsAdmin)
|
|||
// {
|
|||
// // 当前登录用户没有踢人权限
|
|||
// throw new UserFriendlyException("");
|
|||
// }
|
|||
// await _userGroupStore
|
|||
// .RemoveUserFormGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId);
|
|||
//}
|
|||
|
|||
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage input) |
|||
{ |
|||
// TODO:向其他租户发送消息?
|
|||
input.TenantId ??= CurrentTenant.Id; |
|||
|
|||
var messageId = await MessageSender.SendMessageAsync(input); |
|||
|
|||
return new ChatMessageSendResultDto(messageId); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,66 +1,68 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.MessageService.Localization; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
[Authorize] |
|||
public class MyFriendAppService : ApplicationService, IMyFriendAppService |
|||
{ |
|||
protected IFriendStore FriendStore { get; } |
|||
|
|||
protected IUserChatCardRepository UserChatCardRepository { get; } |
|||
|
|||
public MyFriendAppService( |
|||
IFriendStore friendStore, |
|||
IUserChatCardRepository userChatCardRepository) |
|||
{ |
|||
FriendStore = friendStore; |
|||
UserChatCardRepository = userChatCardRepository; |
|||
|
|||
LocalizationResource = typeof(MessageServiceResource); |
|||
} |
|||
|
|||
public virtual async Task CreateAsync(MyFriendCreateDto input) |
|||
{ |
|||
var friendCard = await UserChatCardRepository.GetMemberAsync(input.FriendId); |
|||
|
|||
await FriendStore.AddMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId, friendCard?.NickName ?? friendCard?.UserName ?? input.FriendId.ToString()); |
|||
} |
|||
|
|||
public virtual async Task AddRequestAsync(MyFriendAddRequestDto input) |
|||
{ |
|||
await FriendStore.AddRequestAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId, input.RemarkName, L["AddNewFriendBySearchId"]); |
|||
} |
|||
|
|||
public virtual async Task DeleteAsync(MyFriendOperationDto input) |
|||
{ |
|||
await FriendStore.RemoveMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId); |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<UserFriend>> GetAllListAsync(GetMyFriendsDto input) |
|||
{ |
|||
var myFriends = await FriendStore |
|||
.GetListAsync(CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Sorting, input.Reverse); |
|||
|
|||
return new ListResultDto<UserFriend>(myFriends); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<UserFriend>> GetListAsync(MyFriendGetByPagedDto input) |
|||
{ |
|||
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId()); |
|||
|
|||
var myFriends = await FriendStore |
|||
.GetPagedListAsync(CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Filter, input.Sorting, input.Reverse, |
|||
input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<UserFriend>(myFrientCount, myFriends); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.MessageService.Localization; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
[Authorize] |
|||
public class MyFriendAppService : ApplicationService, IMyFriendAppService |
|||
{ |
|||
protected IFriendStore FriendStore { get; } |
|||
|
|||
protected IUserChatCardRepository UserChatCardRepository { get; } |
|||
|
|||
public MyFriendAppService( |
|||
IFriendStore friendStore, |
|||
IUserChatCardRepository userChatCardRepository) |
|||
{ |
|||
FriendStore = friendStore; |
|||
UserChatCardRepository = userChatCardRepository; |
|||
|
|||
LocalizationResource = typeof(MessageServiceResource); |
|||
} |
|||
|
|||
public virtual async Task CreateAsync(MyFriendCreateDto input) |
|||
{ |
|||
var friendCard = await UserChatCardRepository.GetMemberAsync(input.FriendId); |
|||
|
|||
await FriendStore.AddMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId, friendCard?.NickName ?? friendCard?.UserName ?? input.FriendId.ToString()); |
|||
} |
|||
|
|||
public virtual async Task AddRequestAsync(MyFriendAddRequestDto input) |
|||
{ |
|||
await FriendStore.AddRequestAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId, input.RemarkName, L["AddNewFriendBySearchId"]); |
|||
} |
|||
|
|||
public virtual async Task DeleteAsync(MyFriendOperationDto input) |
|||
{ |
|||
await FriendStore.RemoveMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId); |
|||
} |
|||
|
|||
public virtual async Task<ListResultDto<UserFriend>> GetAllListAsync(GetMyFriendsDto input) |
|||
{ |
|||
var myFriends = await FriendStore |
|||
.GetListAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
input.Sorting); |
|||
|
|||
return new ListResultDto<UserFriend>(myFriends); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<UserFriend>> GetListAsync(MyFriendGetByPagedDto input) |
|||
{ |
|||
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId()); |
|||
|
|||
var myFriends = await FriendStore |
|||
.GetPagedListAsync(CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Filter, input.Sorting, |
|||
input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<UserFriend>(myFrientCount, myFriends); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,121 +1,121 @@ |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
[Authorize] |
|||
public class MyNotificationAppService : ApplicationService, IMyNotificationAppService |
|||
{ |
|||
protected INotificationSender NotificationSender { get; } |
|||
|
|||
protected INotificationStore NotificationStore { get; } |
|||
|
|||
protected INotificationDefinitionManager NotificationDefinitionManager { get; } |
|||
|
|||
public MyNotificationAppService( |
|||
INotificationStore notificationStore, |
|||
INotificationSender notificationSender, |
|||
INotificationDefinitionManager notificationDefinitionManager) |
|||
{ |
|||
NotificationStore = notificationStore; |
|||
NotificationSender = notificationSender; |
|||
NotificationDefinitionManager = notificationDefinitionManager; |
|||
} |
|||
|
|||
public virtual async Task SendNofiterAsync(NotificationSendDto input) |
|||
{ |
|||
UserIdentifier user = null; |
|||
if (input.ToUserId.HasValue) |
|||
{ |
|||
user = new UserIdentifier(input.ToUserId.Value, input.ToUserName); |
|||
} |
|||
await NotificationSender |
|||
.SendNofiterAsync( |
|||
input.Name, |
|||
input.Data, |
|||
user, |
|||
CurrentTenant.Id, |
|||
input.Severity); |
|||
} |
|||
|
|||
public virtual async Task DeleteAsync(long id) |
|||
{ |
|||
await NotificationStore |
|||
.DeleteUserNotificationAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
id); |
|||
} |
|||
|
|||
public virtual Task<ListResultDto<NotificationGroupDto>> GetAssignableNotifiersAsync() |
|||
{ |
|||
var groups = new List<NotificationGroupDto>(); |
|||
|
|||
foreach (var group in NotificationDefinitionManager.GetGroups()) |
|||
{ |
|||
if (!group.AllowSubscriptionToClients) |
|||
{ |
|||
continue; |
|||
|
|||
} |
|||
var notificationGroup = new NotificationGroupDto |
|||
{ |
|||
Name = group.Name, |
|||
DisplayName = group.DisplayName.Localize(StringLocalizerFactory) |
|||
}; |
|||
|
|||
foreach (var notification in group.Notifications) |
|||
{ |
|||
if (!notification.AllowSubscriptionToClients) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
var notificationChildren = new NotificationDto |
|||
{ |
|||
Name = notification.Name, |
|||
DisplayName = notification.DisplayName.Localize(StringLocalizerFactory), |
|||
Description = notification.Description.Localize(StringLocalizerFactory), |
|||
Lifetime = notification.NotificationLifetime, |
|||
Type = notification.NotificationType |
|||
}; |
|||
|
|||
notificationGroup.Notifications.Add(notificationChildren); |
|||
} |
|||
|
|||
groups.Add(notificationGroup); |
|||
} |
|||
|
|||
return Task.FromResult(new ListResultDto<NotificationGroupDto>(groups)); |
|||
} |
|||
|
|||
public virtual async Task<NotificationInfo> GetAsync(long id) |
|||
{ |
|||
return await NotificationStore |
|||
.GetNotificationOrNullAsync(CurrentTenant.Id, id); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<NotificationInfo>> GetListAsync(UserNotificationGetByPagedDto input) |
|||
{ |
|||
var notificationCount = await NotificationStore |
|||
.GetUserNotificationsCountAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
input.Filter, |
|||
input.ReadState); |
|||
|
|||
var notifications = await NotificationStore |
|||
.GetUserNotificationsAsync( |
|||
CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Filter, input.Sorting, input.Reverse, |
|||
input.ReadState, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<NotificationInfo>(notificationCount, notifications); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Users; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
[Authorize] |
|||
public class MyNotificationAppService : ApplicationService, IMyNotificationAppService |
|||
{ |
|||
protected INotificationSender NotificationSender { get; } |
|||
|
|||
protected INotificationStore NotificationStore { get; } |
|||
|
|||
protected INotificationDefinitionManager NotificationDefinitionManager { get; } |
|||
|
|||
public MyNotificationAppService( |
|||
INotificationStore notificationStore, |
|||
INotificationSender notificationSender, |
|||
INotificationDefinitionManager notificationDefinitionManager) |
|||
{ |
|||
NotificationStore = notificationStore; |
|||
NotificationSender = notificationSender; |
|||
NotificationDefinitionManager = notificationDefinitionManager; |
|||
} |
|||
|
|||
public virtual async Task SendNofiterAsync(NotificationSendDto input) |
|||
{ |
|||
UserIdentifier user = null; |
|||
if (input.ToUserId.HasValue) |
|||
{ |
|||
user = new UserIdentifier(input.ToUserId.Value, input.ToUserName); |
|||
} |
|||
await NotificationSender |
|||
.SendNofiterAsync( |
|||
input.Name, |
|||
input.Data, |
|||
user, |
|||
CurrentTenant.Id, |
|||
input.Severity); |
|||
} |
|||
|
|||
public virtual async Task DeleteAsync(long id) |
|||
{ |
|||
await NotificationStore |
|||
.DeleteUserNotificationAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
id); |
|||
} |
|||
|
|||
public virtual Task<ListResultDto<NotificationGroupDto>> GetAssignableNotifiersAsync() |
|||
{ |
|||
var groups = new List<NotificationGroupDto>(); |
|||
|
|||
foreach (var group in NotificationDefinitionManager.GetGroups()) |
|||
{ |
|||
if (!group.AllowSubscriptionToClients) |
|||
{ |
|||
continue; |
|||
|
|||
} |
|||
var notificationGroup = new NotificationGroupDto |
|||
{ |
|||
Name = group.Name, |
|||
DisplayName = group.DisplayName.Localize(StringLocalizerFactory) |
|||
}; |
|||
|
|||
foreach (var notification in group.Notifications) |
|||
{ |
|||
if (!notification.AllowSubscriptionToClients) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
var notificationChildren = new NotificationDto |
|||
{ |
|||
Name = notification.Name, |
|||
DisplayName = notification.DisplayName.Localize(StringLocalizerFactory), |
|||
Description = notification.Description.Localize(StringLocalizerFactory), |
|||
Lifetime = notification.NotificationLifetime, |
|||
Type = notification.NotificationType |
|||
}; |
|||
|
|||
notificationGroup.Notifications.Add(notificationChildren); |
|||
} |
|||
|
|||
groups.Add(notificationGroup); |
|||
} |
|||
|
|||
return Task.FromResult(new ListResultDto<NotificationGroupDto>(groups)); |
|||
} |
|||
|
|||
public virtual async Task<NotificationInfo> GetAsync(long id) |
|||
{ |
|||
return await NotificationStore |
|||
.GetNotificationOrNullAsync(CurrentTenant.Id, id); |
|||
} |
|||
|
|||
public virtual async Task<PagedResultDto<NotificationInfo>> GetListAsync(UserNotificationGetByPagedDto input) |
|||
{ |
|||
var notificationCount = await NotificationStore |
|||
.GetUserNotificationsCountAsync( |
|||
CurrentTenant.Id, |
|||
CurrentUser.GetId(), |
|||
input.Filter, |
|||
input.ReadState); |
|||
|
|||
var notifications = await NotificationStore |
|||
.GetUserNotificationsAsync( |
|||
CurrentTenant.Id, CurrentUser.GetId(), |
|||
input.Filter, input.Sorting, |
|||
input.ReadState, input.SkipCount, input.MaxResultCount); |
|||
|
|||
return new PagedResultDto<NotificationInfo>(notificationCount, notifications); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,9 +1,9 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Localization |
|||
{ |
|||
[LocalizationResourceName("MessageService")] |
|||
public class MessageServiceResource |
|||
{ |
|||
} |
|||
} |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Localization |
|||
{ |
|||
[LocalizationResourceName("AbpMessageService")] |
|||
public class MessageServiceResource |
|||
{ |
|||
} |
|||
} |
|||
|
|||
@ -1,99 +1,103 @@ |
|||
namespace LINGYUN.Abp.MessageService |
|||
{ |
|||
/// <summary>
|
|||
/// 消息系统错误码设计
|
|||
/// 状态码分为两部分 前2位领域 后3位状态
|
|||
///
|
|||
/// <list type="table">
|
|||
/// 领域部分:
|
|||
/// 01 输入
|
|||
/// 02 群组
|
|||
/// 03 用户
|
|||
/// 04 应用
|
|||
/// 05 内部
|
|||
/// 10 输出
|
|||
/// </list>
|
|||
///
|
|||
/// <list type="table">
|
|||
/// 状态部分:
|
|||
/// 200-299 成功
|
|||
/// 300-399 成功但有后续操作
|
|||
/// 400-499 业务异常
|
|||
/// 500-599 内部异常
|
|||
/// 900-999 输入输出异常
|
|||
/// </list>
|
|||
///
|
|||
/// </summary>
|
|||
public class MessageServiceErrorCodes |
|||
{ |
|||
public const string Namespace = "LINGYUN.Abp.Message"; |
|||
/// <summary>
|
|||
/// 消息不完整
|
|||
/// </summary>
|
|||
public const string MessageIncomplete = Namespace + ":01400"; |
|||
/// <summary>
|
|||
/// 您还未加入群组,不能进行操作
|
|||
/// </summary>
|
|||
public const string YouHaveNotJoinedGroup = Namespace + ":01401"; |
|||
/// <summary>
|
|||
/// 已发送群组申请,等待管理员同意
|
|||
/// </summary>
|
|||
public const string YouHaveAddingToGroup = Namespace + ":02301"; |
|||
/// <summary>
|
|||
/// 你需要验证问题才能加入群聊
|
|||
/// </summary>
|
|||
public const string YouNeedValidationQuestingByAddGroup = Namespace + ":02302"; |
|||
/// <summary>
|
|||
/// 管理员已开启全员禁言
|
|||
/// </summary>
|
|||
public const string GroupNotAllowedToSpeak = Namespace + ":02400"; |
|||
/// <summary>
|
|||
/// 管理员已禁止用户发言
|
|||
/// </summary>
|
|||
public const string GroupUserHasBlack = Namespace + ":02403"; |
|||
/// <summary>
|
|||
/// 管理员不允许匿名发言
|
|||
/// </summary>
|
|||
public const string GroupNotAllowedToSpeakAnonymously = Namespace + ":02401"; |
|||
/// <summary>
|
|||
/// 群组不存在或已解散
|
|||
/// </summary>
|
|||
public const string GroupNotFount = Namespace + ":02404"; |
|||
/// <summary>
|
|||
/// 用户已拒接所有消息
|
|||
/// </summary>
|
|||
public const string UserHasRejectAllMessage = Namespace + ":03400"; |
|||
/// <summary>
|
|||
/// 用户已将发信人拉黑
|
|||
/// </summary>
|
|||
public const string UserHasBlack = Namespace + ":03401"; |
|||
/// <summary>
|
|||
/// 用户不允许匿名发言
|
|||
/// </summary>
|
|||
public const string UserNotAllowedToSpeakAnonymously = Namespace + ":03402"; |
|||
/// <summary>
|
|||
/// 用户不接收非好友发言
|
|||
/// </summary>
|
|||
public const string UserHasRejectNotFriendMessage = Namespace + ":03403"; |
|||
/// <summary>
|
|||
/// 接收消息用户不存在或已注销
|
|||
/// </summary>
|
|||
public const string UseNotFount = Namespace + ":03404"; |
|||
/// <summary>
|
|||
/// 用户拒绝添加好友
|
|||
/// </summary>
|
|||
public const string UseRefuseToAddFriend = Namespace + ":03410"; |
|||
/// <summary>
|
|||
/// 对方已是您的好友或已发送验证请求,不能重复操作
|
|||
/// </summary>
|
|||
public const string UseHasBeenAddedTheFriendOrSendAuthorization = Namespace + ":03411"; |
|||
/// <summary>
|
|||
/// 已发送好友申请,等待对方同意
|
|||
/// </summary>
|
|||
public const string YouHaveAddingTheUserToFriend = Namespace + ":03301"; |
|||
/// <summary>
|
|||
/// 你需要验证问题才能添加好友
|
|||
/// </summary>
|
|||
public const string YouNeedValidationQuestingByAddFriend = Namespace + ":03302"; |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.MessageService |
|||
{ |
|||
/// <summary>
|
|||
/// 消息系统错误码设计
|
|||
/// 状态码分为两部分 前2位领域 后3位状态
|
|||
///
|
|||
/// <list type="table">
|
|||
/// 领域部分:
|
|||
/// 01 输入
|
|||
/// 02 群组
|
|||
/// 03 用户
|
|||
/// 04 应用
|
|||
/// 05 内部
|
|||
/// 10 输出
|
|||
/// </list>
|
|||
///
|
|||
/// <list type="table">
|
|||
/// 状态部分:
|
|||
/// 200-299 成功
|
|||
/// 300-399 成功但有后续操作
|
|||
/// 400-499 业务异常
|
|||
/// 500-599 内部异常
|
|||
/// 900-999 输入输出异常
|
|||
/// </list>
|
|||
///
|
|||
/// </summary>
|
|||
public class MessageServiceErrorCodes |
|||
{ |
|||
public const string Namespace = "LINGYUN.Abp.Message"; |
|||
/// <summary>
|
|||
/// 试图撤回过期消息
|
|||
/// </summary>
|
|||
public const string ExpiredMessageCannotBeReCall = Namespace + ":01303"; |
|||
/// <summary>
|
|||
/// 消息不完整
|
|||
/// </summary>
|
|||
public const string MessageIncomplete = Namespace + ":01400"; |
|||
/// <summary>
|
|||
/// 您还未加入群组,不能进行操作
|
|||
/// </summary>
|
|||
public const string YouHaveNotJoinedGroup = Namespace + ":01401"; |
|||
/// <summary>
|
|||
/// 已发送群组申请,等待管理员同意
|
|||
/// </summary>
|
|||
public const string YouHaveAddingToGroup = Namespace + ":02301"; |
|||
/// <summary>
|
|||
/// 你需要验证问题才能加入群聊
|
|||
/// </summary>
|
|||
public const string YouNeedValidationQuestingByAddGroup = Namespace + ":02302"; |
|||
/// <summary>
|
|||
/// 管理员已开启全员禁言
|
|||
/// </summary>
|
|||
public const string GroupNotAllowedToSpeak = Namespace + ":02400"; |
|||
/// <summary>
|
|||
/// 管理员已禁止用户发言
|
|||
/// </summary>
|
|||
public const string GroupUserHasBlack = Namespace + ":02403"; |
|||
/// <summary>
|
|||
/// 管理员不允许匿名发言
|
|||
/// </summary>
|
|||
public const string GroupNotAllowedToSpeakAnonymously = Namespace + ":02401"; |
|||
/// <summary>
|
|||
/// 群组不存在或已解散
|
|||
/// </summary>
|
|||
public const string GroupNotFount = Namespace + ":02404"; |
|||
/// <summary>
|
|||
/// 用户已拒接所有消息
|
|||
/// </summary>
|
|||
public const string UserHasRejectAllMessage = Namespace + ":03400"; |
|||
/// <summary>
|
|||
/// 用户已将发信人拉黑
|
|||
/// </summary>
|
|||
public const string UserHasBlack = Namespace + ":03401"; |
|||
/// <summary>
|
|||
/// 用户不允许匿名发言
|
|||
/// </summary>
|
|||
public const string UserNotAllowedToSpeakAnonymously = Namespace + ":03402"; |
|||
/// <summary>
|
|||
/// 用户不接收非好友发言
|
|||
/// </summary>
|
|||
public const string UserHasRejectNotFriendMessage = Namespace + ":03403"; |
|||
/// <summary>
|
|||
/// 接收消息用户不存在或已注销
|
|||
/// </summary>
|
|||
public const string UseNotFount = Namespace + ":03404"; |
|||
/// <summary>
|
|||
/// 用户拒绝添加好友
|
|||
/// </summary>
|
|||
public const string UseRefuseToAddFriend = Namespace + ":03410"; |
|||
/// <summary>
|
|||
/// 对方已是您的好友或已发送验证请求,不能重复操作
|
|||
/// </summary>
|
|||
public const string UseHasBeenAddedTheFriendOrSendAuthorization = Namespace + ":03411"; |
|||
/// <summary>
|
|||
/// 已发送好友申请,等待对方同意
|
|||
/// </summary>
|
|||
public const string YouHaveAddingTheUserToFriend = Namespace + ":03301"; |
|||
/// <summary>
|
|||
/// 你需要验证问题才能添加好友
|
|||
/// </summary>
|
|||
public const string YouNeedValidationQuestingByAddFriend = Namespace + ":03302"; |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,30 @@ |
|||
using LINGYUN.Abp.MessageService.Localization; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Settings; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Settings |
|||
{ |
|||
public class MessageServiceSettingDefinitionProvider : SettingDefinitionProvider |
|||
{ |
|||
public override void Define(ISettingDefinitionContext context) |
|||
{ |
|||
context.Add( |
|||
new SettingDefinition( |
|||
MessageServiceSettingNames.Messages.RecallExpirationTime, |
|||
"2", |
|||
L("DisplayName:RecallExpirationTime"), |
|||
L("Description:RecallExpirationTime"), |
|||
isVisibleToClients: false, |
|||
isEncrypted: false) |
|||
.WithProviders( |
|||
GlobalSettingValueProvider.ProviderName, |
|||
TenantSettingValueProvider.ProviderName) |
|||
); |
|||
} |
|||
|
|||
protected ILocalizableString L(string name) |
|||
{ |
|||
return LocalizableString.Create<MessageServiceResource>(name); |
|||
} |
|||
} |
|||
} |
|||
@ -1,16 +1,25 @@ |
|||
namespace LINGYUN.Abp.MessageService |
|||
{ |
|||
public class MessageServiceSettingNames |
|||
{ |
|||
public const string GroupName = "Abp.MessageService"; |
|||
|
|||
public class Notifications |
|||
{ |
|||
public const string Default = GroupName + ".Notifications"; |
|||
/// <summary>
|
|||
/// 清理过期消息批次
|
|||
/// </summary>
|
|||
public const string CleanupExpirationBatchCount = Default + ".CleanupExpirationBatchCount"; |
|||
} |
|||
} |
|||
} |
|||
namespace LINGYUN.Abp.MessageService.Settings |
|||
{ |
|||
public class MessageServiceSettingNames |
|||
{ |
|||
public const string GroupName = "Abp.MessageService"; |
|||
|
|||
public class Notifications |
|||
{ |
|||
public const string Default = GroupName + ".Notifications"; |
|||
/// <summary>
|
|||
/// 清理过期消息批次
|
|||
/// </summary>
|
|||
public const string CleanupExpirationBatchCount = Default + ".CleanupExpirationBatchCount"; |
|||
} |
|||
|
|||
public class Messages |
|||
{ |
|||
public const string Default = GroupName + ".Messages"; |
|||
/// <summary>
|
|||
/// 撤回消息过期时间(分)
|
|||
/// </summary>
|
|||
public const string RecallExpirationTime = Default + ".RecallExpirationTime"; |
|||
} |
|||
} |
|||
} |
|||
@ -1,280 +1,277 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Timing; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class FriendStore : IFriendStore, ITransientDependency |
|||
{ |
|||
private readonly IClock _clock; |
|||
private readonly ILogger _logger; |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IDistributedCache<UserFriendCacheItem> _cache; |
|||
private readonly IUserChatFriendRepository _userChatFriendRepository; |
|||
private readonly IUserChatSettingRepository _userChatSettingRepository; |
|||
|
|||
public FriendStore( |
|||
IClock clock, |
|||
ILogger<FriendStore> logger, |
|||
ICurrentTenant currentTenant, |
|||
IDistributedCache<UserFriendCacheItem> cache, |
|||
IUserChatFriendRepository userChatFriendRepository, |
|||
IUserChatSettingRepository userChatSettingRepository |
|||
) |
|||
{ |
|||
_clock = clock; |
|||
_cache = cache; |
|||
_logger = logger; |
|||
_currentTenant = currentTenant; |
|||
_userChatFriendRepository = userChatFriendRepository; |
|||
_userChatSettingRepository = userChatSettingRepository; |
|||
} |
|||
|
|||
public virtual async Task<bool> IsFriendAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository.IsFriendAsync(userId, friendId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task AddMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
if (!await _userChatFriendRepository.IsAddedAsync(userId, friendId)) |
|||
{ |
|||
var userFriend = new UserChatFriend(userId, friendId, remarkName); |
|||
userFriend.SetStatus(UserFriendStatus.Added); |
|||
|
|||
await _userChatFriendRepository.InsertAsync(userFriend); |
|||
} |
|||
|
|||
var userChatFriend = await _userChatFriendRepository |
|||
.FindByUserFriendIdAsync(friendId, userId); |
|||
|
|||
userChatFriend.SetStatus(UserFriendStatus.Added); |
|||
|
|||
await _userChatFriendRepository.UpdateAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task<UserAddFriendResult> AddRequestAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
string description = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
if (await _userChatFriendRepository.IsAddedAsync(userId, friendId)) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseHasBeenAddedTheFriendOrSendAuthorization); |
|||
} |
|||
|
|||
var status = UserFriendStatus.NeedValidation; |
|||
var userChatSetting = await _userChatSettingRepository.FindByUserIdAsync(friendId, cancellationToken); |
|||
if (userChatSetting != null) |
|||
{ |
|||
if (!userChatSetting.AllowAddFriend) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseRefuseToAddFriend); |
|||
} |
|||
|
|||
status = userChatSetting.RequireAddFriendValition |
|||
? UserFriendStatus.NeedValidation |
|||
: UserFriendStatus.Added; |
|||
} |
|||
|
|||
var userChatFriend = new UserChatFriend(userId, friendId, remarkName, description, tenantId) |
|||
{ |
|||
CreationTime = _clock.Now, |
|||
CreatorId = userId, |
|||
}; |
|||
userChatFriend.SetStatus(status); |
|||
|
|||
await _userChatFriendRepository.InsertAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
|
|||
return new UserAddFriendResult(status); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task AddShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await ChangeFriendShieldAsync(tenantId, userId, friendId, true, cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
bool reverse = false, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await GetAllFriendByCacheItemAsync(userId, sorting, reverse, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMembersCountAsync(userId, filter, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetPagedListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserFriend.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMembersAsync(userId, filter, sorting, reverse, |
|||
skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetLastContactListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetLastContactMembersAsync(userId, |
|||
skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<UserFriend> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMemberAsync(userId, friendId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task RemoveMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userChatFriend = await _userChatFriendRepository.FindByUserFriendIdAsync(userId, friendId, cancellationToken); |
|||
if (userChatFriend != null) |
|||
{ |
|||
await _userChatFriendRepository.DeleteAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task RemoveShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await ChangeFriendShieldAsync(tenantId, userId, friendId, false, cancellationToken); |
|||
} |
|||
|
|||
|
|||
protected virtual async Task ChangeFriendShieldAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
bool isBlack = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userChatFriend = await _userChatFriendRepository.FindByUserFriendIdAsync(userId, friendId, cancellationToken); |
|||
if (userChatFriend != null) |
|||
{ |
|||
userChatFriend.Black = isBlack; |
|||
await _userChatFriendRepository.UpdateAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task<List<UserFriend>> GetAllFriendByCacheItemAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
bool reverse = false, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var cacheKey = UserFriendCacheItem.CalculateCacheKey(userId.ToString()); |
|||
_logger.LogDebug($"FriendStore.GetCacheItemAsync: {cacheKey}"); |
|||
|
|||
var cacheItem = await _cache.GetAsync(cacheKey, token: cancellationToken); |
|||
if (cacheItem != null) |
|||
{ |
|||
_logger.LogDebug($"Found in the cache: {cacheKey}"); |
|||
return cacheItem.Friends; |
|||
} |
|||
|
|||
_logger.LogDebug($"Not found in the cache: {cacheKey}"); |
|||
var friends = await _userChatFriendRepository |
|||
.GetAllMembersAsync(userId, sorting, reverse, cancellationToken); |
|||
cacheItem = new UserFriendCacheItem(friends); |
|||
_logger.LogDebug($"Set item in the cache: {cacheKey}"); |
|||
await _cache.SetAsync(cacheKey, cacheItem, token: cancellationToken); |
|||
return friends; |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using Microsoft.Extensions.Logging; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Timing; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class FriendStore : IFriendStore, ITransientDependency |
|||
{ |
|||
private readonly IClock _clock; |
|||
private readonly ILogger _logger; |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IDistributedCache<UserFriendCacheItem> _cache; |
|||
private readonly IUserChatFriendRepository _userChatFriendRepository; |
|||
private readonly IUserChatSettingRepository _userChatSettingRepository; |
|||
|
|||
public FriendStore( |
|||
IClock clock, |
|||
ILogger<FriendStore> logger, |
|||
ICurrentTenant currentTenant, |
|||
IDistributedCache<UserFriendCacheItem> cache, |
|||
IUserChatFriendRepository userChatFriendRepository, |
|||
IUserChatSettingRepository userChatSettingRepository |
|||
) |
|||
{ |
|||
_clock = clock; |
|||
_cache = cache; |
|||
_logger = logger; |
|||
_currentTenant = currentTenant; |
|||
_userChatFriendRepository = userChatFriendRepository; |
|||
_userChatSettingRepository = userChatSettingRepository; |
|||
} |
|||
|
|||
public virtual async Task<bool> IsFriendAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository.IsFriendAsync(userId, friendId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task AddMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
if (!await _userChatFriendRepository.IsAddedAsync(userId, friendId)) |
|||
{ |
|||
var userFriend = new UserChatFriend(userId, friendId, remarkName); |
|||
userFriend.SetStatus(UserFriendStatus.Added); |
|||
|
|||
await _userChatFriendRepository.InsertAsync(userFriend); |
|||
} |
|||
|
|||
var userChatFriend = await _userChatFriendRepository |
|||
.FindByUserFriendIdAsync(friendId, userId); |
|||
|
|||
userChatFriend.SetStatus(UserFriendStatus.Added); |
|||
|
|||
await _userChatFriendRepository.UpdateAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task<UserAddFriendResult> AddRequestAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
string remarkName = "", |
|||
string description = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
if (await _userChatFriendRepository.IsAddedAsync(userId, friendId)) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseHasBeenAddedTheFriendOrSendAuthorization); |
|||
} |
|||
|
|||
var status = UserFriendStatus.NeedValidation; |
|||
var userChatSetting = await _userChatSettingRepository.FindByUserIdAsync(friendId, cancellationToken); |
|||
if (userChatSetting != null) |
|||
{ |
|||
if (!userChatSetting.AllowAddFriend) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseRefuseToAddFriend); |
|||
} |
|||
|
|||
status = userChatSetting.RequireAddFriendValition |
|||
? UserFriendStatus.NeedValidation |
|||
: UserFriendStatus.Added; |
|||
} |
|||
|
|||
var userChatFriend = new UserChatFriend(userId, friendId, remarkName, description, tenantId) |
|||
{ |
|||
CreationTime = _clock.Now, |
|||
CreatorId = userId, |
|||
}; |
|||
userChatFriend.SetStatus(status); |
|||
|
|||
await _userChatFriendRepository.InsertAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
|
|||
return new UserAddFriendResult(status); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task AddShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await ChangeFriendShieldAsync(tenantId, userId, friendId, true, cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await GetAllFriendByCacheItemAsync(userId, sorting, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMembersCountAsync(userId, filter, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetPagedListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserFriend.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMembersAsync(userId, filter, sorting, |
|||
skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetLastContactListAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetLastContactMembersAsync(userId, |
|||
skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<UserFriend> GetMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatFriendRepository |
|||
.GetMemberAsync(userId, friendId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task RemoveMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userChatFriend = await _userChatFriendRepository.FindByUserFriendIdAsync(userId, friendId, cancellationToken); |
|||
if (userChatFriend != null) |
|||
{ |
|||
await _userChatFriendRepository.DeleteAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public virtual async Task RemoveShieldMemberAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await ChangeFriendShieldAsync(tenantId, userId, friendId, false, cancellationToken); |
|||
} |
|||
|
|||
|
|||
protected virtual async Task ChangeFriendShieldAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
Guid friendId, |
|||
bool isBlack = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userChatFriend = await _userChatFriendRepository.FindByUserFriendIdAsync(userId, friendId, cancellationToken); |
|||
if (userChatFriend != null) |
|||
{ |
|||
userChatFriend.Black = isBlack; |
|||
await _userChatFriendRepository.UpdateAsync(userChatFriend, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task<List<UserFriend>> GetAllFriendByCacheItemAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserFriend.UserId), |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
var cacheKey = UserFriendCacheItem.CalculateCacheKey(userId.ToString()); |
|||
_logger.LogDebug($"FriendStore.GetCacheItemAsync: {cacheKey}"); |
|||
|
|||
var cacheItem = await _cache.GetAsync(cacheKey, token: cancellationToken); |
|||
if (cacheItem != null) |
|||
{ |
|||
_logger.LogDebug($"Found in the cache: {cacheKey}"); |
|||
return cacheItem.Friends; |
|||
} |
|||
|
|||
_logger.LogDebug($"Not found in the cache: {cacheKey}"); |
|||
var friends = await _userChatFriendRepository |
|||
.GetAllMembersAsync(userId, sorting, cancellationToken); |
|||
cacheItem = new UserFriendCacheItem(friends); |
|||
_logger.LogDebug($"Set item in the cache: {cacheKey}"); |
|||
await _cache.SetAsync(cacheKey, cacheItem, token: cancellationToken); |
|||
return friends; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,100 +1,104 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IMessageRepository |
|||
{ |
|||
Task InsertUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserMessage> GetUserMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<GroupMessage> GetGroupMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetUserMessagesCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync( |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
bool reverse = true, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserMessage>> GetUserMessagesAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetGroupMessagesCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<GroupMessage>> GetGroupMessagesAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetUserGroupMessagesCountAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<GroupMessage>> GetUserGroupMessagesAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IMessageRepository |
|||
{ |
|||
Task InsertUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task UpdateUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task UpdateGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserMessage> GetUserMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<GroupMessage> GetGroupMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetUserMessagesCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync( |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserMessage>> GetUserMessagesAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetGroupMessagesCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<GroupMessage>> GetGroupMessagesAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<long> GetUserGroupMessagesCountAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<GroupMessage>> GetUserGroupMessagesAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,38 +1,37 @@ |
|||
using LINGYUN.Abp.IM; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IUserChatCardRepository : IBasicRepository<UserChatCard, long> |
|||
{ |
|||
Task<bool> CheckUserIdExistsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetMemberCountAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserCard>> GetMembersAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserChatCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserCard> GetMemberAsync( |
|||
Guid findUserId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IUserChatCardRepository : IBasicRepository<UserChatCard, long> |
|||
{ |
|||
Task<bool> CheckUserIdExistsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetMemberCountAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserCard>> GetMembersAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserChatCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserCard> GetMemberAsync( |
|||
Guid findUserId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,58 +1,56 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IUserChatFriendRepository : IBasicRepository<UserChatFriend, long> |
|||
{ |
|||
Task<bool> IsFriendAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> IsAddedAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserChatFriend> FindByUserFriendIdAsync( |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetAllMembersAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserChatFriend.RemarkName), |
|||
bool reverse = false, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetMembersCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetMembersAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserChatFriend.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetLastContactMembersAsync( |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserFriend> GetMemberAsync( |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public interface IUserChatFriendRepository : IBasicRepository<UserChatFriend, long> |
|||
{ |
|||
Task<bool> IsFriendAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<bool> IsAddedAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserChatFriend> FindByUserFriendIdAsync( |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetAllMembersAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserChatFriend.RemarkName), |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetMembersCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetMembersAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserChatFriend.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<UserFriend>> GetLastContactMembersAsync( |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserFriend> GetMemberAsync( |
|||
Guid userId, |
|||
Guid friendId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,51 +1,52 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public abstract class Message : CreationAuditedAggregateRoot<long>, IMultiTenant |
|||
{ |
|||
/// <summary>
|
|||
/// 租户
|
|||
/// </summary>
|
|||
public virtual Guid? TenantId { get; protected set; } |
|||
/// <summary>
|
|||
/// 消息标识
|
|||
/// </summary>
|
|||
public virtual long MessageId { get; protected set; } |
|||
/// <summary>
|
|||
/// 发送用户名称
|
|||
/// </summary>
|
|||
public virtual string SendUserName { get; protected set; } |
|||
/// <summary>
|
|||
/// 内容
|
|||
/// </summary>
|
|||
public virtual string Content { get; protected set; } |
|||
/// <summary>
|
|||
/// 消息类型
|
|||
/// </summary>
|
|||
public virtual MessageType Type { get; protected set; } |
|||
/// <summary>
|
|||
/// 发送状态
|
|||
/// </summary>
|
|||
public virtual MessageSendState SendState { get; protected set; } |
|||
protected Message() { } |
|||
public Message(long id, Guid sendUserId, string sendUserName, string content, MessageType type = MessageType.Text) |
|||
{ |
|||
MessageId = id; |
|||
CreatorId = sendUserId; |
|||
SendUserName = sendUserName; |
|||
Content = content; |
|||
Type = type; |
|||
CreationTime = DateTime.Now; |
|||
} |
|||
|
|||
public void ChangeSendState(MessageSendState state = MessageSendState.Send) |
|||
{ |
|||
SendState = state; |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using System; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public abstract class Message : CreationAuditedAggregateRoot<long>, IMultiTenant |
|||
{ |
|||
/// <summary>
|
|||
/// 租户
|
|||
/// </summary>
|
|||
public virtual Guid? TenantId { get; protected set; } |
|||
/// <summary>
|
|||
/// 消息标识
|
|||
/// </summary>
|
|||
public virtual long MessageId { get; protected set; } |
|||
/// <summary>
|
|||
/// 发送用户名称
|
|||
/// </summary>
|
|||
public virtual string SendUserName { get; protected set; } |
|||
/// <summary>
|
|||
/// 内容
|
|||
/// </summary>
|
|||
public virtual string Content { get; protected set; } |
|||
/// <summary>
|
|||
/// 消息类型
|
|||
/// </summary>
|
|||
public virtual MessageType Type { get; protected set; } |
|||
/// <summary>
|
|||
/// 发送状态
|
|||
/// </summary>
|
|||
public virtual MessageState SendState { get; protected set; } |
|||
protected Message() { } |
|||
public Message(long id, Guid sendUserId, string sendUserName, string content, MessageType type = MessageType.Text) |
|||
{ |
|||
MessageId = id; |
|||
CreatorId = sendUserId; |
|||
SendUserName = sendUserName; |
|||
Content = content; |
|||
Type = type; |
|||
CreationTime = DateTime.Now; |
|||
ChangeSendState(); |
|||
} |
|||
|
|||
public void ChangeSendState(MessageState state = MessageState.Send) |
|||
{ |
|||
SendState = state; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,82 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.Settings; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Settings; |
|||
using Volo.Abp.Timing; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class MessageProcessor : IMessageProcessor, ITransientDependency |
|||
{ |
|||
private readonly IClock _clock; |
|||
private readonly IMessageRepository _repository; |
|||
private readonly ISettingProvider _settingProvider; |
|||
|
|||
public MessageProcessor(IMessageRepository repository) |
|||
{ |
|||
_repository = repository; |
|||
} |
|||
|
|||
public virtual async Task ReadAsync(ChatMessage message) |
|||
{ |
|||
if (!message.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
long groupId = long.Parse(message.GroupId); |
|||
var groupMessage = await _repository.GetGroupMessageAsync(groupId); |
|||
groupMessage.ChangeSendState(MessageState.Read); |
|||
|
|||
await _repository.UpdateGroupMessageAsync(groupMessage); |
|||
} |
|||
else |
|||
{ |
|||
long messageId = long.Parse(message.MessageId); |
|||
var userMessage = await _repository.GetUserMessageAsync(messageId); |
|||
userMessage.ChangeSendState(MessageState.Read); |
|||
|
|||
await _repository.UpdateUserMessageAsync(userMessage); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task ReCallAsync(ChatMessage message) |
|||
{ |
|||
var expiration = await _settingProvider.GetAsync( |
|||
MessageServiceSettingNames.Messages.RecallExpirationTime, 2d); |
|||
|
|||
Func<Message, bool> hasExpiredMessage = (Message msg) => |
|||
msg.CreationTime.AddMinutes(expiration) < _clock.Now; |
|||
|
|||
if (!message.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
long groupId = long.Parse(message.GroupId); |
|||
var groupMessage = await _repository.GetGroupMessageAsync(groupId); |
|||
if (hasExpiredMessage(groupMessage)) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.ExpiredMessageCannotBeReCall) |
|||
.WithData("Time", expiration); |
|||
} |
|||
|
|||
groupMessage.ChangeSendState(MessageState.ReCall); |
|||
|
|||
await _repository.UpdateGroupMessageAsync(groupMessage); |
|||
} |
|||
else |
|||
{ |
|||
long messageId = long.Parse(message.MessageId); |
|||
var userMessage = await _repository.GetUserMessageAsync(messageId); |
|||
if (hasExpiredMessage(userMessage)) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.ExpiredMessageCannotBeReCall) |
|||
.WithData("Time", expiration); |
|||
} |
|||
|
|||
userMessage.ChangeSendState(MessageState.ReCall); |
|||
|
|||
await _repository.UpdateUserMessageAsync(userMessage); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,257 +1,254 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class MessageStore : IMessageStore, ITransientDependency |
|||
{ |
|||
private readonly IFriendStore _friendStore; |
|||
|
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
private readonly ICurrentTenant _currentTenant; |
|||
|
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
private readonly IGroupRepository _groupRepository; |
|||
|
|||
private readonly IMessageRepository _messageRepository; |
|||
|
|||
private readonly IUserChatSettingRepository _userChatSettingRepository; |
|||
public MessageStore( |
|||
IFriendStore friendStore, |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IGroupRepository groupRepository, |
|||
IMessageRepository messageRepository, |
|||
IUserChatSettingRepository userChatSettingRepository) |
|||
{ |
|||
_friendStore = friendStore; |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_groupRepository = groupRepository; |
|||
_messageRepository = messageRepository; |
|||
_userChatSettingRepository = userChatSettingRepository; |
|||
} |
|||
|
|||
public virtual async Task StoreMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(chatMessage.TenantId)) |
|||
{ |
|||
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
long groupId = long.Parse(chatMessage.GroupId); |
|||
await StoreGroupMessageAsync(chatMessage, groupId, cancellationToken); |
|||
} |
|||
else |
|||
{ |
|||
await StoreUserMessageAsync(chatMessage, cancellationToken); |
|||
} |
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<ChatMessage>> GetGroupMessageAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var groupMessages = await _messageRepository |
|||
.GetGroupMessagesAsync(groupId, filter, sorting, reverse, type, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
var chatMessages = _objectMapper.Map<List<GroupMessage>, List<ChatMessage>>(groupMessages); |
|||
|
|||
return chatMessages; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<ChatMessage>> GetChatMessageAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userMessages = await _messageRepository |
|||
.GetUserMessagesAsync(sendUserId, receiveUserId, filter, sorting, reverse, type, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
var chatMessages = _objectMapper.Map<List<UserMessage>, List<ChatMessage>>(userMessages); |
|||
|
|||
return chatMessages; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<LastChatMessage>> GetLastChatMessagesAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
bool reverse = true, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository |
|||
.GetLastMessagesByOneFriendAsync(userId, sorting, reverse, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<long> GetGroupMessageCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository.GetCountAsync(groupId, filter, type, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<long> GetChatMessageCountAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository.GetCountAsync(sendUserId, receiveUserId, filter, type, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task StoreUserMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
// 检查接收用户
|
|||
if (!chatMessage.ToUserId.HasValue) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseNotFount); |
|||
} |
|||
|
|||
var myFriend = await _friendStore |
|||
.GetMemberAsync(chatMessage.TenantId, chatMessage.ToUserId.Value, chatMessage.FormUserId, cancellationToken); |
|||
|
|||
var userChatSetting = await _userChatSettingRepository |
|||
.FindByUserIdAsync(chatMessage.ToUserId.Value, cancellationToken); |
|||
|
|||
if (userChatSetting != null) |
|||
{ |
|||
if (!userChatSetting.AllowReceiveMessage) |
|||
{ |
|||
// 当前发送的用户不接收消息
|
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectAllMessage); |
|||
} |
|||
|
|||
if (myFriend == null && !chatMessage.IsAnonymous) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectNotFriendMessage); |
|||
} |
|||
|
|||
if (chatMessage.IsAnonymous && !userChatSetting.AllowAnonymous) |
|||
{ |
|||
// 当前用户不允许匿名发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.UserNotAllowedToSpeakAnonymously); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (myFriend == null) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectNotFriendMessage); |
|||
} |
|||
} |
|||
if (myFriend?.Black == true) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasBlack); |
|||
} |
|||
|
|||
var message = new UserMessage( |
|||
long.Parse(chatMessage.MessageId), |
|||
chatMessage.FormUserId, |
|||
chatMessage.FormUserName, |
|||
chatMessage.Content, |
|||
chatMessage.MessageType); |
|||
|
|||
message.SendToUser(chatMessage.ToUserId.Value); |
|||
message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); |
|||
|
|||
await _messageRepository.InsertUserMessageAsync(message, cancellationToken); |
|||
} |
|||
|
|||
protected virtual async Task StoreGroupMessageAsync( |
|||
ChatMessage chatMessage, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userHasBlacked = await _groupRepository |
|||
.UserHasBlackedAsync(groupId, chatMessage.FormUserId, cancellationToken); |
|||
if (userHasBlacked) |
|||
{ |
|||
// 当前发送的用户已被拉黑
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupUserHasBlack); |
|||
} |
|||
var group = await _groupRepository.GetByIdAsync(groupId, cancellationToken); |
|||
if (!group.AllowSendMessage) |
|||
{ |
|||
// 当前群组不允许发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupNotAllowedToSpeak); |
|||
} |
|||
if (chatMessage.IsAnonymous && !group.AllowAnonymous) |
|||
{ |
|||
// 当前群组不允许匿名发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupNotAllowedToSpeakAnonymously); |
|||
} |
|||
|
|||
var message = new GroupMessage( |
|||
long.Parse(chatMessage.MessageId), |
|||
chatMessage.FormUserId, |
|||
chatMessage.FormUserName, |
|||
chatMessage.Content, |
|||
chatMessage.MessageType); |
|||
|
|||
message.SendToGroup(groupId); |
|||
message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); |
|||
|
|||
await _messageRepository.InsertGroupMessageAsync(message, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class MessageStore : IMessageStore, ITransientDependency |
|||
{ |
|||
private readonly IFriendStore _friendStore; |
|||
|
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
private readonly ICurrentTenant _currentTenant; |
|||
|
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
private readonly IGroupRepository _groupRepository; |
|||
|
|||
private readonly IMessageRepository _messageRepository; |
|||
|
|||
private readonly IUserChatSettingRepository _userChatSettingRepository; |
|||
public MessageStore( |
|||
IFriendStore friendStore, |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IGroupRepository groupRepository, |
|||
IMessageRepository messageRepository, |
|||
IUserChatSettingRepository userChatSettingRepository) |
|||
{ |
|||
_friendStore = friendStore; |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_groupRepository = groupRepository; |
|||
_messageRepository = messageRepository; |
|||
_userChatSettingRepository = userChatSettingRepository; |
|||
} |
|||
|
|||
public virtual async Task StoreMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(chatMessage.TenantId)) |
|||
{ |
|||
if (!chatMessage.GroupId.IsNullOrWhiteSpace()) |
|||
{ |
|||
long groupId = long.Parse(chatMessage.GroupId); |
|||
await StoreGroupMessageAsync(chatMessage, groupId, cancellationToken); |
|||
} |
|||
else |
|||
{ |
|||
await StoreUserMessageAsync(chatMessage, cancellationToken); |
|||
} |
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<ChatMessage>> GetGroupMessageAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var groupMessages = await _messageRepository |
|||
.GetGroupMessagesAsync(groupId, filter, sorting, type, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
var chatMessages = _objectMapper.Map<List<GroupMessage>, List<ChatMessage>>(groupMessages); |
|||
|
|||
return chatMessages; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<ChatMessage>> GetChatMessageAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(ChatMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userMessages = await _messageRepository |
|||
.GetUserMessagesAsync(sendUserId, receiveUserId, filter, sorting, type, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
var chatMessages = _objectMapper.Map<List<UserMessage>, List<ChatMessage>>(userMessages); |
|||
|
|||
return chatMessages; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<LastChatMessage>> GetLastChatMessagesAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default |
|||
) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository |
|||
.GetLastMessagesByOneFriendAsync(userId, sorting, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<long> GetGroupMessageCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository.GetCountAsync(groupId, filter, type, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<long> GetChatMessageCountAsync( |
|||
Guid? tenantId, |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _messageRepository.GetCountAsync(sendUserId, receiveUserId, filter, type, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task StoreUserMessageAsync( |
|||
ChatMessage chatMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
// 检查接收用户
|
|||
if (!chatMessage.ToUserId.HasValue) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UseNotFount); |
|||
} |
|||
|
|||
var myFriend = await _friendStore |
|||
.GetMemberAsync(chatMessage.TenantId, chatMessage.ToUserId.Value, chatMessage.FormUserId, cancellationToken); |
|||
|
|||
var userChatSetting = await _userChatSettingRepository |
|||
.FindByUserIdAsync(chatMessage.ToUserId.Value, cancellationToken); |
|||
|
|||
if (userChatSetting != null) |
|||
{ |
|||
if (!userChatSetting.AllowReceiveMessage) |
|||
{ |
|||
// 当前发送的用户不接收消息
|
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectAllMessage); |
|||
} |
|||
|
|||
if (myFriend == null && !chatMessage.IsAnonymous) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectNotFriendMessage); |
|||
} |
|||
|
|||
if (chatMessage.IsAnonymous && !userChatSetting.AllowAnonymous) |
|||
{ |
|||
// 当前用户不允许匿名发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.UserNotAllowedToSpeakAnonymously); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (myFriend == null) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectNotFriendMessage); |
|||
} |
|||
} |
|||
if (myFriend?.Black == true) |
|||
{ |
|||
throw new BusinessException(MessageServiceErrorCodes.UserHasBlack); |
|||
} |
|||
|
|||
var message = new UserMessage( |
|||
long.Parse(chatMessage.MessageId), |
|||
chatMessage.FormUserId, |
|||
chatMessage.FormUserName, |
|||
chatMessage.Content, |
|||
chatMessage.MessageType); |
|||
|
|||
message.SendToUser(chatMessage.ToUserId.Value); |
|||
message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); |
|||
|
|||
await _messageRepository.InsertUserMessageAsync(message, cancellationToken); |
|||
} |
|||
|
|||
protected virtual async Task StoreGroupMessageAsync( |
|||
ChatMessage chatMessage, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userHasBlacked = await _groupRepository |
|||
.UserHasBlackedAsync(groupId, chatMessage.FormUserId, cancellationToken); |
|||
if (userHasBlacked) |
|||
{ |
|||
// 当前发送的用户已被拉黑
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupUserHasBlack); |
|||
} |
|||
var group = await _groupRepository.GetByIdAsync(groupId, cancellationToken); |
|||
if (!group.AllowSendMessage) |
|||
{ |
|||
// 当前群组不允许发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupNotAllowedToSpeak); |
|||
} |
|||
if (chatMessage.IsAnonymous && !group.AllowAnonymous) |
|||
{ |
|||
// 当前群组不允许匿名发言
|
|||
throw new BusinessException(MessageServiceErrorCodes.GroupNotAllowedToSpeakAnonymously); |
|||
} |
|||
|
|||
var message = new GroupMessage( |
|||
long.Parse(chatMessage.MessageId), |
|||
chatMessage.FormUserId, |
|||
chatMessage.FormUserName, |
|||
chatMessage.Content, |
|||
chatMessage.MessageType); |
|||
|
|||
message.SendToGroup(groupId); |
|||
message.SetProperty(nameof(ChatMessage.IsAnonymous), chatMessage.IsAnonymous); |
|||
|
|||
await _messageRepository.InsertGroupMessageAsync(message, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,51 +1,64 @@ |
|||
using LINGYUN.Abp.IM; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class UserCardFinder : IUserCardFinder, ITransientDependency |
|||
{ |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IUserChatCardRepository _userChatCardRepository; |
|||
|
|||
public UserCardFinder( |
|||
ICurrentTenant currentTenant, |
|||
IUserChatCardRepository userChatCardRepository) |
|||
{ |
|||
_currentTenant = currentTenant; |
|||
_userChatCardRepository = userChatCardRepository; |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync(Guid? tenantId, string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMemberCountAsync(findUserName, startAge, endAge, sex); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserCard>> GetListAsync(Guid? tenantId, string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, string sorting = nameof(UserCard.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMembersAsync(findUserName, startAge, endAge, sex, |
|||
sorting, reverse, skipCount, maxResultCount); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<UserCard> GetMemberAsync(Guid? tenantId, Guid findUserId) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMemberAsync(findUserId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class UserCardFinder : IUserCardFinder, ITransientDependency |
|||
{ |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IUserChatCardRepository _userChatCardRepository; |
|||
|
|||
public UserCardFinder( |
|||
ICurrentTenant currentTenant, |
|||
IUserChatCardRepository userChatCardRepository) |
|||
{ |
|||
_currentTenant = currentTenant; |
|||
_userChatCardRepository = userChatCardRepository; |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMemberCountAsync(findUserName, startAge, endAge, sex); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<UserCard>> GetListAsync( |
|||
Guid? tenantId, |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMembersAsync(findUserName, startAge, endAge, sex, |
|||
sorting, skipCount, maxResultCount); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<UserCard> GetMemberAsync(Guid? tenantId, Guid findUserId) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatCardRepository |
|||
.GetMemberAsync(findUserId); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,80 +1,78 @@ |
|||
using LINGYUN.Abp.IM.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public interface IUserChatGroupRepository : IBasicRepository<UserChatGroup, long> |
|||
{ |
|||
/// <summary>
|
|||
/// 成员是否在群组里
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> MemberHasInGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<GroupUserCard> GetMemberAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员数
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetMembersCountAsync( |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员列表
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="reverse"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<GroupUserCard>> GetMembersAsync( |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取成员所在群组列表
|
|||
/// </summary>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<LINGYUN.Abp.IM.Group.Group>> GetMemberGroupsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 从群组中移除成员
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveMemberFormGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public interface IUserChatGroupRepository : IBasicRepository<UserChatGroup, long> |
|||
{ |
|||
/// <summary>
|
|||
/// 成员是否在群组里
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <returns></returns>
|
|||
Task<bool> MemberHasInGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<GroupUserCard> GetMemberAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员数
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<int> GetMembersCountAsync( |
|||
long groupId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取群组成员列表
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="sorting"></param>
|
|||
/// <param name="skipCount"></param>
|
|||
/// <param name="maxResultCount"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<GroupUserCard>> GetMembersAsync( |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 获取成员所在群组列表
|
|||
/// </summary>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task<List<LINGYUN.Abp.IM.Group.Group>> GetMemberGroupsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
/// <summary>
|
|||
/// 从群组中移除成员
|
|||
/// </summary>
|
|||
/// <param name="groupId"></param>
|
|||
/// <param name="userId"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
Task RemoveMemberFormGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,147 +1,146 @@ |
|||
using LINGYUN.Abp.IM.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public class UserGroupStore : IUserGroupStore, ITransientDependency |
|||
{ |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
private readonly IUserChatGroupRepository _userChatGroupRepository; |
|||
|
|||
public UserGroupStore( |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IUserChatGroupRepository userChatGroupRepository) |
|||
{ |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_userChatGroupRepository = userChatGroupRepository; |
|||
} |
|||
|
|||
public virtual async Task<bool> MemberHasInGroupAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.MemberHasInGroupAsync(groupId, userId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task AddUserToGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
Guid acceptUserId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userHasInGroup = await _userChatGroupRepository.MemberHasInGroupAsync(groupId, userId, cancellationToken); |
|||
if (!userHasInGroup) |
|||
{ |
|||
var userGroup = new UserChatGroup(groupId, userId, acceptUserId, tenantId); |
|||
|
|||
await _userChatGroupRepository.InsertAsync(userGroup, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task<GroupUserCard> GetUserGroupCardAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var groupUserCard = await _userChatGroupRepository.GetMemberAsync(groupId, userId, cancellationToken); |
|||
|
|||
return groupUserCard; |
|||
} |
|||
} |
|||
|
|||
public async Task<IEnumerable<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersAsync(groupId, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task<IEnumerable<LINGYUN.Abp.IM.Group.Group>> GetUserGroupsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMemberGroupsAsync(userId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task RemoveUserFormGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userChatGroupRepository.RemoveMemberFormGroupAsync(groupId, userId, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task<int> GetMembersCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersCountAsync(groupId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task<List<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersAsync(groupId, sorting, reverse, skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Group; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public class UserGroupStore : IUserGroupStore, ITransientDependency |
|||
{ |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
private readonly IUserChatGroupRepository _userChatGroupRepository; |
|||
|
|||
public UserGroupStore( |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IUserChatGroupRepository userChatGroupRepository) |
|||
{ |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_userChatGroupRepository = userChatGroupRepository; |
|||
} |
|||
|
|||
public virtual async Task<bool> MemberHasInGroupAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.MemberHasInGroupAsync(groupId, userId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task AddUserToGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
Guid acceptUserId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userHasInGroup = await _userChatGroupRepository.MemberHasInGroupAsync(groupId, userId, cancellationToken); |
|||
if (!userHasInGroup) |
|||
{ |
|||
var userGroup = new UserChatGroup(groupId, userId, acceptUserId, tenantId); |
|||
|
|||
await _userChatGroupRepository.InsertAsync(userGroup, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task<GroupUserCard> GetUserGroupCardAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var groupUserCard = await _userChatGroupRepository.GetMemberAsync(groupId, userId, cancellationToken); |
|||
|
|||
return groupUserCard; |
|||
} |
|||
} |
|||
|
|||
public async Task<IEnumerable<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersAsync(groupId, cancellationToken: cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task<IEnumerable<LINGYUN.Abp.IM.Group.Group>> GetUserGroupsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMemberGroupsAsync(userId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task RemoveUserFormGroupAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userChatGroupRepository.RemoveMemberFormGroupAsync(groupId, userId, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public async Task<int> GetMembersCountAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersCountAsync(groupId, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public async Task<List<GroupUserCard>> GetMembersAsync( |
|||
Guid? tenantId, |
|||
long groupId, |
|||
string sorting = nameof(GroupUserCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userChatGroupRepository.GetMembersAsync(groupId, sorting, skipCount, maxResultCount, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,48 +1,47 @@ |
|||
using LINGYUN.Abp.Notifications; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public interface IUserNotificationRepository : IBasicRepository<UserNotification, long> |
|||
{ |
|||
Task<bool> AnyAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationsAsync( |
|||
IEnumerable<UserNotification> userNotifications, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserNotification> GetByIdAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<Notification>> GetNotificationsAsync( |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<Notification>> GetListAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(Notification.CreationTime), |
|||
bool reverse = true, |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
using LINGYUN.Abp.Notifications; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public interface IUserNotificationRepository : IBasicRepository<UserNotification, long> |
|||
{ |
|||
Task<bool> AnyAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task InsertUserNotificationsAsync( |
|||
IEnumerable<UserNotification> userNotifications, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<UserNotification> GetByIdAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<Notification>> GetNotificationsAsync( |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<int> GetCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default); |
|||
|
|||
Task<List<Notification>> GetListAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(Notification.CreationTime), |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default); |
|||
} |
|||
} |
|||
|
|||
@ -1,439 +1,438 @@ |
|||
using LINGYUN.Abp.MessageService.Subscriptions; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Timing; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] |
|||
[ExposeServices(typeof(INotificationStore))] |
|||
public class NotificationStore : INotificationStore |
|||
{ |
|||
private readonly IClock _clock; |
|||
|
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
private readonly ICurrentTenant _currentTenant; |
|||
|
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
|
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
private readonly INotificationRepository _notificationRepository; |
|||
|
|||
private readonly IUserNotificationRepository _userNotificationRepository; |
|||
|
|||
private readonly IUserSubscribeRepository _userSubscribeRepository; |
|||
|
|||
public NotificationStore( |
|||
IClock clock, |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IJsonSerializer jsonSerializer, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
INotificationRepository notificationRepository, |
|||
IUserSubscribeRepository userSubscribeRepository, |
|||
IUserNotificationRepository userNotificationRepository |
|||
) |
|||
{ |
|||
_clock = clock; |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_jsonSerializer = jsonSerializer; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_notificationRepository = notificationRepository; |
|||
_userSubscribeRepository = userSubscribeRepository; |
|||
_userNotificationRepository = userNotificationRepository; |
|||
} |
|||
|
|||
public virtual async Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notification = await _userNotificationRepository.GetByIdAsync(userId, notificationId); |
|||
if (notification != null) |
|||
{ |
|||
notification.ChangeReadState(readState); |
|||
await _userNotificationRepository.UpdateAsync(notification); |
|||
|
|||
await unitOfWork.SaveChangesAsync(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var notify = await _notificationRepository.GetByIdAsync(notification.GetId(), cancellationToken); |
|||
await _notificationRepository.DeleteAsync(notify.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
await _notificationRepository.DeleteExpritionAsync(batchCount, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notify = await _userNotificationRepository |
|||
.GetByIdAsync(userId, notificationId, cancellationToken); |
|||
await _userNotificationRepository |
|||
.DeleteAsync(notify.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userSubscribeRepository |
|||
.DeleteUserSubscriptionAsync(notificationName, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscribe = await _userSubscribeRepository |
|||
.GetUserSubscribeAsync(notificationName, userId, cancellationToken); |
|||
await _userSubscribeRepository |
|||
.DeleteAsync(userSubscribe.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userSubscribeRepository |
|||
.DeleteUserSubscriptionAsync(notificationName, identifiers.Select(ids => ids.UserId), cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notification = await _notificationRepository |
|||
.GetByIdAsync(notificationId, cancellationToken); |
|||
|
|||
return _objectMapper.Map<Notification, NotificationInfo>(notification); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptions = new List<UserSubscribe>(); |
|||
|
|||
if (identifiers == null) |
|||
{ |
|||
userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync(notificationName, null, cancellationToken); |
|||
} |
|||
else |
|||
{ |
|||
userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync( |
|||
notificationName, |
|||
identifiers.Select(ids => ids.UserId), |
|||
cancellationToken); |
|||
} |
|||
|
|||
return _objectMapper.Map<List<UserSubscribe>, List<NotificationSubscriptionInfo>>(userSubscriptions); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notifications = await _userNotificationRepository |
|||
.GetNotificationsAsync(userId, readState, maxResultCount, cancellationToken); |
|||
|
|||
return _objectMapper.Map<List<Notification>, List<NotificationInfo>>(notifications); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userNotificationRepository |
|||
.GetCountAsync(userId, filter, readState, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
bool reverse = true, |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notifications = await _userNotificationRepository |
|||
.GetListAsync(userId, filter, sorting, reverse, readState, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
return _objectMapper.Map<List<Notification>, List<NotificationInfo>>(notifications); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptionNames = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync(userId, cancellationToken); |
|||
|
|||
var userSubscriptions = new List<NotificationSubscriptionInfo>(); |
|||
|
|||
userSubscriptionNames.ForEach(name => userSubscriptions.Add( |
|||
new NotificationSubscriptionInfo |
|||
{ |
|||
UserId = userId, |
|||
TenantId = tenantId, |
|||
NotificationName = name |
|||
})); |
|||
|
|||
return userSubscriptions; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesByNameAsync(userName, cancellationToken); |
|||
|
|||
var userSubscriptionInfos = new List<NotificationSubscriptionInfo>(); |
|||
|
|||
userSubscriptions.ForEach(us => userSubscriptionInfos.Add( |
|||
new NotificationSubscriptionInfo |
|||
{ |
|||
UserId = us.UserId, |
|||
TenantId = us.TenantId, |
|||
NotificationName = us.NotificationName |
|||
})); |
|||
|
|||
return userSubscriptionInfos; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var notify = new Notification( |
|||
notification.GetId(), |
|||
notification.Name, |
|||
notification.Data.GetType().AssemblyQualifiedName, |
|||
_jsonSerializer.Serialize(notification.Data), |
|||
notification.Severity, notification.TenantId) |
|||
{ |
|||
CreationTime = _clock.Now, |
|||
Type = notification.Type, |
|||
// TODO: 通知过期时间应该可以配置
|
|||
ExpirationTime = _clock.Now.AddDays(60) |
|||
}; |
|||
|
|||
await _notificationRepository.InsertAsync(notify, cancellationToken: cancellationToken); |
|||
|
|||
notification.Id = notify.NotificationId.ToString(); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|||
await _userNotificationRepository |
|||
.InsertAsync(userNotification, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
|
|||
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) |
|||
{ |
|||
CreationTime = _clock.Now |
|||
}; |
|||
|
|||
await _userSubscribeRepository |
|||
.InsertAsync(userSubscription, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscribes = new List<UserSubscribe>(); |
|||
|
|||
foreach (var identifier in identifiers) |
|||
{ |
|||
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)); |
|||
} |
|||
|
|||
await _userSubscribeRepository |
|||
.InsertUserSubscriptionAsync(userSubscribes, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
return await _userSubscribeRepository |
|||
.UserSubscribeExistsAysnc(notificationName, userId, cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var userNofitications = new List<UserNotification>(); |
|||
foreach (var userId in userIds) |
|||
{ |
|||
// 重复检查
|
|||
// TODO:如果存在很多个订阅用户,这是个隐患
|
|||
if (!await _userNotificationRepository.AnyAsync(userId, notification.GetId(), cancellationToken)) |
|||
{ |
|||
var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|||
userNofitications.Add(userNofitication); |
|||
} |
|||
} |
|||
await _userNotificationRepository |
|||
.InsertUserNotificationsAsync(userNofitications, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.MessageService.Subscriptions; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.Timing; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] |
|||
[ExposeServices(typeof(INotificationStore))] |
|||
public class NotificationStore : INotificationStore |
|||
{ |
|||
private readonly IClock _clock; |
|||
|
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
private readonly ICurrentTenant _currentTenant; |
|||
|
|||
private readonly IJsonSerializer _jsonSerializer; |
|||
|
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
|
|||
private readonly INotificationRepository _notificationRepository; |
|||
|
|||
private readonly IUserNotificationRepository _userNotificationRepository; |
|||
|
|||
private readonly IUserSubscribeRepository _userSubscribeRepository; |
|||
|
|||
public NotificationStore( |
|||
IClock clock, |
|||
IObjectMapper objectMapper, |
|||
ICurrentTenant currentTenant, |
|||
IJsonSerializer jsonSerializer, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
INotificationRepository notificationRepository, |
|||
IUserSubscribeRepository userSubscribeRepository, |
|||
IUserNotificationRepository userNotificationRepository |
|||
) |
|||
{ |
|||
_clock = clock; |
|||
_objectMapper = objectMapper; |
|||
_currentTenant = currentTenant; |
|||
_jsonSerializer = jsonSerializer; |
|||
_unitOfWorkManager = unitOfWorkManager; |
|||
_notificationRepository = notificationRepository; |
|||
_userSubscribeRepository = userSubscribeRepository; |
|||
_userNotificationRepository = userNotificationRepository; |
|||
} |
|||
|
|||
public virtual async Task ChangeUserNotificationReadStateAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
NotificationReadState readState, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notification = await _userNotificationRepository.GetByIdAsync(userId, notificationId); |
|||
if (notification != null) |
|||
{ |
|||
notification.ChangeReadState(readState); |
|||
await _userNotificationRepository.UpdateAsync(notification); |
|||
|
|||
await unitOfWork.SaveChangesAsync(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var notify = await _notificationRepository.GetByIdAsync(notification.GetId(), cancellationToken); |
|||
await _notificationRepository.DeleteAsync(notify.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteNotificationAsync( |
|||
int batchCount, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
{ |
|||
await _notificationRepository.DeleteExpritionAsync(batchCount, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserNotificationAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notify = await _userNotificationRepository |
|||
.GetByIdAsync(userId, notificationId, cancellationToken); |
|||
await _userNotificationRepository |
|||
.DeleteAsync(notify.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteAllUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userSubscribeRepository |
|||
.DeleteUserSubscriptionAsync(notificationName, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscribe = await _userSubscribeRepository |
|||
.GetUserSubscribeAsync(notificationName, userId, cancellationToken); |
|||
await _userSubscribeRepository |
|||
.DeleteAsync(userSubscribe.Id, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task DeleteUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
await _userSubscribeRepository |
|||
.DeleteUserSubscriptionAsync(notificationName, identifiers.Select(ids => ids.UserId), cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<NotificationInfo> GetNotificationOrNullAsync( |
|||
Guid? tenantId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notification = await _notificationRepository |
|||
.GetByIdAsync(notificationId, cancellationToken); |
|||
|
|||
return _objectMapper.Map<Notification, NotificationInfo>(notification); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string notificationName, |
|||
IEnumerable<UserIdentifier> identifiers = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptions = new List<UserSubscribe>(); |
|||
|
|||
if (identifiers == null) |
|||
{ |
|||
userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync(notificationName, null, cancellationToken); |
|||
} |
|||
else |
|||
{ |
|||
userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync( |
|||
notificationName, |
|||
identifiers.Select(ids => ids.UserId), |
|||
cancellationToken); |
|||
} |
|||
|
|||
return _objectMapper.Map<List<UserSubscribe>, List<NotificationSubscriptionInfo>>(userSubscriptions); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notifications = await _userNotificationRepository |
|||
.GetNotificationsAsync(userId, readState, maxResultCount, cancellationToken); |
|||
|
|||
return _objectMapper.Map<List<Notification>, List<NotificationInfo>>(notifications); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<int> GetUserNotificationsCountAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
return await _userNotificationRepository |
|||
.GetCountAsync(userId, filter, readState, cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationInfo>> GetUserNotificationsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(NotificationInfo.CreationTime), |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var notifications = await _userNotificationRepository |
|||
.GetListAsync(userId, filter, sorting, readState, skipCount, maxResultCount, cancellationToken); |
|||
|
|||
return _objectMapper.Map<List<Notification>, List<NotificationInfo>>(notifications); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptionNames = await _userSubscribeRepository |
|||
.GetUserSubscribesAsync(userId, cancellationToken); |
|||
|
|||
var userSubscriptions = new List<NotificationSubscriptionInfo>(); |
|||
|
|||
userSubscriptionNames.ForEach(name => userSubscriptions.Add( |
|||
new NotificationSubscriptionInfo |
|||
{ |
|||
UserId = userId, |
|||
TenantId = tenantId, |
|||
NotificationName = name |
|||
})); |
|||
|
|||
return userSubscriptions; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync( |
|||
Guid? tenantId, |
|||
string userName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscriptions = await _userSubscribeRepository |
|||
.GetUserSubscribesByNameAsync(userName, cancellationToken); |
|||
|
|||
var userSubscriptionInfos = new List<NotificationSubscriptionInfo>(); |
|||
|
|||
userSubscriptions.ForEach(us => userSubscriptionInfos.Add( |
|||
new NotificationSubscriptionInfo |
|||
{ |
|||
UserId = us.UserId, |
|||
TenantId = us.TenantId, |
|||
NotificationName = us.NotificationName |
|||
})); |
|||
|
|||
return userSubscriptionInfos; |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertNotificationAsync( |
|||
NotificationInfo notification, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var notify = new Notification( |
|||
notification.GetId(), |
|||
notification.Name, |
|||
notification.Data.GetType().AssemblyQualifiedName, |
|||
_jsonSerializer.Serialize(notification.Data), |
|||
notification.Severity, notification.TenantId) |
|||
{ |
|||
CreationTime = _clock.Now, |
|||
Type = notification.Type, |
|||
// TODO: 通知过期时间应该可以配置
|
|||
ExpirationTime = _clock.Now.AddDays(60) |
|||
}; |
|||
|
|||
await _notificationRepository.InsertAsync(notify, cancellationToken: cancellationToken); |
|||
|
|||
notification.Id = notify.NotificationId.ToString(); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationAsync( |
|||
NotificationInfo notification, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|||
await _userNotificationRepository |
|||
.InsertAsync(userNotification, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
UserIdentifier identifier, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
|
|||
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) |
|||
{ |
|||
CreationTime = _clock.Now |
|||
}; |
|||
|
|||
await _userSubscribeRepository |
|||
.InsertAsync(userSubscription, cancellationToken: cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task InsertUserSubscriptionAsync( |
|||
Guid? tenantId, |
|||
IEnumerable<UserIdentifier> identifiers, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(tenantId)) |
|||
{ |
|||
var userSubscribes = new List<UserSubscribe>(); |
|||
|
|||
foreach (var identifier in identifiers) |
|||
{ |
|||
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)); |
|||
} |
|||
|
|||
await _userSubscribeRepository |
|||
.InsertUserSubscriptionAsync(userSubscribes, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
|
|||
public virtual async Task<bool> IsSubscribedAsync( |
|||
Guid? tenantId, |
|||
Guid userId, |
|||
string notificationName, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (_currentTenant.Change(tenantId)) |
|||
return await _userSubscribeRepository |
|||
.UserSubscribeExistsAysnc(notificationName, userId, cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationsAsync( |
|||
NotificationInfo notification, |
|||
IEnumerable<Guid> userIds, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
using (var unitOfWork = _unitOfWorkManager.Begin()) |
|||
using (_currentTenant.Change(notification.TenantId)) |
|||
{ |
|||
var userNofitications = new List<UserNotification>(); |
|||
foreach (var userId in userIds) |
|||
{ |
|||
// 重复检查
|
|||
// TODO:如果存在很多个订阅用户,这是个隐患
|
|||
if (!await _userNotificationRepository.AnyAsync(userId, notification.GetId(), cancellationToken)) |
|||
{ |
|||
var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId); |
|||
userNofitications.Add(userNofitication); |
|||
} |
|||
} |
|||
await _userNotificationRepository |
|||
.InsertUserNotificationsAsync(userNofitications, cancellationToken); |
|||
|
|||
await unitOfWork.SaveChangesAsync(cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,254 +1,257 @@ |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreMessageRepository : EfCoreRepository<IMessageServiceDbContext, Message, long>, |
|||
IMessageRepository, ITransientDependency |
|||
{ |
|||
public EfCoreMessageRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<GroupMessage> GetGroupMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.MessageId.Equals(id)) |
|||
.AsNoTracking() |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<GroupMessage>> GetGroupMessagesAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
var groupMessages = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(GroupMessage.MessageId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return groupMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetGroupMessagesCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessagesCount = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
return groupMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task<List<GroupMessage>> GetUserGroupMessagesAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
var groupMessages = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(GroupMessage.MessageId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return groupMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetUserGroupMessagesCountAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessagesCount = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
return groupMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserMessage> GetUserMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => x.MessageId.Equals(id)) |
|||
.AsNoTracking() |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync( |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
bool reverse = true, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting ??= nameof(LastChatMessage.SendTime); |
|||
sorting = reverse ? sorting + " DESC" : sorting; |
|||
|
|||
var dbContext = await GetDbContextAsync(); |
|||
var groupMsgQuery = dbContext.Set<UserMessage>() |
|||
.Where(msg => msg.ReceiveUserId == userId || msg.CreatorId == userId) |
|||
.GroupBy(msg => new { msg.CreatorId, msg.ReceiveUserId }) |
|||
.Select(msg => new |
|||
{ |
|||
msg.Key.CreatorId, |
|||
msg.Key.ReceiveUserId, |
|||
MessageId = msg.Max(x => x.MessageId) |
|||
}); |
|||
|
|||
var userMessageQuery = from msg in dbContext.Set<UserMessage>() |
|||
join gMsg in groupMsgQuery |
|||
on msg.MessageId equals gMsg.MessageId |
|||
select new LastChatMessage |
|||
{ |
|||
Content = msg.Content, |
|||
SendTime = msg.CreationTime, |
|||
FormUserId = msg.CreatorId.Value, |
|||
FormUserName = msg.SendUserName, |
|||
MessageId = msg.MessageId.ToString(), |
|||
MessageType = msg.Type, |
|||
TenantId = msg.TenantId, |
|||
ToUserId = msg.ReceiveUserId |
|||
}; |
|||
|
|||
return await userMessageQuery |
|||
.OrderBy(sorting) |
|||
.Take(maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserMessage>> GetUserMessagesAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
bool reverse = true, |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting ??= nameof(UserMessage.MessageId); |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
var userMessages = await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetUserMessagesCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userMessagesCount = await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task InsertGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.AddAsync(groupMessage, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task InsertUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.AddAsync(userMessage, GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Messages; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using LINGYUN.Abp.MessageService.Group; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreMessageRepository : EfCoreRepository<IMessageServiceDbContext, Message, long>, |
|||
IMessageRepository, ITransientDependency |
|||
{ |
|||
public EfCoreMessageRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<GroupMessage> GetGroupMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.MessageId.Equals(id)) |
|||
.AsNoTracking() |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<GroupMessage>> GetGroupMessagesAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessages = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(GroupMessage.MessageId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return groupMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetGroupMessagesCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessagesCount = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
return groupMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task<List<GroupMessage>> GetUserGroupMessagesAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessages = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Distinct() |
|||
.Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(GroupMessage.MessageId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return groupMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetUserGroupMessagesCountAsync( |
|||
Guid sendUserId, |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var groupMessagesCount = await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
return groupMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync( |
|||
long groupId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.Where(x => x.GroupId.Equals(groupId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<long> GetCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserMessage> GetUserMessageAsync( |
|||
long id, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => x.MessageId.Equals(id)) |
|||
.AsNoTracking() |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync( |
|||
Guid userId, |
|||
string sorting = nameof(LastChatMessage.SendTime), |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var groupMsgQuery = dbContext.Set<UserMessage>() |
|||
.Where(msg => msg.ReceiveUserId == userId || msg.CreatorId == userId) |
|||
.GroupBy(msg => new { msg.CreatorId, msg.ReceiveUserId }) |
|||
.Select(msg => new |
|||
{ |
|||
msg.Key.CreatorId, |
|||
msg.Key.ReceiveUserId, |
|||
MessageId = msg.Max(x => x.MessageId) |
|||
}); |
|||
|
|||
var userMessageQuery = from msg in dbContext.Set<UserMessage>() |
|||
join gMsg in groupMsgQuery |
|||
on msg.MessageId equals gMsg.MessageId |
|||
select new LastChatMessage |
|||
{ |
|||
Content = msg.Content, |
|||
SendTime = msg.CreationTime, |
|||
FormUserId = msg.CreatorId.Value, |
|||
FormUserName = msg.SendUserName, |
|||
MessageId = msg.MessageId.ToString(), |
|||
MessageType = msg.Type, |
|||
TenantId = msg.TenantId, |
|||
ToUserId = msg.ReceiveUserId |
|||
}; |
|||
|
|||
return await userMessageQuery |
|||
.OrderBy(sorting ?? nameof(LastChatMessage.SendTime)) |
|||
.Take(maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserMessage>> GetUserMessagesAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
string sorting = nameof(UserMessage.MessageId), |
|||
MessageType? type = null, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userMessages = await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.OrderBy(sorting ?? nameof(UserMessage.MessageId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userMessages; |
|||
} |
|||
|
|||
public virtual async Task<long> GetUserMessagesCountAsync( |
|||
Guid sendUserId, |
|||
Guid receiveUserId, |
|||
string filter = "", |
|||
MessageType? type = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userMessagesCount = await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) || |
|||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId)) |
|||
.WhereIf(type != null, x => x.Type.Equals(type)) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) |
|||
.LongCountAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userMessagesCount; |
|||
} |
|||
|
|||
public virtual async Task InsertGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbContextAsync()).Set<GroupMessage>() |
|||
.AddAsync(groupMessage, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task UpdateGroupMessageAsync( |
|||
GroupMessage groupMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
(await GetDbContextAsync()).Set<GroupMessage>().Update(groupMessage); |
|||
} |
|||
|
|||
public virtual async Task InsertUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbContextAsync()).Set<UserMessage>() |
|||
.AddAsync(userMessage, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task UpdateUserMessageAsync( |
|||
UserMessage userMessage, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
(await GetDbContextAsync()).Set<UserMessage>().Update(userMessage); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,63 +1,74 @@ |
|||
using LINGYUN.Abp.IM; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreUserChatCardRepository : EfCoreRepository<IMessageServiceDbContext, UserChatCard, long>, IUserChatCardRepository |
|||
{ |
|||
public EfCoreUserChatCardRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<bool> CheckUserIdExistsAsync(Guid userId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucc => ucc.UserId == userId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserCard> GetMemberAsync(Guid findUserId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(ucc => ucc.UserId == findUserId) |
|||
.Select(ucc => ucc.ToUserCard()) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMemberCountAsync(string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName)) |
|||
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value) |
|||
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value) |
|||
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex) |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserCard>> GetMembersAsync(string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, string sorting = nameof(UserChatCard.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting ??= nameof(UserChatCard.UserId); |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName)) |
|||
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value) |
|||
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value) |
|||
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex) |
|||
.OrderBy(sorting) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.Select(ucc => ucc.ToUserCard()) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreUserChatCardRepository : EfCoreRepository<IMessageServiceDbContext, UserChatCard, long>, IUserChatCardRepository |
|||
{ |
|||
public EfCoreUserChatCardRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<bool> CheckUserIdExistsAsync(Guid userId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucc => ucc.UserId == userId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserCard> GetMemberAsync(Guid findUserId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(ucc => ucc.UserId == findUserId) |
|||
.Select(ucc => ucc.ToUserCard()) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMemberCountAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName)) |
|||
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value) |
|||
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value) |
|||
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex) |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserCard>> GetMembersAsync( |
|||
string findUserName = "", |
|||
int? startAge = null, |
|||
int? endAge = null, |
|||
Sex? sex = null, |
|||
string sorting = nameof(UserChatCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName)) |
|||
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value) |
|||
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value) |
|||
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex) |
|||
.OrderBy(sorting ?? nameof(UserChatCard.UserId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.Select(ucc => ucc.ToUserCard()) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,220 +1,221 @@ |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreUserChatFriendRepository : EfCoreRepository<IMessageServiceDbContext, UserChatFriend, long>, IUserChatFriendRepository |
|||
{ |
|||
public EfCoreUserChatFriendRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<UserChatFriend> FindByUserFriendIdAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(ucf => ucf.UserId == userId && ucf.FrientId == friendId) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetAllMembersAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserChatFriend.RemarkName), |
|||
bool reverse = false, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting = reverse ? sorting + " DESC" : sorting; |
|||
|
|||
var dbContext = await GetDbContextAsync(); |
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
// on ucf.FrientId equals ucc.UserId // 查询双向好友的
|
|||
on ucf.UserId equals ucc.UserId |
|||
where ucf.UserId == userId && ucf.Status == UserFriendStatus.Added |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName ?? ucc.NickName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.OrderBy(sorting ?? $"{nameof(UserChatFriend.RemarkName)} DESC") |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserFriend> GetMemberAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId && ucf.FrientId == friendId && ucf.Status == UserFriendStatus.Added |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetMembersAsync(Guid userId, string filter = "", string sorting = nameof(UserChatFriend.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
|
|||
var dbContext = await GetDbContextAsync(); |
|||
// 过滤用户资料
|
|||
var userChatCardQuery = dbContext.Set<UserChatCard>() |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter)); |
|||
|
|||
// 过滤好友资料
|
|||
var userChatFriendQuery = dbContext.Set<UserChatFriend>() |
|||
.Where(ucf => ucf.Status == UserFriendStatus.Added) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter)); |
|||
|
|||
// 组合查询
|
|||
var userFriendQuery = from ucf in userChatFriendQuery |
|||
join ucc in userChatCardQuery // TODO: Need LEFT JOIN?
|
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.OrderBy(sorting) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetLastContactMembersAsync( |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userReceiveMsgQuery = dbContext.Set<UserMessage>() |
|||
.Where(um => um.ReceiveUserId == userId); |
|||
|
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
on ucf.FrientId equals ucc.UserId |
|||
join um in userReceiveMsgQuery |
|||
on ucc.UserId equals um.CreatorId |
|||
where ucf.UserId == userId && ucf.Status == UserFriendStatus.Added |
|||
orderby um.CreationTime descending // 消息创建时间倒序
|
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMembersCountAsync(Guid userId, string filter = "", CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userChatCardQuery = dbContext.Set<UserChatCard>() |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter)); |
|||
|
|||
var userChatFriendQuery = dbContext.Set<UserChatFriend>() |
|||
.Where(ucf => ucf.Status == UserFriendStatus.Added) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter)); |
|||
|
|||
var userFriendQuery = from ucf in userChatFriendQuery |
|||
join ucc in userChatCardQuery |
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId |
|||
select ucc; |
|||
|
|||
return await userFriendQuery |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> IsFriendAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucf => ucf.UserId == userId && ucf.FrientId == frientId && ucf.Status == UserFriendStatus.Added, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> IsAddedAsync(Guid userId, Guid frientId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucf => ucf.UserId == userId && ucf.FrientId == frientId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Contract; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Chat |
|||
{ |
|||
public class EfCoreUserChatFriendRepository : EfCoreRepository<IMessageServiceDbContext, UserChatFriend, long>, IUserChatFriendRepository |
|||
{ |
|||
public EfCoreUserChatFriendRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<UserChatFriend> FindByUserFriendIdAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(ucf => ucf.UserId == userId && ucf.FrientId == friendId) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetAllMembersAsync( |
|||
Guid userId, |
|||
string sorting = nameof(UserChatFriend.RemarkName), |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
// on ucf.FrientId equals ucc.UserId // 查询双向好友的
|
|||
on ucf.UserId equals ucc.UserId |
|||
where ucf.UserId == userId && ucf.Status == UserFriendStatus.Added |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName ?? ucc.NickName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.OrderBy(sorting ?? nameof(UserChatFriend.RemarkName)) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserFriend> GetMemberAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId && ucf.FrientId == friendId && ucf.Status == UserFriendStatus.Added |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetMembersAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(UserChatFriend.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
// 过滤用户资料
|
|||
var userChatCardQuery = dbContext.Set<UserChatCard>() |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter)); |
|||
|
|||
// 过滤好友资料
|
|||
var userChatFriendQuery = dbContext.Set<UserChatFriend>() |
|||
.Where(ucf => ucf.Status == UserFriendStatus.Added) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter)); |
|||
|
|||
// 组合查询
|
|||
var userFriendQuery = from ucf in userChatFriendQuery |
|||
join ucc in userChatCardQuery // TODO: Need LEFT JOIN?
|
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId |
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.OrderBy(sorting ?? nameof(UserChatFriend.UserId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<UserFriend>> GetLastContactMembersAsync( |
|||
Guid userId, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userReceiveMsgQuery = dbContext.Set<UserMessage>() |
|||
.Where(um => um.ReceiveUserId == userId); |
|||
|
|||
var userFriendQuery = from ucf in dbContext.Set<UserChatFriend>() |
|||
join ucc in dbContext.Set<UserChatCard>() |
|||
on ucf.FrientId equals ucc.UserId |
|||
join um in userReceiveMsgQuery |
|||
on ucc.UserId equals um.CreatorId |
|||
where ucf.UserId == userId && ucf.Status == UserFriendStatus.Added |
|||
orderby um.CreationTime descending // 消息创建时间倒序
|
|||
select new UserFriend |
|||
{ |
|||
Age = ucc.Age, |
|||
AvatarUrl = ucc.AvatarUrl, |
|||
Birthday = ucc.Birthday, |
|||
Black = ucf.Black, |
|||
Description = ucc.Description, |
|||
DontDisturb = ucf.DontDisturb, |
|||
FriendId = ucf.FrientId, |
|||
NickName = ucc.NickName, |
|||
RemarkName = ucf.RemarkName, |
|||
Sex = ucc.Sex, |
|||
Sign = ucc.Sign, |
|||
SpecialFocus = ucf.SpecialFocus, |
|||
TenantId = ucf.TenantId, |
|||
UserId = ucf.UserId, |
|||
UserName = ucc.UserName |
|||
}; |
|||
|
|||
return await userFriendQuery |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMembersCountAsync(Guid userId, string filter = "", CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userChatCardQuery = dbContext.Set<UserChatCard>() |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter)); |
|||
|
|||
var userChatFriendQuery = dbContext.Set<UserChatFriend>() |
|||
.Where(ucf => ucf.Status == UserFriendStatus.Added) |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter)); |
|||
|
|||
var userFriendQuery = from ucf in userChatFriendQuery |
|||
join ucc in userChatCardQuery |
|||
on ucf.FrientId equals ucc.UserId |
|||
where ucf.UserId == userId |
|||
select ucc; |
|||
|
|||
return await userFriendQuery |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> IsFriendAsync( |
|||
Guid userId, |
|||
Guid frientId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucf => ucf.UserId == userId && ucf.FrientId == frientId && ucf.Status == UserFriendStatus.Added, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> IsAddedAsync(Guid userId, Guid frientId, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(ucf => ucf.UserId == userId && ucf.FrientId == frientId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,171 +1,167 @@ |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.MessageService.Chat; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Internal; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public class EfCoreUserChatGroupRepository : EfCoreRepository<IMessageServiceDbContext, UserChatGroup, long>, |
|||
IUserChatGroupRepository, ITransientDependency |
|||
{ |
|||
public EfCoreUserChatGroupRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<GroupUserCard> GetMemberAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId && ugc.UserId == userId |
|||
select new GroupUserCard |
|||
{ |
|||
TenantId = uc.TenantId, |
|||
UserId = uc.UserId, |
|||
UserName = uc.UserName, |
|||
Age = uc.Age, |
|||
AvatarUrl = uc.AvatarUrl, |
|||
IsAdmin = ugc.IsAdmin, |
|||
IsSuperAdmin = gp.AdminUserId == uc.UserId, |
|||
GroupId = gp.GroupId, |
|||
Birthday = uc.Birthday, |
|||
Description = uc.Description, |
|||
NickName = ugc.NickName ?? uc.NickName, |
|||
Sex = uc.Sex, |
|||
Sign = uc.Sign |
|||
}; |
|||
|
|||
return await cardQuery |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<GroupUserCard>> GetMembersAsync( |
|||
long groupId, |
|||
string sorting = nameof(UserChatCard.UserId), |
|||
bool reverse = false, |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting ??= nameof(UserChatCard.UserId); |
|||
sorting = reverse ? sorting + " desc" : sorting; |
|||
|
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId |
|||
select new GroupUserCard |
|||
{ |
|||
TenantId = uc.TenantId, |
|||
UserId = uc.UserId, |
|||
UserName = uc.UserName, |
|||
Age = uc.Age, |
|||
AvatarUrl = uc.AvatarUrl, |
|||
IsAdmin = ugc.IsAdmin, |
|||
IsSuperAdmin = gp.AdminUserId == uc.UserId, |
|||
GroupId = gp.GroupId, |
|||
Birthday = uc.Birthday, |
|||
Description = uc.Description, |
|||
NickName = ugc.NickName ?? uc.NickName, |
|||
Sex = uc.Sex, |
|||
Sign = uc.Sign |
|||
}; |
|||
|
|||
return await cardQuery |
|||
.OrderBy(sorting ?? nameof(UserChatCard.UserId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMembersCountAsync( |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId |
|||
select ucg; |
|||
|
|||
return await cardQuery |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> MemberHasInGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserChatGroup>() |
|||
.AnyAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<IM.Group.Group>> GetMemberGroupsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var groupQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
where ucg.UserId.Equals(userId) |
|||
group ucg by new |
|||
{ |
|||
gp.AllowAnonymous, |
|||
gp.AllowSendMessage, |
|||
gp.MaxUserCount, |
|||
gp.Name |
|||
} |
|||
into cg |
|||
select new IM.Group.Group |
|||
{ |
|||
AllowAnonymous = cg.Key.AllowAnonymous, |
|||
AllowSendMessage = cg.Key.AllowSendMessage, |
|||
MaxUserLength = cg.Key.MaxUserCount, |
|||
Name = cg.Key.Name, |
|||
GroupUserCount = cg.Count() |
|||
}; |
|||
|
|||
return await groupQuery |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task RemoveMemberFormGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await DeleteAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId, cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.IM.Group; |
|||
using LINGYUN.Abp.MessageService.Chat; |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Internal; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Group |
|||
{ |
|||
public class EfCoreUserChatGroupRepository : EfCoreRepository<IMessageServiceDbContext, UserChatGroup, long>, |
|||
IUserChatGroupRepository, ITransientDependency |
|||
{ |
|||
public EfCoreUserChatGroupRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<GroupUserCard> GetMemberAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId && ugc.UserId == userId |
|||
select new GroupUserCard |
|||
{ |
|||
TenantId = uc.TenantId, |
|||
UserId = uc.UserId, |
|||
UserName = uc.UserName, |
|||
Age = uc.Age, |
|||
AvatarUrl = uc.AvatarUrl, |
|||
IsAdmin = ugc.IsAdmin, |
|||
IsSuperAdmin = gp.AdminUserId == uc.UserId, |
|||
GroupId = gp.GroupId, |
|||
Birthday = uc.Birthday, |
|||
Description = uc.Description, |
|||
NickName = ugc.NickName ?? uc.NickName, |
|||
Sex = uc.Sex, |
|||
Sign = uc.Sign |
|||
}; |
|||
|
|||
return await cardQuery |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<GroupUserCard>> GetMembersAsync( |
|||
long groupId, |
|||
string sorting = nameof(UserChatCard.UserId), |
|||
int skipCount = 0, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId |
|||
select new GroupUserCard |
|||
{ |
|||
TenantId = uc.TenantId, |
|||
UserId = uc.UserId, |
|||
UserName = uc.UserName, |
|||
Age = uc.Age, |
|||
AvatarUrl = uc.AvatarUrl, |
|||
IsAdmin = ugc.IsAdmin, |
|||
IsSuperAdmin = gp.AdminUserId == uc.UserId, |
|||
GroupId = gp.GroupId, |
|||
Birthday = uc.Birthday, |
|||
Description = uc.Description, |
|||
NickName = ugc.NickName ?? uc.NickName, |
|||
Sex = uc.Sex, |
|||
Sign = uc.Sign |
|||
}; |
|||
|
|||
return await cardQuery |
|||
.OrderBy(sorting ?? nameof(UserChatCard.UserId)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetMembersCountAsync( |
|||
long groupId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var cardQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
join ugc in dbContext.Set<UserGroupCard>() |
|||
on ucg.UserId equals ugc.UserId |
|||
join uc in dbContext.Set<UserChatCard>() |
|||
on ugc.UserId equals uc.UserId |
|||
where gp.GroupId == groupId |
|||
select ucg; |
|||
|
|||
return await cardQuery |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<bool> MemberHasInGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbContextAsync()).Set<UserChatGroup>() |
|||
.AnyAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId, |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<IM.Group.Group>> GetMemberGroupsAsync( |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var groupQuery = from gp in dbContext.Set<ChatGroup>() |
|||
join ucg in dbContext.Set<UserChatGroup>() |
|||
on gp.GroupId equals ucg.GroupId |
|||
where ucg.UserId.Equals(userId) |
|||
group ucg by new |
|||
{ |
|||
gp.AllowAnonymous, |
|||
gp.AllowSendMessage, |
|||
gp.MaxUserCount, |
|||
gp.Name |
|||
} |
|||
into cg |
|||
select new IM.Group.Group |
|||
{ |
|||
AllowAnonymous = cg.Key.AllowAnonymous, |
|||
AllowSendMessage = cg.Key.AllowSendMessage, |
|||
MaxUserLength = cg.Key.MaxUserCount, |
|||
Name = cg.Key.Name, |
|||
GroupUserCount = cg.Count() |
|||
}; |
|||
|
|||
return await groupQuery |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task RemoveMemberFormGroupAsync( |
|||
long groupId, |
|||
Guid userId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await DeleteAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId, cancellationToken: GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,133 +1,129 @@ |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public class EfCoreUserNotificationRepository : EfCoreRepository<IMessageServiceDbContext, UserNotification, long>, |
|||
IUserNotificationRepository, ITransientDependency |
|||
{ |
|||
public EfCoreUserNotificationRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<bool> AnyAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(x => x.NotificationId.Equals(notificationId) && x.UserId.Equals(userId), |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationsAsync( |
|||
IEnumerable<UserNotification> userNotifications, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbSetAsync()).AddRangeAsync(userNotifications, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserNotification> GetByIdAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userNofitication = await (await GetDbSetAsync()) |
|||
.Where(x => x.NotificationId.Equals(notificationId) && x.UserId.Equals(userId)) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userNofitication; |
|||
} |
|||
|
|||
public virtual async Task<List<Notification>> GetNotificationsAsync( |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.OrderBy(nameof(Notification.CreationTime) + " DESC") |
|||
.Take(maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), nf => |
|||
nf.NotificationName.Contains(filter) || |
|||
nf.NotificationTypeName.Contains(filter)) |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<Notification>> GetListAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(Notification.CreationTime), |
|||
bool reverse = true, |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
sorting ??= nameof(Notification.CreationTime); |
|||
sorting = reverse ? sorting + " DESC" : sorting; |
|||
|
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), nf => |
|||
nf.NotificationName.Contains(filter) || |
|||
nf.NotificationTypeName.Contains(filter)) |
|||
.OrderBy(sorting) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
using LINGYUN.Abp.MessageService.EntityFrameworkCore; |
|||
using LINGYUN.Abp.Notifications; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Linq.Dynamic.Core; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace LINGYUN.Abp.MessageService.Notifications |
|||
{ |
|||
public class EfCoreUserNotificationRepository : EfCoreRepository<IMessageServiceDbContext, UserNotification, long>, |
|||
IUserNotificationRepository, ITransientDependency |
|||
{ |
|||
public EfCoreUserNotificationRepository( |
|||
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<bool> AnyAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.AnyAsync(x => x.NotificationId.Equals(notificationId) && x.UserId.Equals(userId), |
|||
GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task InsertUserNotificationsAsync( |
|||
IEnumerable<UserNotification> userNotifications, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await (await GetDbSetAsync()).AddRangeAsync(userNotifications, GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<UserNotification> GetByIdAsync( |
|||
Guid userId, |
|||
long notificationId, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var userNofitication = await (await GetDbSetAsync()) |
|||
.Where(x => x.NotificationId.Equals(notificationId) && x.UserId.Equals(userId)) |
|||
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
|||
|
|||
return userNofitication; |
|||
} |
|||
|
|||
public virtual async Task<List<Notification>> GetNotificationsAsync( |
|||
Guid userId, |
|||
NotificationReadState? readState = null, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.OrderBy(nameof(Notification.CreationTime) + " DESC") |
|||
.Take(maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<int> GetCountAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
NotificationReadState? readState = null, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), nf => |
|||
nf.NotificationName.Contains(filter) || |
|||
nf.NotificationTypeName.Contains(filter)) |
|||
.CountAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<Notification>> GetListAsync( |
|||
Guid userId, |
|||
string filter = "", |
|||
string sorting = nameof(Notification.CreationTime), |
|||
NotificationReadState? readState = null, |
|||
int skipCount = 1, |
|||
int maxResultCount = 10, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
var dbContext = await GetDbContextAsync(); |
|||
var userNotifilerQuery = dbContext.Set<UserNotification>() |
|||
.Where(x => x.UserId == userId) |
|||
.WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); |
|||
|
|||
var notifilerQuery = from un in userNotifilerQuery |
|||
join n in dbContext.Set<Notification>() |
|||
on un.NotificationId equals n.NotificationId |
|||
select n; |
|||
|
|||
return await notifilerQuery |
|||
.WhereIf(!filter.IsNullOrWhiteSpace(), nf => |
|||
nf.NotificationName.Contains(filter) || |
|||
nf.NotificationTypeName.Contains(filter)) |
|||
.OrderBy(sorting ??= nameof(Notification.CreationTime)) |
|||
.PageBy(skipCount, maxResultCount) |
|||
.AsNoTracking() |
|||
.ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,20 +1,33 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
|
|||
namespace AuthServer.Host |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AuthIdentityServerModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Logging; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace AuthServer.Host |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AuthIdentityServerModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,13 +1,14 @@ |
|||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 |
|||
LABEL maintainer="colin.in@foxmail.com" |
|||
WORKDIR /app |
|||
|
|||
COPY . /app |
|||
|
|||
ENV TZ=Asia/Shanghai |
|||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone |
|||
|
|||
EXPOSE 80/tcp |
|||
VOLUME [ "./app/Logs" ] |
|||
|
|||
ENTRYPOINT ["dotnet", "LINGYUN.Abp.BackendAdmin.HttpApi.Host.dll"] |
|||
FROM mcr.microsoft.com/dotnet/aspnet:5.0 |
|||
LABEL maintainer="colin.in@foxmail.com" |
|||
WORKDIR /app |
|||
|
|||
COPY . /app |
|||
|
|||
ENV TZ=Asia/Shanghai |
|||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone |
|||
|
|||
EXPOSE 80/tcp |
|||
VOLUME [ "./app/Logs" ] |
|||
VOLUME [ "./app/Modules" ] |
|||
|
|||
ENTRYPOINT ["dotnet", "LINGYUN.Abp.BackendAdmin.HttpApi.Host.dll"] |
|||
|
|||
@ -1,20 +1,20 @@ |
|||
{ |
|||
"iisSettings": { |
|||
"windowsAuthentication": false, |
|||
"anonymousAuthentication": true, |
|||
"iisExpress": { |
|||
"applicationUrl": "http://localhost:54521", |
|||
"sslPort": 0 |
|||
} |
|||
}, |
|||
"profiles": { |
|||
"LINGYUN.Abp.BackendAdminApp.Host": { |
|||
"commandName": "Project", |
|||
"launchBrowser": false, |
|||
"applicationUrl": "http://0.0.0.0:30010", |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
{ |
|||
"iisSettings": { |
|||
"windowsAuthentication": false, |
|||
"anonymousAuthentication": true, |
|||
"iisExpress": { |
|||
"applicationUrl": "http://localhost:54521", |
|||
"sslPort": 0 |
|||
} |
|||
}, |
|||
"profiles": { |
|||
"LINGYUN.Abp.BackendAdminApp.Host": { |
|||
"commandName": "Project", |
|||
"launchBrowser": false, |
|||
"applicationUrl": "http://0.0.0.0:30010", |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.BackendAdmin |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<BackendAdminHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.Abp.BackendAdmin |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<BackendAdminHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.ApiGateway |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<ApiGatewayHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.ApiGateway |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<ApiGatewayHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.ApiGateway |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<ApiGatewayHttpApiHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.ApiGateway |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<ApiGatewayHttpApiHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer4 |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpIdentityServerAdminHttpApiHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.Abp.IdentityServer4 |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpIdentityServerAdminHttpApiHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,25 +1,38 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpLocalizationManagementHttpApiHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.Abp.LocalizationManagement |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpLocalizationManagementHttpApiHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Abp.MessageService |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpMessageServiceHttpApiHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.Abp.MessageService |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AbpMessageServiceHttpApiHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,18 +1,31 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
|
|||
namespace LINGYUN.Platform |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AppPlatformHttpApiHostModule>(); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.Platform |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<AppPlatformHttpApiHostModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,9 +1,9 @@ |
|||
. "./build-aspnetcore-common.ps1" |
|||
|
|||
# Build all solutions |
|||
foreach ($service in $serviceArray) { |
|||
Set-Location $service.Path |
|||
dotnet ef database update |
|||
} |
|||
|
|||
. "./build-aspnetcore-common.ps1" |
|||
|
|||
# Build all solutions |
|||
foreach ($service in $serviceArray) { |
|||
Set-Location $service.Path |
|||
dotnet ef database update |
|||
} |
|||
|
|||
Set-Location $rootFolder |
|||
@ -0,0 +1,31 @@ |
|||
# COMMON PATHS |
|||
|
|||
$rootFolder = (Get-Item -Path "./" -Verbose).FullName |
|||
|
|||
# List of solutions used only in development mode |
|||
$dependenciesFile = Join-Path $rootFolder "../build/modules.dependencies.json" |
|||
|
|||
function ReadFile($path) { |
|||
return (Get-Content -Raw -Encoding "UTF8" -Path "$path" ) |
|||
} |
|||
|
|||
function ReadJsonFile($path) { |
|||
$content = ReadFile $path |
|||
return ConvertFrom-Json -InputObject $content |
|||
} |
|||
|
|||
$modules = (ReadJsonFile -path $dependenciesFile) |
|||
|
|||
foreach ($module in $modules) { |
|||
foreach ($dependencieRoot in $module.dependencies) { |
|||
foreach ($dependencie in $dependencieRoot.dependencies) { |
|||
$thisPath = Join-Path $rootFolder $dependencieRoot.depPath |
|||
$modulePath = Join-Path $rootFolder $dependencieRoot.path |
|||
Write-host $thisPath |
|||
if (!(Test-Path $modulePath)) { |
|||
New-Item -ItemType Directory -Force -Path $modulePath |
|||
} |
|||
Copy-Item (Join-Path $thisPath $dependencie) -Destination $modulePath |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
[ |
|||
{ |
|||
"tag": "net5.0", |
|||
"dependencies": [ |
|||
{ |
|||
"service": "Backend-Admin", |
|||
"path": "/../aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Modules/", |
|||
"depPath": "/../aspnet-core/LocalNuget/net5.0/", |
|||
"dependencies": [ |
|||
"LINGYUN.ApiGateway.Application.Contracts.dll", |
|||
"LINGYUN.ApiGateway.Domain.Shared.dll", |
|||
"LINGYUN.Abp.Aliyun.SettingManagement.dll", |
|||
"LINGYUN.Abp.Sms.Aliyun.dll", |
|||
"LINGYUN.Abp.Aliyun.dll", |
|||
"LINGYUN.Abp.WeChat.MiniProgram.dll", |
|||
"LINGYUN.Abp.WeChat.Official.dll", |
|||
"LINGYUN.Abp.WeChat.dll", |
|||
"LINGYUN.Abp.WeChat.SettingManagement.dll", |
|||
"LINGYUN.Abp.LocalizationManagement.Application.Contracts.dll", |
|||
"LINGYUN.Abp.LocalizationManagement.Domain.Shared.dll", |
|||
"LINGYUN.Abp.OssManagement.Application.Contracts.dll", |
|||
"LINGYUN.Abp.OssManagement.Domain.Shared.dll", |
|||
"LINGYUN.Abp.MessageService.Application.Contracts.dll", |
|||
"LINGYUN.Abp.IM.dll", |
|||
"LINGYUN.Abp.MessageService.Domain.Shared.dll", |
|||
"LINGYUN.Abp.RealTime.dll", |
|||
"LINGYUN.Abp.Notifications.dll", |
|||
"LINGYUN.Platform.Application.Contracts.dll", |
|||
"LINGYUN.Platform.Domain.Shared.dll" |
|||
] |
|||
}, |
|||
{ |
|||
"service": "Backend-Admin", |
|||
"path": "/../aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/Modules/", |
|||
"depPath": "/../aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/bin/Debug/net5.0", |
|||
"dependencies": [ |
|||
"LINGYUN.Abp.Account.Application.Contracts.dll", |
|||
"Volo.Abp.Account.Application.Contracts.dll", |
|||
"Volo.Abp.Identity.Application.Contracts.dll", |
|||
"LINGYUN.Abp.Identity.Application.Contracts.dll", |
|||
"LINGYUN.Abp.Identity.Domain.Shared.dll", |
|||
"Volo.Abp.Identity.Domain.Shared.dll", |
|||
"Volo.Abp.Users.Domain.Shared.dll", |
|||
"Volo.Abp.Users.Abstractions.dll", |
|||
"LINGYUN.Abp.IdentityServer.Application.Contracts.dll", |
|||
"Volo.Abp.IdentityServer.Domain.Shared.dll" |
|||
] |
|||
} |
|||
] |
|||
} |
|||
] |
|||
Loading…
Reference in new issue