mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-21 12:39:57 +08:00
group
This commit is contained in:
parent
d60d8096df
commit
42061ddaf0
@ -917,68 +917,62 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
|
|||||||
} else if req.HandleResult == constant.GroupResponseRefuse {
|
} else if req.HandleResult == constant.GroupResponseRefuse {
|
||||||
chat.GroupApplicationRejectedNotification(req)
|
chat.GroupApplicationRejectedNotification(req)
|
||||||
} else {
|
} else {
|
||||||
|
// TODO
|
||||||
SetErr(ctx, "", constant.ErrArgs, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
SetErr(ctx, "", constant.ErrArgs, &resp.CommonResp.ErrCode, &resp.CommonResp.ErrMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (resp *pbGroup.JoinGroupResp, _ error) {
|
||||||
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
resp = &pbGroup.JoinGroupResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||||
_, err := imdb.GetUserByUserID(req.OpUserID)
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
if err != nil {
|
defer func() {
|
||||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
|
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
|
if _, err := imdb.GetUserByUserID(req.OpUserID); err != nil {
|
||||||
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID)
|
||||||
groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
if groupInfo.Status == constant.GroupStatusDismissed {
|
if groupInfo.Status == constant.GroupStatusDismissed {
|
||||||
errMsg := " group status is dismissed "
|
// TODO
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
//errMsg := " group status is dismissed "
|
||||||
|
//return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
|
SetErrorForResp(constant.ErrArgs, resp.CommonResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if groupInfo.NeedVerification == constant.Directly {
|
if groupInfo.NeedVerification == constant.Directly {
|
||||||
if groupInfo.GroupType != constant.SuperGroup {
|
if groupInfo.GroupType != constant.SuperGroup {
|
||||||
us, err := imdb.GetUserByUserID(req.OpUserID)
|
us, err := imdb.GetUserByUserID(req.OpUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
//to group member
|
//to group member
|
||||||
groupMember := imdb.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID}
|
groupMember := imdb.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID}
|
||||||
utils.CopyStructFields(&groupMember, us)
|
utils.CopyStructFields(&groupMember, us)
|
||||||
callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex)
|
if err := CallbackBeforeMemberJoinGroup(ctx, req.OperationID, &groupMember, groupInfo.Ex); err != nil {
|
||||||
if callbackResp.ErrCode != 0 {
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp)
|
return
|
||||||
}
|
|
||||||
if callbackResp.ActionCode != constant.ActionAllow {
|
|
||||||
if callbackResp.ErrCode == 0 {
|
|
||||||
callbackResp.ErrCode = 201
|
|
||||||
}
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp)
|
|
||||||
return &pbGroup.JoinGroupResp{
|
|
||||||
CommonResp: &pbGroup.CommonResp{
|
|
||||||
ErrCode: int32(callbackResp.ErrCode),
|
|
||||||
ErrMsg: callbackResp.ErrMsg,
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil {
|
if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil {
|
||||||
log.NewError(req.OperationID, "DelGroupAndUserCache failed, ", err.Error(), req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = imdb.InsertIntoGroupMember(groupMember)
|
err = imdb.InsertIntoGroupMember(groupMember)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
var sessionType int
|
var sessionType int
|
||||||
if groupInfo.GroupType == constant.NormalGroup {
|
if groupInfo.GroupType == constant.NormalGroup {
|
||||||
@ -996,26 +990,22 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
|||||||
c.IsNotInGroup = false
|
c.IsNotInGroup = false
|
||||||
c.UpdateUnreadCountTime = utils.GetCurrentTimestampByMill()
|
c.UpdateUnreadCountTime = utils.GetCurrentTimestampByMill()
|
||||||
reqPb.Conversation = &c
|
reqPb.Conversation = &c
|
||||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
etcdConn, err := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||||
if etcdConn == nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
log.NewError(req.OperationID, errMsg)
|
return
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
}
|
||||||
client := pbUser.NewUserClient(etcdConn)
|
client := pbUser.NewUserClient(etcdConn)
|
||||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||||
if err != nil {
|
trace_log.SetContextInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb)
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetConversation rpc failed, ", reqPb.String(), err.Error())
|
|
||||||
} else {
|
|
||||||
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID)
|
||||||
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
|
return
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
|
||||||
} else {
|
} else {
|
||||||
log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType, "not support directly")
|
// todo
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
SetErrorForResp(constant.ErrArgs, resp.CommonResp)
|
||||||
|
return
|
||||||
|
//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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var groupRequest imdb.GroupRequest
|
var groupRequest imdb.GroupRequest
|
||||||
@ -1025,8 +1015,8 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
|||||||
groupRequest.JoinSource = req.JoinSource
|
groupRequest.JoinSource = req.JoinSource
|
||||||
err = imdb.InsertIntoGroupRequest(groupRequest)
|
err = imdb.InsertIntoGroupRequest(groupRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
//_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner)
|
//_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
@ -1034,39 +1024,43 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
|||||||
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
// return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||||
|
|
||||||
chat.JoinGroupApplicationNotification(req)
|
chat.JoinGroupApplicationNotification(req)
|
||||||
log.NewInfo(req.OperationID, "JoinGroup rpc return ")
|
return
|
||||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.QuitGroupResp, error) {
|
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (resp *pbGroup.QuitGroupResp, _ error) {
|
||||||
log.NewInfo(req.OperationID, "QuitGroup args ", req.String())
|
resp = &pbGroup.QuitGroupResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||||
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||||
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error())
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
if groupInfo.GroupType != constant.SuperGroup {
|
if groupInfo.GroupType != constant.SuperGroup {
|
||||||
_, err = imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
_, err = imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetGroupMemberInfoByGroupIDAndUserID failed ", err.Error(), req.GroupID, req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil {
|
if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil {
|
||||||
log.NewError(req.OperationID, "DelGroupAndUserCache failed, ", err.Error(), req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, req.OpUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "DeleteGroupMemberByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = db.DB.DelGroupMember(req.GroupID, req.OpUserID)
|
err = db.DB.DelGroupMember(req.GroupID, req.OpUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "DelGroupMember failed ", req.GroupID, req.OpUserID)
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
// return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
return
|
||||||
}
|
}
|
||||||
//modify quitter conversation info
|
//modify quitter conversation info
|
||||||
var reqPb pbUser.SetConversationReq
|
var reqPb pbUser.SetConversationReq
|
||||||
@ -1078,43 +1072,37 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
|||||||
c.GroupID = req.GroupID
|
c.GroupID = req.GroupID
|
||||||
c.IsNotInGroup = true
|
c.IsNotInGroup = true
|
||||||
reqPb.Conversation = &c
|
reqPb.Conversation = &c
|
||||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
etcdConn, err := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName, req.OperationID)
|
||||||
if etcdConn == nil {
|
if etcdConn == nil {
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
log.NewError(req.OperationID, errMsg)
|
return
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
}
|
||||||
client := pbUser.NewUserClient(etcdConn)
|
client := pbUser.NewUserClient(etcdConn)
|
||||||
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
respPb, err := client.SetConversation(context.Background(), &reqPb)
|
||||||
if err != nil {
|
trace_log.SetContextInfo(ctx, "SetConversation", err, "req", &reqPb, "resp", respPb)
|
||||||
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 {
|
} else {
|
||||||
okUserIDList := []string{req.OpUserID}
|
okUserIDList := []string{req.OpUserID}
|
||||||
if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil {
|
if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, okUserIDList, err.Error())
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if groupInfo.GroupType != constant.SuperGroup {
|
if groupInfo.GroupType != constant.SuperGroup {
|
||||||
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OpUserID); err != nil {
|
if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OpUserID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID)
|
trace_log.SetContextInfo(ctx, "DelGroupMemberInfoFromCache", err, "groupID", req.GroupID, "userID", req.OpUserID)
|
||||||
}
|
}
|
||||||
chat.MemberQuitNotification(req)
|
chat.MemberQuitNotification(req)
|
||||||
} else {
|
} else {
|
||||||
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(req.OpUserID); err != nil {
|
if err := rocksCache.DelJoinedSuperGroupIDListFromCache(req.OpUserID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID)
|
trace_log.SetContextInfo(ctx, "DelJoinedSuperGroupIDListFromCache", err, "userID", req.OpUserID)
|
||||||
}
|
}
|
||||||
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error())
|
trace_log.SetContextInfo(ctx, "DelGroupMemberListHashFromCache", err, "groupID", req.GroupID)
|
||||||
}
|
}
|
||||||
chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID)
|
chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID)
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{}})
|
return
|
||||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
||||||
@ -1133,22 +1121,28 @@ func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
|
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (resp *pbGroup.SetGroupInfoResp, err error) {
|
||||||
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
|
resp = &pbGroup.SetGroupInfoResp{CommonResp: &open_im_sdk.CommonResp{}}
|
||||||
|
ctx = trace_log.NewRpcCtx(ctx, utils.GetSelfFuncName(), req.OperationID)
|
||||||
|
defer func() {
|
||||||
|
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), nil, "rpc req ", req.String(), "rpc resp ", resp.String())
|
||||||
|
trace_log.ShowLog(ctx)
|
||||||
|
}()
|
||||||
if !hasAccess(req) {
|
if !hasAccess(req) {
|
||||||
log.NewError(req.OperationID, "no access ", req)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
group, err := imdb.GetGroupInfoByGroupID(req.GroupInfoForSet.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if group.Status == constant.GroupStatusDismissed {
|
if group.Status == constant.GroupStatusDismissed {
|
||||||
errMsg := " group status is dismissed "
|
// TODO
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
//errMsg := " group status is dismissed "
|
||||||
|
//return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrStatus.ErrCode, ErrMsg: errMsg}}, nil
|
||||||
|
SetErrorForResp(constant.ErrArgs, resp.CommonResp)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner
|
////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner
|
||||||
@ -1179,8 +1173,8 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
|
m["need_verification"] = req.GroupInfoForSet.NeedVerification.Value
|
||||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||||
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.GroupInfoForSet.LookMemberInfo != nil {
|
if req.GroupInfoForSet.LookMemberInfo != nil {
|
||||||
@ -1188,8 +1182,8 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
m["look_member_info"] = req.GroupInfoForSet.LookMemberInfo.Value
|
||||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||||
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
||||||
@ -1197,8 +1191,8 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
m["apply_member_friend"] = req.GroupInfoForSet.ApplyMemberFriend.Value
|
||||||
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
if err := imdb.UpdateGroupInfoDefaultZero(req.GroupInfoForSet.GroupID, m); err != nil {
|
||||||
log.NewError(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), m)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
@ -1213,13 +1207,13 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
groupInfo.NotificationUpdateTime = time.Now()
|
groupInfo.NotificationUpdateTime = time.Now()
|
||||||
}
|
}
|
||||||
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
|
if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
err = imdb.SetGroupInfo(groupInfo)
|
err = imdb.SetGroupInfo(groupInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo)
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
|
log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}})
|
||||||
if changedType != 0 {
|
if changedType != 0 {
|
||||||
@ -1228,21 +1222,24 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
if req.GroupInfoForSet.Notification != "" {
|
if req.GroupInfoForSet.Notification != "" {
|
||||||
//get group member user id
|
//get group member user id
|
||||||
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupInfoForSet.GroupID}
|
getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupInfoForSet.GroupID}
|
||||||
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
etcdConn, err := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID)
|
||||||
if etcdConn == nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
log.NewError(req.OperationID, errMsg)
|
return
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
}
|
||||||
client := pbCache.NewCacheClient(etcdConn)
|
client := pbCache.NewCacheClient(etcdConn)
|
||||||
cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq)
|
cacheResp, err := client.GetGroupMemberIDListFromCache(ctx, getGroupMemberIDListFromCacheReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error())
|
SetErrorForResp(constant.ErrIdentity, resp.CommonResp)
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
return
|
||||||
}
|
}
|
||||||
if cacheResp.CommonResp.ErrCode != 0 {
|
if cacheResp.CommonResp.ErrCode != 0 {
|
||||||
log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
//log.NewError(req.OperationID, "GetGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String())
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
//return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
||||||
|
// TODO
|
||||||
|
resp.CommonResp.ErrCode = cacheResp.CommonResp.ErrCode
|
||||||
|
resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg
|
||||||
|
return
|
||||||
}
|
}
|
||||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||||
|
|
||||||
@ -1257,21 +1254,16 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
|||||||
conversationReq.FieldType = constant.FieldGroupAtType
|
conversationReq.FieldType = constant.FieldGroupAtType
|
||||||
conversation.GroupAtType = constant.GroupNotification
|
conversation.GroupAtType = constant.GroupNotification
|
||||||
conversationReq.UserIDList = cacheResp.UserIDList
|
conversationReq.UserIDList = cacheResp.UserIDList
|
||||||
nEtcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName, req.OperationID)
|
nEtcdConn, err := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImConversationName, req.OperationID)
|
||||||
if etcdConn == nil {
|
if err != nil {
|
||||||
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
|
SetErrorForResp(err, resp.CommonResp)
|
||||||
log.NewError(req.OperationID, errMsg)
|
return
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil
|
|
||||||
}
|
}
|
||||||
nClient := pbConversation.NewConversationClient(nEtcdConn)
|
nClient := pbConversation.NewConversationClient(nEtcdConn)
|
||||||
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
|
conversationReply, err := nClient.ModifyConversationField(context.Background(), &conversationReq)
|
||||||
if err != nil {
|
trace_log.SetContextInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user