You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/api/group/group.go

511 lines
21 KiB

3 years ago
package group
import (
3 years ago
api "Open_IM/pkg/base_info"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
3 years ago
"Open_IM/pkg/common/token_verify"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
3 years ago
rpc "Open_IM/pkg/proto/group"
3 years ago
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
3 years ago
"Open_IM/pkg/utils"
3 years ago
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
func KickGroupMember(c *gin.Context) {
3 years ago
params := api.KickGroupMemberReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.KickGroupMemberReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, "KickGroupMember args ", req.String())
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
3 years ago
client := rpc.NewGroupClient(etcdConn)
3 years ago
RpcResp, err := client.KickGroupMember(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
var memberListResp api.KickGroupMemberResp
memberListResp.ErrMsg = RpcResp.ErrMsg
memberListResp.ErrCode = RpcResp.ErrCode
for _, v := range RpcResp.Id2ResultList {
3 years ago
memberListResp.UserIDResultList = append(memberListResp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
3 years ago
}
3 years ago
if len(memberListResp.UserIDResultList) == 0 {
memberListResp.UserIDResultList = []*api.UserIDResult{}
}
3 years ago
log.NewInfo(req.OperationID, "KickGroupMember api return ", memberListResp)
3 years ago
c.JSON(http.StatusOK, memberListResp)
}
func GetGroupMembersInfo(c *gin.Context) {
3 years ago
params := api.GetGroupMembersInfoReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
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"))
3 years ago
//c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
api.SetErrCodeMsg(c, http.StatusInternalServerError)
3 years ago
return
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.GetGroupMembersInfo(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
memberListResp := api.GetGroupMembersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Data: RpcResp.MemberList}
log.NewInfo(req.OperationID, "GetGroupMembersInfo api return ", memberListResp)
3 years ago
c.JSON(http.StatusOK, memberListResp)
}
func GetGroupMemberList(c *gin.Context) {
3 years ago
params := api.GetGroupMemberListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.GetGroupMemberList(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupMemberList failed, ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
memberListResp := api.GetGroupMemberListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList, NextSeq: RpcResp.NextSeq}
if len(memberListResp.MemberList) == 0 {
memberListResp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
}
3 years ago
/*
jsm := &jsonpb.Marshaler{
OrigName: true,
EnumsAsInts: false,
EmitDefaults: true,
}
var b bytes.Buffer
err = jsm.MarshalToString(memberListResp.MemberList[0])
*/
3 years ago
log.NewInfo(req.OperationID, "GetGroupMemberList api return ", memberListResp)
3 years ago
c.JSON(http.StatusOK, memberListResp)
3 years ago
}
func GetGroupAllMember(c *gin.Context) {
3 years ago
params := api.GetGroupAllMemberReq{}
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetGroupAllMemberReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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
}
3 years ago
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)
RpcResp, err := client.GetGroupAllMember(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupAllMember failed ", err.Error(), req.String())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
memberListResp := api.GetGroupAllMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList}
if len(memberListResp.MemberList) == 0 {
memberListResp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
}
3 years ago
log.NewInfo(req.OperationID, "GetGroupAllMember api return ", memberListResp)
3 years ago
c.JSON(http.StatusOK, memberListResp)
3 years ago
}
func GetJoinedGroupList(c *gin.Context) {
3 years ago
params := api.GetJoinedGroupListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
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
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, "GetJoinedGroupList args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := rpc.NewGroupClient(etcdConn)
3 years ago
RpcResp, err := client.GetJoinedGroupList(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetJoinedGroupList failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupList}
3 years ago
c.JSON(http.StatusOK, GroupListResp)
3 years ago
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
3 years ago
}
func InviteUserToGroup(c *gin.Context) {
3 years ago
params := api.InviteUserToGroupReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.InviteUserToGroupReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
3 years ago
3 years ago
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
client := rpc.NewGroupClient(etcdConn)
3 years ago
RpcResp, err := client.InviteUserToGroup(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "InviteUserToGroup failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
3 years ago
for _, v := range RpcResp.Id2ResultList {
3 years ago
resp.UserIDResultList = append(resp.UserIDResultList, api.UserIDResult{UserID: v.UserID, Result: v.Result})
3 years ago
}
3 years ago
c.JSON(http.StatusOK, resp)
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", resp)
3 years ago
}
func CreateGroup(c *gin.Context) {
3 years ago
params := api.CreateGroupReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.CreateGroupReq{}
3 years ago
utils.CopyStructFields(req, &params)
for _, v := range params.MemberList {
req.InitMemberList = append(req.InitMemberList, &rpc.GroupAddMemberInfo{UserID: v.UserID, RoleLevel: v.RoleLevel})
}
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.CreateGroup(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "CreateGroup failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
3 years ago
3 years ago
resp := api.CreateGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
3 years ago
if RpcResp.ErrCode == 0 {
3 years ago
utils.CopyStructFields(&resp.GroupInfo, RpcResp.GroupInfo)
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, "CreateGroup api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
3 years ago
// 群主或管理员收到的
3 years ago
func GetGroupApplicationList(c *gin.Context) {
3 years ago
params := api.GetGroupApplicationListReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
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"})
3 years ago
return
}
3 years ago
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)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: reply.ErrCode, ErrMsg: reply.ErrMsg}, GroupRequestList: reply.GroupRequestList}
if len(resp.GroupRequestList) == 0 {
resp.GroupRequestList = []*open_im_sdk.GroupRequest{}
}
3 years ago
log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func GetGroupsInfo(c *gin.Context) {
3 years ago
params := api.GetGroupInfoReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GetGroupsInfoReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.GetGroupsInfo(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupsInfo failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
3 years ago
resp := api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupInfoList}
if len(resp.GroupInfoList) == 0 {
resp.GroupInfoList = []*open_im_sdk.GroupInfo{}
}
3 years ago
log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
3 years ago
//process application
3 years ago
func ApplicationGroupResponse(c *gin.Context) {
3 years ago
params := api.ApplicationGroupResponseReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.GroupApplicationResponseReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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"})
3 years ago
return
}
3 years ago
log.NewInfo(req.OperationID, "ApplicationGroupResponse args ", req.String())
3 years ago
3 years ago
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)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GroupApplicationResponse failed ", req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
resp := api.ApplicationGroupResponseResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
3 years ago
log.NewInfo(req.OperationID, "ApplicationGroupResponse api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func JoinGroup(c *gin.Context) {
3 years ago
params := api.JoinGroupReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.JoinGroup(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "JoinGroup failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
3 years ago
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
3 years ago
log.NewInfo(req.OperationID, "JoinGroup api return", RpcResp.String())
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func QuitGroup(c *gin.Context) {
3 years ago
params := api.QuitGroupReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.QuitGroupReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.QuitGroup(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
3 years ago
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
3 years ago
log.NewInfo(req.OperationID, "QuitGroup api return", RpcResp.String())
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}
func SetGroupInfo(c *gin.Context) {
3 years ago
params := api.SetGroupInfoReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.SetGroupInfoReq{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(req.GroupInfo, &params.Group)
req.OperationID = params.OperationID
3 years ago
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
3 years ago
}
3 years ago
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)
3 years ago
RpcResp, err := client.SetGroupInfo(context.Background(), req)
if err != nil {
3 years ago
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
return
}
3 years ago
resp := api.SetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
3 years ago
c.JSON(http.StatusOK, resp)
log.NewInfo(req.OperationID, "SetGroupInfo api return ", resp)
3 years ago
}
func TransferGroupOwner(c *gin.Context) {
3 years ago
params := api.TransferGroupOwnerReq{}
3 years ago
if err := c.BindJSON(&params); err != nil {
3 years ago
log.NewError("0", "BindJSON failed ", err.Error())
3 years ago
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
3 years ago
req := &rpc.TransferGroupOwnerReq{}
3 years ago
utils.CopyStructFields(req, &params)
3 years ago
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"})
3 years ago
return
}
3 years ago
log.NewInfo(req.OperationID, "TransferGroupOwner args ", req.String())
3 years ago
3 years ago
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)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "TransferGroupOwner failed ", req.String())
3 years ago
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
return
}
3 years ago
resp := api.TransferGroupOwnerResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
3 years ago
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
3 years ago
c.JSON(http.StatusOK, resp)
3 years ago
}