OftenContactService.Get.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 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. }
  57. result = data.ToList();
  58. return result;
  59. }
  60. /// <summary>
  61. /// 获取聊天界面和验证最新时间
  62. /// </summary>
  63. /// <param name="request"></param>
  64. /// <returns></returns>
  65. public async Task<OftenContactInfoGenericResult> GetOftenContactInfoGenericResult(OftenContactSearchRequest request)
  66. {
  67. var result = new OftenContactInfoGenericResult();
  68. result.OftenContactInfos = await GetOftenContacts(request);
  69. result.ConfirmationDate = await adminVerifyRepository.GetConfirmationDate(request.UserId);
  70. return result;
  71. }
  72. /// <summary>
  73. /// 获取用户
  74. /// </summary>
  75. /// <param name="individualGroupId"></param>
  76. /// <returns></returns>
  77. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAll(OftenContactSearchRequest request)
  78. {
  79. //获取文件夹数据
  80. var result = new List<OftenContactInfo>();
  81. var data = await _repository.GetContactInfoAllAsync(request);
  82. foreach (var oftenContact in data)
  83. {
  84. if (oftenContact.ChatType == 1)
  85. {
  86. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  87. if (user == null)
  88. continue;
  89. oftenContact.Name = user.Name;
  90. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  91. oftenContact.ImId = user.ImId;
  92. oftenContact.ToUserId = user.Id;
  93. }
  94. if (oftenContact.ChatType == 2)
  95. {
  96. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  97. oftenContact.ContactUserId));
  98. if (groupChat == null)
  99. continue;
  100. oftenContact.Name = groupChat.Name;
  101. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  102. oftenContact.ImId = groupChat.GroupChatImId;
  103. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  104. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  105. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  106. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  107. }
  108. }
  109. result = data.ToList();
  110. return result;
  111. }
  112. }
  113. }