OftenContactService.Get.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if (!string.IsNullOrEmpty(result.ConfirmationDate))
  65. result.ConfirmationDate = Convert.ToDateTime(result.ConfirmationDate).ToString("yyyy-MM-dd hh:mm:ss");
  66. return result;
  67. }
  68. /// <summary>
  69. /// 获取用户
  70. /// </summary>
  71. /// <param name="individualGroupId"></param>
  72. /// <returns></returns>
  73. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAll(OftenContactSearchRequest request)
  74. {
  75. //获取文件夹数据
  76. var result = new List<OftenContactInfo>();
  77. var data = await _repository.GetContactInfoAllAsync(request);
  78. foreach (var oftenContact in data)
  79. {
  80. if (oftenContact.ChatType == 1)
  81. {
  82. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  83. if (user == null)
  84. continue;
  85. oftenContact.Name = user.Name;
  86. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  87. oftenContact.ImId = user.ImId;
  88. oftenContact.ToUserId = user.Id;
  89. }
  90. if (oftenContact.ChatType == 2)
  91. {
  92. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  93. oftenContact.ContactUserId));
  94. if (groupChat == null)
  95. continue;
  96. oftenContact.Name = groupChat.Name;
  97. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  98. oftenContact.ImId = groupChat.GroupChatImId;
  99. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  100. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  101. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  102. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  103. }
  104. }
  105. result = data.ToList();
  106. return result;
  107. }
  108. }
  109. }