|
|
@ -6,8 +6,7 @@ import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
"Open_IM/pkg/common/db"
|
|
|
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
"Open_IM/pkg/common/db/rocks_cache"
|
|
|
|
rocksCache "Open_IM/pkg/common/db/rocks_cache"
|
|
|
|
"Open_IM/pkg/common/http"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/token_verify"
|
|
|
|
"Open_IM/pkg/common/token_verify"
|
|
|
|
cp "Open_IM/pkg/common/utils"
|
|
|
|
cp "Open_IM/pkg/common/utils"
|
|
|
@ -19,12 +18,15 @@ import (
|
|
|
|
pbUser "Open_IM/pkg/proto/user"
|
|
|
|
pbUser "Open_IM/pkg/proto/user"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"errors"
|
|
|
|
"math/big"
|
|
|
|
"math/big"
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type groupServer struct {
|
|
|
|
type groupServer struct {
|
|
|
@ -83,7 +85,8 @@ func (s *groupServer) Run() {
|
|
|
|
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
|
|
|
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError("", "RegisterEtcd failed ", err.Error())
|
|
|
|
log.NewError("", "RegisterEtcd failed ", err.Error())
|
|
|
|
return
|
|
|
|
panic(utils.Wrap(err, "register group module rpc to etcd err"))
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Info("", "RegisterEtcd ", s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
|
|
|
|
log.Info("", "RegisterEtcd ", s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
|
|
|
|
err = srv.Serve(listener)
|
|
|
|
err = srv.Serve(listener)
|
|
|
@ -120,7 +123,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|
|
|
err := imdb.InsertIntoGroup(groupInfo)
|
|
|
|
err := imdb.InsertIntoGroup(groupInfo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var okUserIDList []string
|
|
|
|
var okUserIDList []string
|
|
|
|
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
|
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
@ -130,7 +133,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|
|
|
us, err = imdb.GetUserByUserID(req.OwnerUserID)
|
|
|
|
us, err = imdb.GetUserByUserID(req.OwnerUserID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID)
|
|
|
|
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//to group member
|
|
|
|
//to group member
|
|
|
|
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
|
|
|
|
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
|
|
|
@ -138,9 +141,10 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|
|
|
err = imdb.InsertIntoGroupMember(groupMember)
|
|
|
|
err = imdb.InsertIntoGroupMember(groupMember)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if req.GroupInfo.GroupType != constant.SuperGroup {
|
|
|
|
if req.GroupInfo.GroupType != constant.SuperGroup {
|
|
|
|
//to group member
|
|
|
|
//to group member
|
|
|
|
for _, user := range req.InitMemberList {
|
|
|
|
for _, user := range req.InitMemberList {
|
|
|
@ -314,7 +318,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|
|
|
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
|
|
|
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
|
|
|
|
|
|
|
|
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
|
|
|
|
// log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
|
|
|
|
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var resultNode pbGroup.Id2Result
|
|
|
|
var resultNode pbGroup.Id2Result
|
|
|
@ -483,11 +487,9 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
for _, v := range req.InvitedUserIDList {
|
|
|
|
for _, v := range req.InvitedUserIDList {
|
|
|
|
chat.SuperGroupNotification(req.OperationID, v, v)
|
|
|
|
chat.SuperGroupNotification(req.OperationID, v, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp)
|
|
|
|
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp)
|
|
|
@ -827,7 +829,6 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
|
|
|
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
|
|
|
|
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
|
|
|
|
|
|
|
|
|
|
|
|
groupRequest := db.GroupRequest{}
|
|
|
|
groupRequest := db.GroupRequest{}
|
|
|
|
utils.CopyStructFields(&groupRequest, req)
|
|
|
|
utils.CopyStructFields(&groupRequest, req)
|
|
|
|
groupRequest.UserID = req.FromUserID
|
|
|
|
groupRequest.UserID = req.FromUserID
|
|
|
@ -1162,7 +1163,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
|
|
|
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
|
|
|
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if group.Status == constant.GroupStatusDismissed {
|
|
|
|
if group.Status == constant.GroupStatusDismissed {
|
|
|
@ -1199,7 +1200,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
|
|
|
|
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if req.GroupInfoForSet.LookMemberInfo != nil {
|
|
|
|
if req.GroupInfoForSet.LookMemberInfo != nil {
|
|
|
@ -1208,7 +1209,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
|
|
|
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
|
|
|
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
|
|
@ -1217,7 +1218,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
|
|
|
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
|
@ -1234,11 +1235,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
err = imdb.SetGroupInfo(groupInfo)
|
|
|
|
err = imdb.SetGroupInfo(groupInfo)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
|
|
|
|
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
|
|
|
|
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
|
|
|
|
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
|
|
|
@ -1252,7 +1253,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
if etcdConn == nil {
|
|
|
|
if etcdConn == nil {
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client := pbCache.NewCacheClient(etcdConn)
|
|
|
|
client := pbCache.NewCacheClient(etcdConn)
|
|
|
|
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
|
|
|
|
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
|
|
|
@ -1281,7 +1282,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|
|
|
if etcdConn == nil {
|
|
|
|
if etcdConn == nil {
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
|
|
|
|
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nClient := pbConversation.NewConversationClient(nEtcdConn)
|
|
|
|
nClient := pbConversation.NewConversationClient(nEtcdConn)
|
|
|
|
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
|
|
|
|
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
|
|
|
@ -1336,154 +1337,89 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroupByID(_ context.Context, req *pbGroup.GetGroupByIDReq) (*pbGroup.GetGroupByIDResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
|
|
|
|
|
|
resp := &pbGroup.GetGroupByIDResp{CMSGroup: &pbGroup.CMSGroup{
|
|
|
|
|
|
|
|
GroupInfo: &open_im_sdk.GroupInfo{},
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
group, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
|
|
|
|
|
|
|
|
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(group.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
groupMemberNum, err := imdb.GetGroupMemberNumByGroupID(req.GroupID)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
resp.CMSGroup.GroupInfo.MemberCount = uint32(groupMemberNum)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.CMSGroup.GroupOwnerUserName = groupMember.Nickname
|
|
|
|
|
|
|
|
resp.CMSGroup.GroupOwnerUserID = groupMember.UserID
|
|
|
|
|
|
|
|
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
|
|
|
|
|
|
|
|
resp.CMSGroup.GroupInfo.CreateTime = uint32(group.CreateTime.Unix())
|
|
|
|
|
|
|
|
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
|
|
|
|
|
|
resp := &pbGroup.GetGroupResp{
|
|
|
|
|
|
|
|
CMSGroups: []*pbGroup.CMSGroup{},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "groups", groups)
|
|
|
|
|
|
|
|
nums, err := imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error(), req.GroupName)
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.GroupNums = nums
|
|
|
|
|
|
|
|
resp.Pagination = &open_im_sdk.RequestPagination{
|
|
|
|
|
|
|
|
PageNumber: req.Pagination.PageNumber,
|
|
|
|
|
|
|
|
ShowNumber: req.Pagination.ShowNumber,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range groups {
|
|
|
|
|
|
|
|
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
|
|
|
|
|
utils.CopyStructFields(group.GroupInfo, v)
|
|
|
|
|
|
|
|
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
|
|
|
|
|
|
|
|
group.GroupOwnerUserID = groupMember.UserID
|
|
|
|
|
|
|
|
group.GroupOwnerUserName = groupMember.Nickname
|
|
|
|
|
|
|
|
resp.CMSGroups = append(resp.CMSGroups, group)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
|
|
|
|
func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", req.String())
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", req.String())
|
|
|
|
resp := &pbGroup.GetGroupsResp{
|
|
|
|
resp := &pbGroup.GetGroupsResp{
|
|
|
|
|
|
|
|
CommonResp: &pbGroup.CommonResp{},
|
|
|
|
CMSGroups: []*pbGroup.CMSGroup{},
|
|
|
|
CMSGroups: []*pbGroup.CMSGroup{},
|
|
|
|
Pagination: &open_im_sdk.RequestPagination{},
|
|
|
|
Pagination: &open_im_sdk.ResponsePagination{CurrentPage: req.Pagination.PageNumber, ShowNumber: req.Pagination.ShowNumber},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
groups, err := imdb.GetGroups(int(req.Pagination.PageNumber), int(req.Pagination.ShowNumber))
|
|
|
|
if req.GroupID != "" {
|
|
|
|
if err != nil {
|
|
|
|
groupInfoDB, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroups error", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.GroupNum, err = imdb.GetGroupsCountNum(db.Group{})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.Pagination.PageNumber = req.Pagination.PageNumber
|
|
|
|
|
|
|
|
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
|
|
|
|
|
|
|
|
for _, v := range groups {
|
|
|
|
|
|
|
|
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
|
|
|
|
|
utils.CopyStructFields(group.GroupInfo, v)
|
|
|
|
|
|
|
|
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error(), v)
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
continue
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
|
|
|
|
resp.GroupNum = 1
|
|
|
|
group.GroupOwnerUserID = groupMember.UserID
|
|
|
|
groupInfo := &open_im_sdk.GroupInfo{}
|
|
|
|
group.GroupOwnerUserName = groupMember.Nickname
|
|
|
|
utils.CopyStructFields(groupInfo, groupInfoDB)
|
|
|
|
resp.CMSGroups = append(resp.CMSGroups, group)
|
|
|
|
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
return resp, nil
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
}
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
|
|
|
|
}
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
|
|
|
|
memberNum, err := imdb.GetGroupMembersCount(req.GroupID, "")
|
|
|
|
resp := &pbGroup.OperateUserRoleResp{}
|
|
|
|
if err != nil {
|
|
|
|
oldOwnerUserID, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
if err != nil {
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
|
|
|
|
groupInfo.MemberCount = uint32(memberNum)
|
|
|
|
if etcdConn == nil {
|
|
|
|
resp.CMSGroups = append(resp.CMSGroups, &pbGroup.CMSGroup{GroupInfo: groupInfo, GroupOwnerUserName: groupMember.Nickname, GroupOwnerUserID: groupMember.UserID})
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
} else {
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
|
|
|
return resp, http.WrapError(constant.ErrInternal)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
client := pbGroup.NewGroupClient(etcdConn)
|
|
|
|
|
|
|
|
var reqPb pbGroup.TransferGroupOwnerReq
|
|
|
|
|
|
|
|
reqPb.OperationID = req.OperationID
|
|
|
|
|
|
|
|
reqPb.NewOwnerUserID = req.UserID
|
|
|
|
|
|
|
|
reqPb.GroupID = req.GroupID
|
|
|
|
|
|
|
|
reqPb.OpUserID = "cms admin"
|
|
|
|
|
|
|
|
reqPb.OldOwnerUserID = oldOwnerUserID.UserID
|
|
|
|
|
|
|
|
reply, err := client.TransferGroupOwner(context.Background(), &reqPb)
|
|
|
|
|
|
|
|
if reply.CommonResp.ErrCode != 0 || err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "TransferGroupOwner rpc failed")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range groups {
|
|
|
|
|
|
|
|
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
|
|
|
|
|
|
|
|
utils.CopyStructFields(group.GroupInfo, v)
|
|
|
|
|
|
|
|
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupOwnerInfoByGroupID failed", err.Error(), v)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
|
|
|
|
|
|
|
|
group.GroupOwnerUserID = groupMember.UserID
|
|
|
|
|
|
|
|
group.GroupOwnerUserName = groupMember.Nickname
|
|
|
|
|
|
|
|
resp.CMSGroups = append(resp.CMSGroups, group)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.GroupNum, err = imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error())
|
|
|
|
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups resp", resp.String())
|
|
|
|
return resp, nil
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
|
|
|
|
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
|
|
|
|
resp := &pbGroup.GetGroupMembersCMSResp{}
|
|
|
|
resp := &pbGroup.GetGroupMembersCMSResp{CommonResp: &pbGroup.CommonResp{}}
|
|
|
|
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
|
|
|
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error())
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
|
|
|
|
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error())
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error())
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
|
|
|
|
|
|
|
|
resp.CommonResp.ErrMsg = err.Error()
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewInfo(req.OperationID, groupMembersCount)
|
|
|
|
log.NewInfo(req.OperationID, groupMembersCount)
|
|
|
|
resp.MemberNums = int32(groupMembersCount)
|
|
|
|
resp.MemberNums = int32(groupMembersCount)
|
|
|
@ -1502,151 +1438,6 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou
|
|
|
|
return resp, nil
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.RemoveGroupMembersCMSReq) (*pbGroup.RemoveGroupMembersCMSResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
|
|
|
|
|
|
|
|
resp := &pbGroup.RemoveGroupMembersCMSResp{}
|
|
|
|
|
|
|
|
for _, userId := range req.UserIDList {
|
|
|
|
|
|
|
|
err := imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, userId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
|
|
|
|
|
|
|
|
resp.Failed = append(resp.Failed, userId)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resp.Success = append(resp.Success, userId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
reqKick := &pbGroup.KickGroupMemberReq{
|
|
|
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
|
|
|
KickedUserIDList: resp.Success,
|
|
|
|
|
|
|
|
Reason: "admin kick",
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
OpUserID: req.OpUserID,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var reqPb pbUser.SetConversationReq
|
|
|
|
|
|
|
|
var c pbConversation.Conversation
|
|
|
|
|
|
|
|
for _, v := range resp.Success {
|
|
|
|
|
|
|
|
reqPb.OperationID = req.OperationID
|
|
|
|
|
|
|
|
c.OwnerUserID = v
|
|
|
|
|
|
|
|
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
|
|
|
|
|
|
|
|
c.ConversationType = constant.GroupChatType
|
|
|
|
|
|
|
|
c.GroupID = req.GroupID
|
|
|
|
|
|
|
|
c.IsNotInGroup = true
|
|
|
|
|
|
|
|
reqPb.Conversation = &c
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
|
|
|
|
|
|
|
if etcdConn == nil {
|
|
|
|
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrInternal)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
client := pbUser.NewUserClient(etcdConn)
|
|
|
|
|
|
|
|
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error(), v)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
|
|
|
|
|
|
|
if etcdConn == nil {
|
|
|
|
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cacheClient := pbCache.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
|
|
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cacheResp.CommonResp.ErrCode != 0 {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, userID := range resp.Success {
|
|
|
|
|
|
|
|
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, userID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat.MemberKickedNotification(reqKick, resp.Success)
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGroupMembersCMSReq) (*pbGroup.AddGroupMembersCMSResp, error) {
|
|
|
|
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
|
|
|
|
|
|
|
|
resp := &pbGroup.AddGroupMembersCMSResp{}
|
|
|
|
|
|
|
|
for _, userId := range req.UserIDList {
|
|
|
|
|
|
|
|
if isExist := imdb.IsExistGroupMember(req.GroupID, userId); isExist {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "user is exist in group", userId, req.GroupID)
|
|
|
|
|
|
|
|
resp.Failed = append(resp.Failed, userId)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := imdb.GetUserByUserID(userId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
|
|
|
|
|
|
|
|
resp.Failed = append(resp.Failed, userId)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
groupMember := db.GroupMember{
|
|
|
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
|
|
|
UserID: userId,
|
|
|
|
|
|
|
|
Nickname: user.Nickname,
|
|
|
|
|
|
|
|
FaceURL: "",
|
|
|
|
|
|
|
|
RoleLevel: 1,
|
|
|
|
|
|
|
|
JoinTime: time.Time{},
|
|
|
|
|
|
|
|
JoinSource: constant.JoinByAdmin,
|
|
|
|
|
|
|
|
OperatorUserID: "CmsAdmin",
|
|
|
|
|
|
|
|
Ex: "",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := imdb.InsertIntoGroupMember(groupMember); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "InsertIntoGroupMember failed", req.String())
|
|
|
|
|
|
|
|
resp.Failed = append(resp.Failed, userId)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resp.Success = append(resp.Success, userId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
|
|
|
|
|
|
|
if etcdConn == nil {
|
|
|
|
|
|
|
|
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, errMsg)
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cacheClient := pbCache.NewCacheClient(etcdConn)
|
|
|
|
|
|
|
|
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
|
|
|
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
|
|
|
OperationID: req.OperationID,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if cacheResp.CommonResp.ErrCode != 0 {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
|
|
|
|
|
|
|
return resp, http.WrapError(constant.ErrDB)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
|
|
|
|
|
|
|
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, "admin add you to group", resp.Success)
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
|
|
|
|
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
|
|
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
|
|
resp := &pbGroup.GetUserReqApplicationListResp{}
|
|
|
|
resp := &pbGroup.GetUserReqApplicationListResp{}
|
|
|
|