using System.Linq; using System.Threading.Tasks; using GxPress.Auth; using GxPress.Common.Exceptions; using GxPress.Common.Tools; using GxPress.Repository.Interface; using GxPress.Request.GroupChatUser; using GxPress.Result.GroupChatUser; using GxPress.Service.Interface; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace GxPress.Api.AppControllers { /// /// 群聊组员 /// [Route("api/app/group-chat-user")] [ApiController] [Authorize] public class GroupChatUserController : ControllerBase { private readonly IGroupChatUserRepository _groupChatUserRepository; private readonly IGroupChatUserService _groupChatUserService; private readonly IGroupChatRepository _groupChatRepository; private readonly IOftenContactRepository _oftenContactRepository; private readonly ILoginContext _loginContext; public GroupChatUserController(IGroupChatUserRepository groupChatUserRepository, IGroupChatUserService groupChatUserService, IGroupChatRepository groupChatRepository, ILoginContext loginContext, IOftenContactRepository oftenContactRepository) { _groupChatUserRepository = groupChatUserRepository; _groupChatUserService = groupChatUserService; _groupChatRepository = groupChatRepository; _loginContext = loginContext; _oftenContactRepository = oftenContactRepository; } /// /// 添加 /// /// /// [HttpPost("add")] public async Task Insert(GroupChatUserInRequest request) { return await _groupChatUserRepository.InsertAsync(request); } /// /// 修改 /// /// /// [HttpPost("update")] public async Task Update(GroupChatUserUpRequest request) { return await _groupChatUserRepository.UpdateAsync(request); } /// /// 根据群ID查询群 /// /// /// [HttpPost("group-chat-user-search")] public async Task GetGroupChatUserByGroupChatId( GroupChatUserSearchRequest request) { var userId = _loginContext.AccountId; var groupChat = await _groupChatRepository.GetGroupChatByImIdAsync(request.GroupChatImId); if (groupChat == null) throw new BusinessException("群不存在!"); var result = new GroupChatUserByGroupChatIdResultList { GroupChat = groupChat, Item = await _groupChatUserRepository.GetGroupChatUserByGroupChatIdAsync(request) }; //判断是否是管理员 result.GroupChat.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId; //result.GroupChat.AvatarUrl = StringUtils.AddDomainMin(result.GroupChat.AvatarUrl); //result.GroupChat.QRCoder = StringUtils.AddDomain(result.GroupChat.QRCoder); result.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId; result.IsUser = result.Item.Any(n => n.UserId == userId); result.IsTop = await _oftenContactRepository.GetIsTopAsync(userId, groupChat.GroupChatImId); var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest { UserId = userId, GroupChatId = groupChat.Id }; result.IsDisturb = await _groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest); return result; } /// /// 根据群GUID查询群 /// /// /// [HttpGet("{guid}")] public async Task GetGroupChatUserByGroupChatGuid(string guid) { var userId = _loginContext.AccountId; var groupChatUserSearchRequest = new GroupChatUserSearchRequest(); var groupChat = await _groupChatRepository.GetGroupChatByGuidAsync(guid); if (groupChat == null) throw new BusinessException("群不存在!"); groupChatUserSearchRequest.GroupChatImId = groupChat.GroupChatImId; var result = new GroupChatUserByGroupChatIdResultList { GroupChat = groupChat, Item = await _groupChatUserRepository.GetGroupChatUserByGroupChatIdAsync(groupChatUserSearchRequest) }; //判断是否是管理员 result.GroupChat.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId; result.GroupChat.AvatarUrl = StringUtils.AddDomainMin(result.GroupChat.AvatarUrl); result.GroupChat.QRCoder = StringUtils.AddDomain(result.GroupChat.QRCoder); result.IsAdmin = result.GroupChat.UserId == _loginContext.AccountId; result.IsUser = result.Item.Any(n => n.UserId == userId); result.IsTop = await _oftenContactRepository.GetIsTopAsync(userId, groupChat.GroupChatImId); var groupChatUserIsDisturbRequest = new GroupChatUserIsDisturbRequest { UserId = userId, GroupChatId = groupChat.Id }; result.IsDisturb = await _groupChatUserRepository.IsDisturbAsync(groupChatUserIsDisturbRequest); return result; } /// /// 是否免打扰 /// /// /// [HttpPost("up-is-disturb")] public async Task UpIsDisturb(GroupChatUserIsDisturbRequest request) { request.UserId = _loginContext.AccountId; return await _groupChatUserRepository.UpIsDisturbAsync(request); } /// /// 是否置顶 /// /// /// [HttpPost("up-is-top")] public async Task UpIsTop(GroupChatUserIsTopRequest request) { request.UserId = _loginContext.AccountId; return await _groupChatUserRepository.UpIsTopAsync(request); } } }