diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs new file mode 100644 index 000000000..ff6315a5b --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using System.Linq; + +namespace LINGYUN.Abp.IM.Group +{ + public class GroupUserCard : UserCard + { + public long GroupId { get; set; } + public bool IsAdmin { get; set; } + public bool IsSuperAdmin { get; set; } + public IDictionary Permissions { get; set; } + public GroupUserCard() + { + Permissions = new Dictionary(); + } + + public bool IsGrant(string key) + { + return Permissions.Any(x => x.Equals(key) && x.Value); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs index 85f5f620e..ccd152c80 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs @@ -6,6 +6,14 @@ namespace LINGYUN.Abp.IM.Group { public interface IUserGroupStore { + /// + /// 获取群组用户身份 + /// + /// + /// + /// + /// + Task GetUserGroupCardAsync(Guid? tenantId, long groupId, Guid userId); /// /// 获取用户所在通讯组列表 /// @@ -21,6 +29,25 @@ namespace LINGYUN.Abp.IM.Group /// Task> GetGroupUsersAsync(Guid? tenantId, long groupId); /// + /// 获取通讯组用户数 + /// + /// + /// + /// + /// + Task GetGroupUsersCountAsync(Guid? tenantId, long groupId, string filter = ""); + /// + /// 获取通讯组用户 + /// + /// + /// + /// + /// + /// + /// + /// + Task> GetGroupUsersAsync(Guid? tenantId, long groupId, string filter = "", string sorting = nameof(UserGroup.UserId), int skipCount = 1, int maxResultCount = 10); + /// /// 用户加入通讯组 /// /// diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs index b8be51000..abc64135e 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs @@ -15,13 +15,32 @@ namespace LINGYUN.Abp.IM.Messages /// Task StoreMessageAsync(ChatMessage chatMessage); /// + /// 获取群组聊天记录总数 + /// + /// + /// + /// + /// + /// + Task GetGroupMessageCountAsync(Guid? tenantId, long groupId, string filter = "", MessageType? type = null); + /// /// 获取群组聊天记录 /// /// /// /// /// - Task> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); + Task> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10); + /// + /// 获取与某个用户的聊天记录总数 + /// + /// + /// + /// + /// + /// + /// + Task GetChatMessageCountAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null); /// /// 获取与某个用户的聊天记录 /// @@ -29,7 +48,6 @@ namespace LINGYUN.Abp.IM.Messages /// /// /// - Task> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); - + Task> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs new file mode 100644 index 000000000..ef6b03503 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs @@ -0,0 +1,48 @@ +using System; + +namespace LINGYUN.Abp.IM +{ + public class UserCard + { + public Guid? TenantId { get; set; } + public Guid UserId { get; set; } + + #region 下一个版本细粒度的用户资料 与Identity集成 + + public string UserName { get; set; } + /// + /// 头像 + /// + public string AvatarlUrl { get; set; } + /// + /// 昵称 + /// + public string NickName { get; set; } + /// + /// 年龄 + /// + public int Arg { get; set; } + /// + /// 性别 + /// + public string Sex { get; set; } + /// + /// 国家 + /// + public string Countriy { get; set; } + /// + /// 省份 + /// + public string Province { get; set; } + /// + /// 城市 + /// + public string City { get; set; } + /// + /// 签名 + /// + public string Sign { get; set; } + + #endregion + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs index 6b71643f6..441086346 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs @@ -55,10 +55,8 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp var weChatWeAppNotificationData = new WeChatWeAppSendNotificationData(identifier.UserName, templateId, redirect, weAppState, weAppLang); - // 写入模板数据 weChatWeAppNotificationData.WriteStandardData(NotificationData.ToStandardData(Options.DefaultMsgPrefix, notification.Data)); - // weChatWeAppNotificationData.WriteData(Options.DefaultMsgPrefix, notification.Data.Properties); Logger.LogDebug($"Sending wechat weapp notification: {notification.Name}"); // 发送小程序订阅消息 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs index 45289f231..92b052240 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationOptions.cs @@ -7,10 +7,13 @@ namespace LINGYUN.Abp.Notifications public ITypeList DefinitionProviders { get; } public ITypeList PublishProviders { get; } + + public NotificationDataMappingDictionary NotificationDataMappings { get; } public AbpNotificationOptions() { PublishProviders = new TypeList(); DefinitionProviders = new TypeList(); + NotificationDataMappings = new NotificationDataMappingDictionary(); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs index b4802b2bd..3548976f2 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; @@ -23,6 +24,10 @@ namespace LINGYUN.Abp.Notifications.Internal /// public IDistributedEventBus DistributedEventBus { get; set; } /// + /// Reference to . + /// + private readonly AbpNotificationOptions _notificationOptions; + /// /// Reference to . /// private readonly IBackgroundJobManager _backgroundJobManager; @@ -43,13 +48,13 @@ namespace LINGYUN.Abp.Notifications.Internal /// public DefaultNotificationDispatcher( IBackgroundJobManager backgroundJobManager, - + IOptions options, INotificationStore notificationStore, INotificationDefinitionManager notificationDefinitionManager, INotificationPublishProviderManager notificationPublishProviderManager) { _backgroundJobManager = backgroundJobManager; - + _notificationOptions = options.Value; _notificationStore = notificationStore; _notificationDefinitionManager = notificationDefinitionManager; _notificationPublishProviderManager = notificationPublishProviderManager; @@ -184,7 +189,12 @@ namespace LINGYUN.Abp.Notifications.Internal try { Logger.LogDebug($"Sending notification with provider {provider.Name}"); - + var notifacationDataMapping = _notificationOptions.NotificationDataMappings + .GetMapItemOrNull(provider.Name, notificationInfo.CateGory); + if (notifacationDataMapping != null) + { + notificationInfo.Data = notifacationDataMapping.MappingFunc(notificationInfo.Data); + } // 发布 await provider.PublishAsync(notificationInfo, subscriptionUserIdentifiers); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionary.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionary.cs new file mode 100644 index 000000000..008355e2a --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionary.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace LINGYUN.Abp.Notifications +{ + public class NotificationDataMappingDictionary : Dictionary> + { + public void Mapping(string cateGory, string provider, Func func) + { + if (ContainsKey(cateGory)) + { + this[cateGory] = new List(); + } + this[cateGory].Add(new NotificationDataMappingDictionaryItem(provider, func)); + } + + public void MappingAll(string provider, Func func) + { + foreach(var mapping in this) + { + Mapping(mapping.Key, provider, func); + } + } + + public NotificationDataMappingDictionaryItem GetMapItemOrNull(string cateGory, string provider) + { + if (ContainsKey(cateGory)) + { + return this[cateGory].FirstOrDefault(map => map.Provider.Equals(provider)); + } + return null; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionaryItem.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionaryItem.cs new file mode 100644 index 000000000..24a82a7ad --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDataMappingDictionaryItem.cs @@ -0,0 +1,16 @@ +using System; + +namespace LINGYUN.Abp.Notifications +{ + public class NotificationDataMappingDictionaryItem + { + public string Provider { get; } + + public Func MappingFunc { get; } + public NotificationDataMappingDictionaryItem(string prodiver, Func func) + { + Provider = prodiver; + MappingFunc = func; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs index 2ae41faff..194739e49 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationPublishJob.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using System; using System.Threading.Tasks; using Volo.Abp.BackgroundJobs; @@ -8,14 +9,17 @@ namespace LINGYUN.Abp.Notifications { public class NotificationPublishJob : AsyncBackgroundJob, ITransientDependency { + protected AbpNotificationOptions Options { get; } protected INotificationStore Store { get; } protected IServiceProvider ServiceProvider { get; } public NotificationPublishJob( + IOptions options, INotificationStore store, IServiceProvider serviceProvider) { Store = store; + Options = options.Value; ServiceProvider = serviceProvider; } @@ -26,7 +30,12 @@ namespace LINGYUN.Abp.Notifications if (ServiceProvider.GetRequiredService(providerType) is INotificationPublishProvider publishProvider) { var notification = await Store.GetNotificationOrNullAsync(args.TenantId, args.NotificationId); - + var notifacationDataMapping = Options.NotificationDataMappings + .GetMapItemOrNull(publishProvider.Name, notification.CateGory); + if (notifacationDataMapping != null) + { + notification.Data = notifacationDataMapping.MappingFunc(notification.Data); + } await publishProvider.PublishAsync(notification, args.UserIdentifiers); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.WeChat.Authorization/LINGYUN.Abp.WeChat.Authorization.csproj b/aspnet-core/modules/common/LINGYUN.Abp.WeChat.Authorization/LINGYUN.Abp.WeChat.Authorization.csproj index 95b04ed53..46b1f68bd 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.WeChat.Authorization/LINGYUN.Abp.WeChat.Authorization.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.WeChat.Authorization/LINGYUN.Abp.WeChat.Authorization.csproj @@ -3,6 +3,13 @@ netstandard2.0 + true + 2.9.0 + LINGYUN + + + + D:\LocalNuget diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj new file mode 100644 index 000000000..99b0704d5 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj @@ -0,0 +1,29 @@ + + + + netstandard2.0 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs new file mode 100644 index 000000000..000532693 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs @@ -0,0 +1,26 @@ +using LINGYUN.Abp.MessageService.Localization; +using Volo.Abp.Localization; +using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; + +namespace LINGYUN.Abp.MessageService +{ + [DependsOn(typeof(AbpMessageServiceDomainSharedModule))] + public class AbpMessageServiceApplicationContrantsModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + + Configure(options => + { + options.Resources + .Get() + .AddVirtualJson("/LINGYUN/Abp/MessageService/Localization/ApplicationContracts"); + }); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceConsts.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceConsts.cs new file mode 100644 index 000000000..d0b58ada0 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceConsts.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.MessageService +{ + public class AbpMessageServiceConsts + { + public const string RemoteServiceName = "MessageService"; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/ChatMessageSendResultDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/ChatMessageSendResultDto.cs new file mode 100644 index 000000000..c400f6b94 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/ChatMessageSendResultDto.cs @@ -0,0 +1,11 @@ +namespace LINGYUN.Abp.MessageService.Chat +{ + public class ChatMessageSendResultDto + { + public string MessageId { get; } + public ChatMessageSendResultDto(string messageId) + { + MessageId = messageId; + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupAcceptUserDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupAcceptUserDto.cs new file mode 100644 index 000000000..667d2dad8 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupAcceptUserDto.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class GroupAcceptUserDto + { + [Required] + public Guid UserId { get; set; } + + [Required] + public long GroupId { get; set; } + + public bool AllowAccept { get; set; } = true; + + [StringLength(64)] + public string RejectReason { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs new file mode 100644 index 000000000..6c64ff096 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs @@ -0,0 +1,14 @@ +using LINGYUN.Abp.IM.Messages; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class GroupMessageGetByPagedDto : PagedAndSortedResultRequestDto + { + [Required] + public long GroupId { get; set; } + public string Filter { get; set; } + public MessageType? MessageType { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupRemoveUserDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupRemoveUserDto.cs new file mode 100644 index 000000000..3996c4f29 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupRemoveUserDto.cs @@ -0,0 +1,14 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class GroupRemoveUserDto + { + [Required] + public Guid UserId { get; set; } + + [Required] + public long GroupId { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs new file mode 100644 index 000000000..03f52b729 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class GroupUserGetByPagedDto : PagedAndSortedResultRequestDto + { + [Required] + public long GroupId { get; set; } + + public string Filter { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserGroupGetByGroupIdDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserGroupGetByGroupIdDto.cs new file mode 100644 index 000000000..e44a957f9 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserGroupGetByGroupIdDto.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class UserGroupGetByGroupIdDto + { + [Required] + public long GroupId { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserJoinGroupDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserJoinGroupDto.cs new file mode 100644 index 000000000..a42ec1999 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserJoinGroupDto.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class UserJoinGroupDto + { + [Required] + public long GroupId { get; set; } + + [Required] + [StringLength(100)] + public string JoinInfo { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs new file mode 100644 index 000000000..444dfaf37 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs @@ -0,0 +1,15 @@ +using LINGYUN.Abp.IM.Messages; +using System; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class UserMessageGetByPagedDto : PagedAndSortedResultRequestDto + { + [Required] + public Guid ReceiveUserId { get; set; } + public string Filter { get; set; } + public MessageType? MessageType { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs new file mode 100644 index 000000000..1180b0582 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs @@ -0,0 +1,61 @@ +using LINGYUN.Abp.IM.Group; +using LINGYUN.Abp.IM.Messages; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public interface IChatAppService : IApplicationService + { + /// + /// 发送消息 + /// + /// + /// + Task SendMessageAsync(ChatMessage chatMessage); + /// + /// 申请加入群组 + /// + /// + /// + Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup); + /// + /// 获取我的群组 + /// + /// + Task> GetMyGroupsAsync(); + /// + /// 获取群组用户 + /// + /// + /// + Task> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged); + /// + /// 处理用户群组申请 + /// + /// + /// + Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser); + /// + /// 群组移除用户 + /// + /// + /// + Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser); + /// + /// 获取群组消息 + /// + /// + /// + Task> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged); + /// + /// 获取我的消息 + /// + /// + /// + Task> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged); + + //TOTO: 还应该有获取我的未读消息 获取我的未读群组消息 + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/en.json b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/en.json new file mode 100644 index 000000000..d33bd06cb --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/en.json @@ -0,0 +1,8 @@ +{ + "culture": "en", + "texts": { + "Permission:MessageService": "Message service", + "Permission:Notification": "Notification", + "Permission:Delete": "Delete" + } +} \ No newline at end of file diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/zh-Hans.json b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/zh-Hans.json new file mode 100644 index 000000000..61f89d68c --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/zh-Hans.json @@ -0,0 +1,8 @@ +{ + "culture": "zh-Hans", + "texts": { + "Permission:MessageService": "消息服务", + "Permission:Notification": "通知管理", + "Permission:Delete": "删除" + } +} \ No newline at end of file diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationGetByIdDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationGetByIdDto.cs new file mode 100644 index 000000000..0e6b8a902 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationGetByIdDto.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public class NotificationGetByIdDto + { + [Required] + public long NotificationId { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationChangeReadStateDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationChangeReadStateDto.cs new file mode 100644 index 000000000..aeb8e5dbe --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationChangeReadStateDto.cs @@ -0,0 +1,14 @@ +using LINGYUN.Abp.Notifications; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public class UserNotificationChangeReadStateDto + { + [Required] + public long NotificationId { get; set; } + + [Required] + public NotificationReadState ReadState { get; set; } = NotificationReadState.Read; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByNameDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByNameDto.cs new file mode 100644 index 000000000..127710500 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByNameDto.cs @@ -0,0 +1,11 @@ +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public class UserNotificationGetByNameDto + { + [Required] + [StringLength(NotificationConsts.MaxNameLength)] + public string NotificationName { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs new file mode 100644 index 000000000..d8c102a69 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs @@ -0,0 +1,12 @@ +using LINGYUN.Abp.Notifications; +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public class UserNotificationGetByPagedDto : PagedAndSortedResultRequestDto + { + public string Filter { get; set; } + + public NotificationReadState ReadState { get; set; } = NotificationReadState.Read; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs new file mode 100644 index 000000000..ca446d394 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs @@ -0,0 +1,41 @@ +using LINGYUN.Abp.Notifications; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public interface INotificationAppService : IApplicationService + { + /// + /// 查询通知明细 + /// + /// + /// + Task GetAsync(NotificationGetByIdDto notificationGetById); + /// + /// 删除通知 + /// + /// + /// + Task DeleteAsync(NotificationGetByIdDto notificationGetById); + /// + /// 删除用户通知 + /// + /// + /// + Task DeleteUserNotificationAsync(NotificationGetByIdDto notificationGetById); + /// + /// 变更通知阅读状态 + /// + /// + /// + Task ChangeUserNotificationReadStateAsync(UserNotificationChangeReadStateDto userNotificationChangeRead); + /// + /// 获取用户通知列表 + /// + /// + /// + Task> GetUserNotificationsAsync(UserNotificationGetByPagedDto userNotificationGetByPaged); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissions.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissions.cs new file mode 100644 index 000000000..ed5372ad5 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissions.cs @@ -0,0 +1,14 @@ +namespace LINGYUN.Abp.MessageService.Permissions +{ + public class MessageServicePermissions + { + public const string GroupName = "MessageService"; + + public class Notification + { + public const string Default = GroupName + ".Notification"; + + public const string Delete = Default + ".Delete"; + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissionsDefinitionProvider.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissionsDefinitionProvider.cs new file mode 100644 index 000000000..d3417252d --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissionsDefinitionProvider.cs @@ -0,0 +1,22 @@ +using LINGYUN.Abp.MessageService.Localization; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Localization; + +namespace LINGYUN.Abp.MessageService.Permissions +{ + public class MessageServicePermissionsDefinitionProvider : PermissionDefinitionProvider + { + public override void Define(IPermissionDefinitionContext context) + { + var group = context.AddGroup(MessageServicePermissions.GroupName, L("Permission:MessageService")); + + var noticeGroup = group.AddPermission(MessageServicePermissions.Notification.Default, L("Permission:Notification")); + noticeGroup.AddChild(MessageServicePermissions.Notification.Delete, L("Permission:Delete")); + } + + private static LocalizableString L(string name) + { + return LocalizableString.Create(name); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByNameDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByNameDto.cs new file mode 100644 index 000000000..f5bfcface --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByNameDto.cs @@ -0,0 +1,12 @@ +using LINGYUN.Abp.MessageService.Notifications; +using System.ComponentModel.DataAnnotations; + +namespace LINGYUN.Abp.MessageService.Subscriptions +{ + public class SubscriptionsGetByNameDto + { + [Required] + [StringLength(NotificationConsts.MaxNameLength)] + public string NotificationName { get; set; } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByPagedDto.cs new file mode 100644 index 000000000..0321ab0fa --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByPagedDto.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Application.Dtos; + +namespace LINGYUN.Abp.MessageService.Subscriptions +{ + public class SubscriptionsGetByPagedDto : PagedAndSortedResultRequestDto + { + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/ISubscriptionAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/ISubscriptionAppService.cs new file mode 100644 index 000000000..d1ec7eeab --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/ISubscriptionAppService.cs @@ -0,0 +1,35 @@ +using LINGYUN.Abp.Notifications; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.MessageService.Subscriptions +{ + public interface ISubscriptionAppService : IApplicationService + { + /// + /// 是否已订阅消息 + /// + /// + /// + Task IsSubscribedAsync(SubscriptionsGetByNameDto subscriptionsGetByName); + /// + /// 订阅消息 + /// + /// + /// + Task SubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName); + /// + /// 退订消息 + /// + /// + /// + Task UnSubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName); + /// + /// 获取订阅列表 + /// + /// + /// + Task> GetSubscribedsAsync(SubscriptionsGetByPagedDto subscriptionsGetByPaged); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs new file mode 100644 index 000000000..8351d0454 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs @@ -0,0 +1,12 @@ +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.MessageService +{ + [DependsOn( + typeof(AbpMessageServiceApplicationContrantsModule), + typeof(AbpMessageServiceDomainModule))] + public class AbpMessageServiceApplicationModule : AbpModule + { + + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj new file mode 100644 index 000000000..a158701e2 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0 + + + + + + + + + + + + + diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs new file mode 100644 index 000000000..a0ecd69a9 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs @@ -0,0 +1,127 @@ +using LINGYUN.Abp.IM.Group; +using LINGYUN.Abp.IM.Messages; +using System.Collections.Immutable; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public class ChatAppService : ApplicationService, IChatAppService + { + private IMessageSender _messageSender; + protected IMessageSender MessageSender => LazyGetRequiredService(ref _messageSender); + + private readonly IUserGroupStore _userGroupStore; + private readonly IMessageStore _messageStore; + + public ChatAppService( + IMessageStore messageStore, + IUserGroupStore userGroupStore) + { + _messageStore = messageStore; + _userGroupStore = userGroupStore; + } + + public virtual async Task> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged) + { + var chatMessageCount = await _messageStore + .GetChatMessageCountAsync(CurrentTenant.Id, CurrentUser.GetId(), userMessageGetByPaged.ReceiveUserId, + userMessageGetByPaged.Filter, userMessageGetByPaged.MessageType); + + var chatMessages = await _messageStore + .GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), userMessageGetByPaged.ReceiveUserId, + userMessageGetByPaged.Filter, userMessageGetByPaged.Sorting, userMessageGetByPaged.MessageType, + userMessageGetByPaged.SkipCount, userMessageGetByPaged.MaxResultCount); + + return new PagedResultDto(chatMessageCount, chatMessages); + } + + public virtual async Task> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged) + { + var groupMessageCount = await _messageStore + .GetGroupMessageCountAsync(CurrentTenant.Id, groupMessageGetByPaged.GroupId, + groupMessageGetByPaged.Filter, groupMessageGetByPaged.MessageType); + + var groupMessages = await _messageStore + .GetGroupMessageAsync(CurrentTenant.Id, groupMessageGetByPaged.GroupId, + groupMessageGetByPaged.Filter, groupMessageGetByPaged.Sorting, groupMessageGetByPaged.MessageType, + groupMessageGetByPaged.SkipCount, groupMessageGetByPaged.MaxResultCount); + + return new PagedResultDto(groupMessageCount, groupMessages); + } + + public virtual async Task> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged) + { + var groupUserCount = await _userGroupStore.GetGroupUsersCountAsync(CurrentTenant.Id, + groupUserGetByPaged.GroupId, groupUserGetByPaged.Filter); + + var groupUsers = await _userGroupStore.GetGroupUsersAsync(CurrentTenant.Id, + groupUserGetByPaged.GroupId, groupUserGetByPaged.Filter, groupUserGetByPaged.Sorting, + groupUserGetByPaged.SkipCount, groupUserGetByPaged.MaxResultCount); + + return new PagedResultDto(groupUserCount, groupUsers); + } + + public virtual async Task> GetMyGroupsAsync() + { + var myGroups = await _userGroupStore.GetUserGroupsAsync(CurrentTenant.Id, CurrentUser.GetId()); + + return new ListResultDto(myGroups.ToImmutableList()); + } + + public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser) + { + var myGroupCard = await _userGroupStore + .GetUserGroupCardAsync(CurrentTenant.Id, groupAcceptUser.GroupId, CurrentUser.GetId()); + if (myGroupCard == null) + { + // 当前登录用户不再用户组 + throw new UserFriendlyException(""); + } + if (!myGroupCard.IsGrant(nameof(ChatGroupAdmin.AllowAddPeople))) + { + // 当前登录用户没有加人权限 + throw new UserFriendlyException(""); + } + await _userGroupStore + .AddUserToGroupAsync(CurrentTenant.Id, groupAcceptUser.UserId, groupAcceptUser.GroupId, CurrentUser.GetId()); + } + + public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser) + { + var myGroupCard = await _userGroupStore + .GetUserGroupCardAsync(CurrentTenant.Id, groupRemoveUser.GroupId, CurrentUser.GetId()); + if (myGroupCard == null) + { + // 当前登录用户不再用户组 + throw new UserFriendlyException(""); + } + if (!myGroupCard.IsGrant(nameof(ChatGroupAdmin.AllowKickPeople))) + { + // 当前登录用户没有踢人权限 + throw new UserFriendlyException(""); + } + await _userGroupStore + .RemoveUserFormGroupAsync(CurrentTenant.Id, groupRemoveUser.UserId, groupRemoveUser.GroupId); + } + + public virtual async Task SendMessageAsync(ChatMessage chatMessage) + { + // TODO:向其他租户发送消息? + chatMessage.TenantId = chatMessage.TenantId ?? CurrentTenant.Id; + + await MessageSender.SendMessageAsync(chatMessage); + + return new ChatMessageSendResultDto(chatMessage.MessageId); + } + + public virtual Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup) + { + // TOTO 发送通知? + return Task.CompletedTask; + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs new file mode 100644 index 000000000..f7be4921e --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs @@ -0,0 +1,68 @@ +using LINGYUN.Abp.MessageService.Permissions; +using LINGYUN.Abp.Notifications; +using Microsoft.AspNetCore.Authorization; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + [Authorize] + public class NotificationAppService : ApplicationService, INotificationAppService + { + private readonly INotificationRepository _notificationRepository; + private readonly IUserNotificationRepository _userNotificationRepository; + public NotificationAppService( + INotificationRepository notificationRepository, + IUserNotificationRepository userNotificationRepository) + { + _notificationRepository = notificationRepository; + _userNotificationRepository = userNotificationRepository; + } + + public virtual async Task ChangeUserNotificationReadStateAsync(UserNotificationChangeReadStateDto userNotificationChangeRead) + { + await _userNotificationRepository.ChangeUserNotificationReadStateAsync( + CurrentUser.GetId(), userNotificationChangeRead.NotificationId, userNotificationChangeRead.ReadState); + + } + + [Authorize(MessageServicePermissions.Notification.Delete)] + public virtual async Task DeleteAsync(NotificationGetByIdDto notificationGetById) + { + await _notificationRepository.DeleteAsync(notificationGetById.NotificationId); + } + + public virtual async Task DeleteUserNotificationAsync(NotificationGetByIdDto notificationGetById) + { + var notify = await _userNotificationRepository + .GetByIdAsync(CurrentUser.GetId(), notificationGetById.NotificationId); + await _userNotificationRepository.DeleteAsync(notify.Id); + } + + public virtual async Task GetAsync(NotificationGetByIdDto notificationGetById) + { + var notification = await _notificationRepository.GetByIdAsync(notificationGetById.NotificationId); + + return ObjectMapper.Map(notification); + } + + public virtual async Task> GetUserNotificationsAsync(UserNotificationGetByPagedDto userNotificationGetByPaged) + { + var notificationCount = await _userNotificationRepository + .GetCountAsync(CurrentUser.GetId(), userNotificationGetByPaged.Filter, + userNotificationGetByPaged.ReadState); + + var notifications = await _userNotificationRepository + .GetNotificationsAsync(CurrentUser.GetId(), userNotificationGetByPaged.Filter, + userNotificationGetByPaged.Sorting, userNotificationGetByPaged.ReadState, + userNotificationGetByPaged.SkipCount, userNotificationGetByPaged.MaxResultCount + ); + + return new PagedResultDto(notificationCount, + ObjectMapper.Map, List>(notifications)); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionAppService.cs new file mode 100644 index 000000000..bc198af4d --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionAppService.cs @@ -0,0 +1,65 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.AspNetCore.Authorization; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.MessageService.Subscriptions +{ + [Authorize] + public class SubscriptionAppService : ApplicationService, ISubscriptionAppService + { + private readonly IUserSubscribeRepository _userSubscribeRepository; + + public SubscriptionAppService( + IUserSubscribeRepository userSubscribeRepository) + { + _userSubscribeRepository = userSubscribeRepository; + } + + public virtual async Task> GetSubscribedsAsync(SubscriptionsGetByPagedDto subscriptionsGetByPaged) + { + var userSubscribedCount = await _userSubscribeRepository.GetCountAsync(CurrentUser.GetId()); + + var userSubscribes = await _userSubscribeRepository + .GetUserSubscribesAsync(CurrentUser.GetId(), subscriptionsGetByPaged.Sorting, + subscriptionsGetByPaged.SkipCount, subscriptionsGetByPaged.MaxResultCount); + + return new PagedResultDto(userSubscribedCount, + ObjectMapper.Map, List>(userSubscribes)); + } + + public virtual async Task IsSubscribedAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + var isSubscribed = await _userSubscribeRepository + .UserSubscribeExistsAysnc(subscriptionsGetByName.NotificationName, CurrentUser.GetId()); + + return isSubscribed; + } + + public virtual async Task SubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + var isSubscribed = await _userSubscribeRepository + .UserSubscribeExistsAysnc(subscriptionsGetByName.NotificationName, CurrentUser.GetId()); + if (!isSubscribed) + { + UserSubscribe userSubscribe = new UserSubscribe( + subscriptionsGetByName.NotificationName, + CurrentUser.GetId(), CurrentUser.UserName, CurrentTenant.Id); + + await _userSubscribeRepository.InsertAsync(userSubscribe, true); + } + } + + public virtual async Task UnSubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + var userSubscribe = await _userSubscribeRepository.GetUserSubscribeAsync(subscriptionsGetByName.NotificationName, CurrentUser.GetId()); + if (userSubscribe != null) + { + await _userSubscribeRepository.DeleteAsync(userSubscribe.Id, true); + } + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/ChatGroupConsts.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/ChatGroupConsts.cs similarity index 85% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/ChatGroupConsts.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/ChatGroupConsts.cs index 7c015a16c..c84bcd637 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/ChatGroupConsts.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/ChatGroupConsts.cs @@ -1,4 +1,4 @@ -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class ChatGroupConsts { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/MessageConsts.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/MessageConsts.cs similarity index 78% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/MessageConsts.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/MessageConsts.cs index 6708d9bfa..56960d9ec 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/MessageConsts.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/MessageConsts.cs @@ -1,4 +1,4 @@ -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class MessageConsts { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroup.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs similarity index 95% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroup.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs index defe140e0..cb1eb1136 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroup.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 聊天群组 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroupAdmin.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs similarity index 97% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroupAdmin.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs index 6c31cff0f..6ab195ccf 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroupAdmin.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs @@ -2,7 +2,7 @@ using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 群管理员 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupChatBlack.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupChatBlack.cs similarity index 95% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupChatBlack.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupChatBlack.cs index 8c95ec396..22cfaef08 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupChatBlack.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupChatBlack.cs @@ -2,7 +2,7 @@ using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 用户黑名单 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupMessage.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupMessage.cs similarity index 92% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupMessage.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupMessage.cs index 8897e4fcf..14fe37678 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupMessage.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupMessage.cs @@ -1,7 +1,7 @@ using LINGYUN.Abp.IM.Messages; using System; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class GroupMessage : Message { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IGroupRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs similarity index 92% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IGroupRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs index 864e5170e..845ceeb63 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IGroupRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public interface IGroupRepository : IBasicRepository { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs new file mode 100644 index 000000000..de3bf2bef --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs @@ -0,0 +1,30 @@ +using LINGYUN.Abp.IM.Messages; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.MessageService.Chat +{ + public interface IMessageRepository + { + Task InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false); + + Task InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false); + + Task GetUserMessageAsync(long id); + + Task GetGroupMessageAsync(long id); + + Task GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null); + + Task> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10); + + Task GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null); + + Task> GetGroupMessagesAsync(long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10); + + Task GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null); + + Task> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatGroupRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs similarity index 65% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatGroupRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs index 2772adaff..bcf1bfdfb 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatGroupRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public interface IUserChatGroupRepository : IBasicRepository { @@ -18,8 +18,14 @@ namespace LINGYUN.Abp.MessageService.Messages Task GetUserGroupAsync(long groupId, Guid userId); + Task GetGroupUserCardAsync(long groupId, Guid userId); + Task> GetGroupUsersAsync(long groupId); + Task GetGroupUsersCountAsync(long groupId, string filter = ""); + + Task> GetGroupUsersAsync(long groupId, string filter = "", string sorting = nameof(UserGroup.UserId), int skipCount = 1, int maxResultCount = 10); + Task> GetUserGroupsAsync(Guid userId); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatSettingRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatSettingRepository.cs similarity index 92% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatSettingRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatSettingRepository.cs index a091c38c4..7f7cdbaa7 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatSettingRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatSettingRepository.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public interface IUserChatSettingRepository : IBasicRepository { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/Message.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/Message.cs similarity index 97% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/Message.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/Message.cs index 3bb474be0..07bf27d25 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/Message.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/Message.cs @@ -3,7 +3,7 @@ using System; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public abstract class Message : CreationAuditedEntity, IMultiTenant { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/MessageStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs similarity index 83% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/MessageStore.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs index 46d4cf74e..af3f84572 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/MessageStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs @@ -8,7 +8,7 @@ using Volo.Abp.Domain.Services; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class MessageStore : DomainService, IMessageStore { @@ -54,22 +54,25 @@ namespace LINGYUN.Abp.MessageService.Messages } } - public async Task> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) + public async Task> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", + string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10) { using (CurrentTenant.Change(tenantId)) { - var groupMessages = await MessageRepository.GetGroupMessagesAsync(groupId, filter, type, skipCount, maxResultCount); + var groupMessages = await MessageRepository + .GetGroupMessagesAsync(groupId, filter, sorting, type, skipCount, maxResultCount); var chatMessages = ObjectMapper.Map, List>(groupMessages); return chatMessages; } } - public async Task> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) + public async Task> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", + string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10) { using (CurrentTenant.Change(tenantId)) { - var userMessages = await MessageRepository.GetUserMessagesAsync(sendUserId, receiveUserId, filter, type, skipCount, maxResultCount); + var userMessages = await MessageRepository.GetUserMessagesAsync(sendUserId, receiveUserId, filter, sorting, type, skipCount, maxResultCount); var chatMessages = ObjectMapper.Map, List>(userMessages); return chatMessages; @@ -100,6 +103,8 @@ namespace LINGYUN.Abp.MessageService.Messages var message = new UserMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType); message.SendToUser(chatMessage.ToUserId.Value); await MessageRepository.InsertUserMessageAsync(message); + + chatMessage.MessageId = messageId.ToString(); } protected virtual async Task StoreGroupMessageAsync(ChatMessage chatMessage, long groupId) @@ -127,6 +132,18 @@ namespace LINGYUN.Abp.MessageService.Messages // TODO: 需要压测 高并发场景下的装箱性能影响 message.SendToGroup(groupId); await MessageRepository.InsertGroupMessageAsync(message); + + chatMessage.MessageId = messageId.ToString(); + } + + public Task GetGroupMessageCountAsync(Guid? tenantId, long groupId, string filter = "", MessageType? type = null) + { + throw new NotImplementedException(); + } + + public Task GetChatMessageCountAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null) + { + throw new NotImplementedException(); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatBlack.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatBlack.cs similarity index 94% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatBlack.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatBlack.cs index 4dc1267b6..0d3e07975 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatBlack.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatBlack.cs @@ -2,7 +2,7 @@ using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 用户黑名单 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatGroup.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatGroup.cs similarity index 94% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatGroup.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatGroup.cs index b4b49bc59..9cf6b06b4 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatGroup.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatGroup.cs @@ -2,7 +2,7 @@ using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 用户群组 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatSetting.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatSetting.cs similarity index 97% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatSetting.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatSetting.cs index 926884807..75adcc56c 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatSetting.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatSetting.cs @@ -4,7 +4,7 @@ using System.Linq; using Volo.Abp.Domain.Entities; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class UserChatSetting : Entity, IMultiTenant { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserGroupStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs similarity index 72% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserGroupStore.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs index a94ad250f..89a5881b1 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserGroupStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs @@ -6,7 +6,7 @@ using Volo.Abp.Domain.Services; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class UserGroupStore : DomainService, IUserGroupStore { @@ -44,6 +44,16 @@ namespace LINGYUN.Abp.MessageService.Messages } } + public async Task GetUserGroupCardAsync(Guid? tenantId, long groupId, Guid userId) + { + using (CurrentTenant.Change(tenantId)) + { + var groupUserCard = await UserChatGroupRepository.GetGroupUserCardAsync(groupId, userId); + + return groupUserCard; + } + } + public async Task> GetGroupUsersAsync(Guid? tenantId, long groupId) { using (CurrentTenant.Change(tenantId)) @@ -82,5 +92,21 @@ namespace LINGYUN.Abp.MessageService.Messages } } } + + public async Task GetGroupUsersCountAsync(Guid? tenantId, long groupId, string filter = "") + { + using (CurrentTenant.Change(tenantId)) + { + return await UserChatGroupRepository.GetGroupUsersCountAsync(groupId, filter); + } + } + + public async Task> GetGroupUsersAsync(Guid? tenantId, long groupId, string filter = "", string sorting = "UserId", int skipCount = 1, int maxResultCount = 10) + { + using (CurrentTenant.Change(tenantId)) + { + return await UserChatGroupRepository.GetGroupUsersAsync(groupId, filter, sorting, skipCount, maxResultCount); + } + } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserMessage.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserMessage.cs similarity index 92% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserMessage.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserMessage.cs index 540f4a06b..5aaa1d0a9 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserMessage.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserMessage.cs @@ -1,7 +1,7 @@ using LINGYUN.Abp.IM.Messages; using System; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class UserMessage : Message { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserSpecialFocus.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserSpecialFocus.cs similarity index 95% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserSpecialFocus.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserSpecialFocus.cs index b7835f920..fbf538d53 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserSpecialFocus.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserSpecialFocus.cs @@ -2,7 +2,7 @@ using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { /// /// 用户特别关注 diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs index ea2773bf4..d82153783 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs @@ -1,4 +1,4 @@ -using LINGYUN.Abp.MessageService.Messages; +using LINGYUN.Abp.MessageService.Chat; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs index 3c8bfdc0b..4be5af133 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs @@ -1,6 +1,6 @@ using AutoMapper; using LINGYUN.Abp.IM.Messages; -using LINGYUN.Abp.MessageService.Messages; +using LINGYUN.Abp.MessageService.Chat; using LINGYUN.Abp.MessageService.Notifications; using LINGYUN.Abp.MessageService.Subscriptions; using LINGYUN.Abp.Notifications; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IMessageRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IMessageRepository.cs deleted file mode 100644 index 825e96b9e..000000000 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IMessageRepository.cs +++ /dev/null @@ -1,24 +0,0 @@ -using LINGYUN.Abp.IM.Messages; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace LINGYUN.Abp.MessageService.Messages -{ - public interface IMessageRepository - { - Task InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false); - - Task InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false); - - Task GetUserMessageAsync(long id); - - Task GetGroupMessageAsync(long id); - - Task> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); - - Task> GetGroupMessagesAsync(long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); - - Task> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); - } -} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs index f0a98e351..29ca36a9f 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs @@ -16,6 +16,10 @@ namespace LINGYUN.Abp.MessageService.Notifications Task> GetNotificationsAsync(Guid userId, NotificationReadState readState = NotificationReadState.UnRead, int maxResultCount = 10); + Task GetCountAsync(Guid userId, string filter = "", NotificationReadState readState = NotificationReadState.UnRead); + + Task> GetNotificationsAsync(Guid userId, string filter = "", string sorting = nameof(Notification.NotificationId), NotificationReadState readState = NotificationReadState.UnRead, int skipCount = 1, int maxResultCount = 10); + Task ChangeUserNotificationReadStateAsync(Guid userId, long notificationId, NotificationReadState readState); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs index 3b3915751..1b030facb 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs @@ -24,5 +24,9 @@ namespace LINGYUN.Abp.MessageService.Subscriptions Task DeleteUserSubscriptionAsync(IEnumerable userSubscribes); Task DeleteUserSubscriptionAsync(string notificationName); + + Task> GetUserSubscribesAsync(Guid userId, string sorting = nameof(UserSubscribe.Id), int skipCount = 1, int maxResultCount = 10); + + Task GetCountAsync(Guid userId); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreGroupRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs similarity index 97% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreGroupRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs index e5a674b4c..5701da4d5 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreGroupRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs @@ -8,7 +8,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class EfCoreGroupRepository : EfCoreRepository, IGroupRepository, ITransientDependency diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreMessageRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs similarity index 50% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreMessageRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs index f0e1b29d7..d766e38db 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreMessageRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs @@ -4,12 +4,13 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class EfCoreMessageRepository : EfCoreRepository, IMessageRepository, ITransientDependency @@ -28,42 +29,60 @@ namespace LINGYUN.Abp.MessageService.Messages .FirstOrDefaultAsync(); } - public async Task> GetGroupMessagesAsync(long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) + public async Task> GetGroupMessagesAsync(long groupId, string filter = "", + string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10) { - if(skipCount > 0) - { - skipCount -= 1; - } var groupMessages = await DbContext.Set() .Distinct() - .Where(x => x.GroupId.Equals(groupId) && x.Type.Equals(type)) + .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)) - .OrderByDescending(x => x.MessageId) - .Skip(skipCount * maxResultCount) - .Take(maxResultCount) + .OrderBy(sorting ?? nameof(GroupMessage.MessageId)) + .Page(skipCount, maxResultCount) + .AsNoTracking() .ToListAsync(); return groupMessages; } - public async Task> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) + public async Task GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null) + { + var groupMessagesCount = await DbContext.Set() + .Distinct() + .Where(x => x.GroupId.Equals(groupId)) + .WhereIf(type != null, x => x.Type.Equals(type)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) + .LongCountAsync(); + return groupMessagesCount; + } + + public async Task> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", + string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10) { - if (skipCount > 0) - { - skipCount -= 1; - } var groupMessages = await DbContext.Set() .Distinct() - .Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId) && x.Type.Equals(type)) + .Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) + .WhereIf(type != null, x => x.Type.Equals(type)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) - .OrderByDescending(x => x.MessageId) - .Skip(skipCount * maxResultCount) - .Take(maxResultCount) + .OrderBy(sorting ?? nameof(GroupMessage.MessageId)) + .Page(skipCount, maxResultCount) + .AsNoTracking() .ToListAsync(); return groupMessages; } + public async Task GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null) + { + var groupMessagesCount = await DbContext.Set() + .Distinct() + .Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId)) + .WhereIf(type != null, x => x.Type.Equals(type)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) + .LongCountAsync(); + return groupMessagesCount; + } + public async Task GetUserMessageAsync(long id) { return await DbContext.Set() @@ -72,24 +91,34 @@ namespace LINGYUN.Abp.MessageService.Messages .FirstOrDefaultAsync(); } - public async Task> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) + public async Task> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", + string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10) { - if (skipCount > 0) - { - skipCount -= 1; - } var userMessages = await DbContext.Set() .Distinct() - .Where(x => x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId) && x.Type.Equals(type)) + .Where(x => x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) + .WhereIf(type != null, x => x.Type.Equals(type)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) - .OrderByDescending(x => x.MessageId) - .Skip(skipCount * maxResultCount) - .Take(maxResultCount) + .OrderBy(sorting ?? nameof(GroupMessage.MessageId)) + .Page(skipCount, maxResultCount) + .AsNoTracking() .ToListAsync(); return userMessages; } + public async Task GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null) + { + var userMessagesCount = await DbContext.Set() + .Distinct() + .Where(x => x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) + .WhereIf(type != null, x => x.Type.Equals(type)) + .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter)) + .LongCountAsync(); + + return userMessagesCount; + } + public async Task InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false) { groupMessage = (await DbContext.Set().AddAsync(groupMessage, GetCancellationToken())).Entity; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatGroupRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs similarity index 58% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatGroupRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs index de852f05c..d77b60a04 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatGroupRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs @@ -9,7 +9,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class EfCoreUserChatGroupRepository : EfCoreRepository, IUserChatGroupRepository, ITransientDependency @@ -44,6 +44,49 @@ namespace LINGYUN.Abp.MessageService.Messages return groupUsers; } + public async Task GetGroupUserCardAsync(long groupId, Guid userId) + { + var groupUserCard = await (from cg in DbContext.Set() + join ucg in DbContext.Set().DefaultIfEmpty() + on cg.GroupId equals ucg.GroupId + join cga in DbContext.Set().DefaultIfEmpty() + on cg.GroupId equals cga.GroupId + where ucg.GroupId.Equals(groupId) && cga.UserId.Equals(userId) + select new GroupUserCard + { + IsSuperAdmin = cga != null && cga.IsSuperAdmin, + IsAdmin = cga != null,//能查到数据就是管理员 + GroupId = ucg.GroupId, + UserId = ucg.UserId, + TenantId = ucg.TenantId, + Permissions = new Dictionary + { + { nameof(ChatGroupAdmin.AllowAddPeople), cga != null &&cga.AllowAddPeople }, + { nameof(ChatGroupAdmin.AllowDissolveGroup), cga != null &&cga.AllowDissolveGroup }, + { nameof(ChatGroupAdmin.AllowKickPeople), cga != null &&cga.AllowKickPeople }, + { nameof(ChatGroupAdmin.AllowSendNotice), cga != null &&cga.AllowSendNotice }, + { nameof(ChatGroupAdmin.AllowSilence), cga != null &&cga.AllowSilence }, + { nameof(ChatGroupAdmin.IsSuperAdmin), cga != null &&cga.IsSuperAdmin } + } + }) + .AsNoTracking() + .FirstOrDefaultAsync(); + + return groupUserCard; + } + + public Task> GetGroupUsersAsync(long groupId, string filter = "", string sorting = "UserId", int skipCount = 1, int maxResultCount = 10) + { + // TODO: 复杂的实现,暂时无关紧要,后期再说 :) + throw new NotImplementedException(); + } + + public Task GetGroupUsersCountAsync(long groupId, string filter = "") + { + // TODO: 复杂的实现,暂时无关紧要,后期再说 :) + throw new NotImplementedException(); + } + public async Task GetUserGroupAsync(long groupId, Guid userId) { return await DbSet.Where(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId)) diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatSettingRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs similarity index 96% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatSettingRepository.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs index e68008eaf..66e8926e3 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatSettingRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs @@ -7,7 +7,7 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -namespace LINGYUN.Abp.MessageService.Messages +namespace LINGYUN.Abp.MessageService.Chat { public class EfCoreUserChatSettingRepository : EfCoreRepository, IUserChatSettingRepository, ITransientDependency diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs index aee1cc373..f990d1ec0 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs @@ -1,4 +1,4 @@ -using LINGYUN.Abp.MessageService.Messages; +using LINGYUN.Abp.MessageService.Chat; using LINGYUN.Abp.MessageService.Notifications; using LINGYUN.Abp.MessageService.Subscriptions; using Microsoft.Extensions.DependencyInjection; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs index c18867104..e4f08a537 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs @@ -1,4 +1,4 @@ -using LINGYUN.Abp.MessageService.Messages; +using LINGYUN.Abp.MessageService.Chat; using LINGYUN.Abp.MessageService.Notifications; using LINGYUN.Abp.MessageService.Subscriptions; using Microsoft.EntityFrameworkCore; diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs index 86636675d..3fae6b5c1 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -62,5 +63,36 @@ namespace LINGYUN.Abp.MessageService.Notifications .ToListAsync(); return userNofitications; } + + public virtual async Task GetCountAsync(Guid userId, string filter = "", NotificationReadState readState = NotificationReadState.UnRead) + { + var userNofiticationCount = await (from un in DbContext.Set() + join n in DbContext.Set() + on un.NotificationId equals n.NotificationId + where un.UserId.Equals(userId) && un.ReadStatus.Equals(readState) + && (n.NotificationName.Contains(filter) || n.NotificationTypeName.Contains(filter) + || n.NotificationCateGory.Contains(filter)) + select n) + .Distinct() + .LongCountAsync(); + return userNofiticationCount; + } + + public virtual async Task> GetNotificationsAsync(Guid userId, string filter = "", string sorting = "NotificationId", NotificationReadState readState = NotificationReadState.UnRead, int skipCount = 1, int maxResultCount = 10) + { + var userNofitications = await (from un in DbContext.Set() + join n in DbContext.Set() + on un.NotificationId equals n.NotificationId + where un.UserId.Equals(userId) && un.ReadStatus.Equals(readState) + && (n.NotificationName.Contains(filter) || n.NotificationTypeName.Contains(filter) + || n.NotificationCateGory.Contains(filter)) + orderby sorting ?? nameof(Notification.NotificationId) descending + select n) + .Distinct() + .Page(skipCount, maxResultCount) + .AsNoTracking() + .ToListAsync(); + return userNofitications; + } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs index 7d2178527..ad73dfacd 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -94,5 +95,28 @@ namespace LINGYUN.Abp.MessageService.Subscriptions { return await DbSet.AnyAsync(x => x.UserId.Equals(userId) && x.NotificationName.Equals(notificationName)); } + + public virtual async Task> GetUserSubscribesAsync(Guid userId, string sorting = "Id", int skipCount = 1, int maxResultCount = 10) + { + var userSubscribes = await DbSet + .Distinct() + .Where(x => x.UserId.Equals(userId)) + .OrderBy(sorting ?? nameof(UserSubscribe.Id)) + .Page(skipCount, maxResultCount) + .AsNoTracking() + .ToListAsync(); + + return userSubscribes; + } + + public virtual async Task GetCountAsync(Guid userId) + { + var userSubscribedCount = await DbSet + .Distinct() + .Where(x => x.UserId.Equals(userId)) + .LongCountAsync(); + + return userSubscribedCount; + } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj index 40cfdbeb3..bc850f198 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 @@ -8,5 +8,9 @@ + + + + diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs index ec2306605..d01c83ef2 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs @@ -5,6 +5,7 @@ using Volo.Abp.Modularity; namespace LINGYUN.Abp.MessageService { [DependsOn( + typeof(AbpMessageServiceApplicationContrantsModule), typeof(AbpAspNetCoreMvcModule) )] public class AbpMessageServiceHttpApiModule : AbpModule diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs new file mode 100644 index 000000000..806a68968 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs @@ -0,0 +1,78 @@ +using LINGYUN.Abp.IM.Group; +using LINGYUN.Abp.IM.Messages; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.MessageService.Chat +{ + [RemoteService(Name = AbpMessageServiceConsts.RemoteServiceName)] + [Route("api/chat")] + public class ChatController : AbpController, IChatAppService + { + private readonly IChatAppService _chatAppService; + + public ChatController(IChatAppService chatAppService) + { + _chatAppService = chatAppService; + } + + [HttpPost] + [Route("groups/join")] + public virtual async Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup) + { + await _chatAppService.ApplyJoinGroupAsync(userJoinGroup); + } + + [HttpGet] + [Route("messages/group")] + public virtual async Task> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged) + { + return await _chatAppService.GetGroupMessageAsync(groupMessageGetByPaged); + } + + [HttpGet] + [Route("groups/users")] + public virtual async Task> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged) + { + return await _chatAppService.GetGroupUsersAsync(groupUserGetByPaged); + } + + [HttpGet] + [Route("messages/me")] + public virtual async Task> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged) + { + return await _chatAppService.GetMyChatMessageAsync(userMessageGetByPaged); + } + + [HttpGet] + [Route("groups/me")] + public virtual async Task> GetMyGroupsAsync() + { + return await _chatAppService.GetMyGroupsAsync(); + } + + [HttpPost] + [Route("groups/users/accept")] + public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser) + { + await _chatAppService.GroupAcceptUserAsync(groupAcceptUser); + } + + [HttpDelete] + [Route("groups/users/remove")] + public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser) + { + await _chatAppService.GroupRemoveUserAsync(groupRemoveUser); + } + + [HttpGet] + [Route("messages/send")] + public virtual async Task SendMessageAsync(ChatMessage chatMessage) + { + return await _chatAppService.SendMessageAsync(chatMessage); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs new file mode 100644 index 000000000..b96047ec6 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs @@ -0,0 +1,56 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + [RemoteService(Name = AbpMessageServiceConsts.RemoteServiceName)] + [Route("api/notifications")] + public class NotificationController : AbpController, INotificationAppService + { + private readonly INotificationAppService _notificationAppService; + public NotificationController( + INotificationAppService notificationAppService) + { + _notificationAppService = notificationAppService; + } + + [HttpPut] + [Route("ChangeReadState")] + public virtual async Task ChangeUserNotificationReadStateAsync(UserNotificationChangeReadStateDto userNotificationChangeRead) + { + await _notificationAppService.ChangeUserNotificationReadStateAsync(userNotificationChangeRead); + } + + [HttpDelete] + [Route("{NotificationId}")] + public virtual async Task DeleteAsync(NotificationGetByIdDto notificationGetById) + { + await _notificationAppService.DeleteAsync(notificationGetById); + } + + [HttpDelete] + [Route("User/{NotificationId}")] + public virtual async Task DeleteUserNotificationAsync(NotificationGetByIdDto notificationGetById) + { + await _notificationAppService.DeleteUserNotificationAsync(notificationGetById); + } + + [HttpGet] + [Route("{NotificationId}")] + public virtual async Task GetAsync(NotificationGetByIdDto notificationGetById) + { + return await _notificationAppService.GetAsync(notificationGetById); + } + + [HttpGet] + [Route("User/{NotificationId}")] + public virtual async Task> GetUserNotificationsAsync(UserNotificationGetByPagedDto userNotificationGetByPaged) + { + return await _notificationAppService.GetUserNotificationsAsync(userNotificationGetByPaged); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionController.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionController.cs new file mode 100644 index 000000000..2c09799d2 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionController.cs @@ -0,0 +1,47 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.MessageService.Subscriptions +{ + [RemoteService(Name = AbpMessageServiceConsts.RemoteServiceName)] + [Route("api/subscribes")] + public class SubscriptionController : AbpController, ISubscriptionAppService + { + private readonly ISubscriptionAppService _subscriptionAppService; + + public SubscriptionController( + ISubscriptionAppService subscriptionAppService) + { + _subscriptionAppService = subscriptionAppService; + } + + [HttpGet] + public virtual async Task> GetSubscribedsAsync(SubscriptionsGetByPagedDto subscriptionsGetByPaged) + { + return await _subscriptionAppService.GetSubscribedsAsync(subscriptionsGetByPaged); + } + + [HttpGet] + [Route("IsSubscribed/{NotificationName}")] + public virtual async Task IsSubscribedAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + return await _subscriptionAppService.IsSubscribedAsync(subscriptionsGetByName); + } + + [HttpPost] + public virtual async Task SubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + await _subscriptionAppService.SubscribeAsync(subscriptionsGetByName); + } + + [HttpDelete] + public virtual async Task UnSubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName) + { + await _subscriptionAppService.UnSubscribeAsync(subscriptionsGetByName); + } + } +} diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs index a8623dea1..a3ffed6e2 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs @@ -1,6 +1,7 @@ using LINGYUN.Abp.Notifications; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; @@ -26,9 +27,13 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed /// public ILogger Logger { get; set; } /// + /// Reference to . + /// + protected AbpNotificationOptions Options { get; } + /// /// Reference to . /// - protected IBackgroundJobManager BackgroundJobManager; + protected IBackgroundJobManager BackgroundJobManager { get; } /// /// Reference to . /// @@ -43,12 +48,12 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed /// public NotificationEventHandler( IBackgroundJobManager backgroundJobManager, - + IOptions options, INotificationStore notificationStore, INotificationPublishProviderManager notificationPublishProviderManager) { BackgroundJobManager = backgroundJobManager; - + Options = options.Value; NotificationStore = notificationStore; NotificationPublishProviderManager = notificationPublishProviderManager; @@ -117,7 +122,12 @@ namespace LINGYUN.Abp.MessageService.EventBus.Distributed try { Logger.LogDebug($"Sending notification with provider {provider.Name}"); - + var notifacationDataMapping = Options.NotificationDataMappings + .GetMapItemOrNull(provider.Name, notificationInfo.CateGory); + if (notifacationDataMapping != null) + { + notificationInfo.Data = notifacationDataMapping.MappingFunc(notificationInfo.Data); + } // 发布 await provider.PublishAsync(notificationInfo, subscriptionUserIdentifiers); diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index 08d38c8de..5d9096ddd 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -50,6 +50,7 @@ + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs index a1390d1ce..4df950c71 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs @@ -40,6 +40,7 @@ using Volo.Abp.VirtualFileSystem; namespace LINGYUN.Abp.MessageService { [DependsOn( + typeof(AbpMessageServiceApplicationModule), typeof(AbpMessageServiceHttpApiModule), typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpMessageServiceEntityFrameworkCoreModule), diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index 258bf3ddc..a3aaf328c 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -65,6 +65,7 @@ + diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs deleted file mode 100644 index 517a12025..000000000 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ /dev/null @@ -1,268 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Threading.Tasks; -using Volo.Abp.Application.Services; -using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; -using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; -using Volo.Abp.AspNetCore.Mvc.MultiTenancy; -using Volo.Abp.Authorization.Permissions; -using Volo.Abp.Clients; -using Volo.Abp.DependencyInjection; -using Volo.Abp.EventBus.Local; -using Volo.Abp.Features; -using Volo.Abp.Localization; -using Volo.Abp.MultiTenancy; -using Volo.Abp.PermissionManagement; -using Volo.Abp.Settings; -using Volo.Abp.Users; - -namespace LINGYUN.Platform.AspNetCore.Mvc.ApplicationConfigurations -{ - [Dependency(ServiceLifetime.Transient)] - [ExposeServices(typeof(IAbpApplicationConfigurationAppService))] - public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApplicationConfigurationAppService - { - private readonly AbpLocalizationOptions _localizationOptions; - private readonly AbpMultiTenancyOptions _multiTenancyOptions; - private readonly IServiceProvider _serviceProvider; - private readonly ISettingProvider _settingProvider; - private readonly ISettingDefinitionManager _settingDefinitionManager; - private readonly IFeatureDefinitionManager _featureDefinitionManager; - private readonly IPermissionGrantRepository _permissionGrantRepository; - private readonly IPermissionDefinitionManager _permissionDefinitionManager; - private readonly ILanguageProvider _languageProvider; - private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService; - - private ICurrentClient _currentClient; - - protected ICurrentClient CurrentClient => LazyGetRequiredService(ref _currentClient); - - private ILocalEventBus _localEventBus; - //用于发布权限事件,每次请求此接口后,通过事件总线来缓存权限 - protected ILocalEventBus LocalEventBus => LazyGetRequiredService(ref _localEventBus); - - public AbpApplicationConfigurationAppService( - IOptions localizationOptions, - IOptions multiTenancyOptions, - IServiceProvider serviceProvider, - ISettingProvider settingProvider, - ISettingDefinitionManager settingDefinitionManager, - IFeatureDefinitionManager featureDefinitionManager, - IPermissionGrantRepository permissionGrantRepository, - IPermissionDefinitionManager permissionDefinitionManager, - ILanguageProvider languageProvider, - ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService) - { - _serviceProvider = serviceProvider; - _settingProvider = settingProvider; - _settingDefinitionManager = settingDefinitionManager; - _featureDefinitionManager = featureDefinitionManager; - _permissionGrantRepository = permissionGrantRepository; - _permissionDefinitionManager = permissionDefinitionManager; - _languageProvider = languageProvider; - _cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService; - _localizationOptions = localizationOptions.Value; - _multiTenancyOptions = multiTenancyOptions.Value; - } - - public virtual async Task GetAsync() - { - //TODO: Optimize & cache..? - - Logger.LogDebug("Executing AbpApplicationConfigurationAppService.GetAsync()..."); - - var result = new ApplicationConfigurationDto - { - Auth = await GetAuthConfigAsync(), - Features = await GetFeaturesConfigAsync(), - Localization = await GetLocalizationConfigAsync(), - CurrentUser = GetCurrentUser(), - Setting = await GetSettingConfigAsync(), - MultiTenancy = GetMultiTenancy(), - CurrentTenant = GetCurrentTenant(), - ObjectExtensions = _cachedObjectExtensionsDtoService.Get() - }; - - Logger.LogDebug("Executed AbpApplicationConfigurationAppService.GetAsync()."); - - return result; - } - - protected virtual CurrentTenantDto GetCurrentTenant() - { - return new CurrentTenantDto() - { - Id = CurrentTenant.Id, - Name = CurrentTenant.Name, - IsAvailable = CurrentTenant.IsAvailable - }; - } - - protected virtual MultiTenancyInfoDto GetMultiTenancy() - { - return new MultiTenancyInfoDto - { - IsEnabled = _multiTenancyOptions.IsEnabled - }; - } - - protected virtual CurrentUserDto GetCurrentUser() - { - return new CurrentUserDto - { - IsAuthenticated = CurrentUser.IsAuthenticated, - Id = CurrentUser.Id, - TenantId = CurrentUser.TenantId, - UserName = CurrentUser.UserName, - Email = CurrentUser.Email - }; - } - - protected virtual async Task GetAuthConfigAsync() - { - var authConfig = new ApplicationAuthConfigurationDto(); - - var permissions = _permissionDefinitionManager.GetPermissions(); - - IEnumerable grantPermissions = new List(); - - // TODO: 重写为每次调用接口都在数据库统一查询权限 - // 待框架改进权限Provider机制后再移除 - - // 如果用户已登录,获取用户和角色权限 - if (CurrentUser.IsAuthenticated) - { - var userPermissions = await _permissionGrantRepository.GetListAsync(UserPermissionValueProvider.ProviderName, - CurrentUser.GetId().ToString()); - grantPermissions = grantPermissions.Union(userPermissions); - foreach(var userRole in CurrentUser.Roles) - { - var rolePermissions = await _permissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, - userRole); - grantPermissions = grantPermissions.Union(rolePermissions); - } - } - - // 如果客户端已验证,获取客户端权限 - if(CurrentClient.IsAuthenticated) - { - var clientPermissions = await _permissionGrantRepository.GetListAsync(ClientPermissionValueProvider.ProviderName, - CurrentClient.Id); - grantPermissions = grantPermissions.Union(clientPermissions); - } - - foreach(var permission in permissions) - { - authConfig.Policies[permission.Name] = true; - if(grantPermissions.Any(p => p.Name.Equals(permission.Name))) - { - authConfig.GrantedPolicies[permission.Name] = true; - } - } - - return authConfig; - } - - protected virtual async Task GetLocalizationConfigAsync() - { - var localizationConfig = new ApplicationLocalizationConfigurationDto(); - - localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync()); - - foreach (var resource in _localizationOptions.Resources.Values) - { - var dictionary = new Dictionary(); - - var localizer = _serviceProvider.GetRequiredService( - typeof(IStringLocalizer<>).MakeGenericType(resource.ResourceType) - ) as IStringLocalizer; - - foreach (var localizedString in localizer.GetAllStrings()) - { - dictionary[localizedString.Name] = localizedString.Value; - } - - localizationConfig.Values[resource.ResourceName] = dictionary; - } - - localizationConfig.CurrentCulture = GetCurrentCultureInfo(); - - if (_localizationOptions.DefaultResourceType != null) - { - localizationConfig.DefaultResourceName = LocalizationResourceNameAttribute.GetName( - _localizationOptions.DefaultResourceType - ); - } - - return localizationConfig; - } - - private static CurrentCultureDto GetCurrentCultureInfo() - { - return new CurrentCultureDto - { - Name = CultureInfo.CurrentUICulture.Name, - DisplayName = CultureInfo.CurrentUICulture.DisplayName, - EnglishName = CultureInfo.CurrentUICulture.EnglishName, - NativeName = CultureInfo.CurrentUICulture.NativeName, - IsRightToLeft = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft, - CultureName = CultureInfo.CurrentUICulture.TextInfo.CultureName, - TwoLetterIsoLanguageName = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, - ThreeLetterIsoLanguageName = CultureInfo.CurrentUICulture.ThreeLetterISOLanguageName, - DateTimeFormat = new DateTimeFormatDto - { - CalendarAlgorithmType = CultureInfo.CurrentUICulture.DateTimeFormat.Calendar.AlgorithmType.ToString(), - DateTimeFormatLong = CultureInfo.CurrentUICulture.DateTimeFormat.LongDatePattern, - ShortDatePattern = CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern, - FullDateTimePattern = CultureInfo.CurrentUICulture.DateTimeFormat.FullDateTimePattern, - DateSeparator = CultureInfo.CurrentUICulture.DateTimeFormat.DateSeparator, - ShortTimePattern = CultureInfo.CurrentUICulture.DateTimeFormat.ShortTimePattern, - LongTimePattern = CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern, - } - }; - } - - private async Task GetSettingConfigAsync() - { - var result = new ApplicationSettingConfigurationDto - { - Values = new Dictionary() - }; - - foreach (var settingDefinition in _settingDefinitionManager.GetAll()) - { - if (!settingDefinition.IsVisibleToClients) - { - continue; - } - - result.Values[settingDefinition.Name] = await _settingProvider.GetOrNullAsync(settingDefinition.Name); - } - - return result; - } - - protected virtual async Task GetFeaturesConfigAsync() - { - var result = new ApplicationFeatureConfigurationDto(); - - foreach (var featureDefinition in _featureDefinitionManager.GetAll()) - { - if (!featureDefinition.IsVisibleToClients) - { - continue; - } - - result.Values[featureDefinition.Name] = await FeatureChecker.GetOrNullAsync(featureDefinition.Name); - } - - return result; - } - } -} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationAppService.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationAppService.cs new file mode 100644 index 000000000..a838d0688 --- /dev/null +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationAppService.cs @@ -0,0 +1,115 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending; +using Volo.Abp.Authorization; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Clients; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Features; +using Volo.Abp.Localization; +using Volo.Abp.MultiTenancy; +using Volo.Abp.PermissionManagement; +using Volo.Abp.Settings; +using Volo.Abp.Timing; +using Volo.Abp.Users; + +namespace LINGYUN.Platform.AspNetCore.Mvc.ApplicationConfigurations +{ + [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] + [ExposeServices(typeof(IAbpApplicationConfigurationAppService), typeof(AbpApplicationConfigurationAppService))] + public class ApplicationConfigurationAppService : AbpApplicationConfigurationAppService + { + private readonly IPermissionGrantRepository _permissionGrantRepository; + private readonly IPermissionDefinitionManager _permissionDefinitionManager; + + private ICurrentClient _currentClient; + + protected ICurrentClient CurrentClient => LazyGetRequiredService(ref _currentClient); + + public ApplicationConfigurationAppService( + IOptions localizationOptions, + IOptions multiTenancyOptions, + IServiceProvider serviceProvider, + IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider, + IAuthorizationService authorizationService, + ICurrentUser currentUser, + ISettingProvider settingProvider, + ISettingDefinitionManager settingDefinitionManager, + IFeatureDefinitionManager featureDefinitionManager, + ILanguageProvider languageProvider, + ITimezoneProvider timezoneProvider, + IOptions abpClockOptions, + ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService, + IPermissionGrantRepository permissionGrantRepository, + IPermissionDefinitionManager permissionDefinitionManager) + : base( + localizationOptions, + multiTenancyOptions, + serviceProvider, + abpAuthorizationPolicyProvider, + authorizationService, + currentUser, + settingProvider, + settingDefinitionManager, + featureDefinitionManager, + languageProvider, + timezoneProvider, + abpClockOptions, + cachedObjectExtensionsDtoService) + { + _permissionGrantRepository = permissionGrantRepository; + _permissionDefinitionManager = permissionDefinitionManager; + + } + protected override async Task GetAuthConfigAsync() + { + var authConfig = new ApplicationAuthConfigurationDto(); + + var permissions = _permissionDefinitionManager.GetPermissions(); + + IEnumerable grantPermissions = new List(); + + // TODO: 重写为每次调用接口都在数据库统一查询权限 + // 待框架改进权限Provider机制后再移除 + + // 如果用户已登录,获取用户和角色权限 + if (CurrentUser.IsAuthenticated) + { + var userPermissions = await _permissionGrantRepository.GetListAsync(UserPermissionValueProvider.ProviderName, + CurrentUser.GetId().ToString()); + grantPermissions = grantPermissions.Union(userPermissions); + foreach(var userRole in CurrentUser.Roles) + { + var rolePermissions = await _permissionGrantRepository.GetListAsync(RolePermissionValueProvider.ProviderName, + userRole); + grantPermissions = grantPermissions.Union(rolePermissions); + } + } + + // 如果客户端已验证,获取客户端权限 + if(CurrentClient.IsAuthenticated) + { + var clientPermissions = await _permissionGrantRepository.GetListAsync(ClientPermissionValueProvider.ProviderName, + CurrentClient.Id); + grantPermissions = grantPermissions.Union(clientPermissions); + } + + foreach(var permission in permissions) + { + authConfig.Policies[permission.Name] = true; + if(grantPermissions.Any(p => p.Name.Equals(permission.Name))) + { + authConfig.GrantedPolicies[permission.Name] = true; + } + } + + return authConfig; + } + } +} diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs index 2dc4d3ea9..d4afc33c3 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs @@ -4,6 +4,7 @@ using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.Identity; using LINGYUN.Abp.IdentityServer; using LINGYUN.Abp.Location.Baidu; +using LINGYUN.Abp.MessageService; using LINGYUN.Abp.SettingManagement; using LINGYUN.Abp.TenantManagement; using LINGYUN.ApiGateway; @@ -53,6 +54,7 @@ namespace LINGYUN.Platform typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementDomainIdentityServerModule), typeof(ApiGatewayApplicationContractsModule), + typeof(AbpMessageServiceApplicationContrantsModule), typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityApplicationModule), typeof(Abp.Account.AbpAccountApplicationModule),