Browse Source

增加消息服务Api;重命名chat命名空间

pull/8/head
cKey 6 years ago
parent
commit
2c5d44a73c
  1. 22
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs
  2. 27
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs
  3. 24
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs
  4. 48
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs
  5. 29
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj
  6. 26
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceApplicationContrantsModule.cs
  7. 7
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/AbpMessageServiceConsts.cs
  8. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/ChatMessageSendResultDto.cs
  9. 19
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupAcceptUserDto.cs
  10. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs
  11. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupRemoveUserDto.cs
  12. 13
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs
  13. 10
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserGroupGetByGroupIdDto.cs
  14. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserJoinGroupDto.cs
  15. 15
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs
  16. 61
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs
  17. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/en.json
  18. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Localization/ApplicationContracts/zh-Hans.json
  19. 10
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/NotificationGetByIdDto.cs
  20. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationChangeReadStateDto.cs
  21. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByNameDto.cs
  22. 12
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs
  23. 41
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs
  24. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissions.cs
  25. 22
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Permissions/MessageServicePermissionsDefinitionProvider.cs
  26. 12
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByNameDto.cs
  27. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/Dto/SubscriptionsGetByPagedDto.cs
  28. 35
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Subscriptions/ISubscriptionAppService.cs
  29. 12
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/AbpMessageServiceApplicationModule.cs
  30. 17
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj
  31. 127
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs
  32. 68
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs
  33. 65
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionAppService.cs
  34. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/ChatGroupConsts.cs
  35. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/MessageConsts.cs
  36. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs
  37. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs
  38. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupChatBlack.cs
  39. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupMessage.cs
  40. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs
  41. 30
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs
  42. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs
  43. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatSettingRepository.cs
  44. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/Message.cs
  45. 27
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs
  46. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatBlack.cs
  47. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatGroup.cs
  48. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatSetting.cs
  49. 28
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs
  50. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserMessage.cs
  51. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserSpecialFocus.cs
  52. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs
  53. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs
  54. 24
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IMessageRepository.cs
  55. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs
  56. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs
  57. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs
  58. 83
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs
  59. 45
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
  60. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs
  61. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs
  62. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs
  63. 32
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs
  64. 24
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs
  65. 6
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj
  66. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiModule.cs
  67. 78
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs
  68. 56
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs
  69. 47
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Subscriptions/SubscriptionController.cs
  70. 1
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj
  71. 1
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
  72. 1
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj
  73. 268
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs
  74. 115
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationAppService.cs
  75. 2
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs

22
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<string, bool> Permissions { get; set; }
public GroupUserCard()
{
Permissions = new Dictionary<string, bool>();
}
public bool IsGrant(string key)
{
return Permissions.Any(x => x.Equals(key) && x.Value);
}
}
}

27
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 public interface IUserGroupStore
{ {
/// <summary>
/// 获取群组用户身份
/// </summary>
/// <param name="tenantId"></param>
/// <param name="groupId"></param>
/// <param name="userId"></param>
/// <returns></returns>
Task<GroupUserCard> GetUserGroupCardAsync(Guid? tenantId, long groupId, Guid userId);
/// <summary> /// <summary>
/// 获取用户所在通讯组列表 /// 获取用户所在通讯组列表
/// </summary> /// </summary>
@ -21,6 +29,25 @@ namespace LINGYUN.Abp.IM.Group
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId); Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId);
/// <summary> /// <summary>
/// 获取通讯组用户数
/// </summary>
/// <param name="tenantId"></param>
/// <param name="groupId"></param>
/// <param name="filter"></param>
/// <returns></returns>
Task<int> GetGroupUsersCountAsync(Guid? tenantId, long groupId, string filter = "");
/// <summary>
/// 获取通讯组用户
/// </summary>
/// <param name="tenantId"></param>
/// <param name="groupId"></param>
/// <param name="filter"></param>
/// <param name="sorting"></param>
/// <param name="skipCount"></param>
/// <param name="maxResultCount"></param>
/// <returns></returns>
Task<List<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId, string filter = "", string sorting = nameof(UserGroup.UserId), int skipCount = 1, int maxResultCount = 10);
/// <summary>
/// 用户加入通讯组 /// 用户加入通讯组
/// </summary> /// </summary>
/// <param name="tenantId"></param> /// <param name="tenantId"></param>

24
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs

@ -15,13 +15,32 @@ namespace LINGYUN.Abp.IM.Messages
/// <returns></returns> /// <returns></returns>
Task StoreMessageAsync(ChatMessage chatMessage); Task StoreMessageAsync(ChatMessage chatMessage);
/// <summary> /// <summary>
/// 获取群组聊天记录总数
/// </summary>
/// <param name="tenantId"></param>
/// <param name="groupId"></param>
/// <param name="filter"></param>
/// <param name="type"></param>
/// <returns></returns>
Task<long> GetGroupMessageCountAsync(Guid? tenantId, long groupId, string filter = "", MessageType? type = null);
/// <summary>
/// 获取群组聊天记录 /// 获取群组聊天记录
/// </summary> /// </summary>
/// <param name="tenantId"></param> /// <param name="tenantId"></param>
/// <param name="groupName"></param> /// <param name="groupName"></param>
/// <param name="maxResultCount"></param> /// <param name="maxResultCount"></param>
/// <returns></returns> /// <returns></returns>
Task<List<ChatMessage>> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); Task<List<ChatMessage>> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
/// <summary>
/// 获取与某个用户的聊天记录总数
/// </summary>
/// <param name="tenantId"></param>
/// <param name="sendUserId"></param>
/// <param name="receiveUserId"></param>
/// <param name="filter"></param>
/// <param name="type"></param>
/// <returns></returns>
Task<long> GetChatMessageCountAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null);
/// <summary> /// <summary>
/// 获取与某个用户的聊天记录 /// 获取与某个用户的聊天记录
/// </summary> /// </summary>
@ -29,7 +48,6 @@ namespace LINGYUN.Abp.IM.Messages
/// <param name="userId"></param> /// <param name="userId"></param>
/// <param name="maxResultCount"></param> /// <param name="maxResultCount"></param>
/// <returns></returns> /// <returns></returns>
Task<List<ChatMessage>> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10); Task<List<ChatMessage>> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", string sorting = nameof(ChatMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
} }
} }

48
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; }
/// <summary>
/// 头像
/// </summary>
public string AvatarlUrl { get; set; }
/// <summary>
/// 昵称
/// </summary>
public string NickName { get; set; }
/// <summary>
/// 年龄
/// </summary>
public int Arg { get; set; }
/// <summary>
/// 性别
/// </summary>
public string Sex { get; set; }
/// <summary>
/// 国家
/// </summary>
public string Countriy { get; set; }
/// <summary>
/// 省份
/// </summary>
public string Province { get; set; }
/// <summary>
/// 城市
/// </summary>
public string City { get; set; }
/// <summary>
/// 签名
/// </summary>
public string Sign { get; set; }
#endregion
}
}

29
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN.Abp.MessageService.Application.Contracts.csproj

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="2.9.0" />
<PackageReference Include="Volo.Abp.Authorization" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\MessageService\Localization\ApplicationContracts\en.json" />
<None Remove="LINGYUN\Abp\MessageService\Localization\ApplicationContracts\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\MessageService\Localization\ApplicationContracts\en.json" />
<EmbeddedResource Include="LINGYUN\Abp\MessageService\Localization\ApplicationContracts\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.IM\LINGYUN.Abp.IM.csproj" />
<ProjectReference Include="..\..\common\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj" />
<ProjectReference Include="..\..\message\LINGYUN.Abp.MessageService.Domain.Shared\LINGYUN.Abp.MessageService.Domain.Shared.csproj" />
</ItemGroup>
</Project>

26
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<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpMessageServiceApplicationContrantsModule>();
});
Configure<AbpLocalizationOptions>(options =>
{
options.Resources
.Get<MessageServiceResource>()
.AddVirtualJson("/LINGYUN/Abp/MessageService/Localization/ApplicationContracts");
});
}
}
}

7
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";
}
}

11
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;
}
}
}

19
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; }
}
}

14
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; }
}
}

14
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; }
}
}

13
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; }
}
}

10
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; }
}
}

14
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; }
}
}

15
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; }
}
}

61
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
{
/// <summary>
/// 发送消息
/// </summary>
/// <param name="chatMessage"></param>
/// <returns></returns>
Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage chatMessage);
/// <summary>
/// 申请加入群组
/// </summary>
/// <param name="userJoinGroup"></param>
/// <returns></returns>
Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup);
/// <summary>
/// 获取我的群组
/// </summary>
/// <returns></returns>
Task<ListResultDto<Group>> GetMyGroupsAsync();
/// <summary>
/// 获取群组用户
/// </summary>
/// <param name="groupUserGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<UserGroup>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged);
/// <summary>
/// 处理用户群组申请
/// </summary>
/// <param name="groupAcceptUser"></param>
/// <returns></returns>
Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser);
/// <summary>
/// 群组移除用户
/// </summary>
/// <param name="groupRemoveUser"></param>
/// <returns></returns>
Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser);
/// <summary>
/// 获取群组消息
/// </summary>
/// <param name="groupMessageGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged);
/// <summary>
/// 获取我的消息
/// </summary>
/// <param name="userMessageGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged);
//TOTO: 还应该有获取我的未读消息 获取我的未读群组消息
}
}

8
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"
}
}

8
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": "删除"
}
}

10
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; }
}
}

14
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;
}
}

11
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; }
}
}

12
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;
}
}

41
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
{
/// <summary>
/// 查询通知明细
/// </summary>
/// <param name="notificationGetById"></param>
/// <returns></returns>
Task<NotificationInfo> GetAsync(NotificationGetByIdDto notificationGetById);
/// <summary>
/// 删除通知
/// </summary>
/// <param name="notificationGetById"></param>
/// <returns></returns>
Task DeleteAsync(NotificationGetByIdDto notificationGetById);
/// <summary>
/// 删除用户通知
/// </summary>
/// <param name="notificationGetById"></param>
/// <returns></returns>
Task DeleteUserNotificationAsync(NotificationGetByIdDto notificationGetById);
/// <summary>
/// 变更通知阅读状态
/// </summary>
/// <param name="userNotificationChangeRead"></param>
/// <returns></returns>
Task ChangeUserNotificationReadStateAsync(UserNotificationChangeReadStateDto userNotificationChangeRead);
/// <summary>
/// 获取用户通知列表
/// </summary>
/// <param name="userNotificationGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<NotificationInfo>> GetUserNotificationsAsync(UserNotificationGetByPagedDto userNotificationGetByPaged);
}
}

14
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";
}
}
}

22
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<MessageServiceResource>(name);
}
}
}

12
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; }
}
}

8
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
{
}
}

35
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
{
/// <summary>
/// 是否已订阅消息
/// </summary>
/// <param name="subscriptionsGetByName"></param>
/// <returns></returns>
Task<bool> IsSubscribedAsync(SubscriptionsGetByNameDto subscriptionsGetByName);
/// <summary>
/// 订阅消息
/// </summary>
/// <param name="subscriptionsGetByName"></param>
/// <returns></returns>
Task SubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName);
/// <summary>
/// 退订消息
/// </summary>
/// <param name="subscriptionsGetByName"></param>
/// <returns></returns>
Task UnSubscribeAsync(SubscriptionsGetByNameDto subscriptionsGetByName);
/// <summary>
/// 获取订阅列表
/// </summary>
/// <param name="subscriptionsGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<NotificationSubscriptionInfo>> GetSubscribedsAsync(SubscriptionsGetByPagedDto subscriptionsGetByPaged);
}
}

12
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
{
}
}

17
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN.Abp.MessageService.Application.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Application" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.MessageService.Application.Contracts\LINGYUN.Abp.MessageService.Application.Contracts.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.MessageService.Domain\LINGYUN.Abp.MessageService.Domain.csproj" />
</ItemGroup>
</Project>

127
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<PagedResultDto<ChatMessage>> 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<ChatMessage>(chatMessageCount, chatMessages);
}
public virtual async Task<PagedResultDto<ChatMessage>> 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<ChatMessage>(groupMessageCount, groupMessages);
}
public virtual async Task<PagedResultDto<UserGroup>> 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<UserGroup>(groupUserCount, groupUsers);
}
public virtual async Task<ListResultDto<Group>> GetMyGroupsAsync()
{
var myGroups = await _userGroupStore.GetUserGroupsAsync(CurrentTenant.Id, CurrentUser.GetId());
return new ListResultDto<Group>(myGroups.ToImmutableList());
}
public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto 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<ChatMessageSendResultDto> 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;
}
}
}

68
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<NotificationInfo> GetAsync(NotificationGetByIdDto notificationGetById)
{
var notification = await _notificationRepository.GetByIdAsync(notificationGetById.NotificationId);
return ObjectMapper.Map<Notification, NotificationInfo>(notification);
}
public virtual async Task<PagedResultDto<NotificationInfo>> 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<NotificationInfo>(notificationCount,
ObjectMapper.Map<List<Notification>, List<NotificationInfo>>(notifications));
}
}
}

65
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<PagedResultDto<NotificationSubscriptionInfo>> 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<NotificationSubscriptionInfo>(userSubscribedCount,
ObjectMapper.Map<List<UserSubscribe>, List<NotificationSubscriptionInfo>>(userSubscribes));
}
public virtual async Task<bool> 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);
}
}
}
}

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/ChatGroupConsts.cs → 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 public class ChatGroupConsts
{ {

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Messages/MessageConsts.cs → 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 public class MessageConsts
{ {

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroup.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs

@ -1,10 +1,8 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 聊天群组 /// 聊天群组

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/ChatGroupAdmin.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 群管理员 /// 群管理员

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupChatBlack.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 用户黑名单 /// 用户黑名单

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/GroupMessage.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/GroupMessage.cs

@ -1,7 +1,7 @@
using LINGYUN.Abp.IM.Messages; using LINGYUN.Abp.IM.Messages;
using System; using System;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class GroupMessage : Message public class GroupMessage : Message
{ {

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IGroupRepository.cs → 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 System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public interface IGroupRepository : IBasicRepository<ChatGroup, long> public interface IGroupRepository : IBasicRepository<ChatGroup, long>
{ {

30
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<UserMessage> InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false);
Task<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false);
Task<UserMessage> GetUserMessageAsync(long id);
Task<GroupMessage> GetGroupMessageAsync(long id);
Task<long> GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null);
Task<List<UserMessage>> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
Task<long> GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null);
Task<List<GroupMessage>> GetGroupMessagesAsync(long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
Task<long> GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null);
Task<List<GroupMessage>> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
}
}

8
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatGroupRepository.cs → 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 System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public interface IUserChatGroupRepository : IBasicRepository<UserChatGroup, long> public interface IUserChatGroupRepository : IBasicRepository<UserChatGroup, long>
{ {
@ -18,8 +18,14 @@ namespace LINGYUN.Abp.MessageService.Messages
Task<UserChatGroup> GetUserGroupAsync(long groupId, Guid userId); Task<UserChatGroup> GetUserGroupAsync(long groupId, Guid userId);
Task<GroupUserCard> GetGroupUserCardAsync(long groupId, Guid userId);
Task<List<UserGroup>> GetGroupUsersAsync(long groupId); Task<List<UserGroup>> GetGroupUsersAsync(long groupId);
Task<int> GetGroupUsersCountAsync(long groupId, string filter = "");
Task<List<UserGroup>> GetGroupUsersAsync(long groupId, string filter = "", string sorting = nameof(UserGroup.UserId), int skipCount = 1, int maxResultCount = 10);
Task<List<Group>> GetUserGroupsAsync(Guid userId); Task<List<Group>> GetUserGroupsAsync(Guid userId);
} }
} }

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IUserChatSettingRepository.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatSettingRepository.cs

@ -2,7 +2,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public interface IUserChatSettingRepository : IBasicRepository<UserChatSetting, long> public interface IUserChatSettingRepository : IBasicRepository<UserChatSetting, long>
{ {

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/Message.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public abstract class Message : CreationAuditedEntity<long>, IMultiTenant public abstract class Message : CreationAuditedEntity<long>, IMultiTenant
{ {

27
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/MessageStore.cs → 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.ObjectMapping;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class MessageStore : DomainService, IMessageStore public class MessageStore : DomainService, IMessageStore
{ {
@ -54,22 +54,25 @@ namespace LINGYUN.Abp.MessageService.Messages
} }
} }
public async Task<List<ChatMessage>> GetGroupMessageAsync(Guid? tenantId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) public async Task<List<ChatMessage>> 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)) 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<GroupMessage>, List<ChatMessage>>(groupMessages); var chatMessages = ObjectMapper.Map<List<GroupMessage>, List<ChatMessage>>(groupMessages);
return chatMessages; return chatMessages;
} }
} }
public async Task<List<ChatMessage>> GetChatMessageAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) public async Task<List<ChatMessage>> 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)) 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<UserMessage>, List<ChatMessage>>(userMessages); var chatMessages = ObjectMapper.Map<List<UserMessage>, List<ChatMessage>>(userMessages);
return chatMessages; return chatMessages;
@ -100,6 +103,8 @@ namespace LINGYUN.Abp.MessageService.Messages
var message = new UserMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType); var message = new UserMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType);
message.SendToUser(chatMessage.ToUserId.Value); message.SendToUser(chatMessage.ToUserId.Value);
await MessageRepository.InsertUserMessageAsync(message); await MessageRepository.InsertUserMessageAsync(message);
chatMessage.MessageId = messageId.ToString();
} }
protected virtual async Task StoreGroupMessageAsync(ChatMessage chatMessage, long groupId) protected virtual async Task StoreGroupMessageAsync(ChatMessage chatMessage, long groupId)
@ -127,6 +132,18 @@ namespace LINGYUN.Abp.MessageService.Messages
// TODO: 需要压测 高并发场景下的装箱性能影响 // TODO: 需要压测 高并发场景下的装箱性能影响
message.SendToGroup(groupId); message.SendToGroup(groupId);
await MessageRepository.InsertGroupMessageAsync(message); await MessageRepository.InsertGroupMessageAsync(message);
chatMessage.MessageId = messageId.ToString();
}
public Task<long> GetGroupMessageCountAsync(Guid? tenantId, long groupId, string filter = "", MessageType? type = null)
{
throw new NotImplementedException();
}
public Task<long> GetChatMessageCountAsync(Guid? tenantId, Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null)
{
throw new NotImplementedException();
} }
} }
} }

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatBlack.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 用户黑名单 /// 用户黑名单

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatGroup.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 用户群组 /// 用户群组

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserChatSetting.cs → 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.Domain.Entities;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class UserChatSetting : Entity<long>, IMultiTenant public class UserChatSetting : Entity<long>, IMultiTenant
{ {

28
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserGroupStore.cs → 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.ObjectMapping;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class UserGroupStore : DomainService, IUserGroupStore public class UserGroupStore : DomainService, IUserGroupStore
{ {
@ -44,6 +44,16 @@ namespace LINGYUN.Abp.MessageService.Messages
} }
} }
public async Task<GroupUserCard> GetUserGroupCardAsync(Guid? tenantId, long groupId, Guid userId)
{
using (CurrentTenant.Change(tenantId))
{
var groupUserCard = await UserChatGroupRepository.GetGroupUserCardAsync(groupId, userId);
return groupUserCard;
}
}
public async Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId) public async Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId)
{ {
using (CurrentTenant.Change(tenantId)) using (CurrentTenant.Change(tenantId))
@ -82,5 +92,21 @@ namespace LINGYUN.Abp.MessageService.Messages
} }
} }
} }
public async Task<int> GetGroupUsersCountAsync(Guid? tenantId, long groupId, string filter = "")
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatGroupRepository.GetGroupUsersCountAsync(groupId, filter);
}
}
public async Task<List<UserGroup>> 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);
}
}
} }
} }

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserMessage.cs → aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserMessage.cs

@ -1,7 +1,7 @@
using LINGYUN.Abp.IM.Messages; using LINGYUN.Abp.IM.Messages;
using System; using System;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class UserMessage : Message public class UserMessage : Message
{ {

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/UserSpecialFocus.cs → 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.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
/// <summary> /// <summary>
/// 用户特别关注 /// 用户特别关注

2
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 System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events; using Volo.Abp.Domain.Entities.Events;

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs

@ -1,6 +1,6 @@
using AutoMapper; using AutoMapper;
using LINGYUN.Abp.IM.Messages; using LINGYUN.Abp.IM.Messages;
using LINGYUN.Abp.MessageService.Messages; using LINGYUN.Abp.MessageService.Chat;
using LINGYUN.Abp.MessageService.Notifications; using LINGYUN.Abp.MessageService.Notifications;
using LINGYUN.Abp.MessageService.Subscriptions; using LINGYUN.Abp.MessageService.Subscriptions;
using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications;

24
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Messages/IMessageRepository.cs

@ -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<UserMessage> InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false);
Task<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false);
Task<UserMessage> GetUserMessageAsync(long id);
Task<GroupMessage> GetGroupMessageAsync(long id);
Task<List<UserMessage>> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10);
Task<List<GroupMessage>> GetGroupMessagesAsync(long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10);
Task<List<GroupMessage>> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10);
}
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs

@ -16,6 +16,10 @@ namespace LINGYUN.Abp.MessageService.Notifications
Task<List<Notification>> GetNotificationsAsync(Guid userId, NotificationReadState readState = NotificationReadState.UnRead, int maxResultCount = 10); Task<List<Notification>> GetNotificationsAsync(Guid userId, NotificationReadState readState = NotificationReadState.UnRead, int maxResultCount = 10);
Task<long> GetCountAsync(Guid userId, string filter = "", NotificationReadState readState = NotificationReadState.UnRead);
Task<List<Notification>> 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); Task ChangeUserNotificationReadStateAsync(Guid userId, long notificationId, NotificationReadState readState);
} }
} }

4
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<UserSubscribe> userSubscribes); Task DeleteUserSubscriptionAsync(IEnumerable<UserSubscribe> userSubscribes);
Task DeleteUserSubscriptionAsync(string notificationName); Task DeleteUserSubscriptionAsync(string notificationName);
Task<List<UserSubscribe>> GetUserSubscribesAsync(Guid userId, string sorting = nameof(UserSubscribe.Id), int skipCount = 1, int maxResultCount = 10);
Task<long> GetCountAsync(Guid userId);
} }
} }

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreGroupRepository.cs → 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.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class EfCoreGroupRepository : EfCoreRepository<MessageServiceDbContext, ChatGroup, long>, public class EfCoreGroupRepository : EfCoreRepository<MessageServiceDbContext, ChatGroup, long>,
IGroupRepository, ITransientDependency IGroupRepository, ITransientDependency

83
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreMessageRepository.cs → 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class EfCoreMessageRepository : EfCoreRepository<MessageServiceDbContext, Message, long>, public class EfCoreMessageRepository : EfCoreRepository<MessageServiceDbContext, Message, long>,
IMessageRepository, ITransientDependency IMessageRepository, ITransientDependency
@ -28,42 +29,60 @@ namespace LINGYUN.Abp.MessageService.Messages
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
} }
public async Task<List<GroupMessage>> GetGroupMessagesAsync(long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) public async Task<List<GroupMessage>> 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<GroupMessage>() var groupMessages = await DbContext.Set<GroupMessage>()
.Distinct() .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)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.OrderByDescending(x => x.MessageId) .OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Skip(skipCount * maxResultCount) .Page(skipCount, maxResultCount)
.Take(maxResultCount) .AsNoTracking()
.ToListAsync(); .ToListAsync();
return groupMessages; return groupMessages;
} }
public async Task<List<GroupMessage>> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) public async Task<long> GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null)
{ {
if (skipCount > 0) var groupMessagesCount = await DbContext.Set<GroupMessage>()
{ .Distinct()
skipCount -= 1; .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<List<GroupMessage>> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "",
string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10)
{
var groupMessages = await DbContext.Set<GroupMessage>() var groupMessages = await DbContext.Set<GroupMessage>()
.Distinct() .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)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.OrderByDescending(x => x.MessageId) .OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Skip(skipCount * maxResultCount) .Page(skipCount, maxResultCount)
.Take(maxResultCount) .AsNoTracking()
.ToListAsync(); .ToListAsync();
return groupMessages; return groupMessages;
} }
public async Task<long> GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null)
{
var groupMessagesCount = await DbContext.Set<GroupMessage>()
.Distinct()
.Where(x => x.GroupId.Equals(groupId) && x.CreatorId.Equals(sendUserId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.LongCountAsync();
return groupMessagesCount;
}
public async Task<UserMessage> GetUserMessageAsync(long id) public async Task<UserMessage> GetUserMessageAsync(long id)
{ {
return await DbContext.Set<UserMessage>() return await DbContext.Set<UserMessage>()
@ -72,24 +91,34 @@ namespace LINGYUN.Abp.MessageService.Messages
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
} }
public async Task<List<UserMessage>> GetUserMessagesAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType type = MessageType.Text, int skipCount = 1, int maxResultCount = 10) public async Task<List<UserMessage>> 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<UserMessage>() var userMessages = await DbContext.Set<UserMessage>()
.Distinct() .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)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.OrderByDescending(x => x.MessageId) .OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Skip(skipCount * maxResultCount) .Page(skipCount, maxResultCount)
.Take(maxResultCount) .AsNoTracking()
.ToListAsync(); .ToListAsync();
return userMessages; return userMessages;
} }
public async Task<long> GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null)
{
var userMessagesCount = await DbContext.Set<UserMessage>()
.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<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false) public async Task<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false)
{ {
groupMessage = (await DbContext.Set<GroupMessage>().AddAsync(groupMessage, GetCancellationToken())).Entity; groupMessage = (await DbContext.Set<GroupMessage>().AddAsync(groupMessage, GetCancellationToken())).Entity;

45
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatGroupRepository.cs → 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.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class EfCoreUserChatGroupRepository : EfCoreRepository<MessageServiceDbContext, UserChatGroup, long>, public class EfCoreUserChatGroupRepository : EfCoreRepository<MessageServiceDbContext, UserChatGroup, long>,
IUserChatGroupRepository, ITransientDependency IUserChatGroupRepository, ITransientDependency
@ -44,6 +44,49 @@ namespace LINGYUN.Abp.MessageService.Messages
return groupUsers; return groupUsers;
} }
public async Task<GroupUserCard> GetGroupUserCardAsync(long groupId, Guid userId)
{
var groupUserCard = await (from cg in DbContext.Set<ChatGroup>()
join ucg in DbContext.Set<UserChatGroup>().DefaultIfEmpty()
on cg.GroupId equals ucg.GroupId
join cga in DbContext.Set<ChatGroupAdmin>().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<string, bool>
{
{ 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<List<UserGroup>> GetGroupUsersAsync(long groupId, string filter = "", string sorting = "UserId", int skipCount = 1, int maxResultCount = 10)
{
// TODO: 复杂的实现,暂时无关紧要,后期再说 :)
throw new NotImplementedException();
}
public Task<int> GetGroupUsersCountAsync(long groupId, string filter = "")
{
// TODO: 复杂的实现,暂时无关紧要,后期再说 :)
throw new NotImplementedException();
}
public async Task<UserChatGroup> GetUserGroupAsync(long groupId, Guid userId) public async Task<UserChatGroup> GetUserGroupAsync(long groupId, Guid userId)
{ {
return await DbSet.Where(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId)) return await DbSet.Where(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId))

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Messages/EfCoreUserChatSettingRepository.cs → 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.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Messages namespace LINGYUN.Abp.MessageService.Chat
{ {
public class EfCoreUserChatSettingRepository : EfCoreRepository<MessageServiceDbContext, UserChatSetting, long>, public class EfCoreUserChatSettingRepository : EfCoreRepository<MessageServiceDbContext, UserChatSetting, long>,
IUserChatSettingRepository, ITransientDependency IUserChatSettingRepository, ITransientDependency

2
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.Notifications;
using LINGYUN.Abp.MessageService.Subscriptions; using LINGYUN.Abp.MessageService.Subscriptions;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;

2
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.Notifications;
using LINGYUN.Abp.MessageService.Subscriptions; using LINGYUN.Abp.MessageService.Subscriptions;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

32
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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -62,5 +63,36 @@ namespace LINGYUN.Abp.MessageService.Notifications
.ToListAsync(); .ToListAsync();
return userNofitications; return userNofitications;
} }
public virtual async Task<long> GetCountAsync(Guid userId, string filter = "", NotificationReadState readState = NotificationReadState.UnRead)
{
var userNofiticationCount = await (from un in DbContext.Set<UserNotification>()
join n in DbContext.Set<Notification>()
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<List<Notification>> 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<UserNotification>()
join n in DbContext.Set<Notification>()
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;
}
} }
} }

24
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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -94,5 +95,28 @@ namespace LINGYUN.Abp.MessageService.Subscriptions
{ {
return await DbSet.AnyAsync(x => x.UserId.Equals(userId) && x.NotificationName.Equals(notificationName)); return await DbSet.AnyAsync(x => x.UserId.Equals(userId) && x.NotificationName.Equals(notificationName));
} }
public virtual async Task<List<UserSubscribe>> 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<long> GetCountAsync(Guid userId)
{
var userSubscribedCount = await DbSet
.Distinct()
.Where(x => x.UserId.Equals(userId))
.LongCountAsync();
return userSubscribedCount;
}
} }
} }

6
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN.Abp.MessageService.HttpApi.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
@ -9,4 +9,8 @@
<PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="2.9.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Mvc" Version="2.9.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.MessageService.Application.Contracts\LINGYUN.Abp.MessageService.Application.Contracts.csproj" />
</ItemGroup>
</Project> </Project>

1
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 namespace LINGYUN.Abp.MessageService
{ {
[DependsOn( [DependsOn(
typeof(AbpMessageServiceApplicationContrantsModule),
typeof(AbpAspNetCoreMvcModule) typeof(AbpAspNetCoreMvcModule)
)] )]
public class AbpMessageServiceHttpApiModule : AbpModule public class AbpMessageServiceHttpApiModule : AbpModule

78
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<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged)
{
return await _chatAppService.GetGroupMessageAsync(groupMessageGetByPaged);
}
[HttpGet]
[Route("groups/users")]
public virtual async Task<PagedResultDto<UserGroup>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
{
return await _chatAppService.GetGroupUsersAsync(groupUserGetByPaged);
}
[HttpGet]
[Route("messages/me")]
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged)
{
return await _chatAppService.GetMyChatMessageAsync(userMessageGetByPaged);
}
[HttpGet]
[Route("groups/me")]
public virtual async Task<ListResultDto<Group>> 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<ChatMessageSendResultDto> SendMessageAsync(ChatMessage chatMessage)
{
return await _chatAppService.SendMessageAsync(chatMessage);
}
}
}

56
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<NotificationInfo> GetAsync(NotificationGetByIdDto notificationGetById)
{
return await _notificationAppService.GetAsync(notificationGetById);
}
[HttpGet]
[Route("User/{NotificationId}")]
public virtual async Task<PagedResultDto<NotificationInfo>> GetUserNotificationsAsync(UserNotificationGetByPagedDto userNotificationGetByPaged)
{
return await _notificationAppService.GetUserNotificationsAsync(userNotificationGetByPaged);
}
}
}

47
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<PagedResultDto<NotificationSubscriptionInfo>> GetSubscribedsAsync(SubscriptionsGetByPagedDto subscriptionsGetByPaged)
{
return await _subscriptionAppService.GetSubscribedsAsync(subscriptionsGetByPaged);
}
[HttpGet]
[Route("IsSubscribed/{NotificationName}")]
public virtual async Task<bool> 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);
}
}
}

1
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj

@ -50,6 +50,7 @@
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.SignalR\LINGYUN.Abp.Notifications.SignalR.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.SignalR\LINGYUN.Abp.Notifications.SignalR.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.WeChat\LINGYUN.Abp.Notifications.WeChat.WeApp.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.WeChat\LINGYUN.Abp.Notifications.WeChat.WeApp.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Common.EventBus\LINGYUN.Common.EventBus.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Common.EventBus\LINGYUN.Common.EventBus.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.Application\LINGYUN.Abp.MessageService.Application.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" />
</ItemGroup> </ItemGroup>

1
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 namespace LINGYUN.Abp.MessageService
{ {
[DependsOn( [DependsOn(
typeof(AbpMessageServiceApplicationModule),
typeof(AbpMessageServiceHttpApiModule), typeof(AbpMessageServiceHttpApiModule),
typeof(AbpAspNetCoreMultiTenancyModule), typeof(AbpAspNetCoreMultiTenancyModule),
typeof(AbpMessageServiceEntityFrameworkCoreModule), typeof(AbpMessageServiceEntityFrameworkCoreModule),

1
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj

@ -65,6 +65,7 @@
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Identity.OverrideOptions\LINGYUN.Abp.Identity.OverrideOptions.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Identity.OverrideOptions\LINGYUN.Abp.Identity.OverrideOptions.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Location.Baidu\LINGYUN.Abp.Location.Baidu.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Location.Baidu\LINGYUN.Abp.Location.Baidu.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.Application.Contracts\LINGYUN.Abp.MessageService.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Sms.Aliyun\LINGYUN.Abp.Sms.Aliyun.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Sms.Aliyun\LINGYUN.Abp.Sms.Aliyun.csproj" />
<ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.Application\LINGYUN.Abp.IdentityServer.Application.csproj" /> <ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.Application\LINGYUN.Abp.IdentityServer.Application.csproj" />
<ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.HttpApi\LINGYUN.Abp.IdentityServer.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.HttpApi\LINGYUN.Abp.IdentityServer.HttpApi.csproj" />

268
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN/Platform/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs

@ -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<AbpLocalizationOptions> localizationOptions,
IOptions<AbpMultiTenancyOptions> 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<ApplicationConfigurationDto> 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<ApplicationAuthConfigurationDto> GetAuthConfigAsync()
{
var authConfig = new ApplicationAuthConfigurationDto();
var permissions = _permissionDefinitionManager.GetPermissions();
IEnumerable<PermissionGrant> grantPermissions = new List<PermissionGrant>();
// 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<ApplicationLocalizationConfigurationDto> GetLocalizationConfigAsync()
{
var localizationConfig = new ApplicationLocalizationConfigurationDto();
localizationConfig.Languages.AddRange(await _languageProvider.GetLanguagesAsync());
foreach (var resource in _localizationOptions.Resources.Values)
{
var dictionary = new Dictionary<string, string>();
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<ApplicationSettingConfigurationDto> GetSettingConfigAsync()
{
var result = new ApplicationSettingConfigurationDto
{
Values = new Dictionary<string, string>()
};
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<ApplicationFeatureConfigurationDto> 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;
}
}
}

115
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<AbpLocalizationOptions> localizationOptions,
IOptions<AbpMultiTenancyOptions> multiTenancyOptions,
IServiceProvider serviceProvider,
IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider,
IAuthorizationService authorizationService,
ICurrentUser currentUser,
ISettingProvider settingProvider,
ISettingDefinitionManager settingDefinitionManager,
IFeatureDefinitionManager featureDefinitionManager,
ILanguageProvider languageProvider,
ITimezoneProvider timezoneProvider,
IOptions<AbpClockOptions> 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<ApplicationAuthConfigurationDto> GetAuthConfigAsync()
{
var authConfig = new ApplicationAuthConfigurationDto();
var permissions = _permissionDefinitionManager.GetPermissions();
IEnumerable<PermissionGrant> grantPermissions = new List<PermissionGrant>();
// 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;
}
}
}

2
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.Identity;
using LINGYUN.Abp.IdentityServer; using LINGYUN.Abp.IdentityServer;
using LINGYUN.Abp.Location.Baidu; using LINGYUN.Abp.Location.Baidu;
using LINGYUN.Abp.MessageService;
using LINGYUN.Abp.SettingManagement; using LINGYUN.Abp.SettingManagement;
using LINGYUN.Abp.TenantManagement; using LINGYUN.Abp.TenantManagement;
using LINGYUN.ApiGateway; using LINGYUN.ApiGateway;
@ -53,6 +54,7 @@ namespace LINGYUN.Platform
typeof(AbpPermissionManagementDomainIdentityModule), typeof(AbpPermissionManagementDomainIdentityModule),
typeof(AbpPermissionManagementDomainIdentityServerModule), typeof(AbpPermissionManagementDomainIdentityServerModule),
typeof(ApiGatewayApplicationContractsModule), typeof(ApiGatewayApplicationContractsModule),
typeof(AbpMessageServiceApplicationContrantsModule),
typeof(AbpIdentityHttpApiModule), typeof(AbpIdentityHttpApiModule),
typeof(AbpIdentityApplicationModule), typeof(AbpIdentityApplicationModule),
typeof(Abp.Account.AbpAccountApplicationModule), typeof(Abp.Account.AbpAccountApplicationModule),

Loading…
Cancel
Save