Browse Source

add component: AddUserFriend

pull/116/head
cKey 5 years ago
parent
commit
d74158fd5a
  1. 50
      aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs
  2. 14
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/IFriendStore.cs
  3. 18
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/UserFriend.cs
  4. 17
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/UserFriendGroup.cs
  5. 16
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/IMessageStore.cs
  6. 9
      aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Messages/LastChatMessage.cs
  7. 10
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GetMyFriendsDto.cs
  8. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GetUserLastMessageDto.cs
  9. 35
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IChatAppService.cs
  10. 4
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/IMyFriendAppService.cs
  11. 63
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/ChatAppService.cs
  12. 12
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Chat/MyFriendAppService.cs
  13. 16
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/MessageServiceErrorCodes.cs
  14. 5
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs
  15. 33
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/FriendStore.cs
  16. 7
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IMessageRepository.cs
  17. 6
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/IUserChatFriendRepository.cs
  18. 40
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/MessageStore.cs
  19. 28
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatFriendGroup.cs
  20. 13
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json
  21. 13
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json
  22. 11
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Mapper/MessageServiceDomainAutoMapperProfile.cs
  23. 50
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreMessageRepository.cs
  24. 36
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Chat/EfCoreUserChatFriendRepository.cs
  25. 41
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/ChatController.cs
  26. 10
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Chat/MyFriendController.cs
  27. BIN
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.Host/event-bus-cap.db
  28. 48
      vueJs/src/api/instant-message.ts
  29. 16
      vueJs/src/api/user-lookup.ts
  30. 182
      vueJs/src/components/InstantMessage/components/AddFriend.vue
  31. 118
      vueJs/src/components/InstantMessage/index.vue
  32. 2
      vueJs/src/mixins/EventBusMiXin.ts

50
aspnet-core/modules/common/LINGYUN.Abp.IM.SignalR/LINGYUN/Abp/IM/SignalR/Hubs/MessagesHub.cs

@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Users;
namespace LINGYUN.Abp.IM.SignalR.Hubs
{
@ -39,22 +40,49 @@ namespace LINGYUN.Abp.IM.SignalR.Hubs
return new PagedResultDto<UserFriend>(myFrientCount, lastContractFriends);
}
[HubMethodName("MyFriends")]
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(
Guid? tenantId,
[HubMethodName("MyLastChatMessages")]
public virtual async Task<ListResultDto<LastChatMessage>> GetMyLastChatMessagesAsync(
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10)
{
return await GetLastChatMessagesAsync(CurrentUser.GetId(), sorting, reverse, maxResultCount);
}
[HubMethodName("LastChatMessages")]
public virtual async Task<ListResultDto<LastChatMessage>> GetLastChatMessagesAsync(
Guid userId,
string filter = "",
string sorting = nameof(UserFriend.UserId),
bool reverse = false,
int skipCount = 0,
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10)
{
var myFrientCount = await FriendStore.GetCountAsync(tenantId, userId);
var messages = await MessageStore
.GetLastChatMessagesAsync(
CurrentTenant.Id, userId, sorting, reverse, maxResultCount);
var myFriends = await FriendStore
.GetListAsync(tenantId, userId, filter, sorting, reverse, skipCount, maxResultCount);
return new ListResultDto<LastChatMessage>(messages);
}
[HubMethodName("MyFriends")]
public virtual async Task<ListResultDto<UserFriend>> GetMyFriendsAsync(
string sorting = nameof(UserFriend.RemarkName),
bool reverse = false)
{
return await GetAllFriendsAsync(CurrentUser.GetId(), sorting, reverse);
}
[HubMethodName("AllFriends")]
public virtual async Task<ListResultDto<UserFriend>> GetAllFriendsAsync(
Guid userId,
string sorting = nameof(UserFriend.RemarkName),
bool reverse = false)
{
var userFriends = await FriendStore
.GetListAsync(CurrentTenant.Id, userId, sorting, reverse);
return new PagedResultDto<UserFriend>(myFrientCount, myFriends);
return new ListResultDto<UserFriend>(userFriends);
}
[HubMethodName("AddFriend")]

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

@ -7,6 +7,20 @@ namespace LINGYUN.Abp.IM.Contract
public interface IFriendStore
{
/// <summary>
/// 查询好友列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="sorting"></param>
/// <param name="reverse"></param>
/// <returns></returns>
Task<List<UserFriend>> GetListAsync(
Guid? tenantId,
Guid userId,
string sorting = nameof(UserFriend.UserId),
bool reverse = false
);
/// <summary>
/// 获取好友数量
/// </summary>
/// <param name="tenantId"></param>

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

@ -24,5 +24,23 @@ namespace LINGYUN.Abp.IM.Contract
/// 备注名称
/// </summary>
public string RemarkName { get; set; }
public override int GetHashCode()
{
return FriendId.GetHashCode();
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (obj is UserFriend friend)
{
return friend.FriendId.Equals(FriendId);
}
return false;
}
}
}

17
aspnet-core/modules/common/LINGYUN.Abp.IM/LINGYUN/Abp/IM/Contract/UserFriendGroup.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace LINGYUN.Abp.IM.Contract
{
public class UserFriendGroup
{
public Guid? TenantId { get; set; }
public string DisplayName { get; set; }
public List<UserFriend> UserFriends { get; set; } = new List<UserFriend>();
public void AddFriend(UserFriend friend)
{
UserFriends.AddIfNotContains(friend);
}
}
}

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

@ -49,6 +49,22 @@ namespace LINGYUN.Abp.IM.Messages
int skipCount = 0,
int maxResultCount = 10);
/// <summary>
/// 获取上一次通讯消息记录
/// </summary>
/// <param name="tenantId"></param>
/// <param name="userId"></param>
/// <param name="sorting"></param>
/// <param name="reverse"></param>
/// <param name="maxResultCount"></param>
/// <returns></returns>
Task<List<LastChatMessage>> GetLastChatMessagesAsync(
Guid? tenantId,
Guid userId,
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10
);
/// <summary>
/// 获取与某个用户的聊天记录总数
/// </summary>
/// <param name="tenantId"></param>

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

@ -0,0 +1,9 @@
namespace LINGYUN.Abp.IM.Messages
{
/// <summary>
/// 上一次通讯消息
/// </summary>
public class LastChatMessage : ChatMessage
{
}
}

10
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Chat/Dto/GetMyFriendsDto.cs

@ -0,0 +1,10 @@
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.MessageService.Chat
{
public class GetMyFriendsDto : ISortedResultRequest
{
public string Sorting { get; set; }
public bool Reverse { get; set; }
}
}

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

@ -0,0 +1,11 @@
using Volo.Abp.Application.Dtos;
namespace LINGYUN.Abp.MessageService.Chat
{
public class GetUserLastMessageDto : ILimitedResultRequest, ISortedResultRequest
{
public int MaxResultCount { get; set; }
public string Sorting { get; set; }
public bool Reverse { get; set; }
}
}

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

@ -11,15 +11,15 @@ namespace LINGYUN.Abp.MessageService.Chat
/// <summary>
/// 发送消息
/// </summary>
/// <param name="chatMessage"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage chatMessage);
Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage input);
/// <summary>
/// 申请加入群组
/// </summary>
/// <param name="userJoinGroup"></param>
/// <param name="input"></param>
/// <returns></returns>
Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup);
Task ApplyJoinGroupAsync(UserJoinGroupDto input);
/// <summary>
/// 获取我的群组
/// </summary>
@ -28,34 +28,39 @@ namespace LINGYUN.Abp.MessageService.Chat
/// <summary>
/// 获取群组用户
/// </summary>
/// <param name="groupUserGetByPaged"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged);
Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto input);
/// <summary>
/// 处理用户群组申请
/// </summary>
/// <param name="groupAcceptUser"></param>
/// <param name="input"></param>
/// <returns></returns>
Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser);
Task GroupAcceptUserAsync(GroupAcceptUserDto input);
/// <summary>
/// 群组移除用户
/// </summary>
/// <param name="groupRemoveUser"></param>
/// <param name="input"></param>
/// <returns></returns>
Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser);
Task GroupRemoveUserAsync(GroupRemoveUserDto input);
/// <summary>
/// 获取群组消息
/// </summary>
/// <param name="groupMessageGetByPaged"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged);
Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto input);
/// <summary>
/// 获取我的消息
/// </summary>
/// <param name="userMessageGetByPaged"></param>
/// <param name="input"></param>
/// <returns></returns>
Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged);
Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto input);
/// <summary>
/// 获取我最近的消息
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<ListResultDto<LastChatMessage>> GetMyLastChatMessageAsync(GetUserLastMessageDto input);
//TOTO: 还应该有获取我的未读消息 获取我的未读群组消息
}
}

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

@ -7,9 +7,9 @@ namespace LINGYUN.Abp.MessageService.Chat
{
public interface IMyFriendAppService : IApplicationService
{
Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input);
Task<PagedResultDto<UserFriend>> GetListAsync(MyFriendGetByPagedDto input);
Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input);
Task<ListResultDto<UserFriend>> GetAllListAsync(GetMyFriendsDto input);
Task CreateAsync(MyFriendCreateDto input);

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

@ -27,44 +27,53 @@ namespace LINGYUN.Abp.MessageService.Chat
}
[Authorize]
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged)
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto input)
{
var chatMessageCount = await _messageStore
.GetChatMessageCountAsync(CurrentTenant.Id, CurrentUser.GetId(), userMessageGetByPaged.ReceiveUserId,
userMessageGetByPaged.Filter, userMessageGetByPaged.MessageType);
.GetChatMessageCountAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId,
input.Filter, input.MessageType);
var chatMessages = await _messageStore
.GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), userMessageGetByPaged.ReceiveUserId,
userMessageGetByPaged.Filter, userMessageGetByPaged.Sorting, userMessageGetByPaged.Reverse,
userMessageGetByPaged.MessageType, userMessageGetByPaged.SkipCount, userMessageGetByPaged.MaxResultCount);
.GetChatMessageAsync(CurrentTenant.Id, CurrentUser.GetId(), input.ReceiveUserId,
input.Filter, input.Sorting, input.Reverse,
input.MessageType, input.SkipCount, input.MaxResultCount);
return new PagedResultDto<ChatMessage>(chatMessageCount, chatMessages);
}
public virtual async Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged)
public virtual async Task<ListResultDto<LastChatMessage>> GetMyLastChatMessageAsync(GetUserLastMessageDto input)
{
var chatMessages = await _messageStore
.GetLastChatMessagesAsync(CurrentTenant.Id, CurrentUser.GetId(),
input.Sorting, input.Reverse, input.MaxResultCount);
return new ListResultDto<LastChatMessage>(chatMessages);
}
public virtual async Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto input)
{
// TODO: 增加验证,用户不在群组却来查询这个群组消息,是非法客户端操作
var groupMessageCount = await _messageStore
.GetGroupMessageCountAsync(CurrentTenant.Id, groupMessageGetByPaged.GroupId,
groupMessageGetByPaged.Filter, groupMessageGetByPaged.MessageType);
.GetGroupMessageCountAsync(CurrentTenant.Id, input.GroupId,
input.Filter, input.MessageType);
var groupMessages = await _messageStore
.GetGroupMessageAsync(CurrentTenant.Id, groupMessageGetByPaged.GroupId,
groupMessageGetByPaged.Filter, groupMessageGetByPaged.Sorting, groupMessageGetByPaged.Reverse,
groupMessageGetByPaged.MessageType, groupMessageGetByPaged.SkipCount, groupMessageGetByPaged.MaxResultCount);
.GetGroupMessageAsync(CurrentTenant.Id, input.GroupId,
input.Filter, input.Sorting, input.Reverse,
input.MessageType, input.SkipCount, input.MaxResultCount);
return new PagedResultDto<ChatMessage>(groupMessageCount, groupMessages);
}
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto input)
{
var groupUserCardCount = await _userGroupStore
.GetMembersCountAsync(CurrentTenant.Id, groupUserGetByPaged.GroupId);
.GetMembersCountAsync(CurrentTenant.Id, input.GroupId);
var groupUserCards = await _userGroupStore.GetMembersAsync(CurrentTenant.Id,
groupUserGetByPaged.GroupId, groupUserGetByPaged.Sorting, groupUserGetByPaged.Reverse,
groupUserGetByPaged.SkipCount, groupUserGetByPaged.MaxResultCount);
input.GroupId, input.Sorting, input.Reverse,
input.SkipCount, input.MaxResultCount);
return new PagedResultDto<GroupUserCard>(groupUserCardCount, groupUserCards);
}
@ -77,10 +86,10 @@ namespace LINGYUN.Abp.MessageService.Chat
return new ListResultDto<Group>(myGroups.ToImmutableList());
}
public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser)
public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto input)
{
var myGroupCard = await _userGroupStore
.GetUserGroupCardAsync(CurrentTenant.Id, groupAcceptUser.GroupId, CurrentUser.GetId());
.GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
if (myGroupCard == null)
{
// 当前登录用户不再用户组
@ -92,13 +101,13 @@ namespace LINGYUN.Abp.MessageService.Chat
throw new UserFriendlyException("");
}
await _userGroupStore
.AddUserToGroupAsync(CurrentTenant.Id, groupAcceptUser.UserId, groupAcceptUser.GroupId, CurrentUser.GetId());
.AddUserToGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId, CurrentUser.GetId());
}
public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser)
public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto input)
{
var myGroupCard = await _userGroupStore
.GetUserGroupCardAsync(CurrentTenant.Id, groupRemoveUser.GroupId, CurrentUser.GetId());
.GetUserGroupCardAsync(CurrentTenant.Id, input.GroupId, CurrentUser.GetId());
if (myGroupCard == null)
{
// 当前登录用户不再用户组
@ -110,20 +119,20 @@ namespace LINGYUN.Abp.MessageService.Chat
throw new UserFriendlyException("");
}
await _userGroupStore
.RemoveUserFormGroupAsync(CurrentTenant.Id, groupRemoveUser.UserId, groupRemoveUser.GroupId);
.RemoveUserFormGroupAsync(CurrentTenant.Id, input.UserId, input.GroupId);
}
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage chatMessage)
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage input)
{
// TODO:向其他租户发送消息?
chatMessage.TenantId = chatMessage.TenantId ?? CurrentTenant.Id;
input.TenantId = input.TenantId ?? CurrentTenant.Id;
await MessageSender.SendMessageAsync(chatMessage);
await MessageSender.SendMessageAsync(input);
return new ChatMessageSendResultDto(chatMessage.MessageId);
return new ChatMessageSendResultDto(input.MessageId);
}
public virtual Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup)
public virtual Task ApplyJoinGroupAsync(UserJoinGroupDto input)
{
// TOTO 发送通知?
return Task.CompletedTask;

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

@ -27,18 +27,16 @@ namespace LINGYUN.Abp.MessageService.Chat
await FriendStore.RemoveMemberAsync(CurrentTenant.Id, CurrentUser.GetId(), input.FriendId);
}
public virtual async Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input)
public virtual async Task<ListResultDto<UserFriend>> GetAllListAsync(GetMyFriendsDto input)
{
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId());
var myFriends = await FriendStore
.GetLastContactListAsync(CurrentTenant.Id, CurrentUser.GetId(),
input.SkipCount, input.MaxResultCount);
.GetListAsync(CurrentTenant.Id, CurrentUser.GetId(),
input.Sorting, input.Reverse);
return new PagedResultDto<UserFriend>(myFrientCount, myFriends);
return new ListResultDto<UserFriend>(myFriends);
}
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input)
public virtual async Task<PagedResultDto<UserFriend>> GetListAsync(MyFriendGetByPagedDto input)
{
var myFrientCount = await FriendStore.GetCountAsync(CurrentTenant.Id, CurrentUser.GetId());

16
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/MessageServiceErrorCodes.cs

@ -5,26 +5,30 @@
/// <summary>
/// 管理员已开启全员禁言
/// </summary>
public const string GroupNotAllowedToSpeak = "Messages:Group:1001";
public const string GroupNotAllowedToSpeak = "Messages.Group:1001";
/// <summary>
/// 管理员不允许匿名发言
/// </summary>
public const string GroupNotAllowedToSpeakAnonymously = "Messages:Group:1002";
public const string GroupNotAllowedToSpeakAnonymously = "Messages.Group:1002";
/// <summary>
/// 管理员已禁止用户发言
/// </summary>
public const string GroupUserHasBlack = "Messages:Group:1003";
public const string GroupUserHasBlack = "Messages.Group:1003";
/// <summary>
/// 用户已将发信人拉黑
/// </summary>
public const string UserHasBlack = "Messages:User:1003";
public const string UserHasBlack = "Messages.User:1003";
/// <summary>
/// 用户已拒接所有消息
/// </summary>
public const string UserHasRejectAllMessage = "Messages:User:1001";
public const string UserHasRejectAllMessage = "Messages.User:1001";
/// <summary>
/// 用户不允许匿名发言
/// </summary>
public const string UserNotAllowedToSpeakAnonymously = "Messages:User:1002";
public const string UserNotAllowedToSpeakAnonymously = "Messages.User:1002";
/// <summary>
/// 已经添加对方为好友
/// </summary>
public const string YouHaveAddedTheUserToFriend = "Messages.UserFriend:1001";
}
}

5
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs

@ -34,8 +34,9 @@ namespace LINGYUN.Abp.MessageService
Configure<AbpExceptionLocalizationOptions>(options =>
{
options.MapCodeNamespace("Messages:Group", typeof(MessageServiceResource));
options.MapCodeNamespace("Messages:User", typeof(MessageServiceResource));
options.MapCodeNamespace("Messages.Group", typeof(MessageServiceResource));
options.MapCodeNamespace("Messages.User", typeof(MessageServiceResource));
options.MapCodeNamespace("Messages.UserFriend", typeof(MessageServiceResource));
});
}
}

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

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;
using Volo.Abp.Uow;
@ -22,16 +23,18 @@ namespace LINGYUN.Abp.MessageService.Chat
{
using (CurrentTenant.Change(tenantId))
{
if (!await UserChatFriendRepository.IsAddedAsync(userId, friendId))
if (await UserChatFriendRepository.IsAddedAsync(userId, friendId))
{
var userChatFriend = new UserChatFriend(userId, friendId, remarkName, tenantId)
{
CreationTime = Clock.Now,
CreatorId = userId
};
await UserChatFriendRepository.InsertAsync(userChatFriend);
throw new BusinessException(MessageServiceErrorCodes.YouHaveAddedTheUserToFriend);
}
var userChatFriend = new UserChatFriend(userId, friendId, remarkName, tenantId)
{
CreationTime = Clock.Now,
CreatorId = userId
};
await UserChatFriendRepository.InsertAsync(userChatFriend);
}
}
@ -41,6 +44,20 @@ namespace LINGYUN.Abp.MessageService.Chat
await ChangeFriendShieldAsync(tenantId, userId, friendId, true);
}
public virtual async Task<List<UserFriend>> GetListAsync(
Guid? tenantId,
Guid userId,
string sorting = nameof(UserFriend.UserId),
bool reverse = false
)
{
using (CurrentTenant.Change(tenantId))
{
return await UserChatFriendRepository
.GetAllMembersAsync(userId, sorting, reverse);
}
}
public virtual async Task<int> GetCountAsync(Guid? tenantId, Guid userId, string filter = "")
{
using (CurrentTenant.Change(tenantId))

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

@ -44,6 +44,13 @@ namespace LINGYUN.Abp.MessageService.Chat
MessageType? type = null,
CancellationToken cancellationToken = default);
Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync(
Guid userId,
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10,
CancellationToken cancellationToken = default);
Task<List<UserMessage>> GetUserMessagesAsync(
Guid sendUserId,
Guid receiveUserId,

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

@ -19,6 +19,12 @@ namespace LINGYUN.Abp.MessageService.Chat
Guid friendId,
CancellationToken cancellationToken = default);
Task<List<UserFriend>> GetAllMembersAsync(
Guid userId,
string sorting = nameof(UserChatFriend.RemarkName),
bool reverse = false,
CancellationToken cancellationToken = default);
Task<int> GetMembersCountAsync(
Guid userId,
string filter = "",

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

@ -34,7 +34,7 @@ namespace LINGYUN.Abp.MessageService.Chat
}
[UnitOfWork]
public async Task StoreMessageAsync(ChatMessage chatMessage)
public virtual async Task StoreMessageAsync(ChatMessage chatMessage)
{
using (var unitOfWork = UnitOfWorkManager.Begin())
{
@ -54,7 +54,7 @@ namespace LINGYUN.Abp.MessageService.Chat
}
}
public async Task<List<ChatMessage>> GetGroupMessageAsync(
public virtual async Task<List<ChatMessage>> GetGroupMessageAsync(
Guid? tenantId,
long groupId,
string filter = "",
@ -74,7 +74,7 @@ namespace LINGYUN.Abp.MessageService.Chat
}
}
public async Task<List<ChatMessage>> GetChatMessageAsync(
public virtual async Task<List<ChatMessage>> GetChatMessageAsync(
Guid? tenantId,
Guid sendUserId,
Guid receiveUserId,
@ -95,6 +95,21 @@ namespace LINGYUN.Abp.MessageService.Chat
}
}
public virtual async Task<List<LastChatMessage>> GetLastChatMessagesAsync(
Guid? tenantId,
Guid userId,
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10
)
{
using (CurrentTenant.Change(tenantId))
{
return await MessageRepository
.GetLastMessagesByOneFriendAsync(userId, sorting, reverse, maxResultCount);
}
}
public virtual async Task<long> GetGroupMessageCountAsync(
Guid? tenantId,
long groupId,
@ -130,15 +145,18 @@ namespace LINGYUN.Abp.MessageService.Chat
throw new BusinessException(MessageServiceErrorCodes.UserHasBlack);
}
var userChatSetting = await UserChatSettingRepository.GetByUserIdAsync(chatMessage.ToUserId.Value);
if (!userChatSetting.AllowReceiveMessage)
if (userChatSetting != null)
{
// 当前发送的用户不接收消息
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectAllMessage);
}
if (chatMessage.IsAnonymous && !userChatSetting.AllowAnonymous)
{
// 当前用户不允许匿名发言
throw new BusinessException(MessageServiceErrorCodes.UserNotAllowedToSpeakAnonymously);
if (!userChatSetting.AllowReceiveMessage)
{
// 当前发送的用户不接收消息
throw new BusinessException(MessageServiceErrorCodes.UserHasRejectAllMessage);
}
if (chatMessage.IsAnonymous && !userChatSetting.AllowAnonymous)
{
// 当前用户不允许匿名发言
throw new BusinessException(MessageServiceErrorCodes.UserNotAllowedToSpeakAnonymously);
}
}
var messageId = SnowflakeIdGenerator.Create();
var message = new UserMessage(messageId, chatMessage.FormUserId, chatMessage.FormUserName, chatMessage.Content, chatMessage.MessageType);

28
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Chat/UserChatFriendGroup.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
namespace LINGYUN.Abp.MessageService.Chat
{
public class UserChatFriendGroup : 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 long GroupId { get; protected set; }
/// <summary>
/// 显示名称
/// </summary>
public virtual string DisplayName { get; protected set; }
}
}

13
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json

@ -1,12 +1,13 @@
{
"culture": "en",
"texts": {
"Messages:Group:1001": "The current group is not allowed to speak",
"Messages:Group:1002": "The current group is not allowed to speak anonymously",
"Messages:Group:1003": "The administrator has banned you from speaking!",
"Messages:User:1001": "Users do not receive anonymous comments!",
"Messages:User:1002": "The user has rejected all messages!",
"Messages:User:1003": "The user rejects the message you sent!",
"Messages.Group:1001": "The current group is not allowed to speak",
"Messages.Group:1002": "The current group is not allowed to speak anonymously",
"Messages.Group:1003": "The administrator has banned you from speaking!",
"Messages.User:1001": "Users do not receive anonymous comments!",
"Messages.User:1002": "The user has rejected all messages!",
"Messages.User:1003": "The user rejects the message you sent!",
"Messages.UserFriend:1001": "You have added each other as friends, can not be repeated!",
"WelcomeToApplicationNotification": "User Welcome Notice",
"NewTenantRegisterdNotification": "Tenants create notification",
"WelcomeToApplicationFormUser": "User :{0} welcome to join us!"

13
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json

@ -1,12 +1,13 @@
{
"culture": "zh-Hans",
"texts": {
"Messages:Group:1001": "管理员已开启全员禁言!",
"Messages:Group:1002": "管理员不允许匿名发言!",
"Messages:Group:1003": "管理员已禁止您发言!",
"Messages:User:1001": "用户不接收匿名发言!",
"Messages:User:1002": "用户已拒接所有消息!",
"Messages:User:1003": "用户拒绝您发送的消息!",
"Messages.Group:1001": "管理员已开启全员禁言!",
"Messages.Group:1002": "管理员不允许匿名发言!",
"Messages.Group:1003": "管理员已禁止您发言!",
"Messages.User:1001": "用户不接收匿名发言!",
"Messages.User:1002": "用户已拒接所有消息!",
"Messages.User:1003": "用户拒绝您发送的消息!",
"Messages.UserFriend:1001": "您已经添加对方为好友,不能重复添加!",
"WelcomeToApplicationNotification": "用户欢迎通知",
"NewTenantRegisterdNotification": "租户创建通知",
"WelcomeToApplicationFormUser": "用户:{0} 欢迎您的加入!"

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

@ -54,6 +54,17 @@ namespace LINGYUN.Abp.MessageService.Mapper
.ForMember(dto => dto.MessageType, map => map.MapFrom(src => src.Type))
.ForMember(dto => dto.IsAnonymous, map => map.Ignore())
.ForMember(dto => dto.GroupId, map => map.Ignore());
CreateMap<UserMessage, LastChatMessage>()
.ForMember(dto => dto.Content, map => map.MapFrom(src => src.Content))
.ForMember(dto => dto.ToUserId, map => map.MapFrom(src => src.ReceiveUserId))
.ForMember(dto => dto.MessageId, map => map.MapFrom(src => src.MessageId.ToString()))
.ForMember(dto => dto.FormUserId, map => map.MapFrom(src => src.CreatorId))
.ForMember(dto => dto.FormUserName, map => map.MapFrom(src => src.SendUserName))
.ForMember(dto => dto.SendTime, map => map.MapFrom(src => src.CreationTime))
.ForMember(dto => dto.MessageType, map => map.MapFrom(src => src.Type))
.ForMember(dto => dto.IsAnonymous, map => map.Ignore())
.ForMember(dto => dto.GroupId, map => map.Ignore());
}
}
}

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

@ -132,7 +132,8 @@ namespace LINGYUN.Abp.MessageService.Chat
CancellationToken cancellationToken = default)
{
return await DbContext.Set<UserMessage>()
.Where(x => x.ReceiveUserId.Equals(receiveUserId) && x.CreatorId.Equals(sendUserId))
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) ||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken));
@ -148,6 +149,46 @@ namespace LINGYUN.Abp.MessageService.Chat
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<LastChatMessage>> GetLastMessagesByOneFriendAsync(
Guid userId,
string sorting = nameof(LastChatMessage.SendTime),
bool reverse = true,
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
sorting ??= nameof(LastChatMessage.SendTime);
sorting = reverse ? sorting + " DESC" : sorting;
var groupMsgQuery = DbContext.Set<UserMessage>()
.Where(msg => msg.ReceiveUserId == userId || msg.CreatorId == userId)
.GroupBy(msg => msg.CreatorId)
.Select(msg => new
{
msg.Key,
MessageId = msg.Max(x => x.MessageId)
});
var userMessageQuery = from msg in DbContext.Set<UserMessage>()
join gMsg in groupMsgQuery
on msg.MessageId equals gMsg.MessageId
select new LastChatMessage
{
Content = msg.Content,
SendTime = msg.CreationTime,
FormUserId = msg.CreatorId.Value,
FormUserName = msg.SendUserName,
MessageId = msg.MessageId.ToString(),
MessageType = msg.Type,
TenantId = msg.TenantId,
ToUserId = msg.ReceiveUserId
};
return await userMessageQuery
.OrderBy(sorting)
.Take(maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<UserMessage>> GetUserMessagesAsync(
Guid sendUserId,
Guid receiveUserId,
@ -159,13 +200,14 @@ namespace LINGYUN.Abp.MessageService.Chat
int maxResultCount = 10,
CancellationToken cancellationToken = default)
{
sorting ??= nameof(UserMessage.MessageId);
sorting = reverse ? sorting + " desc" : sorting;
var userMessages = await DbContext.Set<UserMessage>()
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) |
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) ||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))
.OrderBy(sorting ?? nameof(GroupMessage.MessageId))
.OrderBy(sorting)
.PageBy(skipCount, maxResultCount)
.AsNoTracking()
.ToListAsync(GetCancellationToken(cancellationToken));
@ -181,7 +223,7 @@ namespace LINGYUN.Abp.MessageService.Chat
CancellationToken cancellationToken = default)
{
var userMessagesCount = await DbContext.Set<UserMessage>()
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) |
.Where(x => (x.CreatorId.Equals(sendUserId) && x.ReceiveUserId.Equals(receiveUserId)) ||
x.CreatorId.Equals(receiveUserId) && x.ReceiveUserId.Equals(sendUserId))
.WhereIf(type != null, x => x.Type.Equals(type))
.WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Content.Contains(filter) || x.SendUserName.Contains(filter))

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

@ -27,6 +27,41 @@ namespace LINGYUN.Abp.MessageService.Chat
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<UserFriend>> GetAllMembersAsync(
Guid userId,
string sorting = nameof(UserChatFriend.RemarkName),
bool reverse = false,
CancellationToken cancellationToken = default)
{
sorting = reverse ? sorting + " DESC" : sorting;
var userFriendQuery = from ucf in DbContext.Set<UserChatFriend>()
join ucc in DbContext.Set<UserChatCard>()
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 ?? ucc.NickName,
Sex = ucc.Sex,
Sign = ucc.Sign,
SpecialFocus = ucf.SpecialFocus,
TenantId = ucf.TenantId,
UserId = ucf.UserId,
UserName = ucc.UserName
};
return await userFriendQuery
.OrderBy(sorting ?? $"{nameof(UserChatFriend.RemarkName)} DESC")
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<UserFriend> GetMemberAsync(Guid userId, Guid friendId, CancellationToken cancellationToken = default)
{
var userFriendQuery = from ucf in DbContext.Set<UserChatFriend>()
@ -58,6 +93,7 @@ namespace LINGYUN.Abp.MessageService.Chat
public virtual async Task<List<UserFriend>> GetMembersAsync(Guid userId, string filter = "", string sorting = nameof(UserChatFriend.UserId), bool reverse = false, int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default)
{
sorting = reverse ? sorting + " desc" : sorting;
// 过滤用户资料
var userChatCardQuery = DbContext.Set<UserChatCard>()
.WhereIf(!filter.IsNullOrWhiteSpace(), ucc => ucc.UserName.Contains(filter) || ucc.NickName.Contains(filter));

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

@ -21,30 +21,37 @@ namespace LINGYUN.Abp.MessageService.Chat
[HttpPost]
[Route("groups/join")]
public virtual async Task ApplyJoinGroupAsync(UserJoinGroupDto userJoinGroup)
public virtual async Task ApplyJoinGroupAsync(UserJoinGroupDto input)
{
await _chatAppService.ApplyJoinGroupAsync(userJoinGroup);
await _chatAppService.ApplyJoinGroupAsync(input);
}
[HttpGet]
[Route("messages/group")]
public virtual async Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto groupMessageGetByPaged)
[Route("group/messages")]
public virtual async Task<PagedResultDto<ChatMessage>> GetGroupMessageAsync(GroupMessageGetByPagedDto input)
{
return await _chatAppService.GetGroupMessageAsync(groupMessageGetByPaged);
return await _chatAppService.GetGroupMessageAsync(input);
}
[HttpGet]
[Route("groups/users")]
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto groupUserGetByPaged)
public virtual async Task<PagedResultDto<GroupUserCard>> GetGroupUsersAsync(GroupUserGetByPagedDto input)
{
return await _chatAppService.GetGroupUsersAsync(groupUserGetByPaged);
return await _chatAppService.GetGroupUsersAsync(input);
}
[HttpGet]
[Route("messages/me")]
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto userMessageGetByPaged)
[Route("my-messages")]
public virtual async Task<PagedResultDto<ChatMessage>> GetMyChatMessageAsync(UserMessageGetByPagedDto input)
{
return await _chatAppService.GetMyChatMessageAsync(userMessageGetByPaged);
return await _chatAppService.GetMyChatMessageAsync(input);
}
[HttpGet]
[Route("my-last-messages")]
public virtual async Task<ListResultDto<LastChatMessage>> GetMyLastChatMessageAsync(GetUserLastMessageDto input)
{
return await _chatAppService.GetMyLastChatMessageAsync(input);
}
[HttpGet]
@ -56,23 +63,23 @@ namespace LINGYUN.Abp.MessageService.Chat
[HttpPost]
[Route("groups/users/accept")]
public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto groupAcceptUser)
public virtual async Task GroupAcceptUserAsync(GroupAcceptUserDto input)
{
await _chatAppService.GroupAcceptUserAsync(groupAcceptUser);
await _chatAppService.GroupAcceptUserAsync(input);
}
[HttpDelete]
[Route("groups/users/remove")]
public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto groupRemoveUser)
public virtual async Task GroupRemoveUserAsync(GroupRemoveUserDto input)
{
await _chatAppService.GroupRemoveUserAsync(groupRemoveUser);
await _chatAppService.GroupRemoveUserAsync(input);
}
[HttpGet]
[Route("messages/send")]
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage chatMessage)
[Route("send-message")]
public virtual async Task<ChatMessageSendResultDto> SendMessageAsync(ChatMessage input)
{
return await _chatAppService.SendMessageAsync(chatMessage);
return await _chatAppService.SendMessageAsync(input);
}
}
}

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

@ -31,16 +31,16 @@ namespace LINGYUN.Abp.MessageService.Chat
}
[HttpGet]
[Route("last-contacts")]
public virtual async Task<PagedResultDto<UserFriend>> GetLastContactFriendsAsync(PagedResultRequestDto input)
[Route("all")]
public virtual async Task<ListResultDto<UserFriend>> GetAllListAsync(GetMyFriendsDto input)
{
return await MyFriendAppService.GetLastContactFriendsAsync(input);
return await MyFriendAppService.GetAllListAsync(input);
}
[HttpGet]
public virtual async Task<PagedResultDto<UserFriend>> GetMyFriendsAsync(MyFriendGetByPagedDto input)
public virtual async Task<PagedResultDto<UserFriend>> GetListAsync(MyFriendGetByPagedDto input)
{
return await MyFriendAppService.GetMyFriendsAsync(input);
return await MyFriendAppService.GetListAsync(input);
}
}
}

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

Binary file not shown.

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

@ -1,9 +1,14 @@
import ApiService from './serviceBase'
import { PagedResultDto, PagedAndSortedResultRequestDto, PagedResultRequestDto } from './types'
import { PagedResultDto, PagedAndSortedResultRequestDto, ListResultDto } from './types'
const serviceUrl = process.env.VUE_APP_BASE_API
export default class ImApiService {
public static addFriend(payload: AddUserFriend) {
const _url = '/api/im/my-friends'
return ApiService.Post<void>(_url, payload, serviceUrl)
}
public static getMyFriends(payload: MyFriendGetByPaged) {
let _url = '/api/im/my-friends'
_url += '?filter=' + payload.filter
@ -14,8 +19,23 @@ export default class ImApiService {
return ApiService.Get<PagedResultDto<UserFriend>>(_url, serviceUrl)
}
public static getMyAllFriends(payload: MyFrientGetAll) {
let _url = '/api/im/my-friends/all'
_url += '?sorting=' + payload.sorting
_url += '&reverse=' + payload.reverse
return ApiService.Get<ListResultDto<UserFriend>>(_url, serviceUrl)
}
public static getMyLastMessages(payload: GetUserLastMessage) {
let _url = '/api/im/chat/my-last-messages'
_url += '?sorting=' + payload.sorting
_url += '&reverse=' + payload.reverse
_url += '&maxResultCount=' + payload.maxResultCount
return ApiService.Get<ListResultDto<ChatMessage>>(_url, serviceUrl)
}
public static getMyChatMessages(payload: UserMessageGetByPaged) {
let _url = '/api/im/chat/messages/me'
let _url = '/api/im/chat/my-messages'
_url += '?receiveUserId=' + payload.receiveUserId
_url += '&messageType=' + payload.messageType
_url += '&filter=' + payload.filter
@ -27,6 +47,19 @@ export default class ImApiService {
}
}
export class AddUserFriend {
friendId!: string
remarkName!: string
constructor(
friendId: string,
remarkName: string
) {
this.friendId = friendId
this.remarkName = remarkName
}
}
export enum Sex
{
Male,
@ -62,6 +95,17 @@ export class MyFriendGetByPaged extends PagedAndSortedResultRequestDto {
reverse = false
}
export class MyFrientGetAll {
sorting = 'UserName'
reverse = false
}
export class GetUserLastMessage {
sorting = 'SendTime'
reverse = false
maxResultCount = 10
}
export class UserMessageGetByPaged extends PagedAndSortedResultRequestDto {
filter = ''
messageType = MessageType.Text

16
vueJs/src/api/user-lookup.ts

@ -0,0 +1,16 @@
import ApiService from './serviceBase'
import { ListResultDto } from './types'
import { User } from './users'
const IdentityServiceUrl = process.env.VUE_APP_BASE_API
export default class UserLookupApiService {
public static searchUsers(filter = '', sorting = 'UserName', skipCount = 0, maxResultCount = 10) {
let _url = '/api/identity/users/lookup/search'
_url += '?filter=' + filter
_url += '&sorting=' + sorting
_url += '&skipCount=' + skipCount
_url += '&maxResultCount=' + maxResultCount
return ApiService.Get<ListResultDto<User>>(_url, IdentityServiceUrl)
}
}

182
vueJs/src/components/InstantMessage/components/AddFriend.vue

@ -0,0 +1,182 @@
<template>
<div
class="friend-search"
>
<el-card style="top: 10px; width: 100%; height: 100%;">
<div
slot="header"
class="clearfix"
>
<span>添加朋友</span>
</div>
<div>
<el-form class="fs-form">
<el-input
v-model="filterName"
placeholder="请输入内容"
class="fs-form-input"
>
<el-button
slot="append"
icon="el-icon-search"
@click="onSearchFriendClick"
/>
</el-input>
</el-form>
<el-divider />
<div
v-infinite-scroll="onSearchScrollChanged"
style="height: 400px;overflow-y: auto;"
>
<el-row
v-for="(users, index) in userList"
:key="index"
>
<el-col
v-for="user in users"
:key="user.id"
:span="8"
>
<el-card>
<el-row>
<el-col :span="12">
<el-avatar
:size="100"
shape="square"
src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"
/>
</el-col>
<el-col :span="12">
<div style="padding: 14px;">
<el-row>
<span>{{ user.userName | ellipsis(7) }}</span>
</el-row>
<el-row>
<span>{{ user.userName | ellipsis(7) }}</span>
</el-row>
<el-row>
<el-button
type="primary"
size="small"
@click="onAddFriendClick(user)"
>
添加好友
</el-button>
</el-row>
</div>
</el-col>
</el-row>
</el-card>
</el-col>
</el-row>
</div>
</div>
</el-card>
</div>
</template>
<script lang="ts">
import EventBusMiXin from '@/mixins/EventBusMiXin'
import Component, { mixins } from 'vue-class-component'
import { User } from '@/api/users'
import ImApiService, { AddUserFriend } from '@/api/instant-message'
import UserLookupApiService from '@/api/user-lookup'
import { abpPagerFormat } from '@/utils'
@Component({
name: 'AddFriend',
filters: {
ellipsis(value: string, limit: number) {
if (!value) return ''
if (value.length > limit) {
return value.slice(0, limit) + '...'
}
return value
}
}
})
export default class extends mixins(EventBusMiXin) {
private filterName = ''
private currentPage = 1
private maxRsultCount = 10
private isEnd = false
private searchUserList = new Array<User>()
get userList() {
let index = 0
const newArray = []
while (index < this.searchUserList.length) {
newArray.push(this.searchUserList.slice(index, index += 3))
}
return newArray
}
private onFormClosed() {
this.$emit('closed')
}
private onSearchFriendClick() {
this.isEnd = false
this.searchUserList.length = 0
this.currentPage = 1
this.handleSearchUsers()
}
private onSearchScrollChanged() {
if (!this.isEnd) {
this.currentPage += 1
this.handleSearchUsers()
}
}
private handleSearchUsers() {
UserLookupApiService
.searchUsers(
this.filterName, 'UserName',
abpPagerFormat(this.currentPage, this.maxRsultCount),
this.maxRsultCount
)
.then(res => {
if (res.items.length === 0) {
this.isEnd = true
}
if (this.currentPage === 1) {
this.searchUserList = res.items
} else {
this.searchUserList.push(...res.items)
}
this.$forceUpdate()
})
}
private onAddFriendClick(user: User) {
const addFriend = new AddUserFriend(user.id, user.userName)
ImApiService
.addFriend(addFriend)
.then(() => {
this.$message.success('已发送用户好友申请')
this.trigger('onUserFriendAdded', user)
})
}
}
</script>
<style lang="scss" scoped>
.friend-search {
position: absolute;
width: 100%;
height: 100%;
}
.fs-form {
width: 80%;
left: 18%;
}
.fs-form-input {
width: 80%;
left: 20%;
}
</style>

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

@ -1,48 +1,40 @@
<template>
<div class="imui-center">
<lemon-imui
v-show="showDialog"
ref="IMUI"
:user="currentUser"
@send="handleSendMessage"
@pull-messages="onPullMessages"
@change-menu="onChangeMenu"
@change-contact="onChangeContract"
@message-click="handleMessageClick"
@menu-avatar-click="handleMenuAvatarClick"
>
<template #cover>
<div class="cover">
<i class="lemon-icon-message" />
<p><b>Lemon</b> IMUI</p>
</div>
</template>
<template #contact-title="contact">
<span>{{ contact.displayName }}</span>
<small
class="more"
>&#8230;</small>
</template>
</lemon-imui>
<div id="InstantMessage">
<div class="imui-center">
<lemon-imui
v-show="showDialog"
ref="IMUI"
:user="currentUser"
@send="handleSendMessage"
@pull-messages="onPullMessages"
@change-menu="onChangeMenu"
@change-contact="onChangeContract"
@message-click="handleMessageClick"
@menu-avatar-click="handleMenuAvatarClick"
/>
</div>
</div>
</template>
<script lang="ts">
import EventBusMiXin from '@/mixins/EventBusMiXin'
import Component, { mixins } from 'vue-class-component'
import AddFriend from './components/AddFriend.vue'
import { abpPagerFormat } from '@/utils'
import { UserModule } from '@/store/modules/user'
import ImApiService, {
MyFriendGetByPaged,
MyFrientGetAll,
UserMessageGetByPaged,
GetUserLastMessage,
UserFriend,
ChatMessage
} from '@/api/instant-message'
import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr'
import { User } from '@/api/users'
class MyContract {
id = ''
@ -60,6 +52,7 @@ class ChatMenu {
name = ''
title = ''
unread = 0
click?: Function
render?: Function
renderContainer?: Function
isBottom = false
@ -106,19 +99,24 @@ class Message {
}
@Component({
name: 'InstantMessage'
name: 'InstantMessage',
components: {
AddFriend
}
})
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
private chatMenus = new Array<ChatMenu>()
private getMyFriendFilter = new MyFrientGetAll()
private getChatMessageFilter = new UserMessageGetByPaged()
private showAddFriendDialog = false
get currentUser() {
return {
id: UserModule.id,
@ -130,6 +128,7 @@ export default class InstantMessage extends mixins(EventBusMiXin) {
mounted() {
this.unSubscribeAll()
this.subscribe('onShowImDialog', this.onShowImDialog)
this.subscribe('onUserFriendAdded', this.onUserFriendAdded)
this.handleInitDefaultMenus()
this.handleStartConnection()
}
@ -141,12 +140,16 @@ export default class InstantMessage extends mixins(EventBusMiXin) {
private handleInitIMUI() {
const imui = this.$refs.IMUI as any
ImApiService
.getMyFriends(this.dataFilter)
.getMyAllFriends(this.getMyFriendFilter)
.then(res => {
this.myFriends = res.items
this.myFriendCount = res.totalCount
this.myFriendCount = res.items.length
this.handleInitContracts(imui)
})
.finally(() => {
imui.initMenus(this.chatMenus)
this.handleInitLastContractMessages(imui)
})
}
private handleInitContracts(imui: any) {
@ -157,19 +160,52 @@ export default class InstantMessage extends mixins(EventBusMiXin) {
myContract.id = friend.friendId
myContract.displayName = friend.remarkName ?? friend.userName
myContract.unread = 0
myContract.lastSendTime = new Date().getTime()
myContract.lastContent = '1524545'
myContract.type = 'many'
myContracts.push(myContract)
})
imui.initContacts(myContracts)
imui.initMenus(this.chatMenus)
}
private handleInitLastContractMessages(imui: any) {
const filter = new GetUserLastMessage()
ImApiService
.getMyLastMessages(filter)
.then(res => {
res.items
.sort((now, next) => { // ,,,
return next.sendTime < now.sendTime ? 1 : -1
})
.forEach(msg => {
const imuiMsg = new Message()
imuiMsg.fromChatMessage(msg)
let contractId = msg.formUserId
if (msg.formUserId === this.currentUser.id) {
contractId = msg.toUserId
}
imui.updateContact(contractId, {
lastSendTime: imuiMsg.sendTime,
lastContent: imui.lastContentRender(imuiMsg)
})
})
})
}
private handleInitDefaultMenus() {
const lastMsgMenu = new ChatMenu('lastMessages', '历史消息')
const contractsMenu = new ChatMenu('contacts', '联系人')
this.chatMenus.push(lastMsgMenu, contractsMenu)
const addFriendMenu = new ChatMenu('addFriends', '添加朋友')
addFriendMenu.isBottom = true
addFriendMenu.render = () => {
return this.$createElement('i', { class: 'lemon-icon-attah' })
}
addFriendMenu.renderContainer = () => {
return this.$createElement(AddFriend, {
on: {
onUserFriendAdded: this.onUserFriendAdded
}
})
}
this.chatMenus.push(lastMsgMenu, contractsMenu, addFriendMenu)
}
private handleStartConnection() {
@ -253,7 +289,7 @@ export default class InstantMessage extends mixins(EventBusMiXin) {
const message = new Message()
message.fromChatMessage(chatMessage)
const imui = this.$refs.IMUI as any
imui.appendMessage(message)
imui.appendMessage(message, chatMessage.formUserId)
const currentContact = imui.currentContact
if (currentContact && currentContact.id === chatMessage.formUserId) {
currentContact.lastContent = chatMessage.content
@ -297,6 +333,18 @@ export default class InstantMessage extends mixins(EventBusMiXin) {
})
imui.closeDrawer()
}
private onUserFriendAdded(user: User) {
if (UserModule.id && UserModule.userName) {
const chatMessage = new ChatMessage()
chatMessage.formUserId = UserModule.id
chatMessage.formUserName = UserModule.userName
chatMessage.toUserId = user.id
chatMessage.content = '我已经添加你为好友,让我们一起聊天吧!'
console.log(chatMessage)
this.connection.invoke('SendMessage', chatMessage)
}
}
}
</script>

2
vueJs/src/mixins/EventBusMiXin.ts

@ -61,6 +61,6 @@ export default class EventBusMiXin extends Vue {
* @param args
*/
protected trigger(name: string, ...args: any[]) {
this.$events.emit(name, args)
this.$events.emit(name, ...args)
}
}

Loading…
Cancel
Save