GroupChatController.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Auth;
  4. using GxPress.Entity;
  5. using GxPress.Repository.Interface;
  6. using GxPress.Request.App.IM;
  7. using GxPress.Request.GroupChat;
  8. using GxPress.Result.App.GroupChat;
  9. using GxPress.Service.Interface;
  10. using GxPress.Service.Interface.AdminVerify;
  11. using GxPress.Service.Interface.IM;
  12. using Microsoft.AspNetCore.Authorization;
  13. using Microsoft.AspNetCore.Mvc;
  14. namespace GxPress.Api.AppControllers
  15. {
  16. /// <summary>
  17. /// 群
  18. /// </summary>
  19. [Route("api/app/group-chat")]
  20. [ApiController]
  21. [Authorize]
  22. public class GroupChatController : ControllerBase
  23. {
  24. private readonly IGroupChatRepository _groupChatRepository;
  25. private readonly IGroupChatUserRepository _groupChatUserRepository;
  26. private readonly IIMService _imService;
  27. private readonly ILoginContext _loginContext;
  28. private readonly IAdminVerifyService _adminVerifyService;
  29. private readonly IGroupChatUserService _groupChatUserService;
  30. public GroupChatController(IGroupChatRepository groupChatRepository, ILoginContext loginContext,
  31. IIMService imService, IAdminVerifyService adminVerifyService,
  32. IGroupChatUserRepository groupChatUserRepository, IGroupChatUserService groupChatUserService)
  33. {
  34. _groupChatRepository = groupChatRepository;
  35. _imService = imService;
  36. _loginContext = loginContext;
  37. _adminVerifyService = adminVerifyService;
  38. _groupChatUserRepository = groupChatUserRepository;
  39. _groupChatUserService = groupChatUserService;
  40. }
  41. ///// <summary>
  42. ///// 添加
  43. ///// </summary>
  44. ///// <param name="request"></param>
  45. ///// <returns></returns>
  46. //[HttpPost("add")]
  47. //public async Task<bool> Insert(GroupChatInRequest request)
  48. //{
  49. // request.UserId = _loginContext.AccountId;
  50. // return await _groupChatRepository.InsertAsync(request);
  51. //}
  52. /// <summary>
  53. /// 修改
  54. /// </summary>
  55. /// <param name="request"></param>
  56. /// <returns></returns>
  57. [HttpPost("update")]
  58. public async Task<bool> Update(GroupChatUpRequest request)
  59. {
  60. return await _groupChatRepository.UpdateAsync(request);
  61. }
  62. /// <summary>
  63. /// 群组解散群
  64. /// </summary>
  65. /// <param name="groupChatImId"></param>
  66. /// <returns></returns>
  67. [HttpDelete("{groupChatImId}")]
  68. public async Task<bool> DeleteGroupChat(string groupChatImId)
  69. {
  70. return await _imService.DeleteGroupChatAsync(groupChatImId, _loginContext.AccountId);
  71. }
  72. /// <summary>
  73. /// 根据UserId查询群
  74. /// </summary>
  75. /// <returns></returns>
  76. [HttpPost("group-chat-search")]
  77. public async Task<IEnumerable<GroupChat>> GetGroupChatByUserId()
  78. {
  79. var request = new GroupChatSearchRequest { UserId = _loginContext.AccountId };
  80. return await _groupChatRepository.GetGroupChatByUserIdAsync(request);
  81. }
  82. /// <summary>
  83. /// 是否管理员同意
  84. /// </summary>
  85. /// <param name="request"></param>
  86. /// <returns></returns>
  87. [HttpPost("up-is-admin")]
  88. public async Task<bool> UpIsAdmin(GroupChatUpIsAdminRequest request)
  89. {
  90. return await _groupChatRepository.UpIsAdminAsync(request);
  91. }
  92. /// <summary>
  93. /// 是否添加到通讯录
  94. /// </summary>
  95. /// <param name="groupChatId"></param>
  96. /// <returns></returns>
  97. [HttpPut("contacts/{groupChatId}")]
  98. public async Task<bool> UpdateContactsAsync(int groupChatId)
  99. {
  100. return await _groupChatRepository.UpdateContactsAsync(groupChatId, _loginContext.AccountId);
  101. }
  102. /// <summary>
  103. /// 创建群
  104. /// </summary>
  105. /// <param name="request"></param>
  106. /// <returns></returns>
  107. [HttpPost("add")]
  108. public async Task<GroupChatInfoResult> CreateGroupChat(GroupChatInRequest request)
  109. {
  110. request.UserId = _loginContext.AccountId;
  111. //添加群成员
  112. var insertGroupChatUsersRequest = new InsertGroupChatUsersRequest();
  113. insertGroupChatUsersRequest.UserId = request.UserId;
  114. insertGroupChatUsersRequest.UserIds = request.UserIds;
  115. insertGroupChatUsersRequest.SourceType = 2;
  116. //创建群
  117. var result = await _imService.CreateGroupChatAsync(request);
  118. if (result.Success)
  119. {
  120. insertGroupChatUsersRequest.GroupChatImId = result.GroupChatImId;
  121. insertGroupChatUsersRequest.IsFound = true;
  122. await _groupChatUserService.InsertAsync(insertGroupChatUsersRequest);
  123. //获取群信息
  124. return await _groupChatRepository.GetGroupChatInfoByImIdAsync(result.GroupChatImId);
  125. }
  126. return new GroupChatInfoResult();
  127. }
  128. /// <summary>
  129. /// 添加群用户
  130. /// </summary>
  131. /// <param name="request"></param>
  132. /// <returns></returns>
  133. [HttpPost("add-users")]
  134. public async Task<bool> InsertGroupChatUsers(InsertGroupChatUsersRequest request)
  135. {
  136. request.UserId = _loginContext.AccountId;
  137. return await _groupChatUserService.InsertAsync(request);
  138. }
  139. /// <summary>
  140. /// 群删除成员
  141. /// </summary>
  142. /// <param name="request"></param>
  143. /// <returns></returns>
  144. [HttpPost("remove-users")]
  145. public async Task<bool> RemoveGroupChatUsers(InsertGroupChatUsersRequest request)
  146. {
  147. request.UserId = _loginContext.AccountId;
  148. return await _imService.RemoveGroupChatUsersAsync(request);
  149. }
  150. /// <summary>
  151. /// 禁言
  152. /// </summary>
  153. /// <param name="request"></param>
  154. /// <returns></returns>
  155. [HttpPost("in-mute")]
  156. public async Task<bool> InMute(SetGroupChatMuteRequest request)
  157. {
  158. return await _imService.InMute(request.GroupChatImId);
  159. }
  160. /// <summary>
  161. /// 解除禁言
  162. /// </summary>
  163. /// <param name="request"></param>
  164. /// <returns></returns>
  165. [HttpPost("remove-mute")]
  166. public async Task<bool> RemoveMute(SetGroupChatMuteRequest request)
  167. {
  168. return await _imService.RemoveMute(request.GroupChatImId);
  169. }
  170. /// <summary>
  171. /// 根据groupChatGuid获取群信息
  172. /// </summary>
  173. /// <param name="request"></param>
  174. /// <returns></returns>
  175. [HttpPost("guid")]
  176. public async Task<GroupChatInfoResult> GetGroupChatByGuid(GroupChatByGuidRequest request)
  177. {
  178. return await _groupChatRepository.GetGroupChatByGuidAsync(request.GroupChatGuid);
  179. }
  180. /// <summary>
  181. /// set群是否开启
  182. /// </summary>
  183. /// <param name="groupChatImId"></param>
  184. /// <returns></returns>
  185. [HttpPut("{groupChatImId}")]
  186. public async Task<bool> SetIsOpenQrCoder(string groupChatImId)
  187. {
  188. return await _groupChatRepository.SetIsOpenQrCoderAsync(groupChatImId, _loginContext.AccountId);
  189. }
  190. /// <summary>
  191. /// 获取用户加入的群
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpGet("list")]
  195. public async Task<IEnumerable<GroupChatInfoResult>> GetGroupChatsAsync()
  196. {
  197. return await _groupChatRepository.GetGroupChatsAsync(_loginContext.AccountId);
  198. }
  199. }
  200. }