OftenContactService.Get.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. for (int i = 0; i < data.Count; i++)
  25. {
  26. if (data[i].ChatType == 1)
  27. {
  28. var user = await _userRepository.GetAsync(int.Parse(data[i].ContactUserId));
  29. if (user == null)
  30. {
  31. data.Remove(data[i]);
  32. continue;
  33. }
  34. data[i].Name = user.Name;
  35. data[i].AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  36. data[i].ImId = user.ImId;
  37. data[i].ToUserId = user.Id;
  38. }
  39. else if (data[i].ChatType == 2)
  40. {
  41. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  42. data[i].ContactUserId));
  43. if (groupChat == null)
  44. {
  45. data.Remove(data[i]);
  46. continue;
  47. }
  48. data[i].Name = groupChat.Name;
  49. data[i].AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  50. data[i].ImId = groupChat.GroupChatImId;
  51. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  52. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  53. groupChatUserIsDisturbRequest.UserId = data[i].UserId;
  54. data[i].IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  55. }
  56. else
  57. data.Remove(data[i]);
  58. }
  59. result = data.ToList();
  60. return result;
  61. }
  62. /// <summary>
  63. /// 获取聊天界面和验证最新时间
  64. /// </summary>
  65. /// <param name="request"></param>
  66. /// <returns></returns>
  67. public async Task<OftenContactInfoGenericResult> GetOftenContactInfoGenericResult(OftenContactSearchRequest request)
  68. {
  69. var result = new OftenContactInfoGenericResult();
  70. result.OftenContactInfos = await GetOftenContacts(request);
  71. result.ConfirmationDate = await adminVerifyRepository.GetConfirmationDate(request.UserId);
  72. return result;
  73. }
  74. /// <summary>
  75. /// 获取用户
  76. /// </summary>
  77. /// <param name="individualGroupId"></param>
  78. /// <returns></returns>
  79. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAll(OftenContactSearchRequest request)
  80. {
  81. //获取文件夹数据
  82. var result = new List<OftenContactInfo>();
  83. var data = await _repository.GetContactInfoAllAsync(request);
  84. foreach (var oftenContact in data)
  85. {
  86. if (oftenContact.ChatType == 1)
  87. {
  88. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  89. if (user == null)
  90. continue;
  91. oftenContact.Name = user.Name;
  92. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  93. oftenContact.ImId = user.ImId;
  94. oftenContact.ToUserId = user.Id;
  95. }
  96. if (oftenContact.ChatType == 2)
  97. {
  98. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  99. oftenContact.ContactUserId));
  100. if (groupChat == null)
  101. continue;
  102. oftenContact.Name = groupChat.Name;
  103. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  104. oftenContact.ImId = groupChat.GroupChatImId;
  105. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  106. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  107. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  108. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  109. }
  110. }
  111. result = data.ToList();
  112. return result;
  113. }
  114. }
  115. }