Error code standardization

test-errcode
skiffer-git 2 years ago
parent 64caafd6b6
commit 5baf05ba5e

@ -0,0 +1,21 @@
package check
import (
discoveryRegistry "Open_IM/pkg/discoveryregistry"
"context"
)
type BlackChecker struct {
zk discoveryRegistry.SvcDiscoveryRegistry
}
func NewBlackChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *BlackChecker {
return &BlackChecker{
zk: zk,
}
}
// possibleBlackUserID是否被userID拉黑也就是是否在userID的黑名单中
func (b *BlackChecker) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
}

@ -29,3 +29,7 @@ func (c *ConversationChecker) ModifyConversationField(ctx context.Context, req *
func (c *ConversationChecker) getConn() (*grpc.ClientConn, error) {
return c.zk.GetConn(config.Config.RpcRegisterName.OpenImConversationName)
}
func (c *ConversationChecker) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
}

@ -34,3 +34,8 @@ func (f *FriendChecker) GetFriendsInfo(ctx context.Context, ownerUserID, friendU
func (f *FriendChecker) getConn() (*grpc.ClientConn, error) {
return f.zk.GetConn(config.Config.RpcRegisterName.OpenImFriendName)
}
// possibleFriendUserID是否在userID的好友中
func (f *FriendChecker) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
}

@ -102,3 +102,7 @@ func (u *UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string,
return e.UserID
}), nil
}
func (u *UserCheck) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
}

@ -1,10 +1,8 @@
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"
"Open_IM/pkg/proto/sdkws"
@ -58,8 +56,8 @@ type MsgCallBackResp struct {
}
}
func userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (isMute bool, err error) {
groupMemberInfo, err := check.NewGroupChecker().GetGroupMemberInfo(ctx, groupID, userID)
func (m *msgServer) userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (isMute bool, err error) {
groupMemberInfo, err := m.Group.GetGroupMemberInfo(ctx, groupID, userID)
if err != nil {
return false, err
}
@ -70,14 +68,14 @@ func userIsMuteAndIsAdminInGroup(ctx context.Context, groupID, userID string) (i
}
// 如果禁言了,再看下是否群管理员
func groupIsMuted(ctx context.Context, groupID string, userID string) (bool, bool, error) {
groupInfo, err := check.NewGroupChecker().GetGroupInfo(ctx, groupID)
func (m *msgServer) groupIsMuted(ctx context.Context, groupID string, userID string) (bool, bool, error) {
groupInfo, err := m.Group.GetGroupInfo(ctx, groupID)
if err != nil {
return false, false, err
}
if groupInfo.Status == constant.GroupStatusMuted {
groupMemberInfo, err := check.NewGroupChecker().GetGroupMemberInfo(ctx, groupID, userID)
groupMemberInfo, err := m.Group.GetGroupMemberInfo(ctx, groupID, userID)
if err != nil {
return false, false, err
}
@ -86,24 +84,10 @@ func groupIsMuted(ctx context.Context, groupID string, userID string) (bool, boo
return false, false, nil
}
func GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
return localcache.NewGroupMemberIDsLocalCache().GetGroupMemberIDs(ctx, groupID)
func (m *msgServer) GetGroupMemberIDs(ctx context.Context, groupID string) (groupMemberIDs []string, err error) {
return m.GroupLocalCache.GetGroupMemberIDs(ctx, groupID)
}
//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 (m *msgServer)GetSuperGroupMsg(ctx context.Context, groupID string, seq uint32) (*sdkws.MsgData, error) {
// return m.MsgInterface.GetSuperGroupMsg(ctx, groupID, seq)
//}
func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgReq) ([]string, error) {
switch data.MsgData.SessionType {
case constant.SingleChatType:
@ -113,7 +97,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin {
return nil, nil
}
black, err := IsBlocked(data.MsgData.SendID, data.MsgData.RecvID)
black, err := m.black.IsBlocked(ctx, data.MsgData.SendID, data.MsgData.RecvID)
if err != nil {
return nil, err
}
@ -121,7 +105,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
return nil, constant.ErrBlockedByPeer.Wrap()
}
if *config.Config.MessageVerify.FriendVerify {
friend, err := IsFriend(data.MsgData.SendID, data.MsgData.RecvID)
friend, err := m.friend.IsFriend(ctx, data.MsgData.SendID, data.MsgData.RecvID)
if err != nil {
return nil, err
}
@ -135,7 +119,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
if utils.IsContain(data.MsgData.SendID, config.Config.Manager.AppManagerUid) {
return nil, nil
}
userIDList, err := GetGroupMemberIDs(ctx, data.MsgData.GroupID)
userIDList, err := m.GetGroupMemberIDs(ctx, data.MsgData.GroupID)
if err != nil {
return nil, err
}
@ -148,7 +132,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
if !utils.IsContain(data.MsgData.SendID, userIDList) {
return nil, constant.ErrNotInGroupYet.Wrap()
}
isMute, err := userIsMuteAndIsAdminInGroup(ctx, data.MsgData.GroupID, data.MsgData.SendID)
isMute, err := m.userIsMuteAndIsAdminInGroup(ctx, data.MsgData.GroupID, data.MsgData.SendID)
if err != nil {
return nil, err
}
@ -156,7 +140,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
return nil, constant.ErrMutedInGroup.Wrap()
}
isMute, isAdmin, err := groupIsMuted(ctx, data.MsgData.GroupID, data.MsgData.SendID)
isMute, isAdmin, err := m.groupIsMuted(ctx, data.MsgData.GroupID, data.MsgData.SendID)
if err != nil {
return nil, err
}
@ -169,7 +153,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
}
return userIDList, nil
case constant.SuperGroupChatType:
groupInfo, err := check.NewGroupChecker().GetGroupInfo(ctx, data.MsgData.GroupID)
groupInfo, err := m.Group.GetGroupInfo(ctx, data.MsgData.GroupID)
if err != nil {
return nil, err
}
@ -199,7 +183,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
return nil, nil
}
userIDList, err := GetGroupMemberIDs(ctx, data.MsgData.GroupID)
userIDList, err := m.GetGroupMemberIDs(ctx, data.MsgData.GroupID)
if err != nil {
return nil, err
}
@ -213,7 +197,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
return nil, constant.ErrNotInGroupYet.Wrap()
}
}
isMute, err := userIsMuteAndIsAdminInGroup(ctx, data.MsgData.GroupID, data.MsgData.SendID)
isMute, err := m.userIsMuteAndIsAdminInGroup(ctx, data.MsgData.GroupID, data.MsgData.SendID)
if err != nil {
return nil, err
}
@ -221,7 +205,7 @@ func (m *msgServer) messageVerification(ctx context.Context, data *msg.SendMsgRe
return nil, constant.ErrMutedInGroup.Wrap()
}
isMute, isAdmin, err := groupIsMuted(ctx, data.MsgData.GroupID, data.MsgData.SendID)
isMute, isAdmin, err := m.groupIsMuted(ctx, data.MsgData.GroupID, data.MsgData.SendID)
if err != nil {
return nil, err
}
@ -289,27 +273,8 @@ func GetMsgID(sendID string) string {
return utils.Md5(t + "-" + sendID + "-" + strconv.Itoa(rand.Int()))
}
func GetUserGlobalMsgRecvOpt(userID string) (int32, error) {
}
// possibleBlackUserID是否被userID拉黑也就是是否在userID的黑名单中
func IsBlocked(possibleBlackUserID, userID string) (bool, error) {
}
// possibleFriendUserID是否在userID的好友中
func IsFriend(possibleFriendUserID, userID string) (bool, error) {
}
// 没找到不返回错误
func GetSingleConversationRecvMsgOpt(userID, conversationID string) (int32, error) {
}
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, pb *msg.SendMsgReq) (bool, error) {
opt, err := GetUserGlobalMsgRecvOpt(userID)
func (m *msgServer) modifyMessageByUserMessageReceiveOpt(ctx context.Context, userID, sourceID string, sessionType int, pb *msg.SendMsgReq) (bool, error) {
opt, err := m.User.GetUserGlobalMsgRecvOpt(ctx, userID)
if err != nil {
return false, err
}
@ -325,7 +290,7 @@ func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType i
return true, nil
}
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
singleOpt, err := GetSingleConversationRecvMsgOpt(userID, conversationID)
singleOpt, err := m.Conversation.GetSingleConversationRecvMsgOpt(ctx, userID, conversationID)
if err != nil {
return false, err
}
@ -334,7 +299,7 @@ func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType i
return true, nil
case constant.NotReceiveMessage:
if utils.IsContainInt(int(pb.MsgData.ContentType), ExcludeContentType) {
return true
return true, nil
}
return false, nil
case constant.ReceiveNotNotifyMessage:
@ -378,7 +343,7 @@ func (m *msgServer) sendMsgToGroupOptimization(ctx context.Context, list []strin
options[k] = v
}
groupPB.MsgData.Options = options
isSend, err := modifyMessageByUserMessageReceiveOpt(v, groupPB.MsgData.GroupID, constant.GroupChatType, groupPB)
isSend, err := m.modifyMessageByUserMessageReceiveOpt(ctx, v, groupPB.MsgData.GroupID, constant.GroupChatType, groupPB)
if err != nil {
wg.Done()
return err

@ -15,7 +15,7 @@ import (
func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
promePkg.PromeInc(promePkg.WorkSuperGroupChatMsgRecvSuccessCounter)
// callback
if err = callbackBeforeSendGroupMsg(req); err != nil {
if err = CallbackBeforeSendGroupMsg(ctx, req); err != nil {
return nil, err
}
@ -29,7 +29,7 @@ func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *msg.SendMsgR
return nil, err
}
// callback
if err = callbackAfterSendGroupMsg(req); err != nil {
if err = CallbackAfterSendGroupMsg(ctx, req); err != nil {
return nil, err
}
@ -60,7 +60,7 @@ func (m *msgServer) sendMsgNotification(ctx context.Context, req *msg.SendMsgReq
func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
promePkg.PromeInc(promePkg.SingleChatMsgRecvSuccessCounter)
if err = callbackBeforeSendSingleMsg(req); err != nil {
if err = CallbackBeforeSendSingleMsg(ctx, req); err != nil {
return nil, err
}
_, err = m.messageVerification(ctx, req)
@ -84,7 +84,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq)
return nil, constant.ErrInternalServer.Wrap("insert to mq")
}
}
err = callbackAfterSendSingleMsg(req)
err = CallbackAfterSendSingleMsg(ctx, req)
if err != nil {
return nil, err
}
@ -98,7 +98,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq)
func (m *msgServer) sendMsgGroupChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
// callback
promePkg.PromeInc(promePkg.GroupChatMsgRecvSuccessCounter)
err = callbackBeforeSendGroupMsg(req)
err = CallbackBeforeSendGroupMsg(ctx, req)
if err != nil {
return nil, err
}
@ -163,7 +163,7 @@ func (m *msgServer) sendMsgGroupChat(ctx context.Context, req *msg.SendMsgReq) (
wg.Wait()
// callback
err = callbackAfterSendGroupMsg(req)
err = CallbackAfterSendGroupMsg(ctx, req)
if err != nil {
return nil, err
}
@ -234,7 +234,7 @@ func (m *msgServer) SendMsg(ctx context.Context, req *msg.SendMsgReq) (resp *msg
return nil, constant.ErrMessageHasReadDisable.Wrap()
}
m.encapsulateMsgData(req.MsgData)
if err := callbackMsgModify(req); err != nil {
if err := CallbackMsgModify(ctx, req); err != nil {
return nil, err
}
switch req.MsgData.SessionType {

@ -3,6 +3,7 @@ package msg
import (
"Open_IM/internal/common/check"
"Open_IM/pkg/common/db/controller"
"Open_IM/pkg/common/db/localcache"
"Open_IM/pkg/common/db/relation"
tablerelation "Open_IM/pkg/common/db/table/relation"
discoveryRegistry "Open_IM/pkg/discoveryregistry"
@ -19,6 +20,9 @@ type msgServer struct {
Group *check.GroupChecker
User *check.UserCheck
Conversation *check.ConversationChecker
friend *check.FriendChecker
*localcache.GroupLocalCache
black *check.BlackChecker
}
type deleteMsg struct {
@ -41,7 +45,10 @@ func Start(client *openKeeper.ZkClient, server *grpc.Server) error {
User: check.NewUserCheck(client),
Group: check.NewGroupChecker(client),
//MsgInterface: controller.MsgInterface(),
RegisterCenter: client,
RegisterCenter: client,
GroupLocalCache: localcache.NewGroupMemberIDsLocalCache(client),
black: check.NewBlackChecker(client),
friend: check.NewFriendChecker(client),
}
s.initPrometheus()
msg.RegisterMsgServer(server, s)

@ -128,7 +128,13 @@ message userRegisterResp {
}
message getGlobalRecvMessageOptReq{
string userID = 1;
}
message getGlobalRecvMessageOptResp{
int32 globalRecvMsgOpt = 1;
}
service user {
//
@ -137,8 +143,10 @@ service user {
rpc updateUserInfo(updateUserInfoReq) returns(updateUserInfoResp);
//
rpc setGlobalRecvMessageOpt(setGlobalRecvMessageOptReq) returns(setGlobalRecvMessageOptResp);
//
rpc getGlobalRecvMessageOpt(getGlobalRecvMessageOptReq) returns(getGlobalRecvMessageOptResp);
//userID
rpc accountCheck(accountCheckReq)returns(accountCheckResp);
rpc accountCheck(accountCheckReq) returns (accountCheckResp);
//userID
rpc getPaginationUsers(getPaginationUsersReq) returns (getPaginationUsersResp);
//

Loading…
Cancel
Save