OftenContactService.Get.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.Entity;
  7. using GxPress.Request.App.OftenContact;
  8. using GxPress.Request.GroupChatUser;
  9. using GxPress.Result.App.OftenContact;
  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="individualGroupId"></param>
  58. /// <returns></returns>
  59. public async Task<IEnumerable<OftenContactInfo>> GetOftenContactsAll(OftenContactSearchRequest request)
  60. {
  61. //获取文件夹数据
  62. var result = new List<OftenContactInfo>();
  63. var data = await _repository.GetContactInfoAllAsync(request);
  64. foreach (var oftenContact in data)
  65. {
  66. if (oftenContact.ChatType == 1)
  67. {
  68. var user = await _userRepository.GetAsync(int.Parse(oftenContact.ContactUserId));
  69. if (user == null)
  70. continue;
  71. oftenContact.Name = user.Name;
  72. oftenContact.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  73. oftenContact.ImId = user.ImId;
  74. oftenContact.ToUserId = user.Id;
  75. }
  76. if (oftenContact.ChatType == 2)
  77. {
  78. var groupChat = await _groupChatRepository.GetAsync(Q.Where(nameof(Entity.GroupChat.GroupChatImId),
  79. oftenContact.ContactUserId));
  80. if (groupChat == null)
  81. continue;
  82. oftenContact.Name = groupChat.Name;
  83. oftenContact.AvatarUrl = StringUtils.AddDomainMin(groupChat.AvatarUrl);
  84. oftenContact.ImId = groupChat.GroupChatImId;
  85. var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest();
  86. groupChatUserIsDisturbRequest.GroupChatId = groupChat.Id;
  87. groupChatUserIsDisturbRequest.UserId = oftenContact.UserId;
  88. oftenContact.IsDisturb = await groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest);
  89. }
  90. }
  91. result = data.ToList();
  92. return result;
  93. }
  94. }
  95. }