Browse Source

Refactor the module: Instant messaging

pull/116/head
cKey 5 years ago
parent
commit
a999be4a3e
  1. 7
      aspnet-core/LINGYUN.MicroService.sln
  2. 14
      aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj
  3. 25
      aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs
  4. 18
      aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenModule.cs
  5. 0
      aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/Microsoft/AspNetCore/Builder/SignalRJwtTokenApplicationBuilderExtensions.cs
  6. 45
      aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/Microsoft/AspNetCore/Http/SignalRJwtTokenMiddleware.cs
  7. 2
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN.Abp.IM.SignalR.csproj
  8. 14
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/AbpIMSignalRModule.cs
  9. 71
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs
  10. 4
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSender.cs
  11. 110
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/IFriendStore.cs
  12. 28
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/UserFriend.cs
  13. 12
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs
  14. 17
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs
  15. 60
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/IUserCardFinder.cs
  16. 41
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs
  17. 9
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Sex.cs
  18. 25
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs
  19. 1
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN.Abp.Notifications.SignalR.csproj
  20. 11
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/AbpNotificationsSignalRModule.cs
  21. 25
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/Microsoft/AspNetCore/Http/SignalRJwtTokenMiddleware.cs
  22. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs
  23. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs
  24. 7
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendCreateDto.cs
  25. 15
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendGetByPagedDto.cs
  26. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendOperationDto.cs
  27. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs
  28. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs
  29. 18
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IMyFriendAppService.cs
  30. 29
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs
  31. 53
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/MyFriendAppService.cs
  32. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj
  33. 13
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/UserChatCardConsts.cs
  34. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDbProperties.cs
  35. 54
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatDataSeeder.cs
  36. 27
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs
  37. 69
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs
  38. 119
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/FriendStore.cs
  39. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IChatDataSeeder.cs
  40. 15
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs
  41. 82
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs
  42. 38
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatCardRepository.cs
  43. 47
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatFriendRepository.cs
  44. 77
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs
  45. 63
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs
  46. 47
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserCardFinder.cs
  47. 105
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatCard.cs
  48. 54
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatFriend.cs
  49. 74
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupCard.cs
  50. 35
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs
  51. 31
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs
  52. 17
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/DateTimeHelper.cs
  53. 36
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs
  54. 147
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs
  55. 63
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatCardRepository.cs
  56. 164
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatFriendRepository.cs
  57. 343
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs
  58. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs
  59. 3
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs
  60. 14
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/IMessageServiceDbContext.cs
  61. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContext.cs
  62. 48
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs
  63. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs
  64. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs
  65. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs
  66. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs
  67. 46
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/MyFriendController.cs
  68. 6
      aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs
  69. BIN
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/event-bus-cap.db
  70. 7
      aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs
  71. 590
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024093309_Add-MemberCard-Entity.Designer.cs
  72. 125
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024093309_Add-MemberCard-Entity.cs
  73. 634
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024114206_Add-UserChatFriend-Entity.Designer.cs
  74. 44
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024114206_Add-UserChatFriend-Entity.cs
  75. 307
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/MessageServiceHostMigrationsDbContextModelSnapshot.cs
  76. 8
      vueJs/package-lock.json
  77. 1
      vueJs/package.json
  78. 71
      vueJs/src/api/instant-message.ts
  79. 122
      vueJs/src/components/InstantMessage/index.vue
  80. 3
      vueJs/src/main.ts
  81. 3
      vueJs/src/shims.d.ts
  82. 25
      vueJs/src/views/dashboard/admin/index.vue

7
aspnet-core/LINGYUN.MicroService.sln

@ -251,6 +251,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.PermissionManag
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Account.Web", "modules\account\LINGYUN.Abp.Account.Web\LINGYUN.Abp.Account.Web.csproj", "{5F43141B-6C63-4547-B9D6-D69EC3D7CA7E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.AspNetCore.SignalR.JwtToken", "modules\common\LINGYUN.Abp.AspNetCore.SignalR\LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj", "{A66D48C9-F141-4111-9169-CEB64AFFF61D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -665,6 +667,10 @@ Global
{5F43141B-6C63-4547-B9D6-D69EC3D7CA7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F43141B-6C63-4547-B9D6-D69EC3D7CA7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F43141B-6C63-4547-B9D6-D69EC3D7CA7E}.Release|Any CPU.Build.0 = Release|Any CPU
{A66D48C9-F141-4111-9169-CEB64AFFF61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A66D48C9-F141-4111-9169-CEB64AFFF61D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A66D48C9-F141-4111-9169-CEB64AFFF61D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A66D48C9-F141-4111-9169-CEB64AFFF61D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -791,6 +797,7 @@ Global
{B46D6DAF-98C6-441F-9FA5-3CAD7CF27727} = {CC362C67-6FC1-42B3-A130-8120AA8D790C}
{2D377D3A-70EC-4BB3-9F4C-6C933693DA98} = {52B5D4F7-237B-4E0A-A167-68442164F70A}
{5F43141B-6C63-4547-B9D6-D69EC3D7CA7E} = {9E72FEB9-A626-4312-892B-CDD043879758}
{A66D48C9-F141-4111-9169-CEB64AFFF61D} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718}

14
aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.AspNetCore.SignalR" Version="3.2.0" />
</ItemGroup>
</Project>

25
aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenMapPathOptions.cs

@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace LINGYUN.Abp.AspNetCore.SignalR.JwtToken
{
public class AbpAspNetCoreSignalRJwtTokenMapPathOptions
{
public List<string> MapJwtTokenPaths { get; set; }
public AbpAspNetCoreSignalRJwtTokenMapPathOptions()
{
MapJwtTokenPaths = new List<string>();
}
public void MapPath(string path)
{
if (path.StartsWith("/signalr-hubs/"))
{
MapJwtTokenPaths.AddIfNotContains(path);
}
else
{
MapJwtTokenPaths.AddIfNotContains($"/signalr-hubs/{path}");
}
}
}
}

18
aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/LINGYUN/Abp/AspNetCore/SignalR/JwtToken/AbpAspNetCoreSignalRJwtTokenModule.cs

@ -0,0 +1,18 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.AspNetCore.SignalR.JwtToken
{
[DependsOn(
typeof(AbpAspNetCoreSignalRModule))]
public class AbpAspNetCoreSignalRJwtTokenModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
Configure<AbpAspNetCoreSignalRJwtTokenMapPathOptions>(configuration.GetSection("SignalR:MapPath"));
}
}
}

0
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/Microsoft/AspNetCore/Builder/SignalRJwtTokenApplicationBuilderExtensions.cs → aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/Microsoft/AspNetCore/Builder/SignalRJwtTokenApplicationBuilderExtensions.cs

45
aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.SignalR/Microsoft/AspNetCore/Http/SignalRJwtTokenMiddleware.cs

@ -0,0 +1,45 @@
using LINGYUN.Abp.AspNetCore.SignalR.JwtToken;
using Microsoft.Extensions.Options;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Microsoft.AspNetCore.Http
{
public class SignalRJwtTokenMiddleware : IMiddleware, ITransientDependency
{
protected AbpAspNetCoreSignalRJwtTokenMapPathOptions Options { get; }
public SignalRJwtTokenMiddleware(IOptions<AbpAspNetCoreSignalRJwtTokenMapPathOptions> options)
{
Options = options.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (Options.MapJwtTokenPaths.Any(path => context.Request.Path.StartsWithSegments(path)))
{
if (context.User.Identity?.IsAuthenticated != true)
{
if (context.Request.Query.TryGetValue("access_token", out var accessToken))
{
context.Request.Headers.Add("Authorization", $"Bearer {accessToken}");
}
}
}
//if (context.Request.Path.StartsWithSegments("/signalr-hubs/"))
//{
// if (context.User.Identity?.IsAuthenticated != true)
// {
// if (context.Request.Query.TryGetValue("access_token", out var accessToken))
// {
// context.Request.Headers.Add("Authorization", $"Bearer {accessToken}");
// }
// }
//}
await next(context);
}
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN.Abp.IM.SignalR.csproj

@ -9,9 +9,11 @@
<ItemGroup>
<PackageReference Include="Volo.Abp.AspNetCore.SignalR" Version="3.2.0" />
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.AspNetCore.SignalR\LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.IM\LINGYUN.Abp.IM.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj" />
</ItemGroup>

14
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/AbpIMSignalRModule.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.RealTime;
using LINGYUN.Abp.AspNetCore.SignalR.JwtToken;
using LINGYUN.Abp.RealTime;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.Modularity;
@ -6,9 +7,16 @@ namespace LINGYUN.Abp.IM.SignalR
{
[DependsOn(
typeof(AbpRealTimeModule),
typeof(AbpAspNetCoreSignalRModule))]
typeof(AbpAspNetCoreSignalRModule),
typeof(AbpAspNetCoreSignalRJwtTokenModule))]
public class AbpIMSignalRModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpAspNetCoreSignalRJwtTokenMapPathOptions>(options =>
{
options.MapPath("messages");
});
}
}
}

71
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessageHub.cs → aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs

@ -1,23 +1,82 @@
using LINGYUN.Abp.IM.Messages;
using LINGYUN.Abp.IM.Contract;
using LINGYUN.Abp.IM.Messages;
using LINGYUN.Abp.RealTime.Client;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.IM.SignalR.Hubs
{
[Authorize]
public class MessageHub : OnlineClientHubBase
public class MessagesHub : OnlineClientHubBase
{
private readonly IMessageStore _messageStore;
protected IFriendStore FriendStore { get; }
protected IMessageStore MessageStore { get; }
public MessageHub(
public MessagesHub(
IFriendStore friendStore,
IMessageStore messageStore)
{
_messageStore = messageStore;
FriendStore = friendStore;
MessageStore = messageStore;
}
[HubMethodName("LastContactFriends")]
public virtual async Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(
Guid? tenantId,
Guid userId,
int skipCount = 0,
int maxResultCount = 10)
{
var myFrientCount = await FriendStore.GetCountAsync(tenantId, userId);
var lastContractFriends = await FriendStore
.GetLastContactListAsync(tenantId, userId, skipCount, maxResultCount);
return new PagedResultDto<UserFriend>(myFrientCount, lastContractFriends);
}
[HubMethodName("MyFriends")]
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(
Guid? tenantId,
Guid userId,
string filter = "",
string sorting = nameof(UserFriend.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10)
{
var myFrientCount = await FriendStore.GetCountAsync(tenantId, userId);
var myFriends = await FriendStore
.GetListAsync(tenantId, userId, filter, sorting, reverse, skipCount, maxResultCount);
return new PagedResultDto<UserFriend>(myFrientCount, myFriends);
}
[HubMethodName("AddFriend")]
public virtual async Task AddFriendAsync(
Guid? tenantId,
Guid userId,
Guid friendId,
string remarkName = "")
{
await FriendStore.AddMemberAsync(tenantId, userId, friendId, remarkName);
}
[HubMethodName("RemoveFriend")]
public virtual async Task RemoveFriendAsync(
Guid? tenantId,
Guid userId,
Guid friendId,
string remarkName = "")
{
await FriendStore.RemoveMemberAsync(tenantId, userId, friendId);
}
/// <summary>
/// 客户端调用发送消息方法
/// </summary>
@ -27,7 +86,7 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs
public virtual async Task SendMessageAsync(ChatMessage chatMessage)
{
// 持久化
await _messageStore.StoreMessageAsync(chatMessage);
await MessageStore.StoreMessageAsync(chatMessage);
try
{

4
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Messages/SignalRMessageSender.cs

@ -16,13 +16,13 @@ namespace LINGYUN.Abp.IM.SignalR.Messages
private readonly IOnlineClientManager _onlineClientManager;
private readonly IHubContext<MessageHub> _hubContext;
private readonly IHubContext<MessagesHub> _hubContext;
private readonly IMessageStore _messageStore;
public SignalRMessageSender(
IOnlineClientManager onlineClientManager,
IHubContext<MessageHub> hubContext,
IHubContext<MessagesHub> hubContext,
IMessageStore messageStore)
{
_hubContext = hubContext;

110
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/IFriendStore.cs

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LINGYUN.Abp.IM.Contract
{
public interface IFriendStore
{
/// <summary>
/// 获取好友数量
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="filter"></param>
/// <returns></returns>
Task<int> GetCountAsync(
Guid? tenantId,
Guid userId,
string filter = "");
/// <summary>
/// 获取好友列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="filter"></param>
/// <param name="sorting"></param>
/// <param name="reverse"></param>
/// <param name="skipCount"></param>
/// <param name="maxResultCount"></param>
/// <returns></returns>
Task<List<UserFriend>> GetListAsync(
Guid? tenantId,
Guid userId,
string filter = "",
string sorting = nameof(UserFriend.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10);
/// <summary>
/// 获取最近联系好友列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="skipCount"></param>
/// <param name="maxResultCount"></param>
/// <returns></returns>
Task<List<UserFriend>> GetLastContactListAsync(
Guid? tenantId,
Guid userId,
int skipCount = 0,
int maxResultCount = 10);
/// <summary>
/// 获取好友信息
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="friendId"></param>
/// <returns></returns>
Task<UserFriend> GetMemberAsync(
Guid? tenantId,
Guid userId,
Guid friendId);
/// <summary>
/// 添加好友
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="friendId"></param>
/// <param name="remarkName"></param>
/// <returns></returns>
Task AddMemberAsync(
Guid? tenantId,
Guid userId,
Guid friendId,
string remarkName = "");
/// <summary>
/// 移除好友
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="friendId"></param>
/// <returns></returns>
Task RemoveMemberAsync(
Guid? tenantId,
Guid userId,
Guid friendId);
/// <summary>
/// 添加黑名单
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="friendId"></param>
/// <returns></returns>
Task AddShieldMemberAsync(
Guid? tenantId,
Guid userId,
Guid friendId);
/// <summary>
/// 移除黑名单
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="friendId"></param>
/// <returns></returns>
Task RemoveShieldMemberAsync(
Guid? tenantId,
Guid userId,
Guid friendId);
}
}

28
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/UserFriend.cs

@ -0,0 +1,28 @@
using System;
namespace LINGYUN.Abp.IM.Contract
{
public class UserFriend : UserCard
{
/// <summary>
/// 好友标识
/// </summary>
public Guid FriendId { get; set; }
/// <summary>
/// 已添加黑名单
/// </summary>
public bool Black { get; set; }
/// <summary>
/// 特别关注
/// </summary>
public bool SpecialFocus { get; set; }
/// <summary>
/// 消息免打扰
/// </summary>
public bool DontDisturb { get; set; }
/// <summary>
/// 备注名称
/// </summary>
public string RemarkName { get; set; }
}
}

12
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/GroupUserCard.cs

@ -1,22 +1,12 @@
using System.Collections.Generic;
using System.Linq;
namespace LINGYUN.Abp.IM.Group
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);
}
}
}

17
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Group/IUserGroupStore.cs

@ -22,20 +22,19 @@ namespace LINGYUN.Abp.IM.Group
/// <returns></returns>
Task<IEnumerable<Group>> GetUserGroupsAsync(Guid? tenantId, Guid userId);
/// <summary>
/// 获取通讯组所有用户
/// 获取群组成员列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="groupId"></param>
/// <returns></returns>
Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId);
Task<IEnumerable<GroupUserCard>> GetMembersAsync(Guid? tenantId, long groupId);
/// <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 = "");
Task<int> GetMembersCountAsync(Guid? tenantId, long groupId);
/// <summary>
/// 获取通讯组用户
/// </summary>
@ -46,7 +45,13 @@ namespace LINGYUN.Abp.IM.Group
/// <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);
Task<List<GroupUserCard>> GetMembersAsync(
Guid? tenantId,
long groupId,
string sorting = nameof(GroupUserCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10);
/// <summary>
/// 用户加入通讯组
/// </summary>

60
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/IUserCardFinder.cs

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LINGYUN.Abp.IM
{
/// <summary>
/// IM用户资料查找接口
/// </summary>
public interface IUserCardFinder
{
/// <summary>
/// 查询IM用户数量
/// </summary>
/// <param name="tenantId"></param>
/// <param name="findUserName">用户名称</param>
/// <param name="startAge">起止年龄</param>
/// <param name="endAge">起止年龄</param>
/// <param name="sex">性别</param>
/// <returns></returns>
Task<int> GetCountAsync(
Guid? tenantId,
string findUserName = "",
int? startAge = null,
int? endAge = null,
Sex? sex = null);
/// <summary>
/// 查询IM用户列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="findUserName">用户名称</param>
/// <param name="startAge">起止年龄</param>
/// <param name="endAge">起止年龄</param>
/// <param name="sex">性别</param>
/// <param name="sorting">排序字段</param>
/// <param name="reverse">是否倒序</param>
/// <param name="skipCount">起始记录位置</param>
/// <param name="maxResultCount">最大返回数量</param>
/// <returns></returns>
Task<List<UserCard>> GetListAsync(
Guid? tenantId,
string findUserName = "",
int? startAge = null,
int? endAge = null,
Sex? sex = null,
string sorting = nameof(UserCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10);
/// <summary>
/// 获取IM用户信息
/// </summary>
/// <param name="tenantId"></param>
/// <param name="findUserId"></param>
/// <returns></returns>
Task<UserCard> GetMemberAsync(
Guid? tenantId,
Guid findUserId);
}
}

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

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

9
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Sex.cs

@ -0,0 +1,9 @@
namespace LINGYUN.Abp.IM
{
public enum Sex
{
Male,
Female,
Other
}
}

25
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/UserCard.cs

@ -5,15 +5,16 @@ namespace LINGYUN.Abp.IM
public class UserCard
{
public Guid? TenantId { get; set; }
public Guid UserId { get; set; }
#region 下一个版本细粒度的用户资料 与Identity集成
#region 细粒度的用户资料
public string UserName { get; set; }
/// <summary>
/// 头像
/// </summary>
public string AvatarlUrl { get; set; }
public string AvatarUrl { get; set; }
/// <summary>
/// 昵称
/// </summary>
@ -21,27 +22,23 @@ namespace LINGYUN.Abp.IM
/// <summary>
/// 年龄
/// </summary>
public int Arg { get; set; }
public int Age { get; set; }
/// <summary>
/// 性别
/// </summary>
public string Sex { get; set; }
/// <summary>
/// 国家
/// </summary>
public string Countriy { get; set; }
public Sex Sex { get; set; }
/// <summary>
/// 省份
/// 签名
/// </summary>
public string Province { get; set; }
public string Sign { get; set; }
/// <summary>
/// 城市
/// 说明
/// </summary>
public string City { get; set; }
public string Description { get; set; }
/// <summary>
/// 签名
/// 生日
/// </summary>
public string Sign { get; set; }
public DateTime? Birthday { get; set; }
#endregion
}

1
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN.Abp.Notifications.SignalR.csproj

@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.AspNetCore.SignalR\LINGYUN.Abp.AspNetCore.SignalR.JwtToken.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Notifications\LINGYUN.Abp.Notifications.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.RealTime\LINGYUN.Abp.RealTime.csproj" />
</ItemGroup>

11
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/AbpNotificationsSignalRModule.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.RealTime;
using LINGYUN.Abp.AspNetCore.SignalR.JwtToken;
using LINGYUN.Abp.RealTime;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.Modularity;
@ -7,7 +8,8 @@ namespace LINGYUN.Abp.Notifications.SignalR
[DependsOn(
typeof(AbpRealTimeModule),
typeof(AbpNotificationModule),
typeof(AbpAspNetCoreSignalRModule))]
typeof(AbpAspNetCoreSignalRModule),
typeof(AbpAspNetCoreSignalRJwtTokenModule))]
public class AbpNotificationsSignalRModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
@ -16,6 +18,11 @@ namespace LINGYUN.Abp.Notifications.SignalR
{
options.PublishProviders.Add<SignalRNotificationPublishProvider>();
});
Configure<AbpAspNetCoreSignalRJwtTokenMapPathOptions>(options =>
{
options.MapPath("notifications");
});
}
}
}

25
aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/Microsoft/AspNetCore/Http/SignalRJwtTokenMiddleware.cs

@ -1,25 +0,0 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Microsoft.AspNetCore.Http
{
public class SignalRJwtTokenMiddleware : IMiddleware, ITransientDependency
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
// 仅针对自定义的SignalR hub
if (context.Request.Path.StartsWithSegments("/signalr-hubs/notifications"))
{
if (context.User.Identity?.IsAuthenticated != true)
{
if (context.Request.Query.TryGetValue("access_token", out var accessToken))
{
context.Request.Headers.Add("Authorization", $"Bearer {accessToken}");
}
}
}
await next(context);
}
}
}

1
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupMessageGetByPagedDto.cs

@ -8,6 +8,7 @@ namespace LINGYUN.Abp.MessageService.Chat
{
[Required]
public long GroupId { get; set; }
public bool Reverse { get; set; }
public string Filter { get; set; }
public MessageType? MessageType { get; set; }
}

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GroupUserGetByPagedDto.cs

@ -8,6 +8,8 @@ namespace LINGYUN.Abp.MessageService.Chat
[Required]
public long GroupId { get; set; }
public bool Reverse { get; set; }
public string Filter { get; set; }
}
}

7
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendCreateDto.cs

@ -0,0 +1,7 @@
namespace LINGYUN.Abp.MessageService.Chat
{
public class MyFriendCreateDto : MyFriendOperationDto
{
public string RemarkName { get; set; }
}
}

15
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendGetByPagedDto.cs

@ -0,0 +1,15 @@
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.MessageService.Chat
{
public class MyFriendGetByPagedDto : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
public bool Reverse { get; set; }
}
public class MyLastContractFriendGetByPagedDto : PagedResultRequestDto
{
}
}

11
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/MyFriendOperationDto.cs

@ -0,0 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace LINGYUN.Abp.MessageService.Chat
{
public class MyFriendOperationDto
{
[Required]
public Guid FriendId { get; set; }
}
}

1
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/UserMessageGetByPagedDto.cs

@ -9,6 +9,7 @@ namespace LINGYUN.Abp.MessageService.Chat
{
[Required]
public Guid ReceiveUserId { get; set; }
public bool Reverse { get; set; }
public string Filter { get; set; }
public MessageType? MessageType { get; set; }
}

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs

@ -30,7 +30,7 @@ namespace LINGYUN.Abp.MessageService.Chat
/// </summary>
/// <param name="groupUserGetByPaged"></param>
/// <returns></returns>
Task<PagedResultDto<UserGroup>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged);
Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged);
/// <summary>
/// 处理用户群组申请
/// </summary>

18
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IMyFriendAppService.cs

@ -0,0 +1,18 @@
using LINGYUN.Abp.IM.Contract;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace LINGYUN.Abp.MessageService.Chat
{
public interface IMyFriendAppService : IApplicationService
{
Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input);
Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input);
Task CreateAsync(MyFriendCreateDto input);
Task DeleteAsync(MyFriendOperationDto input);
}
}

29
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs

@ -1,5 +1,6 @@
using LINGYUN.Abp.IM.Group;
using LINGYUN.Abp.IM.Messages;
using Microsoft.AspNetCore.Authorization;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Volo.Abp;
@ -25,6 +26,7 @@ namespace LINGYUN.Abp.MessageService.Chat
_userGroupStore = userGroupStore;
}
[Authorize]
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged)
{
var chatMessageCount = await _messageStore
@ -33,38 +35,41 @@ namespace LINGYUN.Abp.MessageService.Chat
var chatMessages = await _messageStore
.GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), userMessageGetByPaged.ReceiveUserId,
userMessageGetByPaged.Filter, userMessageGetByPaged.Sorting, userMessageGetByPaged.MessageType,
userMessageGetByPaged.SkipCount, userMessageGetByPaged.MaxResultCount);
userMessageGetByPaged.Filter, userMessageGetByPaged.Sorting, userMessageGetByPaged.Reverse,
userMessageGetByPaged.MessageType, userMessageGetByPaged.SkipCount, userMessageGetByPaged.MaxResultCount);
return new PagedResultDto<ChatMessage>(chatMessageCount, chatMessages);
}
public virtual async Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged)
{
// TODO: 增加验证,用户不在群组却来查询这个群组消息,是非法客户端操作
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);
groupMessageGetByPaged.Filter, groupMessageGetByPaged.Sorting, groupMessageGetByPaged.Reverse,
groupMessageGetByPaged.MessageType, groupMessageGetByPaged.SkipCount, groupMessageGetByPaged.MaxResultCount);
return new PagedResultDto<ChatMessage>(groupMessageCount, groupMessages);
}
public virtual async Task<PagedResultDto<UserGroup>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
{
var groupUserCount = await _userGroupStore.GetGroupUsersCountAsync(CurrentTenant.Id,
groupUserGetByPaged.GroupId, groupUserGetByPaged.Filter);
var groupUserCardCount = await _userGroupStore
.GetMembersCountAsync(CurrentTenant.Id, groupUserGetByPaged.GroupId);
var groupUsers = await _userGroupStore.GetGroupUsersAsync(CurrentTenant.Id,
groupUserGetByPaged.GroupId, groupUserGetByPaged.Filter, groupUserGetByPaged.Sorting,
var groupUserCards = await _userGroupStore.GetMembersAsync(CurrentTenant.Id,
groupUserGetByPaged.GroupId, groupUserGetByPaged.Sorting, groupUserGetByPaged.Reverse,
groupUserGetByPaged.SkipCount, groupUserGetByPaged.MaxResultCount);
return new PagedResultDto<UserGroup>(groupUserCount, groupUsers);
return new PagedResultDto<GroupUserCard>(groupUserCardCount, groupUserCards);
}
[Authorize]
public virtual async Task<ListResultDto<Group>> GetMyGroupsAsync()
{
var myGroups = await _userGroupStore.GetUserGroupsAsync(CurrentTenant.Id, CurrentUser.GetId());
@ -81,7 +86,7 @@ namespace LINGYUN.Abp.MessageService.Chat
// 当前登录用户不再用户组
throw new UserFriendlyException("");
}
if (!myGroupCard.IsGrant(nameof(ChatGroupAdmin.AllowAddPeople)))
if (!myGroupCard.IsAdmin)
{
// 当前登录用户没有加人权限
throw new UserFriendlyException("");
@ -99,7 +104,7 @@ namespace LINGYUN.Abp.MessageService.Chat
// 当前登录用户不再用户组
throw new UserFriendlyException("");
}
if (!myGroupCard.IsGrant(nameof(ChatGroupAdmin.AllowKickPeople)))
if (!myGroupCard.IsAdmin)
{
// 当前登录用户没有踢人权限
throw new UserFriendlyException("");

53
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/MyFriendAppService.cs

@ -0,0 +1,53 @@
using LINGYUN.Abp.IM.Contract;
using Microsoft.AspNetCore.Authorization;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Users;
namespace LINGYUN.Abp.MessageService.Chat
{
[Authorize]
public class MyFriendAppService : ApplicationService, IMyFriendAppService
{
protected IFriendStore FriendStore { get; }
public MyFriendAppService(IFriendStore friendStore)
{
FriendStore = friendStore;
}
public virtual async Task CreateAsync(MyFriendCreateDto input)
{
await FriendStore.AddMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId, input.RemarkName);
}
public virtual async Task DeleteAsync(MyFriendOperationDto input)
{
await FriendStore.RemoveMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId);
}
public virtual async Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input)
{
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId());
var myFriends = await FriendStore
.GetLastContactListAsync(CurrentTenant.Id, CurrentUser.GetId(),
input.SkipCount, input.MaxResultCount);
return new PagedResultDto<UserFriend>(myFrientCount, myFriends);
}
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input)
{
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId());
var myFriends = await FriendStore
.GetListAsync(CurrentTenant.Id, CurrentUser.GetId(),
input.Filter, input.Sorting, input.Reverse,
input.SkipCount, input.MaxResultCount);
return new PagedResultDto<UserFriend>(myFrientCount, myFriends);
}
}
}

1
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Volo.Abp.Localization" Version="3.2.0" />
<PackageReference Include="Volo.Abp.Users.Domain.Shared" Version="3.2.0" />
</ItemGroup>
</Project>

13
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Chat/UserChatCardConsts.cs

@ -0,0 +1,13 @@
using Volo.Abp.Users;
namespace LINGYUN.Abp.MessageService.Chat
{
public class UserChatCardConsts
{
public static int MaxUserNameLength { get; set; } = AbpUserConsts.MaxUserNameLength;
public static int MaxSignLength { get; set; } = 30;
public static int MaxNickNameLength { get; set; } = AbpUserConsts.MaxUserNameLength;
public static int MaxDescriptionLength { get; set; } = 50;
public static int MaxAvatarUrlLength { get; set; } = 512;
}
}

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

@ -5,5 +5,7 @@
public const string DefaultTablePrefix = "App";
public const string DefaultSchema = null;
public const string ConnectionStringName = "MessageService";
}
}

54
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatDataSeeder.cs

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
using Volo.Abp.Uow;
using Volo.Abp.Users;
namespace LINGYUN.Abp.MessageService.Chat
{
public class ChatDataSeeder : IChatDataSeeder, ITransientDependency
{
protected IClock Clock { get; }
protected ICurrentTenant CurrentTenant { get; }
protected IUserChatCardRepository UserChatCardRepository { get; }
protected IUserChatSettingRepository UserChatSettingRepository { get; }
public ChatDataSeeder(
IClock clock,
ICurrentTenant currentTenant,
IUserChatCardRepository userChatCardRepository,
IUserChatSettingRepository userChatSettingRepository)
{
Clock = clock;
CurrentTenant = currentTenant;
UserChatCardRepository = userChatCardRepository;
UserChatSettingRepository = userChatSettingRepository;
}
[UnitOfWork]
public virtual async Task SeedAsync(IUserData user)
{
using (CurrentTenant.Change(user.TenantId))
{
var userHasOpendIm = await UserChatSettingRepository.UserHasOpendImAsync(user.Id);
if (!userHasOpendIm)
{
var userChatSetting = new UserChatSetting(user.Id, user.TenantId);
await UserChatSettingRepository.InsertAsync(userChatSetting);
var userChatCard = new UserChatCard(user.Id, user.UserName, IM.Sex.Male, user.UserName, tenantId: user.TenantId)
{
CreationTime = Clock.Now,
CreatorId = user.Id
};
await UserChatCardRepository.InsertAsync(userChatCard);
}
}
}
}
}

27
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroup.cs

@ -14,6 +14,10 @@ namespace LINGYUN.Abp.MessageService.Chat
/// </summary>
public virtual Guid? TenantId { get; protected set; }
/// <summary>
/// 群主
/// </summary>
public virtual Guid AdminUserId { get; protected set; }
/// <summary>
/// 群组标识
/// </summary>
public virtual long GroupId { get; protected set; }
@ -28,11 +32,11 @@ namespace LINGYUN.Abp.MessageService.Chat
/// <summary>
/// 群组地址
/// </summary>
public virtual string Address { get; protected set; }
public virtual string Address { get; set; }
/// <summary>
/// 群组公告
/// </summary>
public virtual string Notice { get; protected set; }
public virtual string Notice { get; set; }
/// <summary>
/// 最大用户数量
/// </summary>
@ -52,23 +56,20 @@ namespace LINGYUN.Abp.MessageService.Chat
protected ChatGroup()
{
}
public ChatGroup(long id, string name, string tag = "", string address = "", int maxUserCount = 200)
public ChatGroup(
long id,
Guid adminUserId,
string name,
string tag = "",
string address = "",
int maxUserCount = 200)
{
GroupId = id;
AdminUserId = adminUserId;
Name = name;
Tag = tag;
Address = address;
MaxUserCount = maxUserCount;
}
public void ChangeAddress(string address)
{
Address = address;
}
public void SetNotice(string notice)
{
Notice = notice;
}
}
}

69
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/ChatGroupAdmin.cs

@ -1,69 +0,0 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Chat
{
/// <summary>
/// 群管理员
/// </summary>
public class ChatGroupAdmin : AuditedEntity<long>, IMultiTenant
{
/// <summary>
/// 租户
/// </summary>
public virtual Guid? TenantId { get; protected set; }
/// <summary>
/// 群组标识
/// </summary>
public virtual long GroupId { get; protected set; }
/// <summary>
/// 管理员用户
/// </summary>
public virtual Guid UserId { get; protected set; }
/// <summary>
/// 是否群主
/// </summary>
public virtual bool IsSuperAdmin { get; protected set; }
/// <summary>
/// 允许禁言
/// </summary>
public virtual bool AllowSilence { get; set; }
/// <summary>
/// 允许踢人
/// </summary>
public virtual bool AllowKickPeople { get; set; }
/// <summary>
/// 允许加人
/// </summary>
public virtual bool AllowAddPeople { get; set; }
/// <summary>
/// 允许发送群公告
/// </summary>
public virtual bool AllowSendNotice { get; set; }
/// <summary>
/// 允许解散群组
/// </summary>
public virtual bool AllowDissolveGroup { get; set; }
protected ChatGroupAdmin() { }
public ChatGroupAdmin(long groupId, Guid userId, bool isSuperAdmin = false)
{
GroupId = groupId;
UserId = userId;
AllowSilence = true;
AllowKickPeople = true;
AllowAddPeople = true;
AllowSendNotice = true;
SetSuperAdmin(isSuperAdmin);
}
public void SetSuperAdmin(bool isSuperAdmin = false)
{
IsSuperAdmin = isSuperAdmin;
if (isSuperAdmin)
{
AllowDissolveGroup = true;
}
}
}
}

119
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/FriendStore.cs

@ -0,0 +1,119 @@
using LINGYUN.Abp.IM.Contract;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
using Volo.Abp.Uow;
namespace LINGYUN.Abp.MessageService.Chat
{
public class FriendStore : DomainService, IFriendStore
{
protected IUserChatFriendRepository UserChatFriendRepository { get; }
public FriendStore(
IUserChatFriendRepository userChatFriendRepository)
{
UserChatFriendRepository = userChatFriendRepository;
}
[UnitOfWork]
public virtual async Task AddMemberAsync(Guid? tenantId, Guid userId, Guid friendId, string remarkName = "")
{
using (CurrentTenant.Change(tenantId))
{
if (!await UserChatFriendRepository.IsAddedAsync(userId, friendId))
{
var userChatFriend = new UserChatFriend(userId, friendId, remarkName, tenantId)
{
CreationTime = Clock.Now,
CreatorId = userId
};
await UserChatFriendRepository.InsertAsync(userChatFriend);
}
}
}
[UnitOfWork]
public virtual async Task AddShieldMemberAsync(Guid? tenantId, Guid userId, Guid friendId)
{
await ChangeFriendShieldAsync(tenantId, userId, friendId, true);
}
public virtual async Task<int> GetCountAsync(Guid? tenantId, Guid userId, string filter = "")
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatFriendRepository
.GetMembersCountAsync(userId, filter);
}
}
public virtual async Task<List<UserFriend>> GetListAsync(Guid? tenantId, Guid userId, string filter = "", string sorting = nameof(UserFriend.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatFriendRepository
.GetMembersAsync(userId, filter, sorting, reverse,
skipCount, maxResultCount);
}
}
public virtual async Task<List<UserFriend>> GetLastContactListAsync(
Guid? tenantId,
Guid userId,
int skipCount = 0,
int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatFriendRepository
.GetLastContactMembersAsync(userId,
skipCount, maxResultCount);
}
}
public virtual async Task<UserFriend> GetMemberAsync(Guid? tenantId, Guid userId, Guid friendId)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatFriendRepository
.GetMemberAsync(userId, friendId);
}
}
[UnitOfWork]
public virtual async Task RemoveMemberAsync(Guid? tenantId, Guid userId, Guid friendId)
{
using (CurrentTenant.Change(tenantId))
{
var userChatFriend = await UserChatFriendRepository.FindByUserFriendIdAsync(userId, friendId);
if (userChatFriend != null)
{
await UserChatFriendRepository.DeleteAsync(userChatFriend);
}
}
}
[UnitOfWork]
public virtual async Task RemoveShieldMemberAsync(Guid? tenantId, Guid userId, Guid friendId)
{
await ChangeFriendShieldAsync(tenantId, userId, friendId, false);
}
protected virtual async Task ChangeFriendShieldAsync(Guid? tenantId, Guid userId, Guid friendId, bool isBlack = false)
{
using (CurrentTenant.Change(tenantId))
{
var userChatFriend = await UserChatFriendRepository.FindByUserFriendIdAsync(userId, friendId);
if (userChatFriend != null)
{
userChatFriend.Black = isBlack;
await UserChatFriendRepository.UpdateAsync(userChatFriend);
}
}
}
}
}

11
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IChatDataSeeder.cs

@ -0,0 +1,11 @@
using System.Threading.Tasks;
using Volo.Abp.Users;
namespace LINGYUN.Abp.MessageService.Chat
{
public interface IChatDataSeeder
{
Task SeedAsync(
IUserData user);
}
}

15
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IGroupRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -13,10 +14,18 @@ namespace LINGYUN.Abp.MessageService.Chat
/// <param name="id"></param>
/// <param name="formUserId"></param>
/// <returns></returns>
Task<bool> UserHasBlackedAsync(long id, Guid formUserId);
Task<bool> UserHasBlackedAsync(
long id,
Guid formUserId,
CancellationToken cancellationToken = default);
Task<ChatGroup> GetByIdAsync(long id);
Task<ChatGroup> GetByIdAsync(
long id,
CancellationToken cancellationToken = default);
Task<List<UserGroupCard>> GetGroupAdminAsync(
long id,
CancellationToken cancellationToken = default);
Task<List<ChatGroupAdmin>> GetGroupAdminAsync(long id);
}
}

82
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs

@ -1,30 +1,92 @@
using LINGYUN.Abp.IM.Messages;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace LINGYUN.Abp.MessageService.Chat
{
public interface IMessageRepository
{
Task<UserMessage> InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false);
Task InsertUserMessageAsync(
UserMessage userMessage,
CancellationToken cancellationToken = default);
Task<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false);
Task InsertGroupMessageAsync(
GroupMessage groupMessage,
CancellationToken cancellationToken = default);
Task<UserMessage> GetUserMessageAsync(long id);
Task<UserMessage> GetUserMessageAsync(
long id,
CancellationToken cancellationToken = default);
Task<GroupMessage> GetGroupMessageAsync(long id);
Task<GroupMessage> GetGroupMessageAsync(
long id,
CancellationToken cancellationToken = default);
Task<long> GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null);
Task<long> GetUserMessagesCountAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default);
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> GetCountAsync(
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default);
Task<long> GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null);
Task<long> GetCountAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default);
Task<List<GroupMessage>> GetGroupMessagesAsync(long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
Task<List<UserMessage>> GetUserMessagesAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<long> GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null);
Task<long> GetGroupMessagesCountAsync(
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default);
Task<List<GroupMessage>> GetUserGroupMessagesAsync(Guid sendUserId, long groupId, string filter = "", string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10);
Task<List<GroupMessage>> GetGroupMessagesAsync(
long groupId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<long> GetUserGroupMessagesCountAsync(
Guid sendUserId,
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default);
Task<List<GroupMessage>> GetUserGroupMessagesAsync(
Guid sendUserId,
long groupId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
}
}

38
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatCardRepository.cs

@ -0,0 +1,38 @@
using LINGYUN.Abp.IM;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.MessageService.Chat
{
public interface IUserChatCardRepository : IBasicRepository<UserChatCard, long>
{
Task<bool> CheckUserIdExistsAsync(
Guid userId,
CancellationToken cancellationToken = default);
Task<int> GetMemberCountAsync(
string findUserName = "",
int? startAge = null,
int? endAge = null,
Sex? sex = null,
CancellationToken cancellationToken = default);
Task<List<UserCard>> GetMembersAsync(
string findUserName = "",
int? startAge = null,
int? endAge = null,
Sex? sex = null,
string sorting = nameof(UserChatCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<UserCard> GetMemberAsync(
Guid findUserId,
CancellationToken cancellationToken = default);
}
}

47
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatFriendRepository.cs

@ -0,0 +1,47 @@
using LINGYUN.Abp.IM.Contract;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace LINGYUN.Abp.MessageService.Chat
{
public interface IUserChatFriendRepository : IBasicRepository<UserChatFriend, long>
{
Task<bool> IsAddedAsync(
Guid userId,
Guid frientId,
CancellationToken cancellationToken = default);
Task<UserChatFriend> FindByUserFriendIdAsync(
Guid userId,
Guid friendId,
CancellationToken cancellationToken = default);
Task<int> GetMembersCountAsync(
Guid userId,
string filter = "",
CancellationToken cancellationToken = default);
Task<List<UserFriend>> GetMembersAsync(
Guid userId,
string filter = "",
string sorting = nameof(UserChatFriend.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<List<UserFriend>> GetLastContactMembersAsync(
Guid userId,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<UserFriend> GetMemberAsync(
Guid userId,
Guid friendId,
CancellationToken cancellationToken = default);
}
}

77
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatGroupRepository.cs

@ -1,6 +1,7 @@
using LINGYUN.Abp.IM.Group;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -9,23 +10,71 @@ namespace LINGYUN.Abp.MessageService.Chat
public interface IUserChatGroupRepository : IBasicRepository<UserChatGroup, long>
{
/// <summary>
/// 用户是否在组里
/// 成员是否在群组里
/// </summary>
/// <param name="id"></param>
/// <param name="userId"></param>
/// <returns></returns>
Task<bool> UserHasInGroupAsync(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<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<bool> MemberHasInGroupAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default);
/// <summary>
/// 获取群组成员
/// </summary>
/// <param name="groupId"></param>
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<GroupUserCard> GetMemberAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default);
/// <summary>
/// 获取群组成员数
/// </summary>
/// <param name="groupId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> GetMembersCountAsync(
long groupId,
CancellationToken cancellationToken = default);
/// <summary>
/// 获取群组成员列表
/// </summary>
/// <param name="groupId"></param>
/// <param name="sorting"></param>
/// <param name="reverse"></param>
/// <param name="skipCount"></param>
/// <param name="maxResultCount"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<GroupUserCard>> GetMembersAsync(
long groupId,
string sorting = nameof(UserChatCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
/// <summary>
/// 获取成员所在群组列表
/// </summary>
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<List<Group>> GetMemberGroupsAsync(
Guid userId,
CancellationToken cancellationToken = default);
/// <summary>
/// 从群组中移除成员
/// </summary>
/// <param name="groupId"></param>
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveMemberFormGroupAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default);
}
}

63
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs

@ -54,31 +54,72 @@ namespace LINGYUN.Abp.MessageService.Chat
}
}
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)
public async Task<List<ChatMessage>> GetGroupMessageAsync(
Guid? tenantId,
long groupId,
string filter = "",
string sorting = nameof(ChatMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
var groupMessages = await MessageRepository
.GetGroupMessagesAsync(groupId, filter, sorting, type, skipCount, maxResultCount);
.GetGroupMessagesAsync(groupId, filter, sorting, reverse, type, skipCount, maxResultCount);
var chatMessages = ObjectMapper.Map<List<GroupMessage>, List<ChatMessage>>(groupMessages);
return chatMessages;
}
}
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)
public async Task<List<ChatMessage>> GetChatMessageAsync(
Guid? tenantId,
Guid sendUserId,
Guid receiveUserId,
string filter = "",
string sorting = nameof(ChatMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
var userMessages = await MessageRepository.GetUserMessagesAsync(sendUserId, receiveUserId, filter, sorting, type, skipCount, maxResultCount);
var userMessages = await MessageRepository
.GetUserMessagesAsync(sendUserId, receiveUserId, filter, sorting, reverse, type, skipCount, maxResultCount);
var chatMessages = ObjectMapper.Map<List<UserMessage>, List<ChatMessage>>(userMessages);
return chatMessages;
}
}
public virtual async Task<long> GetGroupMessageCountAsync(
Guid? tenantId,
long groupId,
string filter = "",
MessageType? type = null)
{
using (CurrentTenant.Change(tenantId))
{
return await MessageRepository.GetCountAsync(groupId, filter, type);
}
}
public virtual async Task<long> GetChatMessageCountAsync(
Guid? tenantId,
Guid sendUserId,
Guid receiveUserId,
string filter = "",
MessageType? type = null)
{
using (CurrentTenant.Change(tenantId))
{
return await MessageRepository.GetCountAsync(sendUserId, receiveUserId, filter, type);
}
}
protected virtual async Task StoreUserMessageAsync(ChatMessage chatMessage)
{
var userHasBlacked = await UserChatSettingRepository
@ -135,15 +176,5 @@ namespace LINGYUN.Abp.MessageService.Chat
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();
}
}
}

47
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserCardFinder.cs

@ -0,0 +1,47 @@
using LINGYUN.Abp.IM;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Services;
namespace LINGYUN.Abp.MessageService.Chat
{
public class UserCardFinder : DomainService, IUserCardFinder
{
protected IUserChatCardRepository UserChatCardRepository { get; }
public UserCardFinder(
IUserChatCardRepository userChatCardRepository)
{
UserChatCardRepository = userChatCardRepository;
}
public virtual async Task<int> GetCountAsync(Guid? tenantId, string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatCardRepository
.GetMemberCountAsync(findUserName, startAge, endAge, sex);
}
}
public virtual async Task<List<UserCard>> GetListAsync(Guid? tenantId, string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, string sorting = nameof(UserCard.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatCardRepository
.GetMembersAsync(findUserName, startAge, endAge, sex,
sorting, reverse, skipCount, maxResultCount);
}
}
public virtual async Task<UserCard> GetMemberAsync(Guid? tenantId, Guid findUserId)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatCardRepository
.GetMemberAsync(findUserId);
}
}
}
}

105
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatCard.cs

@ -0,0 +1,105 @@
using LINGYUN.Abp.IM;
using LINGYUN.Abp.MessageService.Utils;
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.MessageService.Chat
{
/// <summary>
/// 用户卡片
/// </summary>
public class UserChatCard : AuditedAggregateRoot<long>, IMultiTenant
{
/// <summary>
/// 租户
/// </summary>
public virtual Guid? TenantId { get; protected set; }
/// <summary>
/// 用户标识
/// </summary>
public virtual Guid UserId { get; protected set; }
/// <summary>
/// 用户名
/// </summary>
public virtual string UserName { get; protected set; }
/// <summary>
/// 性别
/// </summary>
public virtual Sex Sex { get; set; }
/// <summary>
/// 签名
/// </summary>
public virtual string Sign { get; set; }
/// <summary>
/// 昵称
/// </summary>
public virtual string NickName { get; set; }
/// <summary>
/// 说明
/// </summary>
public virtual string Description { get; set; }
/// <summary>
/// 头像地址
/// </summary>
public virtual string AvatarUrl { get; protected set; }
/// <summary>
/// 生日
/// </summary>
public virtual DateTime? Birthday { get; protected set; }
/// <summary>
/// 年龄
/// </summary>
public virtual int Age { get; protected set; }
protected UserChatCard()
{
}
public UserChatCard(
Guid userId,
string userName,
Sex sex,
string nickName = null,
string avatarUrl = "",
Guid? tenantId = null)
{
Sex = sex;
UserId = userId;
UserName = userName;
NickName = nickName ?? userName;
AvatarUrl = avatarUrl;
TenantId = tenantId;
}
public void SetBirthday(DateTime birthday, IClock clock)
{
Birthday = birthday;
Age = DateTimeHelper.CalcAgrByBirthdate(birthday, clock.Now);
}
public void SetAvatarUrl(string url)
{
AvatarUrl = url;
}
public UserCard ToUserCard()
{
return new UserCard
{
Age = Age,
AvatarUrl = AvatarUrl,
Birthday = Birthday,
Description = Description,
NickName = NickName,
Sex = Sex,
Sign = Sign,
UserId = UserId,
UserName = UserName,
TenantId = TenantId
};
}
}
}

54
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatFriend.cs

@ -0,0 +1,54 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Chat
{
public class UserChatFriend : CreationAuditedEntity<long>, IMultiTenant
{
/// <summary>
/// 租户
/// </summary>
public virtual Guid? TenantId { get; protected set; }
/// <summary>
/// 用户标识
/// </summary>
public virtual Guid UserId { get; protected set; }
/// <summary>
/// 好友标识
/// </summary>
public virtual Guid FrientId { get; protected set; }
/// <summary>
/// 已添加黑名单
/// </summary>
public virtual bool Black { get; set; }
/// <summary>
/// 消息免打扰
/// </summary>
public virtual bool DontDisturb { get; set; }
/// <summary>
/// 特别关注
/// </summary>
public virtual bool SpecialFocus { get; set; }
/// <summary>
/// 备注名称
/// </summary>
public virtual string RemarkName { get; set; }
protected UserChatFriend()
{
}
public UserChatFriend(
Guid userId,
Guid friendId,
string remarkName = "",
Guid? tenantId = null)
{
UserId = userId;
FrientId = friendId;
RemarkName = remarkName;
TenantId = tenantId;
}
}
}

74
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupCard.cs

@ -0,0 +1,74 @@
using System;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Timing;
namespace LINGYUN.Abp.MessageService.Chat
{
/// <summary>
/// 用户群组卡片
/// </summary>
public class UserGroupCard : AuditedAggregateRoot<long>, IMultiTenant
{
/// <summary>
/// 租户
/// </summary>
public virtual Guid? TenantId { get; protected set; }
/// <summary>
/// 用户标识
/// </summary>
public virtual Guid UserId { get; protected set; }
/// <summary>
/// 昵称
/// </summary>
public virtual string NickName { get; set; }
/// <summary>
/// 是否管理员
/// </summary>
public virtual bool IsAdmin { get; protected set; }
/// <summary>
/// 禁言期止
/// </summary>
public virtual DateTime? SilenceEnd { get; protected set; }
protected UserGroupCard()
{
}
public UserGroupCard(
Guid userId,
string nickName = "",
bool isAdmin = false,
DateTime? silenceEnd = null,
Guid? tenantId = null)
{
UserId = userId;
NickName = nickName;
IsAdmin = isAdmin;
SilenceEnd = silenceEnd;
TenantId = tenantId;
}
/// <summary>
/// 设置管理员
/// </summary>
/// <param name="admin"></param>
public void SetAdmin(bool admin)
{
IsAdmin = admin;
}
/// <summary>
/// 禁言
/// </summary>
/// <param name="clock"></param>
/// <param name="seconds"></param>
public void Silence(IClock clock, double seconds)
{
SilenceEnd = clock.Now.AddSeconds(seconds);
}
/// <summary>
/// 解除禁言
/// </summary>
public void UnSilence()
{
SilenceEnd = null;
}
}
}

35
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserGroupStore.cs

@ -31,7 +31,7 @@ namespace LINGYUN.Abp.MessageService.Chat
{
using (CurrentTenant.Change(tenantId))
{
var userHasInGroup = await UserChatGroupRepository.UserHasInGroupAsync(groupId, userId);
var userHasInGroup = await UserChatGroupRepository.MemberHasInGroupAsync(groupId, userId);
if (!userHasInGroup)
{
var userGroup = new UserChatGroup(groupId, userId, acceptUserId, tenantId);
@ -48,19 +48,17 @@ namespace LINGYUN.Abp.MessageService.Chat
{
using (CurrentTenant.Change(tenantId))
{
var groupUserCard = await UserChatGroupRepository.GetGroupUserCardAsync(groupId, userId);
var groupUserCard = await UserChatGroupRepository.GetMemberAsync(groupId, userId);
return groupUserCard;
}
}
public async Task<IEnumerable<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId)
public async Task<IEnumerable<GroupUserCard>> GetMembersAsync(Guid? tenantId, long groupId)
{
using (CurrentTenant.Change(tenantId))
{
var userGroups = await UserChatGroupRepository.GetGroupUsersAsync(groupId);
return userGroups;
return await UserChatGroupRepository.GetMembersAsync(groupId);
}
}
@ -68,9 +66,7 @@ namespace LINGYUN.Abp.MessageService.Chat
{
using (CurrentTenant.Change(tenantId))
{
var groups = await UserChatGroupRepository.GetUserGroupsAsync(userId);
return groups;
return await UserChatGroupRepository.GetMemberGroupsAsync(userId);
}
}
@ -81,31 +77,32 @@ namespace LINGYUN.Abp.MessageService.Chat
{
using (CurrentTenant.Change(tenantId))
{
var userGroup = await UserChatGroupRepository.GetUserGroupAsync(groupId, userId);
if(userGroup != null)
{
await UserChatGroupRepository.DeleteAsync(userGroup);
await UserChatGroupRepository.RemoveMemberFormGroupAsync(groupId, userId);
await unitOfWork.SaveChangesAsync();
}
}
}
}
public async Task<int> GetGroupUsersCountAsync(Guid? tenantId, long groupId, string filter = "")
public async Task<int> GetMembersCountAsync(Guid? tenantId, long groupId)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatGroupRepository.GetGroupUsersCountAsync(groupId, filter);
return await UserChatGroupRepository.GetMembersCountAsync(groupId);
}
}
public async Task<List<UserGroup>> GetGroupUsersAsync(Guid? tenantId, long groupId, string filter = "", string sorting = "UserId", int skipCount = 1, int maxResultCount = 10)
public async Task<List<GroupUserCard>> GetMembersAsync(
Guid? tenantId,
long groupId,
string sorting = nameof(GroupUserCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatGroupRepository.GetGroupUsersAsync(groupId, filter, sorting, skipCount, maxResultCount);
return await UserChatGroupRepository.GetMembersAsync(groupId, sorting, reverse, skipCount, maxResultCount);
}
}
}

31
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateJoinIMEventHandler.cs

@ -3,47 +3,26 @@ using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
using Volo.Abp.Users;
namespace LINGYUN.Abp.MessageService.EventBus.Distributed
{
public class UserCreateJoinIMEventHandler : ILocalEventHandler<EntityCreatedEventData<UserEto>>, ITransientDependency
{
private readonly ICurrentTenant _currentTenant;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IUserChatSettingRepository _userChatSettingRepository;
private readonly IChatDataSeeder _chatDataSeeder;
public UserCreateJoinIMEventHandler(
ICurrentTenant currentTenant,
IUnitOfWorkManager unitOfWorkManager,
IUserChatSettingRepository userChatSettingRepository)
IChatDataSeeder chatDataSeeder)
{
_currentTenant = currentTenant;
_unitOfWorkManager = unitOfWorkManager;
_userChatSettingRepository = userChatSettingRepository;
_chatDataSeeder = chatDataSeeder;
}
/// <summary>
/// 接收添加用户事件,启用IM模块时增加用户配置
/// 接收添加用户事件,初始化IM用户种子
/// </summary>
/// <param name="eventData"></param>
/// <returns></returns>
public async Task HandleEventAsync(EntityCreatedEventData<UserEto> eventData)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (_currentTenant.Change(eventData.Entity.TenantId))
{
var userHasOpendIm = await _userChatSettingRepository.UserHasOpendImAsync(eventData.Entity.Id);
if (!userHasOpendIm)
{
var userChatSetting = new UserChatSetting(eventData.Entity.Id, eventData.Entity.TenantId);
await _userChatSettingRepository.InsertAsync(userChatSetting);
await unitOfWork.SaveChangesAsync();
}
}
}
await _chatDataSeeder.SeedAsync(eventData.Entity);
}
}
}

17
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/DateTimeHelper.cs

@ -0,0 +1,17 @@
using System;
namespace LINGYUN.Abp.MessageService.Utils
{
public static class DateTimeHelper
{
public static int CalcAgrByBirthdate(DateTime birthdate, DateTime nowTime)
{
int age = nowTime.Year - birthdate.Year;
if (nowTime.Month < birthdate.Month || (nowTime.Month == birthdate.Month && nowTime.Day < birthdate.Day))
{
age--;
}
return age < 0 ? 0 : age;
}
}
}

36
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreGroupRepository.cs

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -10,35 +11,46 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreGroupRepository : EfCoreRepository<MessageServiceDbContext, ChatGroup, long>,
public class EfCoreGroupRepository : EfCoreRepository<IMessageServiceDbContext, ChatGroup, long>,
IGroupRepository, ITransientDependency
{
public EfCoreGroupRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<ChatGroup> GetByIdAsync(long id)
public virtual async Task<ChatGroup> GetByIdAsync(
long id,
CancellationToken cancellationToken = default)
{
return await DbSet.Where(x => x.GroupId.Equals(id)).FirstOrDefaultAsync();
return await DbSet
.Where(x => x.GroupId.Equals(id))
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<ChatGroupAdmin>> GetGroupAdminAsync(long id)
public virtual async Task<List<UserGroupCard>> GetGroupAdminAsync(
long id,
CancellationToken cancellationToken = default)
{
var groupAdmins = await (from gp in DbContext.Set<ChatGroup>()
join gpa in DbContext.Set<ChatGroupAdmin>()
on gp.GroupId equals gpa.GroupId
select gpa)
.Distinct()
.ToListAsync();
join ucg in DbContext.Set<UserChatGroup>()
on gp.GroupId equals ucg.GroupId
join ugc in DbContext.Set<UserGroupCard>()
on ucg.UserId equals ugc.UserId
where ugc.IsAdmin
select ugc)
.ToListAsync(GetCancellationToken(cancellationToken));
return groupAdmins;
}
public async Task<bool> UserHasBlackedAsync(long id, Guid formUserId)
public virtual async Task<bool> UserHasBlackedAsync(
long id,
Guid formUserId,
CancellationToken cancellationToken = default)
{
var userHasBlack = await DbContext.Set<GroupChatBlack>()
.AnyAsync(x => x.GroupId.Equals(id) && x.ShieldUserId.Equals(formUserId));
.AnyAsync(x => x.GroupId.Equals(id) && x.ShieldUserId.Equals(formUserId), GetCancellationToken(cancellationToken));
return userHasBlack;
}
}

147
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -12,88 +13,153 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreMessageRepository : EfCoreRepository<MessageServiceDbContext, Message, long>,
public class EfCoreMessageRepository : EfCoreRepository<IMessageServiceDbContext, Message, long>,
IMessageRepository, ITransientDependency
{
public EfCoreMessageRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<GroupMessage> GetGroupMessageAsync(long id)
public virtual async Task<GroupMessage> GetGroupMessageAsync(
long id,
CancellationToken cancellationToken = default)
{
return await DbContext.Set<GroupMessage>()
.Where(x => x.MessageId.Equals(id))
.AsNoTracking()
.FirstOrDefaultAsync();
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<GroupMessage>> GetGroupMessagesAsync(long groupId, string filter = "",
string sorting = nameof(UserMessage.MessageId), MessageType? type = null, int skipCount = 1, int maxResultCount = 10)
public virtual async Task<List<GroupMessage>> GetGroupMessagesAsync(
long groupId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
sorting = reverse ? sorting + " desc" : sorting;
var groupMessages = await DbContext.Set<GroupMessage>()
.Distinct()
.Where(x => x.GroupId.Equals(groupId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Page(skipCount, maxResultCount)
.PageBy(skipCount, maxResultCount)
.AsNoTracking()
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
return groupMessages;
}
public async Task<long> GetGroupMessagesCountAsync(long groupId, string filter = "", MessageType? type = null)
public virtual async Task<long> GetGroupMessagesCountAsync(
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default)
{
var groupMessagesCount = await DbContext.Set<GroupMessage>()
.Distinct()
.Where(x => x.GroupId.Equals(groupId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.LongCountAsync();
.LongCountAsync(GetCancellationToken(cancellationToken));
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)
public virtual async Task<List<GroupMessage>> GetUserGroupMessagesAsync(
Guid sendUserId,
long groupId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
sorting = reverse ? sorting + " desc" : sorting;
var groupMessages = await 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))
.OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Page(skipCount, maxResultCount)
.PageBy(skipCount, maxResultCount)
.AsNoTracking()
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
return groupMessages;
}
public async Task<long> GetUserGroupMessagesCountAsync(Guid sendUserId, long groupId, string filter = "", MessageType? type = null)
public virtual async Task<long> GetUserGroupMessagesCountAsync(
Guid sendUserId,
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default)
{
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();
.LongCountAsync(GetCancellationToken(cancellationToken));
return groupMessagesCount;
}
public async Task<UserMessage> GetUserMessageAsync(long id)
public virtual async Task<long> GetCountAsync(
long groupId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default)
{
return await DbContext.Set<GroupMessage>()
.Where(x => x.GroupId.Equals(groupId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default)
{
return await DbContext.Set<UserMessage>()
.Where(x => x.ReceiveUserId.Equals(receiveUserId) && x.CreatorId.Equals(sendUserId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<UserMessage> GetUserMessageAsync(
long id,
CancellationToken cancellationToken = default)
{
return await DbContext.Set<UserMessage>()
.Where(x => x.MessageId.Equals(id))
.AsNoTracking()
.FirstOrDefaultAsync();
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
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)
public virtual async Task<List<UserMessage>> GetUserMessagesAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
string sorting = nameof(UserMessage.MessageId),
bool reverse = true,
MessageType? type = null,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
sorting = reverse ? sorting + " desc" : sorting;
var userMessages = await DbContext.Set<UserMessage>()
.Distinct()
.Where(x => x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId))
@ -102,45 +168,42 @@ namespace LINGYUN.Abp.MessageService.Chat
.OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.Page(skipCount, maxResultCount)
.AsNoTracking()
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
return userMessages;
}
public async Task<long> GetUserMessagesCountAsync(Guid sendUserId, Guid receiveUserId, string filter = "", MessageType? type = null)
public virtual async Task<long> GetUserMessagesCountAsync(
Guid sendUserId,
Guid receiveUserId,
string filter = "",
MessageType? type = null,
CancellationToken cancellationToken = default)
{
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();
.LongCountAsync(GetCancellationToken(cancellationToken));
return userMessagesCount;
}
public async Task<GroupMessage> InsertGroupMessageAsync(GroupMessage groupMessage, bool saveChangs = false)
{
groupMessage = (await DbContext.Set<GroupMessage>().AddAsync(groupMessage, GetCancellationToken())).Entity;
if(saveChangs)
public virtual async Task InsertGroupMessageAsync(
GroupMessage groupMessage,
CancellationToken cancellationToken = default)
{
await DbContext.SaveChangesAsync();
await DbContext.Set<GroupMessage>()
.AddAsync(groupMessage, GetCancellationToken(cancellationToken));
}
return groupMessage;
}
public async Task<UserMessage> InsertUserMessageAsync(UserMessage userMessage, bool saveChangs = false)
{
userMessage = (await DbContext.Set<UserMessage>().AddAsync(userMessage, GetCancellationToken())).Entity;
if (saveChangs)
public virtual async Task InsertUserMessageAsync(
UserMessage userMessage,
CancellationToken cancellationToken = default)
{
await DbContext.SaveChangesAsync();
}
return userMessage;
await DbContext.Set<UserMessage>()
.AddAsync(userMessage, GetCancellationToken(cancellationToken));
}
}
}

63
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatCardRepository.cs

@ -0,0 +1,63 @@
using LINGYUN.Abp.IM;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreUserChatCardRepository : EfCoreRepository<IMessageServiceDbContext, UserChatCard, long>, IUserChatCardRepository
{
public EfCoreUserChatCardRepository(
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<bool> CheckUserIdExistsAsync(Guid userId, CancellationToken cancellationToken = default)
{
return await DbSet
.AnyAsync(ucc => ucc.UserId == userId,
GetCancellationToken(cancellationToken));
}
public virtual async Task<UserCard> GetMemberAsync(Guid findUserId, CancellationToken cancellationToken = default)
{
return await DbSet
.Where(ucc => ucc.UserId == findUserId)
.Select(ucc => ucc.ToUserCard())
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<int> GetMemberCountAsync(string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, CancellationToken cancellationToken = default)
{
return await DbSet
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName))
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value)
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value)
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex)
.CountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<UserCard>> GetMembersAsync(string findUserName = "", int? startAge = null, int? endAge = null, Sex? sex = null, string sorting = nameof(UserChatCard.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default)
{
sorting ??= nameof(UserChatCard.UserId);
sorting = reverse ? sorting + " desc" : sorting;
return await DbSet
.WhereIf(!findUserName.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(findUserName))
.WhereIf(startAge.HasValue, ucc => ucc.Age >= startAge.Value)
.WhereIf(endAge.HasValue, ucc => ucc.Age <= endAge.Value)
.WhereIf(sex.HasValue, ucc => ucc.Sex == sex)
.OrderBy(sorting)
.PageBy(skipCount, maxResultCount)
.Select(ucc => ucc.ToUserCard())
.ToListAsync(GetCancellationToken(cancellationToken));
}
}
}

164
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatFriendRepository.cs

@ -0,0 +1,164 @@
using LINGYUN.Abp.IM.Contract;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreUserChatFriendRepository : EfCoreRepository<IMessageServiceDbContext, UserChatFriend, long>, IUserChatFriendRepository
{
public EfCoreUserChatFriendRepository(
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<UserChatFriend> FindByUserFriendIdAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default)
{
return await DbSet
.Where(ucf => ucf.UserId == userId && ucf.FrientId == friendId)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<UserFriend> GetMemberAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default)
{
var userFriendQuery = from ucf in DbContext.Set<UserChatFriend>()
join ucc in DbContext.Set<UserChatCard>()
on ucf.FrientId equals ucc.UserId
where ucf.UserId == userId && ucf.FrientId == friendId
select new UserFriend
{
Age = ucc.Age,
AvatarUrl = ucc.AvatarUrl,
Birthday = ucc.Birthday,
Black = ucf.Black,
Description = ucc.Description,
DontDisturb = ucf.DontDisturb,
FriendId = ucf.FrientId,
NickName = ucc.NickName,
RemarkName = ucf.RemarkName,
Sex = ucc.Sex,
Sign = ucc.Sign,
SpecialFocus = ucf.SpecialFocus,
TenantId = ucf.TenantId,
UserId = ucf.UserId,
UserName = ucc.UserName
};
return await userFriendQuery
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<UserFriend>> GetMembersAsync(Guid userId, string filter = "", string sorting = nameof(UserChatFriend.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default)
{
// 过滤用户资料
var userChatCardQuery = DbContext.Set<UserChatCard>()
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter));
// 过滤好友资料
var userChatFriendQuery = DbContext.Set<UserChatFriend>()
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter));
// 组合查询
var userFriendQuery = from ucf in userChatFriendQuery
join ucc in userChatCardQuery // TODO: Need LEFT JOIN?
on ucf.FrientId equals ucc.UserId
where ucf.UserId == userId
select new UserFriend
{
Age = ucc.Age,
AvatarUrl = ucc.AvatarUrl,
Birthday = ucc.Birthday,
Black = ucf.Black,
Description = ucc.Description,
DontDisturb = ucf.DontDisturb,
FriendId = ucf.FrientId,
NickName = ucc.NickName,
RemarkName = ucf.RemarkName,
Sex = ucc.Sex,
Sign = ucc.Sign,
SpecialFocus = ucf.SpecialFocus,
TenantId = ucf.TenantId,
UserId = ucf.UserId,
UserName = ucc.UserName
};
return await userFriendQuery
.OrderBy(sorting)
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<UserFriend>> GetLastContactMembersAsync(
Guid userId,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
var userReceiveMsgQuery = DbContext.Set<UserMessage>()
.Where(um => um.ReceiveUserId == userId);
var userFriendQuery = from ucf in DbContext.Set<UserChatFriend>()
join ucc in DbContext.Set<UserChatCard>()
on ucf.FrientId equals ucc.UserId
join um in userReceiveMsgQuery
on ucc.UserId equals um.CreatorId
where ucf.UserId == userId
orderby um.CreationTime descending // 消息创建时间倒序
select new UserFriend
{
Age = ucc.Age,
AvatarUrl = ucc.AvatarUrl,
Birthday = ucc.Birthday,
Black = ucf.Black,
Description = ucc.Description,
DontDisturb = ucf.DontDisturb,
FriendId = ucf.FrientId,
NickName = ucc.NickName,
RemarkName = ucf.RemarkName,
Sex = ucc.Sex,
Sign = ucc.Sign,
SpecialFocus = ucf.SpecialFocus,
TenantId = ucf.TenantId,
UserId = ucf.UserId,
UserName = ucc.UserName
};
return await userFriendQuery
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<int> GetMembersCountAsync(Guid userId, string filter = "", CancellationToken cancellationToken = default)
{
var userChatCardQuery = DbContext.Set<UserChatCard>()
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter));
var userChatFriendQuery = DbContext.Set<UserChatFriend>()
.WhereIf(!filter.IsNullOrWhiteSpace(), ucf => ucf.RemarkName.Contains(filter));
var userFriendQuery = from ucf in userChatFriendQuery
join ucc in userChatCardQuery
on ucf.FrientId equals ucc.UserId
where ucf.UserId == userId
select ucc;
return await userFriendQuery
.CountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<bool> IsAddedAsync(Guid userId, Guid frientId, CancellationToken cancellationToken = default)
{
return await DbSet
.AnyAsync(ucf => ucf.UserId == userId && ucf.FrientId == frientId,
GetCancellationToken(cancellationToken));
}
}
}

343
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatGroupRepository.cs

@ -1,11 +1,12 @@
using LINGYUN.Abp.IM.Group;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -13,122 +14,292 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreUserChatGroupRepository : EfCoreRepository<MessageServiceDbContext, UserChatGroup, long>,
public class EfCoreUserChatGroupRepository : EfCoreRepository<IMessageServiceDbContext, UserChatGroup, long>,
IUserChatGroupRepository, ITransientDependency
{
public EfCoreUserChatGroupRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider) : base(dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public async Task<List<UserGroup>> GetGroupUsersAsync(long groupId)
public virtual async Task<GroupUserCard> GetMemberAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default)
{
// TODO: 急需单元测试,对这段代码不是太自信...
var groupUsers = await (from ug in DbSet
join x in (
from gaj in DbContext.Set<ChatGroupAdmin>()
where gaj.GroupId.Equals(groupId)
select gaj
) on ug.UserId equals x.UserId
into y from ga in y.DefaultIfEmpty()
where ug.GroupId.Equals(groupId)
select new UserGroup
var cardQuery = from gp in DbContext.Set<ChatGroup>()
join ucg in DbContext.Set<UserChatGroup>()
on gp.GroupId equals ucg.GroupId
join ugc in DbContext.Set<UserGroupCard>()
on ucg.UserId equals ugc.UserId
join uc in DbContext.Set<UserChatCard>()
on ugc.UserId equals uc.UserId
where gp.GroupId == groupId && ugc.UserId == userId
select new GroupUserCard
{
GroupId = ug.GroupId,
IsSuperAdmin = ga != null && ga.IsSuperAdmin,
IsAdmin = ga != null,
TenantId = ug.TenantId,
UserId = ug.UserId
})
.Distinct()
.AsNoTracking()
.ToListAsync();
return groupUsers;
TenantId = uc.TenantId,
UserId = uc.UserId,
UserName = uc.UserName,
Age = uc.Age,
AvatarUrl = uc.AvatarUrl,
IsAdmin = ugc.IsAdmin,
IsSuperAdmin = gp.AdminUserId == uc.UserId,
GroupId = gp.GroupId,
Birthday = uc.Birthday,
Description = uc.Description,
NickName = ugc.NickName ?? uc.NickName,
Sex = uc.Sex,
Sign = uc.Sign
};
return await cardQuery
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public async Task<GroupUserCard> GetGroupUserCardAsync(long groupId, Guid userId)
public virtual async Task<List<GroupUserCard>> GetMembersAsync(
long groupId,
string sorting = nameof(UserChatCard.UserId),
bool reverse = false,
int skipCount = 0,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
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)
sorting ??= nameof(UserChatCard.UserId);
sorting = reverse ? sorting + " desc" : sorting;
var cardQuery = from gp in DbContext.Set<ChatGroup>()
join ucg in DbContext.Set<UserChatGroup>()
on gp.GroupId equals ucg.GroupId
join ugc in DbContext.Set<UserGroupCard>()
on ucg.UserId equals ugc.UserId
join uc in DbContext.Set<UserChatCard>()
on ugc.UserId equals uc.UserId
where gp.GroupId == groupId
select new GroupUserCard
{
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();
TenantId = uc.TenantId,
UserId = uc.UserId,
UserName = uc.UserName,
Age = uc.Age,
AvatarUrl = uc.AvatarUrl,
IsAdmin = ugc.IsAdmin,
IsSuperAdmin = gp.AdminUserId == uc.UserId,
GroupId = gp.GroupId,
Birthday = uc.Birthday,
Description = uc.Description,
NickName = ugc.NickName ?? uc.NickName,
Sex = uc.Sex,
Sign = uc.Sign
};
return groupUserCard;
return await cardQuery
.OrderBy(sorting ?? nameof(UserChatCard.UserId))
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public Task<List<UserGroup>> GetGroupUsersAsync(long groupId, string filter = "", string sorting = "UserId", int skipCount = 1, int maxResultCount = 10)
public virtual async Task<int> GetMembersCountAsync(
long groupId,
CancellationToken cancellationToken = default)
{
// TODO: 复杂的实现,暂时无关紧要,后期再说 :)
throw new NotImplementedException();
}
var cardQuery = from gp in DbContext.Set<ChatGroup>()
join ucg in DbContext.Set<UserChatGroup>()
on gp.GroupId equals ucg.GroupId
join ugc in DbContext.Set<UserGroupCard>()
on ucg.UserId equals ugc.UserId
join uc in DbContext.Set<UserChatCard>()
on ugc.UserId equals uc.UserId
where gp.GroupId == groupId
select ucg;
public Task<int> GetGroupUsersCountAsync(long groupId, string filter = "")
{
// TODO: 复杂的实现,暂时无关紧要,后期再说 :)
throw new NotImplementedException();
return await cardQuery
.CountAsync(GetCancellationToken(cancellationToken));
}
public async Task<UserChatGroup> GetUserGroupAsync(long groupId, Guid userId)
public virtual async Task<bool> MemberHasInGroupAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default)
{
return await DbSet.Where(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId))
.AsNoTracking()
.FirstOrDefaultAsync();
return await DbContext.Set<UserChatGroup>()
.AnyAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId,
GetCancellationToken(cancellationToken));
}
public async Task<List<Group>> GetUserGroupsAsync(Guid userId)
public virtual async Task<List<Group>> GetMemberGroupsAsync(
Guid userId,
CancellationToken cancellationToken = default)
{
// TODO: 急需单元测试,对这段代码不是太自信...
var userGroups = await (from ucg in DbSet
join cg in DbContext.Set<ChatGroup>()
on ucg.GroupId equals cg.GroupId
group cg by new
var groupQuery = from gp in DbContext.Set<ChatGroup>()
join ucg in DbContext.Set<UserChatGroup>()
on gp.GroupId equals ucg.GroupId
where ucg.UserId.Equals(userId)
group ucg by new
{
cg.GroupId,
cg.Name,
cg.AllowAnonymous,
cg.AllowSendMessage,
cg.MaxUserCount
gp.AllowAnonymous,
gp.AllowSendMessage,
gp.MaxUserCount,
gp.Name
}
into ug
orderby ug.Key.GroupId descending
into cg
select new Group
{
AllowAnonymous = ug.Key.AllowAnonymous,
AllowSendMessage = ug.Key.AllowSendMessage,
GroupUserCount = ug.Count(),
MaxUserLength = ug.Key.MaxUserCount,
Name = ug.Key.Name
})
.Distinct()
.ToListAsync();
return userGroups;
AllowAnonymous = cg.Key.AllowAnonymous,
AllowSendMessage = cg.Key.AllowSendMessage,
MaxUserLength = cg.Key.MaxUserCount,
Name = cg.Key.Name,
GroupUserCount = cg.Count()
};
return await groupQuery
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<bool> UserHasInGroupAsync(long groupId, Guid userId)
public virtual async Task RemoveMemberFormGroupAsync(
long groupId,
Guid userId,
CancellationToken cancellationToken = default)
{
return await DbSet.AnyAsync(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId));
await DeleteAsync(ucg => ucg.GroupId == groupId && ucg.UserId == userId);
}
//public virtual async Task<List<GroupUserCard>> GetGroupUsersAsync(
// long groupId,
// CancellationToken cancellationToken = default)
//{
// // TODO: 急需单元测试,对这段代码不是太自信...
// var groupUsers = await (from cg in DbContext.Set<ChatGroup>()
// join ucg in DbContext.Set<UserChatGroup>()
// on cg.GroupId equals ucg.GroupId
// join ugc in DbContext.Set<UserGroupCard>()
// on ucg.UserId equals ugc.UserId
// where cg.GroupId.Equals(groupId)
// select new GroupUserCard
// {
// GroupId = ucg.GroupId,
// IsSuperAdmin = ugc.UserId == cg.AdminUserId,
// IsAdmin = ugc.IsAdmin,
// TenantId = ucg.TenantId,
// UserId = ucg.UserId
// })
// .Distinct()
// .AsNoTracking()
// .ToListAsync(GetCancellationToken(cancellationToken));
// return groupUsers;
//}
//public virtual async Task<GroupUserCard> GetMemberAsync(
// long groupId,
// Guid userId,
// CancellationToken cancellationToken = default)
//{
// var groupUserCard = await (from cg in DbContext.Set<ChatGroup>()
// join ucg in DbContext.Set<UserChatGroup>().DefaultIfEmpty()
// on cg.GroupId equals ucg.GroupId
// join ucc in DbContext.Set<UserChatCard>().DefaultIfEmpty()
// on ucg.UserId equals ucc.UserId
// 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(GetCancellationToken(cancellationToken));
// return groupUserCard;
//}
//public virtual Task<List<UserGroup>> GetUsersAsync(
// long groupId,
// string filter = "",
// string sorting = nameof(UserGroup.UserId),
// bool reverse = false,
// int skipCount = 0,
// int maxResultCount = 10,
// CancellationToken cancellationToken = default)
//{
// sorting = reverse ? sorting + " desc" : sorting;
// // TODO: 复杂的实现,暂时无关紧要,后期再说 :)
// throw new NotImplementedException();
//}
//public virtual Task<int> GetMembersCountAsync(
// long groupId,
// string filter = "",
// CancellationToken cancellationToken = default)
//{
// var ss = (from ucg in DbContext.Set<UserChatGroup>()
// join cg in DbContext.Set<ChatGroup>() on ucg.GroupId equals cg.GroupId
// select cg)
// .WhereIf(!filter.IsNullOrWhiteSpace(),)
// // TODO: 复杂的实现,暂时无关紧要,后期再说 :)
// //throw new NotImplementedException();
//}
//public virtual async Task<UserChatGroup> GetUserGroupAsync(
// long groupId,
// Guid userId,
// CancellationToken cancellationToken = default)
//{
// return await DbSet.Where(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId))
// .AsNoTracking()
// .FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
//}
//public virtual async Task<List<Group>> GetUserGroupsAsync(
// Guid userId,
// CancellationToken cancellationToken = default)
//{
// // TODO: 急需单元测试,对这段代码不是太自信...
// var userGroups = await (from ucg in DbSet
// join cg in DbContext.Set<ChatGroup>()
// on ucg.GroupId equals cg.GroupId
// group cg by new
// {
// cg.GroupId,
// cg.Name,
// cg.AllowAnonymous,
// cg.AllowSendMessage,
// cg.MaxUserCount
// }
// into ug
// orderby ug.Key.GroupId descending
// select new Group
// {
// AllowAnonymous = ug.Key.AllowAnonymous,
// AllowSendMessage = ug.Key.AllowSendMessage,
// GroupUserCount = ug.Count(),
// MaxUserLength = ug.Key.MaxUserCount,
// Name = ug.Key.Name
// })
// .Distinct()
// .ToListAsync(GetCancellationToken(cancellationToken));
// return userGroups;
//}
//public virtual async Task<bool> MemberHasInGroupAsync(
// long groupId,
// Guid userId,
// CancellationToken cancellationToken = default)
//{
// return await DbSet
// .AnyAsync(x => x.GroupId.Equals(groupId) && x.UserId.Equals(userId), GetCancellationToken(cancellationToken));
//}
}
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatSettingRepository.cs

@ -9,11 +9,11 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Chat
{
public class EfCoreUserChatSettingRepository : EfCoreRepository<MessageServiceDbContext, UserChatSetting, long>,
public class EfCoreUserChatSettingRepository : EfCoreRepository<IMessageServiceDbContext, UserChatSetting, long>,
IUserChatSettingRepository, ITransientDependency
{
public EfCoreUserChatSettingRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

3
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs

@ -22,8 +22,11 @@ namespace LINGYUN.Abp.MessageService.EntityFrameworkCore
options.AddRepository<ChatGroup, IGroupRepository>();
options.AddRepository<UserChatGroup, IUserChatGroupRepository>();
options.AddRepository<UserChatCard, IUserChatCardRepository>();
options.AddRepository<UserChatSetting, IUserChatSettingRepository>();
options.AddRepository<UserChatFriend, IUserChatFriendRepository>();
options.AddDefaultRepositories(includeAllEntities: true);
});
}

14
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/IMessageServiceDbContext.cs

@ -0,0 +1,14 @@
using LINGYUN.Abp.MessageService.Chat;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.EntityFrameworkCore
{
[ConnectionStringName(AbpMessageServiceDbProperties.ConnectionStringName)]
public interface IMessageServiceDbContext : IEfCoreDbContext
{
DbSet<UserChatCard> UserChatCards { get; set; }
DbSet<UserGroupCard> UserGroupCards { get; set; }
}
}

11
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContext.cs

@ -1,17 +1,20 @@
using Microsoft.EntityFrameworkCore;
using LINGYUN.Abp.MessageService.Chat;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.EntityFrameworkCore
{
[ConnectionStringName("MessageService")]
public class MessageServiceDbContext : AbpDbContext<MessageServiceDbContext>
[ConnectionStringName(AbpMessageServiceDbProperties.ConnectionStringName)]
public class MessageServiceDbContext : AbpDbContext<MessageServiceDbContext>, IMessageServiceDbContext
{
public DbSet<UserChatCard> UserChatCards { get; set; }
public DbSet<UserGroupCard> UserGroupCards { get; set; }
public MessageServiceDbContext(DbContextOptions<MessageServiceDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureMessageService(options =>

48
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs

@ -89,6 +89,45 @@ namespace LINGYUN.Abp.MessageService.EntityFrameworkCore
b.HasIndex(p => new { p.TenantId, p.GroupId });
});
builder.Entity<UserChatFriend>(b =>
{
b.ToTable(options.TablePrefix + "UserChatFriends", options.Schema);
b.Property(p => p.RemarkName).HasMaxLength(UserChatCardConsts.MaxUserNameLength);
b.ConfigureByConvention();
b.HasIndex(p => new { p.TenantId, p.UserId, p.FrientId });
});
builder.Entity<UserChatCard>(b =>
{
b.ToTable(options.TablePrefix + "UserChatCards", options.Schema);
b.Property(p => p.UserName).HasMaxLength(UserChatCardConsts.MaxUserNameLength).IsRequired();
b.Property(p => p.AvatarUrl).HasMaxLength(UserChatCardConsts.MaxAvatarUrlLength);
b.Property(p => p.Description).HasMaxLength(UserChatCardConsts.MaxDescriptionLength);
b.Property(p => p.NickName).HasMaxLength(UserChatCardConsts.MaxNickNameLength);
b.Property(p => p.Sign).HasMaxLength(UserChatCardConsts.MaxSignLength);
b.ConfigureByConvention();
b.HasIndex(p => new { p.TenantId, p.UserId });
});
builder.Entity<UserGroupCard>(b =>
{
b.ToTable(options.TablePrefix + "UserGroupCards", options.Schema);
b.Property(p => p.NickName).HasMaxLength(UserChatCardConsts.MaxNickNameLength);
b.ConfigureByConvention();
b.HasIndex(p => new { p.TenantId, p.UserId });
});
builder.Entity<UserChatSetting>(b =>
{
b.ToTable(options.TablePrefix + "UserChatSettings", options.Schema);
@ -125,15 +164,6 @@ namespace LINGYUN.Abp.MessageService.EntityFrameworkCore
b.HasIndex(p => new { p.TenantId, p.GroupId });
});
builder.Entity<ChatGroupAdmin>(b =>
{
b.ToTable(options.TablePrefix + "ChatGroupAdmins", options.Schema);
b.ConfigureMultiTenant();
b.HasIndex(p => new { p.TenantId, p.GroupId });
});
builder.Entity<ChatGroup>(b =>
{
b.ToTable(options.TablePrefix + "ChatGroups", options.Schema);

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationRepository.cs

@ -9,11 +9,11 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Notifications
{
public class EfCoreNotificationRepository : EfCoreRepository<MessageServiceDbContext, Notification, long>,
public class EfCoreNotificationRepository : EfCoreRepository<IMessageServiceDbContext, Notification, long>,
INotificationRepository, ITransientDependency
{
public EfCoreNotificationRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs

@ -12,11 +12,11 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Notifications
{
public class EfCoreUserNotificationRepository : EfCoreRepository<MessageServiceDbContext, UserNotification, long>,
public class EfCoreUserNotificationRepository : EfCoreRepository<IMessageServiceDbContext, UserNotification, long>,
IUserNotificationRepository, ITransientDependency
{
public EfCoreUserNotificationRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs

@ -11,11 +11,11 @@ using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Subscriptions
{
public class EfCoreUserSubscribeRepository : EfCoreRepository<MessageServiceDbContext, UserSubscribe, long>,
public class EfCoreUserSubscribeRepository : EfCoreRepository<IMessageServiceDbContext, UserSubscribe, long>,
IUserSubscribeRepository, ITransientDependency
{
public EfCoreUserSubscribeRepository(
IDbContextProvider<MessageServiceDbContext> dbContextProvider)
IDbContextProvider<IMessageServiceDbContext> dbContextProvider)
: base(dbContextProvider)
{
}

4
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs

@ -9,7 +9,7 @@ using Volo.Abp.AspNetCore.Mvc;
namespace LINGYUN.Abp.MessageService.Chat
{
[RemoteService(Name = AbpMessageServiceConsts.RemoteServiceName)]
[Route("api/chat")]
[Route("api/im/chat")]
public class ChatController : AbpController, IChatAppService
{
private readonly IChatAppService _chatAppService;
@ -35,7 +35,7 @@ namespace LINGYUN.Abp.MessageService.Chat
[HttpGet]
[Route("groups/users")]
public virtual async Task<PagedResultDto<UserGroup>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
{
return await _chatAppService.GetGroupUsersAsync(groupUserGetByPaged);
}

46
aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/MyFriendController.cs

@ -0,0 +1,46 @@
using LINGYUN.Abp.IM.Contract;
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/im/my-friends")]
public class MyFriendController : AbpController, IMyFriendAppService
{
protected IMyFriendAppService MyFriendAppService { get; }
public MyFriendController(IMyFriendAppService myFriendAppService)
{
MyFriendAppService = myFriendAppService;
}
[HttpPost]
public virtual async Task CreateAsync(MyFriendCreateDto input)
{
await MyFriendAppService.CreateAsync(input);
}
[HttpDelete]
public virtual async Task DeleteAsync(MyFriendOperationDto input)
{
await MyFriendAppService.DeleteAsync(input);
}
[HttpGet]
[Route("last-contacts")]
public virtual async Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input)
{
return await MyFriendAppService.GetLastContactFriendsAsync(input);
}
[HttpGet]
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input)
{
return await MyFriendAppService.GetMyFriendsAsync(input);
}
}
}

6
aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs

@ -36,6 +36,7 @@ using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.FeatureManagement;
@ -181,6 +182,11 @@ namespace LINGYUN.Abp.BackendAdmin
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<AbpDistributedEntityEventOptions>(options =>
{
options.AutoEventSelectors.AddNamespace("Volo.Abp.TenantManagement");
});
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);

BIN
aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/event-bus-cap.db

Binary file not shown.

7
aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs

@ -30,6 +30,7 @@ using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.Identity.Localization;
@ -174,6 +175,12 @@ namespace LINGYUN.Abp.IdentityServer4
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<AbpDistributedEntityEventOptions>(options =>
{
options.AutoEventSelectors.AddNamespace("Volo.Abp.Identity");
options.AutoEventSelectors.AddNamespace("Volo.Abp.IdentityServer");
});
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);

590
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024093309_Add-MemberCard-Entity.Designer.cs

@ -0,0 +1,590 @@
// <auto-generated />
using System;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Migrations
{
[DbContext(typeof(MessageServiceHostMigrationsDbContext))]
[Migration("20201024093309_Add-MemberCard-Entity")]
partial class AddMemberCardEntity
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "3.1.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.ChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<Guid>("AdminUserId")
.HasColumnType("char(36)");
b.Property<bool>("AllowAnonymous")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowSendMessage")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("Description")
.HasColumnType("varchar(128) CHARACTER SET utf8mb4")
.HasMaxLength(128);
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<int>("MaxUserCount")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("varchar(20) CHARACTER SET utf8mb4")
.HasMaxLength(20);
b.Property<string>("Notice")
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<string>("Tag")
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "Name");
b.ToTable("AppChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppGroupChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppGroupMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<int>("Age")
.HasColumnType("int");
b.Property<string>("AvatarUrl")
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<DateTime?>("Birthday")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("Description")
.HasColumnType("varchar(50) CHARACTER SET utf8mb4")
.HasMaxLength(50);
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<int>("Sex")
.HasColumnType("int");
b.Property<string>("Sign")
.HasColumnType("varchar(30) CHARACTER SET utf8mb4")
.HasMaxLength(30);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId", "UserId");
b.ToTable("AppUserChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatSetting", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("AllowAddFriend")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowAnonymous")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowReceiveMessage")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowSendMessage")
.HasColumnType("tinyint(1)");
b.Property<bool>("RequireAddFriendValition")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatSettings");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserGroupCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("IsAdmin")
.HasColumnType("tinyint(1)");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<DateTime?>("SilenceEnd")
.HasColumnType("datetime(6)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserGroupCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<Guid>("ReceiveUserId")
.HasColumnType("char(36)");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "ReceiveUserId");
b.ToTable("AppUserMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserSpecialFocus", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<Guid>("FocusUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserSpecialFocuss");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.Notification", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<DateTime?>("ExpirationTime")
.HasColumnType("datetime(6)");
b.Property<string>("NotificationCateGory")
.IsRequired()
.HasColumnType("varchar(50) CHARACTER SET utf8mb4")
.HasMaxLength(50);
b.Property<string>("NotificationData")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<long>("NotificationId")
.HasColumnType("bigint");
b.Property<string>("NotificationName")
.IsRequired()
.HasColumnType("varchar(100) CHARACTER SET utf8mb4")
.HasMaxLength(100);
b.Property<string>("NotificationTypeName")
.IsRequired()
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<sbyte>("Severity")
.HasColumnType("tinyint");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "NotificationName");
b.ToTable("AppNotifications");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.UserNotification", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<long>("NotificationId")
.HasColumnType("bigint");
b.Property<int>("ReadStatus")
.HasColumnType("int");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId", "NotificationId")
.HasName("IX_Tenant_User_Notification_Id");
b.ToTable("AppUserNotifications");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Subscriptions.UserSubscribe", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("NotificationName")
.IsRequired()
.HasColumnType("varchar(100) CHARACTER SET utf8mb4")
.HasMaxLength(100);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("varchar(128) CHARACTER SET utf8mb4")
.HasMaxLength(128)
.HasDefaultValue("/");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId", "NotificationName")
.IsUnique()
.HasName("IX_Tenant_User_Notification_Name");
b.ToTable("AppUserSubscribes");
});
#pragma warning restore 612, 618
}
}
}

125
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024093309_Add-MemberCard-Entity.cs

@ -0,0 +1,125 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace LINGYUN.Abp.MessageService.Migrations
{
public partial class AddMemberCardEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppChatGroupAdmins");
migrationBuilder.AddColumn<Guid>(
name: "AdminUserId",
table: "AppChatGroups",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.CreateTable(
name: "AppUserChatCards",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
ExtraProperties = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
CreatorId = table.Column<Guid>(nullable: true),
LastModificationTime = table.Column<DateTime>(nullable: true),
LastModifierId = table.Column<Guid>(nullable: true),
TenantId = table.Column<Guid>(nullable: true),
UserId = table.Column<Guid>(nullable: false),
UserName = table.Column<string>(maxLength: 256, nullable: false),
Sex = table.Column<int>(nullable: false),
Sign = table.Column<string>(maxLength: 30, nullable: true),
NickName = table.Column<string>(maxLength: 256, nullable: true),
Description = table.Column<string>(maxLength: 50, nullable: true),
AvatarUrl = table.Column<string>(maxLength: 512, nullable: true),
Birthday = table.Column<DateTime>(nullable: true),
Age = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppUserChatCards", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AppUserGroupCards",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
ExtraProperties = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(nullable: false),
CreatorId = table.Column<Guid>(nullable: true),
LastModificationTime = table.Column<DateTime>(nullable: true),
LastModifierId = table.Column<Guid>(nullable: true),
TenantId = table.Column<Guid>(nullable: true),
UserId = table.Column<Guid>(nullable: false),
NickName = table.Column<string>(maxLength: 256, nullable: true),
IsAdmin = table.Column<bool>(nullable: false),
SilenceEnd = table.Column<DateTime>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AppUserGroupCards", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AppUserChatCards_TenantId_UserId",
table: "AppUserChatCards",
columns: new[] { "TenantId", "UserId" });
migrationBuilder.CreateIndex(
name: "IX_AppUserGroupCards_TenantId_UserId",
table: "AppUserGroupCards",
columns: new[] { "TenantId", "UserId" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppUserChatCards");
migrationBuilder.DropTable(
name: "AppUserGroupCards");
migrationBuilder.DropColumn(
name: "AdminUserId",
table: "AppChatGroups");
migrationBuilder.CreateTable(
name: "AppChatGroupAdmins",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
AllowAddPeople = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowDissolveGroup = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowKickPeople = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowSendNotice = table.Column<bool>(type: "tinyint(1)", nullable: false),
AllowSilence = table.Column<bool>(type: "tinyint(1)", nullable: false),
CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
CreatorId = table.Column<string>(type: "char(36)", nullable: true),
GroupId = table.Column<long>(type: "bigint", nullable: false),
IsSuperAdmin = table.Column<bool>(type: "tinyint(1)", nullable: false),
LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
LastModifierId = table.Column<string>(type: "char(36)", nullable: true),
TenantId = table.Column<string>(type: "char(36)", nullable: true),
UserId = table.Column<string>(type: "char(36)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppChatGroupAdmins", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AppChatGroupAdmins_TenantId_GroupId",
table: "AppChatGroupAdmins",
columns: new[] { "TenantId", "GroupId" });
}
}
}

634
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024114206_Add-UserChatFriend-Entity.Designer.cs

@ -0,0 +1,634 @@
// <auto-generated />
using System;
using LINGYUN.Abp.MessageService.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
namespace LINGYUN.Abp.MessageService.Migrations
{
[DbContext(typeof(MessageServiceHostMigrationsDbContext))]
[Migration("20201024114206_Add-UserChatFriend-Entity")]
partial class AddUserChatFriendEntity
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "3.1.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.ChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<Guid>("AdminUserId")
.HasColumnType("char(36)");
b.Property<bool>("AllowAnonymous")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowSendMessage")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("Description")
.HasColumnType("varchar(128) CHARACTER SET utf8mb4")
.HasMaxLength(128);
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<int>("MaxUserCount")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("varchar(20) CHARACTER SET utf8mb4")
.HasMaxLength(20);
b.Property<string>("Notice")
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<string>("Tag")
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "Name");
b.ToTable("AppChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppGroupChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppGroupMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<int>("Age")
.HasColumnType("int");
b.Property<string>("AvatarUrl")
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<DateTime?>("Birthday")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("Description")
.HasColumnType("varchar(50) CHARACTER SET utf8mb4")
.HasMaxLength(50);
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<int>("Sex")
.HasColumnType("int");
b.Property<string>("Sign")
.HasColumnType("varchar(30) CHARACTER SET utf8mb4")
.HasMaxLength(30);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatFriend", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("Black")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<bool>("DontDisturb")
.HasColumnType("tinyint(1)");
b.Property<Guid>("FrientId")
.HasColumnType("char(36)");
b.Property<string>("RemarkName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<bool>("SpecialFocus")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId", "FrientId");
b.ToTable("AppUserChatFriends");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId", "UserId");
b.ToTable("AppUserChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatSetting", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("AllowAddFriend")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowAnonymous")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowReceiveMessage")
.HasColumnType("tinyint(1)");
b.Property<bool>("AllowSendMessage")
.HasColumnType("tinyint(1)");
b.Property<bool>("RequireAddFriendValition")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserChatSettings");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserGroupCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("IsAdmin")
.HasColumnType("tinyint(1)");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<DateTime?>("SilenceEnd")
.HasColumnType("datetime(6)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserGroupCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<Guid>("ReceiveUserId")
.HasColumnType("char(36)");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "ReceiveUserId");
b.ToTable("AppUserMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserSpecialFocus", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<Guid>("FocusUserId")
.HasColumnType("char(36)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserSpecialFocuss");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.Notification", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<DateTime?>("ExpirationTime")
.HasColumnType("datetime(6)");
b.Property<string>("NotificationCateGory")
.IsRequired()
.HasColumnType("varchar(50) CHARACTER SET utf8mb4")
.HasMaxLength(50);
b.Property<string>("NotificationData")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<long>("NotificationId")
.HasColumnType("bigint");
b.Property<string>("NotificationName")
.IsRequired()
.HasColumnType("varchar(100) CHARACTER SET utf8mb4")
.HasMaxLength(100);
b.Property<string>("NotificationTypeName")
.IsRequired()
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<sbyte>("Severity")
.HasColumnType("tinyint");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "NotificationName");
b.ToTable("AppNotifications");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.UserNotification", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<long>("NotificationId")
.HasColumnType("bigint");
b.Property<int>("ReadStatus")
.HasColumnType("int");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId", "NotificationId")
.HasName("IX_Tenant_User_Notification_Id");
b.ToTable("AppUserNotifications");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Subscriptions.UserSubscribe", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("NotificationName")
.IsRequired()
.HasColumnType("varchar(100) CHARACTER SET utf8mb4")
.HasMaxLength(100);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("varchar(128) CHARACTER SET utf8mb4")
.HasMaxLength(128)
.HasDefaultValue("/");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId", "NotificationName")
.IsUnique()
.HasName("IX_Tenant_User_Notification_Name");
b.ToTable("AppUserSubscribes");
});
#pragma warning restore 612, 618
}
}
}

44
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/20201024114206_Add-UserChatFriend-Entity.cs

@ -0,0 +1,44 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
namespace LINGYUN.Abp.MessageService.Migrations
{
public partial class AddUserChatFriendEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AppUserChatFriends",
columns: table => new
{
Id = table.Column<long>(nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
CreationTime = table.Column<DateTime>(nullable: false),
CreatorId = table.Column<Guid>(nullable: true),
TenantId = table.Column<Guid>(nullable: true),
UserId = table.Column<Guid>(nullable: false),
FrientId = table.Column<Guid>(nullable: false),
Black = table.Column<bool>(nullable: false),
DontDisturb = table.Column<bool>(nullable: false),
SpecialFocus = table.Column<bool>(nullable: false),
RemarkName = table.Column<string>(maxLength: 256, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AppUserChatFriends", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_AppUserChatFriends_TenantId_UserId_FrientId",
table: "AppUserChatFriends",
columns: new[] { "TenantId", "UserId", "FrientId" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppUserChatFriends");
}
}
}

307
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Migrations/MessageServiceHostMigrationsDbContextModelSnapshot.cs

@ -16,10 +16,10 @@ namespace LINGYUN.Abp.MessageService.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("ProductVersion", "3.1.7")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.ChatGroup", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.ChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -29,6 +29,9 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<Guid>("AdminUserId")
.HasColumnType("char(36)");
b.Property<bool>("AllowAnonymous")
.HasColumnType("tinyint(1)");
@ -39,7 +42,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
@ -54,7 +57,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<string>("LastModifierId")
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
@ -74,7 +77,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
@ -85,61 +88,82 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.ToTable("AppChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.ChatGroupAdmin", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("AllowAddPeople")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<bool>("AllowDissolveGroup")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<bool>("AllowKickPeople")
.HasColumnType("tinyint(1)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<bool>("AllowSendNotice")
.HasColumnType("tinyint(1)");
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<bool>("AllowSilence")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppGroupChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.GroupMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<bool>("IsSuperAdmin")
.HasColumnType("tinyint(1)");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<string>("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.ToTable("AppChatGroupAdmins");
b.ToTable("AppGroupMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.GroupChatBlack", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatBlack", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -148,105 +172,147 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<string>("ShieldUserId")
.IsRequired()
b.Property<Guid>("ShieldUserId")
.HasColumnType("char(36)");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppGroupChatBlacks");
b.ToTable("AppUserChatBlacks");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.GroupMessage", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("longtext CHARACTER SET utf8mb4")
.HasMaxLength(1048576);
b.Property<int>("Age")
.HasColumnType("int");
b.Property<string>("AvatarUrl")
.HasColumnType("varchar(512) CHARACTER SET utf8mb4")
.HasMaxLength(512);
b.Property<DateTime?>("Birthday")
.HasColumnType("datetime(6)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<string>("Description")
.HasColumnType("varchar(50) CHARACTER SET utf8mb4")
.HasMaxLength(50);
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<sbyte>("SendState")
.HasColumnType("tinyint");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<string>("SendUserName")
.IsRequired()
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<int>("Sex")
.HasColumnType("int");
b.Property<string>("TenantId")
b.Property<string>("Sign")
.HasColumnType("varchar(30) CHARACTER SET utf8mb4")
.HasMaxLength(30);
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.HasKey("Id");
b.HasIndex("TenantId", "GroupId");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppGroupMessages");
b.ToTable("AppUserChatCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.UserChatBlack", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatFriend", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<bool>("Black")
.HasColumnType("tinyint(1)");
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("ShieldUserId")
.IsRequired()
b.Property<bool>("DontDisturb")
.HasColumnType("tinyint(1)");
b.Property<Guid>("FrientId")
.HasColumnType("char(36)");
b.Property<string>("TenantId")
b.Property<string>("RemarkName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<bool>("SpecialFocus")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.HasIndex("TenantId", "UserId", "FrientId");
b.ToTable("AppUserChatBlacks");
b.ToTable("AppUserChatFriends");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.UserChatGroup", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatGroup", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -256,19 +322,18 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("GroupId")
.HasColumnType("bigint");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
@ -278,7 +343,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.ToTable("AppUserChatGroups");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.UserChatSetting", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatSetting", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -299,12 +364,11 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.Property<bool>("RequireAddFriendValition")
.HasColumnType("tinyint(1)");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
@ -314,7 +378,63 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.ToTable("AppUserChatSettings");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.UserMessage", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserGroupCard", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnName("ConcurrencyStamp")
.HasColumnType("varchar(40) CHARACTER SET utf8mb4")
.HasMaxLength(40);
b.Property<DateTime>("CreationTime")
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("CreatorId")
.HasColumnName("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("longtext CHARACTER SET utf8mb4");
b.Property<bool>("IsAdmin")
.HasColumnType("tinyint(1)");
b.Property<DateTime?>("LastModificationTime")
.HasColumnName("LastModificationTime")
.HasColumnType("datetime(6)");
b.Property<Guid?>("LastModifierId")
.HasColumnName("LastModifierId")
.HasColumnType("char(36)");
b.Property<string>("NickName")
.HasColumnType("varchar(256) CHARACTER SET utf8mb4")
.HasMaxLength(256);
b.Property<DateTime?>("SilenceEnd")
.HasColumnType("datetime(6)");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("TenantId", "UserId");
b.ToTable("AppUserGroupCards");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserMessage", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -329,14 +449,13 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnName("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<long>("MessageId")
.HasColumnType("bigint");
b.Property<string>("ReceiveUserId")
.IsRequired()
b.Property<Guid>("ReceiveUserId")
.HasColumnType("char(36)");
b.Property<sbyte>("SendState")
@ -347,7 +466,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnType("varchar(64) CHARACTER SET utf8mb4")
.HasMaxLength(64);
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
@ -361,7 +480,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.ToTable("AppUserMessages");
});
modelBuilder.Entity("LINGYUN.Abp.MessageService.Messages.UserSpecialFocus", b =>
modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserSpecialFocus", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
@ -370,19 +489,17 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)");
b.Property<string>("CreatorId")
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)");
b.Property<string>("FocusUserId")
.IsRequired()
b.Property<Guid>("FocusUserId")
.HasColumnType("char(36)");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
@ -431,7 +548,7 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.Property<sbyte>("Severity")
.HasColumnType("tinyint");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
@ -457,12 +574,11 @@ namespace LINGYUN.Abp.MessageService.Migrations
b.Property<int>("ReadStatus")
.HasColumnType("int");
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.HasKey("Id");
@ -488,12 +604,11 @@ namespace LINGYUN.Abp.MessageService.Migrations
.HasColumnType("varchar(100) CHARACTER SET utf8mb4")
.HasMaxLength(100);
b.Property<string>("TenantId")
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("char(36)");
b.Property<string>("UserId")
.IsRequired()
b.Property<Guid>("UserId")
.HasColumnType("char(36)");
b.Property<string>("UserName")

8
vueJs/package-lock.json

@ -14595,6 +14595,14 @@
"integrity": "sha1-W4o6d2Xf4AEmHd6RVYnngvjJTR4=",
"dev": true
},
"lemon-imui": {
"version": "1.0.4",
"resolved": "https://registry.npm.taobao.org/lemon-imui/download/lemon-imui-1.0.4.tgz",
"integrity": "sha1-cq+I/hTHnTLv886bV97T1XoG5TI=",
"requires": {
"vue": "^2.6.10"
}
},
"leven": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/leven/download/leven-3.1.0.tgz",

1
vueJs/package.json

@ -31,6 +31,7 @@
"js-cookie": "^2.2.1",
"jsonlint": "^1.6.3",
"jszip": "^3.3.0",
"lemon-imui": "^1.0.4",
"lodash": "^4.17.15",
"morgan": "^1.10.0",
"normalize.css": "^8.0.1",

71
vueJs/src/api/instant-message.ts

@ -0,0 +1,71 @@
import ApiService from './serviceBase'
import { PagedResultDto, PagedAndSortedResultRequestDto, PagedResultRequestDto } from './types'
const serviceUrl = process.env.VUE_APP_BASE_API
export default class ImApiService {
public static getMyFriends(payload: MyFriendGetByPaged) {
let _url = 'api/im/my-friends'
_url += '?filter=' + payload.filter
_url += '&sorting=' + payload.sorting
_url += '&reverse=' + payload.reverse
_url += '&skipCount=' + payload.skipCount
_url += '&maxResultCount=' + payload.maxResultCount
return ApiService.Get<PagedResultDto<UserFriend>>(_url, serviceUrl)
}
}
export enum Sex
{
Male,
Female,
Other
}
export class UserCard {
tenantId?: string
userId = ''
userName = ''
avatarUrl = ''
nickName = ''
age = 0
sex = Sex.Male
sign = ''
description = ''
birthday?: Date
}
export class UserFriend extends UserCard {
friendId = ''
remarkName = ''
black = false
specialFocus = false
dontDisturb = false
}
export class MyFriendGetByPaged extends PagedAndSortedResultRequestDto {
filter = ''
sorting = 'UserName'
skipCount = 0
reverse = false
}
export enum MessageType {
Text = 0,
Image = 10,
Link = 20,
Video = 30
}
export class ChatMessage {
tenantId?: string
groupId = ''
messageId = ''
formUserId = ''
formUserName = ''
toUserId = ''
content = ''
sendTime = new Date()
isAnonymous = false
messageType = MessageType.Text
}

122
vueJs/src/components/InstantMessage/index.vue

@ -0,0 +1,122 @@
<template>
<div>
<lemon-imui
v-show="showDialog"
ref="IMUI"
:user="currentUser"
@send="handleSendMessage"
/>
</div>
</template>
<script lang="ts">
import EventBusMiXin from '@/mixins/EventBusMiXin'
import Component, { mixins } from 'vue-class-component'
import { UserModule } from '@/store/modules/user'
import ImApiService, { MyFriendGetByPaged, UserFriend, ChatMessage } from '@/api/instant-message'
import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr'
class MyContract {
id = ''
displayName = ''
avatar = ''
type = ''
index = 'A'
unread = 0
lastSendTime = 0
lastContent = '0'
}
@Component({
name: 'InstantMessage'
})
export default class InstantMessage extends mixins(EventBusMiXin) {
private showDialog = false
private dataFilter = new MyFriendGetByPaged()
private myFriendCount = 0
private myFriends = new Array<UserFriend>()
private connection!: HubConnection
get currentUser() {
return {
id: UserModule.id,
displayName: UserModule.userName,
avatar: ''
}
}
mounted() {
this.subscribe('onShowImDialog', this.onShowImDialog)
this.handleStartConnection()
}
destroyed() {
this.unSubscribe('onShowImDialog')
}
private handleStartConnection() {
if (!this.connection) {
const builder = new HubConnectionBuilder()
const userToken = UserModule.token.replace('Bearer ', '')
this.connection = builder
.withUrl('/signalr-hubs/signalr-hubs/messages', { accessTokenFactory: () => userToken })
.withAutomaticReconnect({ nextRetryDelayInMilliseconds: () => 60000 })
.build()
this.connection.onclose(error => {
console.log('signalr connection has closed, error:')
console.log(error)
})
}
if (this.connection.state !== HubConnectionState.Connected) {
this.connection
.start()
.then(() => {
ImApiService
.getMyFriends(this.dataFilter)
.then(res => {
this.myFriends = res.items
this.myFriendCount = res.totalCount
this.handleInitContracts()
})
})
}
}
private handleInitContracts() {
const myContracts = new Array<MyContract>()
this.myFriends
.forEach(friend => {
const myContract = new MyContract()
myContract.id = friend.friendId
myContract.displayName = friend.remarkName ?? friend.userName
myContracts.push(myContract)
})
const imui = this.$refs.IMUI as any
imui.initContacts(myContracts)
}
private onShowImDialog() {
this.showDialog = !this.showDialog
}
private handleSendMessage(message: any, next: any, file: any) {
console.log(message, next, file)
const chatMessage = new ChatMessage()
chatMessage.formUserId = message.fromUser.id
chatMessage.formUserName = message.fromUser.displayName
chatMessage.toUserId = message.toContactId
chatMessage.content = message.content
this.connection
.invoke('SendMessage', chatMessage)
.then(() => {
setTimeout(() => {
next()
}, 1000)
})
}
}
</script>

3
vueJs/src/main.ts

@ -8,10 +8,12 @@ import SvgIcon from 'vue-svgicon'
import uploader from 'vue-simple-uploader'
import contextMenu from 'vue-contextmenujs'
import VueEvents from '@/components/EventBus'
import LemonIMUI from 'lemon-imui'
import '@/styles/element-variables.scss'
import 'view-design/dist/styles/iview.css'
import '@/styles/index.scss'
import 'lemon-imui/dist/index.css'
import App from '@/App.vue'
import store from '@/store'
@ -44,6 +46,7 @@ Vue.use(SvgIcon, {
Vue.use(uploader)
Vue.use(contextMenu)
Vue.use(VueEvents)
Vue.use(LemonIMUI)
// Register global directives
Object.keys(directives).forEach(key => {

3
vueJs/src/shims.d.ts

@ -31,3 +31,6 @@ declare module 'vue-simple-uploader'
// TODO vue-contextmenujs
declare module 'vue-contextmenujs'
// TODO lemon-imui
declare module 'lemon-imui'

25
vueJs/src/views/dashboard/admin/index.vue

@ -1,21 +1,36 @@
<template>
<div class="dashboard-editor-container" />
<div class="dashboard-editor-container">
IM测试页
<el-button @click="onShowImDialogClick">
打开IM
</el-button>
<instant-message />
</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import EventBusMiXin from '@/mixins/EventBusMiXin'
import Component, { mixins } from 'vue-class-component'
import InstantMessage from '@/components/InstantMessage/index.vue'
@Component({
name: 'DashboardAdmin'
name: 'DashboardAdmin',
components: {
InstantMessage
}
})
export default class extends Vue {
export default class extends mixins(EventBusMiXin) {
private onShowImDialogClick() {
this.trigger('onShowImDialog')
}
}
</script>
<style lang="scss" scoped>
.dashboard-editor-container {
padding: 32px;
background-color: rgb(240, 242, 245);
background-color: rgb(12, 73, 165);
position: relative;
.github-corner {

Loading…
Cancel
Save