OftenContactService.Get.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.Request.App.OftenContact;
  7. using GxPress.Request.GroupChatUser;
  8. using GxPress.Result.App.OftenContact;
  9. using System;
  10. namespace GxPress.Service.Implement.OftenContact
  11. {
  12. public partial class OftenContactService
  13. {
  14. /// <summary>
  15. /// 获取用户
  16. /// </summary>
  17. /// <param name="individualGroupId"></param>
  18. /// <returns></returns>
  19. public async Task<IEnumerable<OftenContactInfo>> GetOftenContacts(OftenContactSearchRequest request)
  20. {
  21. //获取文件夹数据
  22. var result = new List<OftenContactInfo>();
  23. var data = await _repository.GetContactInfosAsync(request);
  24. foreach (var oftenContact in data)
  25. {
  26. if (oftenContact.ChatType == 1)
  27. {
  28. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  29. if (user == null)
  30. continue;
  31. oftenContact.Name = user.Name;
  32. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  33. oftenContact.ImId = user.ImId;
  34. oftenContact.ToUserId = user.Id;
  35. }
  36. if (oftenContact.ChatType == 2)
  37. {
  38. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  39. oftenContact.ContactUserId));
  40. if (groupChat == null)
  41. continue;
  42. oftenContact.Name = groupChat.Name;
  43. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  44. oftenContact.ImId = groupChat.GroupChatImId;
  45. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  46. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  47. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  48. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  49. }
  50. }
  51. result = data.ToList();
  52. return result;
  53. }
  54. /// <summary>
  55. /// 获取聊天界面和验证最新时间
  56. /// </summary>
  57. /// <param name="request"></param>
  58. /// <returns></returns>
  59. public async Task<OftenContactInfoGenericResult> GetOftenContactInfoGenericResult(OftenContactSearchRequest request)
  60. {
  61. var result = new OftenContactInfoGenericResult();
  62. result.OftenContactInfos = await GetOftenContacts(request);
  63. result.ConfirmationDate = await adminVerifyRepository.GetConfirmationDate(request.UserId);
  64. return result;
  65. }
  66. /// <summary>
  67. /// 获取用户
  68. /// </summary>
  69. /// <param name="individualGroupId"></param>
  70. /// <returns></returns>
  71. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAll(OftenContactSearchRequest request)
  72. {
  73. //获取文件夹数据
  74. var result = new List<OftenContactInfo>();
  75. var data = await _repository.GetContactInfoAllAsync(request);
  76. foreach (var oftenContact in data)
  77. {
  78. if (oftenContact.ChatType == 1)
  79. {
  80. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  81. if (user == null)
  82. continue;
  83. oftenContact.Name = user.Name;
  84. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  85. oftenContact.ImId = user.ImId;
  86. oftenContact.ToUserId = user.Id;
  87. }
  88. if (oftenContact.ChatType == 2)
  89. {
  90. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  91. oftenContact.ContactUserId));
  92. if (groupChat == null)
  93. continue;
  94. oftenContact.Name = groupChat.Name;
  95. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  96. oftenContact.ImId = groupChat.GroupChatImId;
  97. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  98. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  99. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  100. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  101. }
  102. }
  103. result = data.ToList();
  104. return result;
  105. }
  106. }
  107. }