2021-06-28 15:27:35 +08:00
|
|
|
package group
|
|
|
|
|
|
|
|
|
|
import (
|
2021-12-26 18:47:11 +08:00
|
|
|
api "Open_IM/pkg/base_info"
|
2021-10-11 22:12:01 +08:00
|
|
|
"Open_IM/pkg/common/config"
|
|
|
|
|
"Open_IM/pkg/common/log"
|
2021-12-23 17:22:49 +08:00
|
|
|
"Open_IM/pkg/common/token_verify"
|
2021-10-11 22:12:01 +08:00
|
|
|
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
2021-12-26 18:47:11 +08:00
|
|
|
rpc "Open_IM/pkg/proto/group"
|
2021-12-29 21:50:11 +08:00
|
|
|
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
2021-12-26 18:47:11 +08:00
|
|
|
"Open_IM/pkg/utils"
|
2021-06-28 15:27:35 +08:00
|
|
|
"context"
|
2021-12-30 20:51:33 +08:00
|
|
|
|
2021-06-28 15:27:35 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2021-12-30 20:51:33 +08:00
|
|
|
|
2021-06-28 15:27:35 +08:00
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
2021-12-30 20:51:33 +08:00
|
|
|
|
|
|
|
|
jsonData "Open_IM/internal/utils"
|
2021-06-28 15:27:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func KickGroupMember(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.KickGroupMemberReq{}
|
2021-06-28 15:27:35 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.KickGroupMemberReq{}
|
2021-12-30 14:03:55 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "KickGroupMember args ", req.String())
|
|
|
|
|
|
2021-12-23 17:22:49 +08:00
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
2021-12-26 18:47:11 +08:00
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-06-28 15:27:35 +08:00
|
|
|
RpcResp, err := client.KickGroupMember(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-30 14:03:55 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
var memberListResp api.KickGroupMemberResp
|
|
|
|
|
memberListResp.ErrMsg = RpcResp.ErrMsg
|
|
|
|
|
memberListResp.ErrCode = RpcResp.ErrCode
|
|
|
|
|
for _, v := range RpcResp.Id2ResultList {
|
2021-12-30 14:03:55 +08:00
|
|
|
memberListResp.UserIDResultList = append(memberListResp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-30 14:03:55 +08:00
|
|
|
if len(memberListResp.UserIDResultList) == 0 {
|
|
|
|
|
memberListResp.UserIDResultList = []*api.UserIDResult{}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "KickGroupMember api return ", memberListResp)
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusOK, memberListResp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetGroupMembersInfo(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetGroupMembersInfoReq{}
|
2021-06-28 15:27:35 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetGroupMembersInfoReq{}
|
|
|
|
|
utils.CopyStructFields(req, params)
|
|
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
2021-12-27 18:22:32 +08:00
|
|
|
//c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
api.SetErrCodeMsg(c, http.StatusInternalServerError)
|
2021-12-26 18:47:11 +08:00
|
|
|
return
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-06-28 15:27:35 +08:00
|
|
|
|
|
|
|
|
RpcResp, err := client.GetGroupMembersInfo(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 09:04:04 +08:00
|
|
|
memberListResp := api.GetGroupMembersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
|
|
|
|
memberListResp.Data = jsonData.JsonDataList(RpcResp.MemberList)
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupMembersInfo api return ", memberListResp)
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusOK, memberListResp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetGroupMemberList(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetGroupMemberListReq{}
|
2021-06-28 15:27:35 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetGroupMemberListReq{}
|
|
|
|
|
utils.CopyStructFields(req, params)
|
|
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupMemberList args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
|
|
|
|
|
2021-06-28 15:27:35 +08:00
|
|
|
RpcResp, err := client.GetGroupMemberList(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupMemberList failed, ", err.Error(), req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 16:27:57 +08:00
|
|
|
memberListResp := api.GetGroupMemberListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList, NextSeq: RpcResp.NextSeq}
|
2021-12-31 09:04:04 +08:00
|
|
|
memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
2021-12-30 17:27:11 +08:00
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupMemberList api return ", memberListResp)
|
2021-12-30 16:27:57 +08:00
|
|
|
c.JSON(http.StatusOK, memberListResp)
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-30 17:46:11 +08:00
|
|
|
func GetGroupAllMemberList(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetGroupAllMemberReq{}
|
2021-07-02 18:56:39 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-07-02 18:56:39 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetGroupAllMemberReq{}
|
2021-12-30 17:44:06 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-07-02 18:56:39 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupAllMember args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-07-02 18:56:39 +08:00
|
|
|
RpcResp, err := client.GetGroupAllMember(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupAllMember failed ", err.Error(), req.String())
|
2021-07-02 18:56:39 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 17:44:06 +08:00
|
|
|
memberListResp := api.GetGroupAllMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
2021-12-31 09:04:04 +08:00
|
|
|
memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupAllMember api return ", memberListResp)
|
2021-12-30 17:44:06 +08:00
|
|
|
c.JSON(http.StatusOK, memberListResp)
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetJoinedGroupList(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetJoinedGroupListReq{}
|
2021-06-28 15:27:35 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetJoinedGroupListReq{}
|
|
|
|
|
utils.CopyStructFields(req, params)
|
|
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetJoinedGroupList args ", req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-06-28 15:27:35 +08:00
|
|
|
RpcResp, err := client.GetJoinedGroupList(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GetJoinedGroupList failed ", err.Error(), req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 14:03:55 +08:00
|
|
|
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupList}
|
2021-12-31 09:04:04 +08:00
|
|
|
GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
|
2021-12-31 09:04:04 +08:00
|
|
|
c.JSON(http.StatusOK, GroupListResp)
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InviteUserToGroup(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.InviteUserToGroupReq{}
|
2021-06-28 15:27:35 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.InviteUserToGroupReq{}
|
2021-12-30 16:19:06 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-06-28 15:27:35 +08:00
|
|
|
RpcResp, err := client.InviteUserToGroup(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "InviteUserToGroup failed ", err.Error(), req.String())
|
2021-06-28 15:27:35 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 16:19:06 +08:00
|
|
|
resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
2021-12-26 18:47:11 +08:00
|
|
|
for _, v := range RpcResp.Id2ResultList {
|
2022-01-13 11:10:29 +08:00
|
|
|
resp.UserIDResultList = append(resp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
2021-06-28 15:27:35 +08:00
|
|
|
}
|
2021-12-31 09:04:04 +08:00
|
|
|
|
|
|
|
|
if len(resp.UserIDResultList) == 0 {
|
2022-01-13 11:10:29 +08:00
|
|
|
resp.UserIDResultList = *new([]*api.UserIDResult)
|
2021-12-31 09:04:04 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-30 16:19:06 +08:00
|
|
|
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", resp)
|
2021-12-31 09:04:04 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreateGroup(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.CreateGroupReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-01-18 20:04:58 +08:00
|
|
|
req := &rpc.CreateGroupReq{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
|
|
utils.CopyStructFields(req.GroupInfo, ¶ms)
|
|
|
|
|
|
2021-12-29 17:26:06 +08:00
|
|
|
for _, v := range params.MemberList {
|
|
|
|
|
req.InitMemberList = append(req.InitMemberList, &rpc.GroupAddMemberInfo{UserID: v.UserID, RoleLevel: v.RoleLevel})
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2022-01-18 21:17:35 +08:00
|
|
|
req.OwnerUserID = req.OpUserID
|
|
|
|
|
req.OperationID = params.OperationID
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-12-23 17:22:49 +08:00
|
|
|
RpcResp, err := client.CreateGroup(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-29 17:46:27 +08:00
|
|
|
log.NewError(req.OperationID, "CreateGroup failed ", err.Error(), req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
|
2021-12-29 17:26:06 +08:00
|
|
|
resp := api.CreateGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
2021-12-26 18:47:11 +08:00
|
|
|
if RpcResp.ErrCode == 0 {
|
2021-12-29 17:43:49 +08:00
|
|
|
utils.CopyStructFields(&resp.GroupInfo, RpcResp.GroupInfo)
|
2021-12-31 09:25:11 +08:00
|
|
|
resp.Data = jsonData.JsonDataOne(&resp.GroupInfo)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2021-12-29 17:52:01 +08:00
|
|
|
log.NewInfo(req.OperationID, "CreateGroup api return ", resp)
|
2021-12-29 17:26:06 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-30 10:35:09 +08:00
|
|
|
// 群主或管理员收到的
|
2022-01-19 17:17:51 +08:00
|
|
|
func GetRecvGroupApplicationList(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetGroupApplicationListReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetGroupApplicationListReq{}
|
|
|
|
|
utils.CopyStructFields(req, params)
|
|
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
2021-12-23 17:22:49 +08:00
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupApplicationList args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
|
|
|
|
reply, err := client.GetGroupApplicationList(context.Background(), req)
|
2021-12-23 17:22:49 +08:00
|
|
|
if err != nil {
|
2021-12-30 10:35:09 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 10:35:09 +08:00
|
|
|
resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: reply.ErrCode, ErrMsg: reply.ErrMsg}, GroupRequestList: reply.GroupRequestList}
|
2021-12-31 09:25:11 +08:00
|
|
|
resp.Data = jsonData.JsonDataList(resp.GroupRequestList)
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
|
2021-12-30 10:35:09 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetGroupsInfo(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.GetGroupInfoReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GetGroupsInfoReq{}
|
2021-12-30 11:04:53 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-12-23 17:22:49 +08:00
|
|
|
RpcResp, err := client.GetGroupsInfo(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GetGroupsInfo failed ", err.Error(), req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 11:04:53 +08:00
|
|
|
resp := api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupInfoList}
|
2021-12-31 09:25:11 +08:00
|
|
|
resp.Data = jsonData.JsonDataList(resp.GroupInfoList)
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
|
2021-12-30 11:04:53 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
//process application
|
2021-12-23 17:22:49 +08:00
|
|
|
func ApplicationGroupResponse(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.ApplicationGroupResponseReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.GroupApplicationResponseReq{}
|
2021-12-30 11:42:10 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
2021-12-23 17:22:49 +08:00
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "ApplicationGroupResponse args ", req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
|
|
|
|
reply, err := client.GroupApplicationResponse(context.Background(), req)
|
2021-12-23 17:22:49 +08:00
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "GroupApplicationResponse failed ", req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 11:42:10 +08:00
|
|
|
resp := api.ApplicationGroupResponseResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "ApplicationGroupResponse api return ", resp)
|
2021-12-30 11:42:10 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func JoinGroup(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.JoinGroupReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.JoinGroupReq{}
|
|
|
|
|
utils.CopyStructFields(req, params)
|
|
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
|
|
|
|
|
2021-12-23 17:22:49 +08:00
|
|
|
RpcResp, err := client.JoinGroup(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "JoinGroup failed ", err.Error(), req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-27 21:08:42 +08:00
|
|
|
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
|
2021-12-30 09:23:18 +08:00
|
|
|
log.NewInfo(req.OperationID, "JoinGroup api return", RpcResp.String())
|
2021-12-26 18:47:11 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func QuitGroup(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.QuitGroupReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.QuitGroupReq{}
|
2021-12-29 21:47:56 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "QuitGroup args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-12-23 17:22:49 +08:00
|
|
|
RpcResp, err := client.QuitGroup(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-27 21:08:42 +08:00
|
|
|
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
|
2021-12-30 09:26:40 +08:00
|
|
|
log.NewInfo(req.OperationID, "QuitGroup api return", RpcResp.String())
|
2021-12-26 18:47:11 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func SetGroupInfo(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.SetGroupInfoReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-29 21:50:11 +08:00
|
|
|
req := &rpc.SetGroupInfoReq{GroupInfo: &open_im_sdk.GroupInfo{}}
|
2022-01-19 09:33:31 +08:00
|
|
|
utils.CopyStructFields(req.GroupInfo, ¶ms)
|
2021-12-29 21:50:11 +08:00
|
|
|
req.OperationID = params.OperationID
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
|
|
|
|
return
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
2021-12-23 17:22:49 +08:00
|
|
|
RpcResp, err := client.SetGroupInfo(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-29 21:26:56 +08:00
|
|
|
resp := api.SetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
2021-12-26 18:47:11 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
|
log.NewInfo(req.OperationID, "SetGroupInfo api return ", resp)
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TransferGroupOwner(c *gin.Context) {
|
2021-12-26 18:47:11 +08:00
|
|
|
params := api.TransferGroupOwnerReq{}
|
2021-12-23 17:22:49 +08:00
|
|
|
if err := c.BindJSON(¶ms); err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError("0", "BindJSON failed ", err.Error())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
req := &rpc.TransferGroupOwnerReq{}
|
2021-12-30 13:39:36 +08:00
|
|
|
utils.CopyStructFields(req, ¶ms)
|
2021-12-26 18:47:11 +08:00
|
|
|
var ok bool
|
|
|
|
|
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
|
|
|
|
if !ok {
|
|
|
|
|
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
2021-12-23 17:22:49 +08:00
|
|
|
return
|
|
|
|
|
}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "TransferGroupOwner args ", req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
|
2021-12-26 18:47:11 +08:00
|
|
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
|
|
|
|
client := rpc.NewGroupClient(etcdConn)
|
|
|
|
|
reply, err := client.TransferGroupOwner(context.Background(), req)
|
2021-12-23 17:22:49 +08:00
|
|
|
if err != nil {
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewError(req.OperationID, "TransferGroupOwner failed ", req.String())
|
2021-12-23 17:22:49 +08:00
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 13:39:36 +08:00
|
|
|
resp := api.TransferGroupOwnerResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
2021-12-26 18:47:11 +08:00
|
|
|
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
|
2021-12-30 13:39:36 +08:00
|
|
|
c.JSON(http.StatusOK, resp)
|
|
|
|
|
|
2021-12-23 17:22:49 +08:00
|
|
|
}
|