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/rpc/group/group.go

2053 lines
96 KiB

package group
import (
3 years ago
chat "Open_IM/internal/rpc/msg"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
2 years ago
"Open_IM/pkg/common/db/rocks_cache"
3 years ago
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
3 years ago
"Open_IM/pkg/common/token_verify"
3 years ago
cp "Open_IM/pkg/common/utils"
3 years ago
"Open_IM/pkg/grpc-etcdv3/getcdv3"
3 years ago
pbCache "Open_IM/pkg/proto/cache"
pbConversation "Open_IM/pkg/proto/conversation"
pbGroup "Open_IM/pkg/proto/group"
3 years ago
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/utils"
"context"
"google.golang.org/grpc"
"math/big"
3 years ago
"net"
"strconv"
"strings"
"time"
)
3 years ago
type groupServer struct {
rpcPort int
rpcRegisterName string
etcdSchema string
etcdAddr []string
}
func NewGroupServer(port int) *groupServer {
3 years ago
log.NewPrivateLog(constant.LogFileName)
3 years ago
return &groupServer{
rpcPort: port,
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
etcdSchema: config.Config.Etcd.EtcdSchema,
etcdAddr: config.Config.Etcd.EtcdAddr,
}
}
3 years ago
3 years ago
func (s *groupServer) Run() {
3 years ago
log.NewInfo("", "group rpc start ")
3 years ago
listenIP := ""
if config.Config.ListenIP == "" {
listenIP = "0.0.0.0"
} else {
listenIP = config.Config.ListenIP
}
address := listenIP + ":" + strconv.Itoa(s.rpcPort)
3 years ago
//listener network
3 years ago
listener, err := net.Listen("tcp", address)
3 years ago
if err != nil {
3 years ago
panic("listening err:" + err.Error() + s.rpcRegisterName)
3 years ago
}
3 years ago
log.NewInfo("", "listen network success, ", address, listener)
3 years ago
defer listener.Close()
//grpc server
2 years ago
recvSize := 1024 * 1024 * constant.GroupRPCRecvSize
sendSize := 1024 * 1024 * constant.GroupRPCSendSize
2 years ago
var options = []grpc.ServerOption{
grpc.MaxRecvMsgSize(recvSize),
grpc.MaxSendMsgSize(sendSize),
}
srv := grpc.NewServer(options...)
3 years ago
defer srv.GracefulStop()
//Service registers with etcd
pbGroup.RegisterGroupServer(srv, s)
3 years ago
rpcRegisterIP := config.Config.RpcRegisterIP
2 years ago
if config.Config.RpcRegisterIP == "" {
3 years ago
rpcRegisterIP, err = utils.GetLocalIP()
if err != nil {
log.Error("", "GetLocalIP failed ", err.Error())
}
}
3 years ago
log.NewInfo("", "rpcRegisterIP", rpcRegisterIP)
3 years ago
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName, 10)
3 years ago
if err != nil {
3 years ago
log.NewError("", "RegisterEtcd failed ", err.Error())
panic(utils.Wrap(err, "register group module rpc to etcd err"))
3 years ago
}
3 years ago
log.Info("", "RegisterEtcd ", s.etcdSchema, strings.Join(s.etcdAddr, ","), rpcRegisterIP, s.rpcPort, s.rpcRegisterName)
3 years ago
err = srv.Serve(listener)
if err != nil {
3 years ago
log.NewError("", "Serve failed ", err.Error())
3 years ago
return
}
3 years ago
log.NewInfo("", "group rpc success")
3 years ago
}
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, "CreateGroup, args ", req.String())
3 years ago
if !token_verify.CheckAccess(req.OpUserID, req.OwnerUserID) {
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID)
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
3 years ago
}
groupId := req.GroupInfo.GroupID
if groupId == "" {
groupId = utils.Md5(req.OperationID + strconv.FormatInt(time.Now().UnixNano(), 10))
bi := big.NewInt(0)
bi.SetString(groupId[0:8], 16)
groupId = bi.String()
}
3 years ago
//to group
3 years ago
groupInfo := db.Group{}
3 years ago
utils.CopyStructFields(&groupInfo, req.GroupInfo)
3 years ago
groupInfo.CreatorUserID = req.OpUserID
3 years ago
groupInfo.GroupID = groupId
2 years ago
if groupInfo.NotificationUpdateTime.Unix() < 0 {
groupInfo.NotificationUpdateTime = utils.UnixSecondToTime(0)
}
3 years ago
err := imdb.InsertIntoGroup(groupInfo)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo)
3 years ago
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
3 years ago
}
3 years ago
var okUserIDList []string
3 years ago
resp := &pbGroup.CreateGroupResp{GroupInfo: &open_im_sdk.GroupInfo{}}
groupMember := db.GroupMember{}
us := &db.User{}
if req.OwnerUserID != "" {
3 years ago
us, err = imdb.GetUserByUserID(req.OwnerUserID)
if err != nil {
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)
3 years ago
}
3 years ago
//to group member
groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID}
3 years ago
utils.CopyStructFields(&groupMember, us)
3 years ago
err = imdb.InsertIntoGroupMember(groupMember)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
3 years ago
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, http.WrapError(constant.ErrDB)
3 years ago
}
3 years ago
}
if req.GroupInfo.GroupType != constant.SuperGroup {
3 years ago
//to group member
for _, user := range req.InitMemberList {
2 years ago
us, err := rocksCache.GetUserInfoFromCache(user.UserID)
3 years ago
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), user.UserID)
continue
}
if user.RoleLevel == constant.GroupOwner {
log.NewError(req.OperationID, "only one owner, failed ", user)
continue
}
groupMember.RoleLevel = user.RoleLevel
groupMember.JoinSource = constant.JoinByInvitation
groupMember.InviterUserID = req.OpUserID
3 years ago
utils.CopyStructFields(&groupMember, us)
err = imdb.InsertIntoGroupMember(groupMember)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
continue
}
okUserIDList = append(okUserIDList, user.UserID)
}
2 years ago
group, err := rocksCache.GetGroupInfoFromCache(groupId)
3 years ago
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = err.Error()
return resp, nil
}
utils.CopyStructFields(resp.GroupInfo, group)
2 years ago
memberCount, err := rocksCache.GetGroupMemberNumFromCache(groupId)
2 years ago
resp.GroupInfo.MemberCount = uint32(memberCount)
3 years ago
if err != nil {
log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = err.Error()
return resp, nil
}
if req.OwnerUserID != "" {
resp.GroupInfo.OwnerUserID = req.OwnerUserID
okUserIDList = append(okUserIDList, req.OwnerUserID)
}
// superGroup stored in mongodb
3 years ago
} else {
3 years ago
for _, v := range req.InitMemberList {
okUserIDList = append(okUserIDList, v.UserID)
}
3 years ago
if err := db.DB.CreateSuperGroup(groupId, okUserIDList, len(okUserIDList)); err != nil {
log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId)
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = err.Error() + ": CreateSuperGroup failed"
return resp, nil
}
}
if len(okUserIDList) != 0 {
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
3 years ago
if req.GroupInfo.GroupType != constant.SuperGroup {
for _, userID := range okUserIDList {
if err := rocksCache.DelJoinedGroupIDListFromCache(userID); err != nil {
log.NewWarn(req.OperationID, utils.GetSelfFuncName(), userID, err.Error())
}
}
3 years ago
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList)
3 years ago
} else {
for _, userID := range okUserIDList {
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(userID); err != nil {
log.NewWarn(req.OperationID, utils.GetSelfFuncName(), userID, err.Error())
}
}
go func() {
for _, v := range okUserIDList {
chat.SuperGroupNotification(req.OperationID, v, v)
}
}()
3 years ago
}
return resp, nil
} else {
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
return resp, nil
}
3 years ago
}
func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJoinedGroupListReq) (*pbGroup.GetJoinedGroupListResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GetJoinedGroupList, args ", req.String())
if !token_verify.CheckAccess(req.OpUserID, req.FromUserID) {
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
3 years ago
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
2 years ago
joinedGroupList, err := rocksCache.GetJoinedGroupIDListFromCache(req.FromUserID)
if err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetJoinedGroupIDListFromCache failed", err.Error(), req.FromUserID)
3 years ago
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "joinedGroupList: ", joinedGroupList)
var resp pbGroup.GetJoinedGroupListResp
for _, v := range joinedGroupList {
3 years ago
var groupNode open_im_sdk.GroupInfo
2 years ago
num, err := rocksCache.GetGroupMemberNumFromCache(v)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), v)
continue
}
3 years ago
owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v)
if err2 != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err2.Error(), v)
3 years ago
continue
}
2 years ago
group, err := rocksCache.GetGroupInfoFromCache(v)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), v)
3 years ago
continue
}
2 years ago
if group.GroupType == constant.SuperGroup {
continue
}
if group.Status == constant.GroupStatusDismissed {
log.NewError(req.OperationID, "constant.GroupStatusDismissed ", group)
continue
}
utils.CopyStructFields(&groupNode, group)
groupNode.CreateTime = uint32(group.CreateTime.Unix())
groupNode.NotificationUpdateTime = uint32(group.NotificationUpdateTime.Unix())
if group.NotificationUpdateTime.Unix() < 0 {
groupNode.NotificationUpdateTime = 0
}
groupNode.MemberCount = uint32(num)
groupNode.OwnerUserID = owner.UserID
resp.GroupList = append(resp.GroupList, &groupNode)
3 years ago
log.NewDebug(req.OperationID, "joinedGroup ", groupNode)
}
3 years ago
log.NewInfo(req.OperationID, "GetJoinedGroupList rpc return ", resp.String())
return &resp, nil
}
func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.InviteUserToGroupReq) (*pbGroup.InviteUserToGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
3 years ago
if !imdb.IsExistGroupMember(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
3 years ago
log.NewError(req.OperationID, "no permission InviteUserToGroup ", req.GroupID, req.OpUserID)
3 years ago
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
}
3 years ago
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil
3 years ago
}
if groupInfo.Status == constant.GroupStatusDismissed {
errMsg := " group status is dismissed "
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}, nil
}
var resp pbGroup.InviteUserToGroupResp
if groupInfo.NeedVerification == constant.AllNeedVerification &&
!imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) && !token_verify.IsManagerUserID(req.OpUserID) {
var resp pbGroup.InviteUserToGroupResp
joinReq := pbGroup.JoinGroupReq{}
for _, v := range req.InvitedUserIDList {
var groupRequest db.GroupRequest
groupRequest.UserID = v
groupRequest.GroupID = req.GroupID
groupRequest.JoinSource = constant.JoinByInvitation
groupRequest.InviterUserID = req.OpUserID
err = imdb.InsertIntoGroupRequest(groupRequest)
if err != nil {
var resultNode pbGroup.Id2Result
resultNode.Result = -1
resultNode.UserID = v
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
} else {
var resultNode pbGroup.Id2Result
resultNode.Result = 0
resultNode.UserID = v
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
joinReq.GroupID = req.GroupID
joinReq.OperationID = req.OperationID
joinReq.OpUserID = v
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
chat.JoinGroupApplicationNotification(&joinReq)
}
}
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp)
return &resp, nil
}
//
//from User: invite: applicant
//to user: invite: invited
3 years ago
var okUserIDList []string
3 years ago
if groupInfo.GroupType != constant.SuperGroup {
for _, v := range req.InvitedUserIDList {
var resultNode pbGroup.Id2Result
resultNode.UserID = v
resultNode.Result = 0
toUserInfo, err := imdb.GetUserByUserID(v)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), v)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
}
3 years ago
if imdb.IsExistGroupMember(req.GroupID, v) {
log.NewError(req.OperationID, "IsExistGroupMember ", req.GroupID, v)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
}
var toInsertInfo db.GroupMember
utils.CopyStructFields(&toInsertInfo, toUserInfo)
toInsertInfo.GroupID = req.GroupID
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
toInsertInfo.OperatorUserID = req.OpUserID
toInsertInfo.InviterUserID = req.OpUserID
toInsertInfo.JoinSource = constant.JoinByInvitation
3 years ago
err = imdb.InsertIntoGroupMember(toInsertInfo)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceURL)
resultNode.Result = -1
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
continue
}
okUserIDList = append(okUserIDList, v)
err = db.DB.AddGroupMember(req.GroupID, toUserInfo.UserID)
if err != nil {
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), req.GroupID, toUserInfo.UserID)
}
3 years ago
resp.Id2ResultList = append(resp.Id2ResultList, &resultNode)
}
3 years ago
var haveConUserID []string
conversations, err := imdb.GetConversationsByConversationIDMultipleOwner(okUserIDList, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType))
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetConversationsByConversationIDMultipleOwner failed ", err.Error(), req.GroupID, constant.GroupChatType)
}
3 years ago
for _, v := range conversations {
haveConUserID = append(haveConUserID, v.OwnerUserID)
}
3 years ago
var reqPb pbUser.SetConversationReq
2 years ago
var c pbConversation.Conversation
3 years ago
for _, v := range conversations {
reqPb.OperationID = req.OperationID
c.OwnerUserID = v.OwnerUserID
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.RecvMsgOpt = v.RecvMsgOpt
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsPinned = v.IsPinned
c.AttachedInfo = v.AttachedInfo
c.IsPrivateChat = v.IsPrivateChat
c.GroupAtType = v.GroupAtType
c.IsNotInGroup = false
c.Ex = v.Ex
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
3 years ago
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.OwnerUserID)
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.OwnerUserID)
}
}
3 years ago
for _, v := range utils.DifferenceString(haveConUserID, okUserIDList) {
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 = false
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
3 years ago
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)
}
}
} else {
okUserIDList = req.InvitedUserIDList
if err := db.DB.AddUserToSuperGroup(req.GroupID, req.InvitedUserIDList); err != nil {
log.NewError(req.OperationID, "AddUserToSuperGroup failed ", req.GroupID, err)
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil
}
3 years ago
}
2 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
3 years ago
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
if groupInfo.GroupType != constant.SuperGroup {
for _, userID := range okUserIDList {
err = rocksCache.DelJoinedGroupIDListFromCache(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
}
}
2 years ago
3 years ago
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList)
3 years ago
} else {
for _, v := range req.InvitedUserIDList {
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(v); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
}
for _, v := range req.InvitedUserIDList {
chat.SuperGroupNotification(req.OperationID, v, v)
}
3 years ago
}
log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp)
return &resp, nil
}
func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String())
var resp pbGroup.GetGroupAllMemberResp
2 years ago
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
3 years ago
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg
return &resp, nil
}
3 years ago
if groupInfo.GroupType != constant.SuperGroup {
2 years ago
memberList, err := rocksCache.GetGroupMembersInfoFromCache(req.Count, req.Offset, req.GroupID)
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
3 years ago
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg
return &resp, nil
}
for _, v := range memberList {
var node open_im_sdk.GroupMemberFullInfo
2 years ago
cp.GroupMemberDBCopyOpenIM(&node, v)
3 years ago
resp.MemberList = append(resp.MemberList, &node)
}
3 years ago
}
2 years ago
log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", len(resp.MemberList))
return &resp, nil
}
func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GetGroupMemberList args ", req.String())
var resp pbGroup.GetGroupMemberListResp
3 years ago
memberList, err := imdb.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30)
if err != nil {
3 years ago
resp.ErrCode = constant.ErrDB.ErrCode
3 years ago
resp.ErrMsg = constant.ErrDB.ErrMsg
3 years ago
log.NewError(req.OperationID, "GetGroupMemberByGroupId failed,", req.GroupID, req.Filter, req.NextSeq, 30)
return &resp, nil
}
for _, v := range memberList {
3 years ago
var node open_im_sdk.GroupMemberFullInfo
3 years ago
utils.CopyStructFields(&node, &v)
resp.MemberList = append(resp.MemberList, &node)
}
//db operate get db sorted by join time
if int32(len(memberList)) < 30 {
resp.NextSeq = 0
} else {
resp.NextSeq = req.NextSeq + int32(len(memberList))
}
3 years ago
resp.ErrCode = 0
3 years ago
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
return &resp, nil
}
func (s *groupServer) getGroupUserLevel(groupID, userID string) (int, error) {
opFlag := 0
if !token_verify.IsManagerUserID(userID) {
opInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
if err != nil {
return opFlag, utils.Wrap(err, "")
}
if opInfo.RoleLevel == constant.GroupOrdinaryUsers {
opFlag = 0
} else if opInfo.RoleLevel == constant.GroupOwner {
opFlag = 2 //owner
} else {
opFlag = 3 //admin
}
} else {
opFlag = 1 //app manager
}
return opFlag, nil
}
func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGroupMemberReq) (*pbGroup.KickGroupMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String())
2 years ago
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupInfoByGroupID", req.GroupID, err.Error())
3 years ago
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
3 years ago
var okUserIDList []string
var resp pbGroup.KickGroupMemberResp
if groupInfo.GroupType != constant.SuperGroup {
opFlag := 0
if !token_verify.IsManagerUserID(req.OpUserID) {
2 years ago
opInfo, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, req.OpUserID)
if err != nil {
errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + err.Error() + req.GroupID + req.OpUserID
log.Error(req.OperationID, errMsg)
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
3 years ago
}
if opInfo.RoleLevel == constant.GroupOrdinaryUsers {
errMsg := req.OperationID + " opInfo.RoleLevel == constant.GroupOrdinaryUsers " + opInfo.UserID + opInfo.GroupID
log.Error(req.OperationID, errMsg)
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: errMsg}, nil
} else if opInfo.RoleLevel == constant.GroupOwner {
opFlag = 2 //owner
} else {
opFlag = 3 //admin
3 years ago
}
} else {
opFlag = 1 //app manager
}
//op is group owner?
3 years ago
if len(req.KickedUserIDList) == 0 {
log.NewError(req.OperationID, "failed, kick list 0")
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}, nil
}
3 years ago
3 years ago
//remove
for _, v := range req.KickedUserIDList {
2 years ago
kickedInfo, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, v)
if err != nil {
log.NewError(req.OperationID, " GetGroupMemberInfoByGroupIDAndUserID failed ", req.GroupID, v, err.Error())
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
continue
}
if kickedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
log.Error(req.OperationID, "is constant.GroupAdmin, can't kicked ", v)
3 years ago
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
continue
}
if kickedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
log.NewDebug(req.OperationID, "is constant.GroupOwner, can't kicked ", v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
continue
}
2 years ago
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, v)
3 years ago
if err != nil {
log.NewError(req.OperationID, "RemoveGroupMember failed ", err.Error(), req.GroupID, v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1})
} else {
log.NewDebug(req.OperationID, "kicked ", v)
resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0})
okUserIDList = append(okUserIDList, v)
}
}
3 years ago
var reqPb pbUser.SetConversationReq
2 years ago
var c pbConversation.Conversation
3 years ago
for _, v := range okUserIDList {
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
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
resp.ErrCode = constant.ErrInternal.ErrCode
resp.ErrMsg = errMsg
return &resp, nil
}
3 years ago
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)
}
}
3 years ago
} else {
okUserIDList = req.KickedUserIDList
if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, req.KickedUserIDList, err.Error())
resp.ErrCode = constant.ErrDB.ErrCode
resp.ErrMsg = constant.ErrDB.ErrMsg
return &resp, nil
}
}
3 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil
}
3 years ago
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
2 years ago
3 years ago
if groupInfo.GroupType != constant.SuperGroup {
for _, userID := range okUserIDList {
err = rocksCache.DelJoinedGroupIDListFromCache(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
}
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
}
2 years ago
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.MemberKickedNotification(req, okUserIDList)
3 years ago
} else {
for _, userID := range okUserIDList {
err = rocksCache.DelJoinedSuperGroupIDListFromCache(userID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID)
}
}
go func() {
for _, v := range req.KickedUserIDList {
chat.SuperGroupNotification(req.OperationID, v, v)
}
}()
3 years ago
}
2 years ago
3 years ago
log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String())
return &resp, nil
}
func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetGroupMembersInfoReq) (*pbGroup.GetGroupMembersInfoResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
var resp pbGroup.GetGroupMembersInfoResp
2 years ago
resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{}
2 years ago
for _, userID := range req.MemberList {
2 years ago
groupMember, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, userID)
2 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, userID, err.Error())
continue
}
2 years ago
var memberNode open_im_sdk.GroupMemberFullInfo
utils.CopyStructFields(&memberNode, groupMember)
memberNode.JoinTime = int32(groupMember.JoinTime.Unix())
resp.MemberList = append(resp.MemberList, &memberNode)
}
2 years ago
2 years ago
//groupMembers, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID)
//if err != nil {
// log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
// resp.ErrCode = constant.ErrDB.ErrCode
// resp.ErrMsg = constant.ErrDB.ErrMsg
// return &resp, nil
//}
//for _, member := range groupMembers {
// if utils.IsContain(member.UserID, req.MemberList) {
// var memberNode open_im_sdk.GroupMemberFullInfo
// utils.CopyStructFields(&memberNode, member)
// memberNode.JoinTime = int32(member.JoinTime.Unix())
// resp.MemberList = append(resp.MemberList, &memberNode)
// }
//}
3 years ago
resp.ErrCode = 0
3 years ago
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp.String())
return &resp, nil
}
3 years ago
3 years ago
func (s *groupServer) GetGroupApplicationList(_ context.Context, req *pbGroup.GetGroupApplicationListReq) (*pbGroup.GetGroupApplicationListResp, error) {
log.NewInfo(req.OperationID, "GetGroupApplicationList args ", req.String())
3 years ago
reply, err := imdb.GetGroupApplicationList(req.FromUserID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.FromUserID)
3 years ago
return &pbGroup.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
}
3 years ago
3 years ago
log.NewDebug(req.OperationID, "GetGroupApplicationList reply ", reply)
3 years ago
resp := pbGroup.GetGroupApplicationListResp{}
for _, v := range reply {
3 years ago
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
group, err := imdb.GetGroupInfoByGroupID(v.GroupID)
if err != nil {
log.Error(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), v.GroupID)
continue
}
if group.Status == constant.GroupStatusDismissed {
log.Debug(req.OperationID, "group constant.GroupStatusDismissed ", group.GroupID)
continue
}
3 years ago
user, err := imdb.GetUserByUserID(v.UserID)
if err != nil {
log.Error(req.OperationID, "GetUserByUserID failed ", err.Error(), v.UserID)
continue
}
3 years ago
cp.GroupRequestDBCopyOpenIM(&node, &v)
3 years ago
cp.UserDBCopyOpenIMPublicUser(node.UserInfo, user)
3 years ago
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
3 years ago
log.NewDebug(req.OperationID, "node ", node, "v ", v)
3 years ago
resp.GroupRequestList = append(resp.GroupRequestList, &node)
3 years ago
}
log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp)
return &resp, nil
3 years ago
}
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsInfoReq) (*pbGroup.GetGroupsInfoResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
groupsInfoList := make([]*open_im_sdk.GroupInfo, 0)
3 years ago
for _, groupID := range req.GroupIDList {
2 years ago
groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
3 years ago
continue
}
3 years ago
var groupInfo open_im_sdk.GroupInfo
2 years ago
cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis)
2 years ago
//groupInfo.NeedVerification
2 years ago
2 years ago
groupInfo.NeedVerification = groupInfoFromRedis.NeedVerification
3 years ago
groupsInfoList = append(groupsInfoList, &groupInfo)
}
3 years ago
resp := pbGroup.GetGroupsInfoResp{GroupInfoList: groupsInfoList}
2 years ago
log.NewInfo(req.OperationID, "GetGroupsInfo rpc return ", resp.String())
3 years ago
return &resp, nil
3 years ago
}
3 years ago
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
3 years ago
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
3 years ago
3 years ago
groupRequest := db.GroupRequest{}
3 years ago
utils.CopyStructFields(&groupRequest, req)
3 years ago
groupRequest.UserID = req.FromUserID
groupRequest.HandleUserID = req.OpUserID
3 years ago
groupRequest.HandledTime = time.Now()
3 years ago
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
log.NewError(req.OperationID, "IsManagerUserID IsGroupOwnerAdmin false ", req.GroupID, req.OpUserID)
3 years ago
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
3 years ago
err := imdb.UpdateGroupRequest(groupRequest)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), groupRequest)
3 years ago
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
request, err := imdb.GetGroupRequestByGroupIDAndUserID(req.GroupID, req.FromUserID)
if err != nil {
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.GroupID, req.FromUserID)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
3 years ago
if req.HandleResult == constant.GroupResponseAgree {
user, err := imdb.GetUserByUserID(req.FromUserID)
if err != nil {
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.FromUserID)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
3 years ago
member := db.GroupMember{}
member.GroupID = req.GroupID
member.UserID = req.FromUserID
member.RoleLevel = constant.GroupOrdinaryUsers
member.OperatorUserID = req.OpUserID
3 years ago
member.FaceURL = user.FaceURL
3 years ago
member.Nickname = user.Nickname
member.JoinSource = request.JoinSource
member.InviterUserID = request.InviterUserID
3 years ago
err = imdb.InsertIntoGroupMember(member)
if err != nil {
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
var reqPb pbUser.SetConversationReq
reqPb.OperationID = req.OperationID
2 years ago
var c pbConversation.Conversation
conversation, err := imdb.GetConversation(req.FromUserID, utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType))
if err != nil {
c.OwnerUserID = req.FromUserID
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsNotInGroup = false
} else {
c.OwnerUserID = conversation.OwnerUserID
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.RecvMsgOpt = conversation.RecvMsgOpt
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsPinned = conversation.IsPinned
c.AttachedInfo = conversation.AttachedInfo
c.IsPrivateChat = conversation.IsPrivateChat
c.GroupAtType = conversation.GroupAtType
c.IsNotInGroup = false
c.Ex = conversation.Ex
}
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
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())
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
}
2 years ago
2 years ago
etcdCacheConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
2 years ago
if etcdCacheConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
cacheClient := pbCache.NewCacheClient(etcdCacheConn)
2 years ago
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
if err := rocksCache.DelJoinedGroupIDListFromCache(req.FromUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.FromUserID, err.Error())
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.GroupApplicationAcceptedNotification(req)
3 years ago
chat.MemberEnterNotification(req)
3 years ago
} else if req.HandleResult == constant.GroupResponseRefuse {
chat.GroupApplicationRejectedNotification(req)
} else {
log.Error(req.OperationID, "HandleResult failed ", req.HandleResult)
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, "rpc GroupApplicationResponse return ", pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}})
3 years ago
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{}}, nil
3 years ago
}
3 years ago
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
3 years ago
_, err := imdb.GetUserByUserID(req.OpUserID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
3 years ago
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
3 years ago
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if groupInfo.Status == constant.GroupStatusDismissed {
errMsg := " group status is dismissed "
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
}
if groupInfo.NeedVerification == constant.Directly {
if groupInfo.GroupType != constant.SuperGroup {
2 years ago
us, err := imdb.GetUserByUserID(req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
//to group member
groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID}
2 years ago
utils.CopyStructFields(&groupMember, us)
err = imdb.InsertIntoGroupMember(groupMember)
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
}
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
err = rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
} else {
2 years ago
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType, "not support directly")
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
}
}
3 years ago
var groupRequest db.GroupRequest
3 years ago
groupRequest.UserID = req.OpUserID
groupRequest.ReqMsg = req.ReqMessage
groupRequest.GroupID = req.GroupID
groupRequest.JoinSource = req.JoinSource
3 years ago
err = imdb.InsertIntoGroupRequest(groupRequest)
3 years ago
if err != nil {
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
3 years ago
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
//_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner)
//if err != nil {
// log.NewError(req.OperationID, "GetGroupMemberListByGroupIDAndRoleLevel failed ", err.Error(), req.GroupID, constant.GroupOwner)
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
//}
3 years ago
3 years ago
chat.JoinGroupApplicationNotification(req)
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
3 years ago
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
3 years ago
}
3 years ago
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.QuitGroupResp, error) {
log.NewInfo(req.OperationID, "QuitGroup args ", req.String())
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
3 years ago
if err != nil {
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
3 years ago
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
if groupInfo.GroupType != constant.SuperGroup {
_, err = imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "GetGroupMemberInfoByGroupIDAndUserID failed ", err.Error(), req.GroupID, req.OpUserID)
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "DeleteGroupMemberByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.OpUserID)
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
err = db.DB.DelGroupMember(req.GroupID, req.OpUserID)
if err != nil {
log.NewError(req.OperationID, "DelGroupMember failed ", req.GroupID, req.OpUserID)
// return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
}
//modify quitter conversation info
var reqPb pbUser.SetConversationReq
2 years ago
var c pbConversation.Conversation
reqPb.OperationID = req.OperationID
c.OwnerUserID = req.OpUserID
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsNotInGroup = true
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
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())
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
}
} else {
okUserIDList := []string{req.OpUserID}
if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, okUserIDList, err.Error())
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
}
3 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
2 years ago
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
2 years ago
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil
}
2 years ago
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
GroupID: req.GroupID,
OperationID: req.OperationID,
})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
}
if groupInfo.GroupType != constant.SuperGroup {
if err := rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID)
}
2 years ago
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
2 years ago
}
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OpUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.MemberQuitNotification(req)
} else {
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(req.OpUserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID)
}
chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID)
}
3 years ago
log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}})
3 years ago
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
3 years ago
}
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
if utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
return true
}
2 years ago
groupUserInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupInfoForSet.GroupID, req.OpUserID)
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "GetGroupMemberInfoByGroupIDAndUserID failed, ", err.Error(), req.GroupInfoForSet.GroupID, req.OpUserID)
3 years ago
return false
}
3 years ago
if groupUserInfo.RoleLevel == constant.GroupOwner || groupUserInfo.RoleLevel == constant.GroupAdmin {
3 years ago
return true
}
3 years ago
return false
3 years ago
}
3 years ago
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
3 years ago
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
if !hasAccess(req) {
3 years ago
log.NewError(req.OperationID, "no access ", req)
3 years ago
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
3 years ago
}
2 years ago
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID)
3 years ago
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, http.WrapError(constant.ErrDB)
3 years ago
}
3 years ago
if group.Status == constant.GroupStatusDismissed {
errMsg := " group status is dismissed "
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner
3 years ago
var changedType int32
2 years ago
groupName := ""
notification := ""
introduction := ""
faceURL := ""
2 years ago
if group.GroupName != req.GroupInfoForSet.GroupName && req.GroupInfoForSet.GroupName != "" {
3 years ago
changedType = 1
2 years ago
groupName = req.GroupInfoForSet.GroupName
3 years ago
}
2 years ago
if group.Notification != req.GroupInfoForSet.Notification && req.GroupInfoForSet.Notification != "" {
3 years ago
changedType = changedType | (1 << 1)
2 years ago
notification = req.GroupInfoForSet.Notification
3 years ago
}
2 years ago
if group.Introduction != req.GroupInfoForSet.Introduction && req.GroupInfoForSet.Introduction != "" {
3 years ago
changedType = changedType | (1 << 2)
2 years ago
introduction = req.GroupInfoForSet.Introduction
3 years ago
}
2 years ago
if group.FaceURL != req.GroupInfoForSet.FaceURL && req.GroupInfoForSet.FaceURL != "" {
3 years ago
changedType = changedType | (1 << 3)
2 years ago
faceURL = req.GroupInfoForSet.FaceURL
3 years ago
}
2 years ago
if req.GroupInfoForSet.NeedVerification != nil {
changedType = changedType | (1 << 4)
m := make(map[string]interface{})
2 years ago
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
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)
}
}
2 years ago
if req.GroupInfoForSet.LookMemberInfo != nil {
changedType = changedType | (1 << 5)
m := make(map[string]interface{})
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
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)
}
}
if req.GroupInfoForSet.ApplyMemberFriend != nil {
changedType = changedType | (1 << 6)
m := make(map[string]interface{})
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
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)
}
}
//
//if req.RoleLevel != nil {
//
//}
3 years ago
//only administrators can set group information
3 years ago
var groupInfo db.Group
2 years ago
utils.CopyStructFields(&groupInfo, req.GroupInfoForSet)
if req.GroupInfoForSet.Notification != "" {
groupInfo.NotificationUserID = req.OpUserID
groupInfo.NotificationUpdateTime = time.Now()
}
3 years ago
err = imdb.SetGroupInfo(groupInfo)
if err != nil {
3 years ago
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
3 years ago
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
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)
}
3 years ago
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
3 years ago
if changedType != 0 {
2 years ago
chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification)
3 years ago
}
2 years ago
if req.GroupInfoForSet.Notification != "" {
//get group member user id
2 years ago
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupInfoForSet.GroupID}
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
}
client := pbCache.NewCacheClient(etcdConn)
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
if err != nil {
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error())
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
}
var conversationReq pbConversation.ModifyConversationFieldReq
conversation := pbConversation.Conversation{
OwnerUserID: req.OpUserID,
2 years ago
ConversationID: utils.GetConversationIDBySessionType(req.GroupInfoForSet.GroupID, constant.GroupChatType),
ConversationType: constant.GroupChatType,
2 years ago
GroupID: req.GroupInfoForSet.GroupID,
}
conversationReq.Conversation = &conversation
conversationReq.OperationID = req.OperationID
conversationReq.FieldType = constant.FieldGroupAtType
conversation.GroupAtType = constant.GroupNotification
conversationReq.UserIDList = cacheResp.UserIDList
2 years ago
nEtcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, http.WrapError(constant.ErrInternal)
}
nClient := pbConversation.NewConversationClient(nEtcdConn)
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
if err != nil {
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), err.Error())
} else if conversationReply.CommonResp.ErrCode != 0 {
log.NewError(conversationReq.OperationID, "ModifyConversationField rpc failed, ", conversationReq.String(), conversationReply.String())
}
}
3 years ago
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
3 years ago
}
3 years ago
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
3 years ago
log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String())
3 years ago
3 years ago
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
if groupInfo.Status == constant.GroupStatusDismissed {
errMsg := " group status is dismissed "
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
if req.OldOwnerUserID == req.NewOwnerUserID {
3 years ago
log.NewError(req.OperationID, "same owner ", req.OldOwnerUserID, req.NewOwnerUserID)
3 years ago
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
}
3 years ago
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers}
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
3 years ago
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
groupMemberInfo = db.GroupMember{GroupID: req.GroupID, UserID: req.NewOwnerUserID, RoleLevel: constant.GroupOwner}
3 years ago
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo)
3 years ago
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
}
2 years ago
err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.NewOwnerUserID)
if err != nil {
log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.NewOwnerUserID)
}
err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OldOwnerUserID)
if err != nil {
log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.OldOwnerUserID)
2 years ago
}
3 years ago
chat.GroupOwnerTransferredNotification(req)
3 years ago
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
3 years ago
}
3 years ago
2 years ago
func (s *groupServer) GetGroupByID(_ context.Context, req *pbGroup.GetGroupByIDReq) (*pbGroup.GetGroupByIDResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
2 years ago
resp := &pbGroup.GetGroupByIDResp{CMSGroup: &pbGroup.CMSGroup{
GroupInfo: &open_im_sdk.GroupInfo{},
3 years ago
}}
2 years ago
group, err := imdb.GetGroupInfoByGroupID(req.GroupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupById error", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
2 years ago
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(group.GroupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster", err.Error())
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
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
3 years ago
resp.CMSGroup.GroupInfo.CreatorUserID = group.CreatorUserID
2 years ago
resp.CMSGroup.GroupInfo.CreateTime = uint32(group.CreateTime.Unix())
2 years ago
utils.CopyStructFields(resp.CMSGroup.GroupInfo, group)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
3 years ago
return resp, nil
}
3 years ago
func (s *groupServer) GetGroup(_ context.Context, req *pbGroup.GetGroupReq) (*pbGroup.GetGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
3 years ago
resp := &pbGroup.GetGroupResp{
3 years ago
CMSGroups: []*pbGroup.CMSGroup{},
3 years ago
}
groups, err := imdb.GetGroupsByName(req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsByName error", req.String(), req.GroupName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "groups", groups)
nums, err := imdb.GetGroupsCountNum(db.Group{GroupName: req.GroupName})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupsCountNum error", err.Error(), req.GroupName)
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
resp.GroupNums = nums
3 years ago
resp.Pagination = &open_im_sdk.RequestPagination{
PageNumber: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
3 years ago
for _, v := range groups {
2 years ago
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
2 years ago
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster error", err.Error())
3 years ago
continue
3 years ago
}
2 years ago
2 years ago
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID
2 years ago
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
3 years ago
return resp, nil
}
func (s *groupServer) GetGroups(_ context.Context, req *pbGroup.GetGroupsReq) (*pbGroup.GetGroupsResp, error) {
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", req.String())
3 years ago
resp := &pbGroup.GetGroupsResp{
3 years ago
CMSGroups: []*pbGroup.CMSGroup{},
3 years ago
Pagination: &open_im_sdk.RequestPagination{},
}
3 years ago
groups, err := imdb.GetGroups(int(req.Pagination.PageNumber), int(req.Pagination.ShowNumber))
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroups error", err.Error())
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
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)
}
3 years ago
resp.Pagination.PageNumber = req.Pagination.PageNumber
resp.Pagination.ShowNumber = req.Pagination.ShowNumber
for _, v := range groups {
2 years ago
group := &pbGroup.CMSGroup{GroupInfo: &open_im_sdk.GroupInfo{}}
utils.CopyStructFields(group.GroupInfo, v)
2 years ago
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(v.GroupID)
3 years ago
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error(), v)
continue
3 years ago
}
2 years ago
group.GroupInfo.CreateTime = uint32(v.CreateTime.Unix())
group.GroupOwnerUserID = groupMember.UserID
2 years ago
group.GroupOwnerUserName = groupMember.Nickname
resp.CMSGroups = append(resp.CMSGroups, group)
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "GetGroups ", resp.String())
3 years ago
return resp, nil
}
3 years ago
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
3 years ago
resp := &pbGroup.OperateUserRoleResp{}
2 years ago
oldOwnerUserID, err := imdb.GetGroupOwnerInfoByGroupID(req.GroupID)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return resp, http.WrapError(constant.ErrInternal)
}
3 years ago
client := pbGroup.NewGroupClient(etcdConn)
var reqPb pbGroup.TransferGroupOwnerReq
reqPb.OperationID = req.OperationID
2 years ago
reqPb.NewOwnerUserID = req.UserID
reqPb.GroupID = req.GroupID
3 years ago
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 {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
}
}
3 years ago
return resp, nil
}
func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGroupMembersCMSReq) (*pbGroup.GetGroupMembersCMSResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
3 years ago
resp := &pbGroup.GetGroupMembersCMSResp{}
2 years ago
groupMembers, err := imdb.GetGroupMembersByGroupIdCMS(req.GroupID, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersByGroupIdCMS Error", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
2 years ago
groupMembersCount, err := imdb.GetGroupMembersCount(req.GroupID, req.UserName)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMembersCMS Error", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
3 years ago
}
3 years ago
log.NewInfo(req.OperationID, groupMembersCount)
2 years ago
resp.MemberNums = int32(groupMembersCount)
3 years ago
for _, groupMember := range groupMembers {
2 years ago
member := open_im_sdk.GroupMemberFullInfo{}
utils.CopyStructFields(&member, groupMember)
2 years ago
member.JoinTime = int32(groupMember.JoinTime.Unix())
member.MuteEndTime = uint32(groupMember.MuteEndTime.Unix())
2 years ago
resp.Members = append(resp.Members, &member)
3 years ago
}
3 years ago
resp.Pagination = &open_im_sdk.ResponsePagination{
CurrentPage: req.Pagination.PageNumber,
ShowNumber: req.Pagination.ShowNumber,
}
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp.String())
3 years ago
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{}
2 years ago
for _, userId := range req.UserIDList {
2 years ago
err := imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, userId)
3 years ago
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
resp.Failed = append(resp.Failed, userId)
} else {
resp.Success = append(resp.Success, userId)
}
}
3 years ago
reqKick := &pbGroup.KickGroupMemberReq{
2 years ago
GroupID: req.GroupID,
3 years ago
KickedUserIDList: resp.Success,
Reason: "admin kick",
OperationID: req.OperationID,
2 years ago
OpUserID: req.OpUserID,
3 years ago
}
var reqPb pbUser.SetConversationReq
2 years ago
var c pbConversation.Conversation
for _, v := range resp.Success {
reqPb.OperationID = req.OperationID
c.OwnerUserID = v
2 years ago
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
2 years ago
c.GroupID = req.GroupID
c.IsNotInGroup = true
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
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)
}
}
3 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
2 years ago
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
2 years ago
return resp, http.WrapError(constant.ErrDB)
}
2 years ago
cacheClient := pbCache.NewCacheClient(etcdConn)
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
2 years ago
GroupID: req.GroupID,
2 years ago
OperationID: req.OperationID,
})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return resp, http.WrapError(constant.ErrDB)
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
2 years ago
}
2 years ago
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
2 years ago
}
2 years ago
for _, userID := range resp.Success {
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, userID)
2 years ago
}
2 years ago
}
3 years ago
3 years ago
chat.MemberKickedNotification(reqKick, resp.Success)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp)
3 years ago
return resp, nil
}
func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGroupMembersCMSReq) (*pbGroup.AddGroupMembersCMSResp, error) {
2 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
3 years ago
resp := &pbGroup.AddGroupMembersCMSResp{}
2 years ago
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)
3 years ago
resp.Failed = append(resp.Failed, userId)
continue
}
user, err := imdb.GetUserByUserID(userId)
if err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserByUserID", err.Error())
3 years ago
resp.Failed = append(resp.Failed, userId)
continue
}
3 years ago
groupMember := db.GroupMember{
2 years ago
GroupID: req.GroupID,
3 years ago
UserID: userId,
Nickname: user.Nickname,
3 years ago
FaceURL: "",
3 years ago
RoleLevel: 1,
JoinTime: time.Time{},
JoinSource: constant.JoinByAdmin,
OperatorUserID: "CmsAdmin",
Ex: "",
}
if err := imdb.InsertIntoGroupMember(groupMember); err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), "InsertIntoGroupMember failed", req.String())
3 years ago
resp.Failed = append(resp.Failed, userId)
} else {
3 years ago
resp.Success = append(resp.Success, userId)
3 years ago
}
}
3 years ago
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
2 years ago
log.NewError(req.OperationID, errMsg)
2 years ago
return resp, http.WrapError(constant.ErrDB)
}
3 years ago
cacheClient := pbCache.NewCacheClient(etcdConn)
2 years ago
cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{
2 years ago
GroupID: req.GroupID,
OperationID: req.OperationID,
2 years ago
})
3 years ago
if err != nil {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error())
3 years ago
return resp, http.WrapError(constant.ErrDB)
}
if cacheResp.CommonResp.ErrCode != 0 {
2 years ago
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
3 years ago
return resp, http.WrapError(constant.ErrDB)
}
2 years ago
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
2 years ago
}
2 years ago
if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
2 years ago
}
3 years ago
2 years ago
chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, "admin add you to group", resp.Success)
3 years ago
return resp, nil
}
3 years ago
3 years ago
func (s *groupServer) GetUserReqApplicationList(_ context.Context, req *pbGroup.GetUserReqApplicationListReq) (*pbGroup.GetUserReqApplicationListResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
3 years ago
resp := &pbGroup.GetUserReqApplicationListResp{}
groupRequests, err := imdb.GetUserReqGroupByUserID(req.UserID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetUserReqGroupByUserID failed ", err.Error())
resp.CommonResp = &pbGroup.CommonResp{
ErrCode: constant.ErrDB.ErrCode,
ErrMsg: constant.ErrDB.ErrMsg,
}
return resp, nil
}
for _, groupReq := range groupRequests {
node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}}
group, err := imdb.GetGroupInfoByGroupID(groupReq.GroupID)
if err != nil {
log.Error(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupReq.GroupID)
continue
}
user, err := imdb.GetUserByUserID(groupReq.UserID)
if err != nil {
log.Error(req.OperationID, "GetUserByUserID failed ", err.Error(), groupReq.UserID)
continue
}
cp.GroupRequestDBCopyOpenIM(&node, &groupReq)
cp.UserDBCopyOpenIMPublicUser(node.UserInfo, user)
cp.GroupDBCopyOpenIM(node.GroupInfo, group)
resp.GroupRequestList = append(resp.GroupRequestList, &node)
}
resp.CommonResp = &pbGroup.CommonResp{
ErrCode: 0,
ErrMsg: "",
}
return resp, nil
3 years ago
}
3 years ago
func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
3 years ago
if !token_verify.IsManagerUserID(req.OpUserID) && !imdb.IsGroupOwnerAdmin(req.GroupID, req.OpUserID) {
3 years ago
log.NewError(req.OperationID, "verify failed ", req.OpUserID, req.GroupID)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
err := imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusDismissed)
if err != nil {
log.NewError(req.OperationID, "OperateGroupStatus failed ", req.GroupID, constant.GroupStatusDismissed)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
if err != nil {
3 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
3 years ago
if groupInfo.GroupType != constant.SuperGroup {
memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID)
if err != nil {
3 years ago
log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID)
}
3 years ago
//modify quitter conversation info
var reqPb pbUser.SetConversationReq
2 years ago
var c pbConversation.Conversation
3 years ago
for _, v := range memberList {
reqPb.OperationID = req.OperationID
c.OwnerUserID = v.UserID
c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType)
c.ConversationType = constant.GroupChatType
c.GroupID = req.GroupID
c.IsNotInGroup = true
reqPb.Conversation = &c
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
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.UserID)
} else {
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String(), v.UserID)
}
}
err = imdb.DeleteGroupMemberByGroupID(req.GroupID)
if err != nil {
log.NewError(req.OperationID, "DeleteGroupMemberByGroupID failed ", req.GroupID)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
chat.GroupDismissedNotification(req)
} else {
err = db.DB.DeleteSuperGroup(req.GroupID)
if err != nil {
log.NewError(req.OperationID, "DeleteGroupMemberByGroupID failed ", req.GroupID)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
3 years ago
3 years ago
}
3 years ago
}
2 years ago
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
2 years ago
if etcdConn == nil {
2 years ago
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
2 years ago
log.NewError(req.OperationID, errMsg)
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: errMsg}}, nil
}
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 &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil
}
if cacheResp.CommonResp.ErrCode != 0 {
log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
3 years ago
// rpc MuteGroupMember(MuteGroupMemberReq) returns(MuteGroupMemberResp);
// rpc CancelMuteGroupMember(CancelMuteGroupMemberReq) returns(CancelMuteGroupMemberResp);
// rpc MuteGroup(MuteGroupReq) returns(MuteGroupResp);
// rpc CancelMuteGroup(CancelMuteGroupReq) returns(CancelMuteGroupResp);
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
if err != nil {
errMsg := req.OperationID + " getGroupUserLevel failed " + req.GroupID + req.OpUserID + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
3 years ago
}
if opFlag == 0 {
errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
log.Error(req.OperationID, errMsg)
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
if err != nil {
2 years ago
errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.UserID + err.Error()
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
2 years ago
errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupOwner " + req.GroupID + req.UserID
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
2 years ago
errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.UserID
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
3 years ago
groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano())
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
3 years ago
if err != nil {
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
if err != nil {
errMsg := req.OperationID + " getGroupUserLevel failed " + req.GroupID + req.OpUserID + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if opFlag == 0 {
errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
log.Error(req.OperationID, errMsg)
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
3 years ago
}
mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
if err != nil {
2 years ago
errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.UserID + err.Error()
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
2 years ago
errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupOwner " + req.GroupID + req.UserID
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
2 years ago
errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.UserID
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
3 years ago
groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID}
groupMemberInfo.MuteEndTime = time.Unix(0, 0)
err = imdb.UpdateGroupMemberInfo(groupMemberInfo)
3 years ago
if err != nil {
log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo)
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (*pbGroup.MuteGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
if err != nil {
errMsg := req.OperationID + " getGroupUserLevel failed " + req.GroupID + req.OpUserID + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if opFlag == 0 {
errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
log.Error(req.OperationID, errMsg)
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID)
//if err != nil {
// errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
//if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
// errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupOwner " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
//if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
// errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
err = imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusMuted)
3 years ago
if err != nil {
log.Error(req.OperationID, "OperateGroupStatus failed ", err.Error(), req.GroupID, constant.GroupStatusMuted)
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
3 years ago
}
func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) {
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID)
if err != nil {
errMsg := req.OperationID + " getGroupUserLevel failed " + req.GroupID + req.OpUserID + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
if opFlag == 0 {
errMsg := req.OperationID + "opFlag == 0 " + req.GroupID + req.OpUserID
log.Error(req.OperationID, errMsg)
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
}
//mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.)
//if err != nil {
// errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
//if mutedInfo.RoleLevel == constant.GroupOwner && opFlag != 1 {
// errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupOwner " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
//if mutedInfo.RoleLevel == constant.GroupAdmin && opFlag == 3 {
// errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.OpUserID + err.Error()
// return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil
//}
2 years ago
log.Debug(req.OperationID, "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk})
err = imdb.UpdateGroupInfoDefaultZero(req.GroupID, map[string]interface{}{"status": constant.GroupOk})
3 years ago
if err != nil {
3 years ago
log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), req.GroupID)
3 years ago
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
3 years ago
chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID)
3 years ago
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
3 years ago
}
func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String())
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.OpUserID) {
errMsg := req.OperationID + " verify failed " + req.OpUserID + req.GroupID
log.Error(req.OperationID, errMsg)
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
}
groupMemberInfo := db.GroupMember{}
groupMemberInfo.UserID = req.UserID
groupMemberInfo.GroupID = req.GroupID
if req.Nickname == "" {
userNickname, err := imdb.GetUserNameByUserID(groupMemberInfo.UserID)
if err != nil {
errMsg := req.OperationID + " GetUserNameByUserID failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
groupMemberInfo.Nickname = userNickname
} else {
groupMemberInfo.Nickname = req.Nickname
}
err := imdb.UpdateGroupMemberInfo(groupMemberInfo)
if err != nil {
errMsg := req.OperationID + " UpdateGroupMemberInfo failed " + err.Error()
log.Error(req.OperationID, errMsg)
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
}
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil {
2 years ago
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
}
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""})
return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
}
func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (resp *pbGroup.SetGroupMemberInfoResp, err error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp = &pbGroup.SetGroupMemberInfoResp{CommonResp: &pbGroup.CommonResp{}}
groupMember := db.GroupMember{
GroupID: req.GroupID,
UserID: req.UserID,
}
m := make(map[string]interface{})
if req.RoleLevel != nil {
m["role_level"] = req.RoleLevel.Value
}
if req.FaceURL != nil {
m["user_group_face_url"] = req.FaceURL.Value
}
if req.Nickname != nil {
m["nickname"] = req.Nickname.Value
}
if req.Ex != nil {
m["ex"] = req.Ex.Value
}
err = imdb.UpdateGroupMemberInfoByMap(groupMember, m)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetGroupMemberInfo failed", err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error()
return resp, nil
}
2 years ago
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, req.UserID)
2 years ago
}
2 years ago
if req.RoleLevel != nil {
switch req.RoleLevel.Value {
case constant.GroupOrdinaryUsers:
2 years ago
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToOrdinaryUserNotification)
2 years ago
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
2 years ago
case constant.GroupAdmin, constant.GroupOwner:
2 years ago
//msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToAdminNotification)
2 years ago
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
2 years ago
}
} else {
chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID)
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
return resp, nil
}
2 years ago
func (s *groupServer) GetGroupAbstractInfo(c context.Context, req *pbGroup.GetGroupAbstractInfoReq) (*pbGroup.GetGroupAbstractInfoResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
resp := &pbGroup.GetGroupAbstractInfoResp{CommonResp: &pbGroup.CommonResp{}}
hashCode, err := rocksCache.GetGroupMemberListHashFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberListHashFromCache failed", req.GroupID, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.GroupMemberListHash = hashCode
num, err := rocksCache.GetGroupMemberNumFromCache(req.GroupID)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberNumByGroupID failed", req.GroupID, err.Error())
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.GroupMemberNumber = int32(num)
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String())
return resp, nil
}