using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.App.IM;
using GxPress.Request.GroupChat;
using GxPress.Result.App.GroupChat;
using GxPress.Service.Interface;
using GxPress.Service.Interface.AdminVerify;
using GxPress.Service.Interface.IM;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace GxPress.Api.AppControllers
{
///
/// 群
///
[Route("api/app/group-chat")]
[ApiController]
[Authorize]
public class GroupChatController : ControllerBase
{
private readonly IGroupChatRepository _groupChatRepository;
private readonly IGroupChatUserRepository _groupChatUserRepository;
private readonly IIMService _imService;
private readonly ILoginContext _loginContext;
private readonly IAdminVerifyService _adminVerifyService;
private readonly IGroupChatUserService _groupChatUserService;
public GroupChatController(IGroupChatRepository groupChatRepository, ILoginContext loginContext,
IIMService imService, IAdminVerifyService adminVerifyService,
IGroupChatUserRepository groupChatUserRepository, IGroupChatUserService groupChatUserService)
{
_groupChatRepository = groupChatRepository;
_imService = imService;
_loginContext = loginContext;
_adminVerifyService = adminVerifyService;
_groupChatUserRepository = groupChatUserRepository;
_groupChatUserService = groupChatUserService;
}
/////
///// 添加
/////
/////
/////
//[HttpPost("add")]
//public async Task Insert(GroupChatInRequest request)
//{
// request.UserId = _loginContext.AccountId;
// return await _groupChatRepository.InsertAsync(request);
//}
///
/// 修改
///
///
///
[HttpPost("update")]
public async Task Update(GroupChatUpRequest request)
{
return await _groupChatRepository.UpdateAsync(request);
}
///
/// 群组解散群
///
///
///
[HttpDelete("{groupChatImId}")]
public async Task DeleteGroupChat(string groupChatImId)
{
return await _imService.DeleteGroupChatAsync(groupChatImId, _loginContext.AccountId);
}
///
/// 根据UserId查询群
///
///
[HttpPost("group-chat-search")]
public async Task> GetGroupChatByUserId()
{
var request = new GroupChatSearchRequest { UserId = _loginContext.AccountId };
return await _groupChatRepository.GetGroupChatByUserIdAsync(request);
}
///
/// 是否管理员同意
///
///
///
[HttpPost("up-is-admin")]
public async Task UpIsAdmin(GroupChatUpIsAdminRequest request)
{
return await _groupChatRepository.UpIsAdminAsync(request);
}
///
/// 创建群
///
///
///
[HttpPost("add")]
public async Task CreateGroupChat(GroupChatInRequest request)
{
request.UserId = _loginContext.AccountId;
//添加群成员
var insertGroupChatUsersRequest = new InsertGroupChatUsersRequest();
insertGroupChatUsersRequest.UserId = request.UserId;
insertGroupChatUsersRequest.UserIds = request.UserIds;
insertGroupChatUsersRequest.SourceType = 2;
//创建群
var result = await _imService.CreateGroupChatAsync(request);
if (result.Success)
{
insertGroupChatUsersRequest.GroupChatImId = result.GroupChatImId;
insertGroupChatUsersRequest.IsFound = true;
await _groupChatUserService.InsertAsync(insertGroupChatUsersRequest);
//获取群信息
return await _groupChatRepository.GetGroupChatInfoByImIdAsync(result.GroupChatImId);
}
return new GroupChatInfoResult();
}
///
/// 添加群用户
///
///
///
[HttpPost("add-users")]
public async Task InsertGroupChatUsers(InsertGroupChatUsersRequest request)
{
request.UserId = _loginContext.AccountId;
return await _groupChatUserService.InsertAsync(request);
}
///
/// 群删除成员
///
///
///
[HttpPost("remove-users")]
public async Task RemoveGroupChatUsers(InsertGroupChatUsersRequest request)
{
request.UserId = _loginContext.AccountId;
return await _imService.RemoveGroupChatUsersAsync(request);
}
///
/// 禁言
///
///
///
[HttpPost("in-mute")]
public async Task InMute(SetGroupChatMuteRequest request)
{
return await _imService.InMute(request.GroupChatImId);
}
///
/// 解除禁言
///
///
///
[HttpPost("remove-mute")]
public async Task RemoveMute(SetGroupChatMuteRequest request)
{
return await _imService.RemoveMute(request.GroupChatImId);
}
///
/// 根据groupChatGuid获取群信息
///
///
///
[HttpPost("guid")]
public async Task GetGroupChatByGuid(GroupChatByGuidRequest request)
{
return await _groupChatRepository.GetGroupChatByGuidAsync(request.GroupChatGuid);
}
///
/// set群是否开启
///
///
///
[HttpPut("{groupChatImId}")]
public async Task SetIsOpenQrCoder(string groupChatImId)
{
return await _groupChatRepository.SetIsOpenQrCoderAsync(groupChatImId, _loginContext.AccountId);
}
}
}