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