test-errcode
withchao 2 years ago
parent a9dec0c832
commit d7ea41fa1a

@ -2,16 +2,20 @@ package check
import (
sdkws "Open_IM/pkg/proto/sdkws"
"context"
"errors"
)
type GroupChecker struct {
type GroupChecker struct{}
func NewGroupChecker() GroupChecker {
return GroupChecker{}
}
func NewGroupChecker() *GroupChecker {
return &GroupChecker{}
func (GroupChecker) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
return nil, errors.New("TODO:GetUserInfo")
}
func (g *GroupChecker) GetGroupInfo(groupID string) (*sdkws.GroupInfo, error) {
func (GroupChecker) GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
return nil, errors.New("TODO:GetUserInfo")
}

@ -10,28 +10,28 @@ import (
// return nil, errors.New("TODO:GetUserInfo")
//}
func NewUserCheck() *UserCheck {
return &UserCheck{}
func NewUserCheck() UserCheck {
return UserCheck{}
}
type UserCheck struct{}
func (u *UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
func (UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
return nil, errors.New("todo")
}
func (u *UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
func (UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
return nil, errors.New("todo")
}
func (u *UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
func (UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
return nil, errors.New("todo")
}
func (u *UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
func (UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
return nil, errors.New("todo")
}
func (u *UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
func (UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
return nil, errors.New("todo")
}

@ -1,4 +1,4 @@
package msg
package notification
import (
"Open_IM/pkg/common/config"
@ -70,7 +70,7 @@ func ConversationChangeNotification(ctx context.Context, userID string) {
SetConversationNotification(operationID, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
}
//会话未读数同步
// 会话未读数同步
func ConversationUnreadChangeNotification(context context.Context, userID, conversationID string, updateUnreadCountTime int64) {
log.NewInfo(operationID, utils.GetSelfFuncName())
ConversationChangedTips := &sdkws.ConversationUpdateTips{

@ -7,36 +7,36 @@ import (
"context"
)
func (s *msgServer) DelMsgList(ctx context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
func (m *msgServer) DelMsgList(ctx context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
resp := &common.DelMsgListResp{}
if err := s.MsgInterface.DelMsgFromCache(ctx, req.UserID, req.SeqList); err != nil {
if err := m.MsgInterface.DelMsgFromCache(ctx, req.UserID, req.SeqList); err != nil {
return nil, err
}
DeleteMessageNotification(ctx, req.UserID, req.SeqList)
return resp, nil
}
func (s *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
func (m *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
resp := &msg.DelSuperGroupMsgResp{}
if err := tokenverify.CheckAdmin(ctx); err != nil {
return nil, err
}
maxSeq, err := s.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID)
maxSeq, err := m.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID)
if err != nil {
return nil, err
}
if err := s.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
if err := m.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
return nil, err
}
return resp, nil
}
func (s *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.ClearMsgResp, error) {
func (m *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.ClearMsgResp, error) {
resp := &msg.ClearMsgResp{}
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
return nil, err
}
if err := s.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil {
if err := m.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil {
return nil, err
}
return resp, nil

@ -14,8 +14,8 @@ import (
"time"
)
func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg.SetMessageReactionExtensionsReq) (resp *msg.SetMessageReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc args is:", req.String())
func (m *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg.SetMessageReactionExtensionsReq) (resp *msg.SetMessageReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m args is:", req.String())
var rResp msg.SetMessageReactionExtensionsResp
rResp.ClientMsgID = req.ClientMsgID
rResp.MsgFirstModifyTime = req.MsgFirstModifyTime
@ -72,7 +72,7 @@ func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg
log.Debug(req.OperationID, "redis handle firstly", req.String())
rResp.MsgFirstModifyTime = utils.GetCurrentTimestampByMill()
for k, v := range req.ReactionExtensionList {
err := rpc.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, k)
err := m.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, k)
if err != nil {
setKeyResultInfo(&rResp, 100, err.Error(), req.ClientMsgID, k, v)
continue
@ -91,7 +91,7 @@ func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg
log.Error(req.OperationID, "SetMessageReactionExpire err:", err.Error(), req.String())
}
} else {
err := rpc.dMessageLocker.LockGlobalMessage(req.ClientMsgID)
err := m.dMessageLocker.LockGlobalMessage(req.ClientMsgID)
if err != nil {
rResp.ErrCode = 100
rResp.ErrMsg = err.Error()
@ -149,7 +149,7 @@ func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg
rResp.Result = append(rResp.Result, temp)
}
}
lockErr := rpc.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
lockErr := m.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
if lockErr != nil {
log.Error(req.OperationID, "UnLockGlobalMessage err:", lockErr.Error())
}
@ -159,7 +159,7 @@ func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg
log.Debug(req.OperationID, "redis handle secondly", req.String())
for k, v := range req.ReactionExtensionList {
err := rpc.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, k)
err := m.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, k)
if err != nil {
setKeyResultInfo(&rResp, 100, err.Error(), req.ClientMsgID, k, v)
continue
@ -195,7 +195,7 @@ func (rpc *msgServer) SetMessageReactionExtensions(ctx context.Context, req *msg
} else {
notification.ExtendMessageUpdatedNotification(req.OperationID, req.OpUserID, req.SourceID, req.SessionType, req, &rResp, false, true)
}
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc return is:", rResp.String())
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", rResp.String())
return &rResp, nil
}
@ -216,8 +216,8 @@ func setDeleteKeyResultInfo(r *msg.DeleteMessageListReactionExtensionsResp, errC
_ = db.DB.UnLockMessageTypeKey(clientMsgID, typeKey)
}
func (rpc *msgServer) GetMessageListReactionExtensions(ctx context.Context, req *msg.GetMessageListReactionExtensionsReq) (resp *msg.GetMessageListReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc args is:", req.String())
func (m *msgServer) GetMessageListReactionExtensions(ctx context.Context, req *msg.GetMessageListReactionExtensionsReq) (resp *msg.GetMessageListReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m args is:", req.String())
var rResp msg.GetMessageListReactionExtensionsResp
for _, messageValue := range req.MessageReactionKeyList {
var oneMessage msg.SingleMessageExtensionResult
@ -267,17 +267,17 @@ func (rpc *msgServer) GetMessageListReactionExtensions(ctx context.Context, req
}
rResp.SingleMessageResult = append(rResp.SingleMessageResult, &oneMessage)
}
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc return is:", rResp.String())
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", rResp.String())
return &rResp, nil
}
func (rpc *msgServer) AddMessageReactionExtensions(ctx context.Context, req *msg.ModifyMessageReactionExtensionsReq) (resp *msg.ModifyMessageReactionExtensionsResp, err error) {
func (m *msgServer) AddMessageReactionExtensions(ctx context.Context, req *msg.ModifyMessageReactionExtensionsReq) (resp *msg.ModifyMessageReactionExtensionsResp, err error) {
return
}
func (rpc *msgServer) DeleteMessageReactionExtensions(ctx context.Context, req *msg.DeleteMessageListReactionExtensionsReq) (resp *msg.DeleteMessageListReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc args is:", req.String())
func (m *msgServer) DeleteMessageReactionExtensions(ctx context.Context, req *msg.DeleteMessageListReactionExtensionsReq) (resp *msg.DeleteMessageListReactionExtensionsResp, err error) {
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m args is:", req.String())
var rResp msg.DeleteMessageListReactionExtensionsResp
callbackResp := notification.callbackDeleteMessageReactionExtensions(req)
if callbackResp.ActionCode != constant.ActionAllow || callbackResp.ErrCode != 0 {
@ -328,7 +328,7 @@ func (rpc *msgServer) DeleteMessageReactionExtensions(ctx context.Context, req *
if isExists {
log.Debug(req.OperationID, "redis handle this delete", req.String())
for _, v := range req.ReactionExtensionList {
err := rpc.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, v.TypeKey)
err := m.dMessageLocker.LockMessageTypeKey(req.ClientMsgID, v.TypeKey)
if err != nil {
setDeleteKeyResultInfo(&rResp, 100, err.Error(), req.ClientMsgID, v.TypeKey, v)
continue
@ -354,7 +354,7 @@ func (rpc *msgServer) DeleteMessageReactionExtensions(ctx context.Context, req *
}
}
} else {
err := rpc.dMessageLocker.LockGlobalMessage(req.ClientMsgID)
err := m.dMessageLocker.LockGlobalMessage(req.ClientMsgID)
if err != nil {
rResp.ErrCode = 100
rResp.ErrMsg = err.Error()
@ -413,13 +413,13 @@ func (rpc *msgServer) DeleteMessageReactionExtensions(ctx context.Context, req *
rResp.Result = append(rResp.Result, temp)
}
}
lockErr := rpc.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
lockErr := m.dMessageLocker.UnLockGlobalMessage(req.ClientMsgID)
if lockErr != nil {
log.Error(req.OperationID, "UnLockGlobalMessage err:", lockErr.Error())
}
}
notification.ExtendMessageDeleteNotification(req.OperationID, req.OpUserID, req.SourceID, req.SessionType, req, &rResp, false, isExists)
log.Debug(req.OperationID, utils.GetSelfFuncName(), "rpc return is:", rResp.String())
log.Debug(req.OperationID, utils.GetSelfFuncName(), "m return is:", rResp.String())
return &rResp, nil
}

@ -7,17 +7,17 @@ import (
"context"
)
func (s *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgStatusReq) (*pbMsg.SetSendMsgStatusResp, error) {
func (m *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgStatusReq) (*pbMsg.SetSendMsgStatusResp, error) {
resp := &pbMsg.SetSendMsgStatusResp{}
if err := s.MsgInterface.SetSendMsgStatus(ctx, tracelog.GetOperationID(ctx), req.Status); err != nil {
if err := m.MsgInterface.SetSendMsgStatus(ctx, tracelog.GetOperationID(ctx), req.Status); err != nil {
return nil, err
}
return resp, nil
}
func (s *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (*pbMsg.GetSendMsgStatusResp, error) {
func (m *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (*pbMsg.GetSendMsgStatusResp, error) {
resp := &pbMsg.GetSendMsgStatusResp{}
status, err := s.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
status, err := m.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
if IsNotFound(err) {
resp.Status = constant.MsgStatusNotExist
return resp, nil

@ -1,11 +1,13 @@
package msg
import (
"Open_IM/internal/common/check"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/localcache"
"Open_IM/pkg/common/tracelog"
"Open_IM/pkg/proto/msg"
sdkws "Open_IM/pkg/proto/sdkws"
"Open_IM/pkg/proto/sdkws"
"Open_IM/pkg/utils"
"context"
"math/rand"
@ -57,7 +59,7 @@ type MsgCallBackResp struct {
}
func userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (isMute bool, err error) {
groupMemberInfo, err := GetGroupMemberInfo(ctx, groupID, userID)
groupMemberInfo, err := check.NewGroupChecker().GetGroupMemberInfo(ctx, groupID, userID)
if err != nil {
return false, err
}
@ -69,13 +71,13 @@ func userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (i
// 如果禁言了,再看下是否群管理员
func groupIsMuted(ctx context.Context, groupID string, userID string) (bool, bool, error) {
groupInfo, err := GetGroupInfo(ctx, groupID)
groupInfo, err := check.NewGroupChecker().GetGroupInfo(ctx, groupID)
if err != nil {
return false, false, err
}
if groupInfo.Status == constant.GroupStatusMuted {
groupMemberInfo, err := GetGroupMemberInfo(ctx, groupID, userID)
groupMemberInfo, err := check.NewGroupChecker().GetGroupMemberInfo(ctx, groupID, userID)
if err != nil {
return false, false, err
}
@ -85,20 +87,24 @@ func groupIsMuted(ctx context.Context, groupID string, userID string) (bool, boo
}
func GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
return localcache.NewGroupMemberIDsLocalCache().GetGroupMemberIDs(ctx, groupID)
}
func GetGroupInfo(ctx context.Context, groupID string) (sdkws.GroupInfo, error) {
//func GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
// return check.NewGroupChecker().GetGroupInfo(ctx, groupID)
//
//
//}
}
//func GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
// check.NewGroupChecker().GetGroupMemberInfo
//}
func GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
//func (m *msgServer)GetSuperGroupMsg(ctx context.Context, groupID string, seq uint32) (*sdkws.MsgData, error) {
// return m.MsgInterface.GetSuperGroupMsg(ctx, groupID, seq)
//}
}
func GetSuperGroupMsg(ctx context.Context, groupID string, seq uint32) (*sdkws.MsgData, error) {
}
func (rpc *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) ([]string, error) {
func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) ([]string, error) {
switch data.MsgData.SessionType {
case constant.SingleChatType:
if utils.IsContain(data.MsgData.SendID, config.Config.Manager.AppManagerUid) {
@ -163,7 +169,7 @@ func (rpc *msgServer) messageVerification(ctx context.Context, data *msg.SendMsg
}
return userIDList, nil
case constant.SuperGroupChatType:
groupInfo, err := GetGroupInfo(ctx, data.MsgData.GroupID)
groupInfo, err := check.NewGroupChecker().GetGroupInfo(ctx, data.MsgData.GroupID)
if err != nil {
return nil, err
}
@ -175,7 +181,7 @@ func (rpc *msgServer) messageVerification(ctx context.Context, data *msg.SendMsg
}
if revokeMessage.RevokerID != revokeMessage.SourceMessageSendID {
resp, err := GetSuperGroupMsg(ctx, data.MsgData.GroupID, revokeMessage.Seq)
resp, err := m.MsgInterface.GetSuperGroupMsg(ctx, data.MsgData.GroupID, revokeMessage.Seq)
if err != nil {
return nil, err
}
@ -231,7 +237,7 @@ func (rpc *msgServer) messageVerification(ctx context.Context, data *msg.SendMsg
return nil, nil
}
}
func (rpc *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
func (m *msgServer) encapsulateMsgData(msg *sdkws.MsgData) {
msg.ServerMsgID = GetMsgID(msg.SendID)
msg.SendTime = utils.GetCurrentTimestampByMill()
switch msg.ContentType {

@ -75,7 +75,7 @@ func (rpc *rpcChat) initPrometheus() {
promePkg.NewWorkSuperGroupChatMsgProcessFailedCounter()
}
func (rpc *msgServer) Run() {
func (m *msgServer) Run() {
log.Info("", "rpcChat init...")
listenIP := ""
if config.Config.ListenIP == "" {
@ -83,10 +83,10 @@ func (rpc *msgServer) Run() {
} else {
listenIP = config.Config.ListenIP
}
address := listenIP + ":" + strconv.Itoa(rpc.rpcPort)
address := listenIP + ":" + strconv.Itoa(m.rpcPort)
listener, err := net.Listen("tcp", address)
if err != nil {
panic("listening err:" + err.Error() + rpc.rpcRegisterName)
panic("listening err:" + err.Error() + m.rpcRegisterName)
}
log.Info("", "listen network success, address ", address)
recvSize := 1024 * 1024 * 30
@ -109,26 +109,26 @@ func (rpc *msgServer) Run() {
defer srv.GracefulStop()
rpcRegisterIP := config.Config.RpcRegisterIP
msg.RegisterMsgServer(srv, rpc)
msg.RegisterMsgServer(srv, m)
if config.Config.RpcRegisterIP == "" {
rpcRegisterIP, err = utils.GetLocalIP()
if err != nil {
log.Error("", "GetLocalIP failed ", err.Error())
}
}
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), rpcRegisterIP, rpc.rpcPort, rpc.rpcRegisterName, 10, "")
err = getcdv3.RegisterEtcd(m.etcdSchema, strings.Join(m.etcdAddr, ","), rpcRegisterIP, m.rpcPort, m.rpcRegisterName, 10, "")
if err != nil {
log.Error("", "register rpcChat to etcd failed ", err.Error())
panic(utils.Wrap(err, "register chat module rpc to etcd err"))
panic(utils.Wrap(err, "register chat module m to etcd err"))
}
go rpc.runCh()
rpc.initPrometheus()
go m.runCh()
m.initPrometheus()
err = srv.Serve(listener)
if err != nil {
log.Error("", "rpc rpcChat failed ", err.Error())
log.Error("", "m rpcChat failed ", err.Error())
return
}
log.Info("", "rpc rpcChat init success")
log.Info("", "m rpcChat init success")
}
func (rpc *rpcChat) runCh() {

@ -33,6 +33,7 @@ type MsgInterface interface {
GetUserMinSeq(ctx context.Context, userID string) (uint32, error)
GetMessageListBySeq(ctx context.Context, userID string, seqs []uint32) ([]*sdkws.MsgData, error)
GetSuperGroupMsg(ctx context.Context, groupID string, seq uint32) (*sdkws.MsgData, error)
}
type MsgDatabaseInterface interface {

@ -24,8 +24,8 @@ type GroupMemberIDsHash struct {
userIDs []string
}
func NewGroupMemberIDsLocalCache(client discoveryRegistry.SvcDiscoveryRegistry) GroupLocalCache {
return GroupLocalCache{
func NewGroupMemberIDsLocalCache(client discoveryRegistry.SvcDiscoveryRegistry) *GroupLocalCache {
return &GroupLocalCache{
cache: make(map[string]GroupMemberIDsHash, 0),
client: client,
}

Loading…
Cancel
Save