mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 11:36:44 +08:00
Error code standardization
This commit is contained in:
parent
b7d724a5e4
commit
05d00a8174
@ -11,4 +11,5 @@ func Access(ctx context.Context, ownerUserID string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return tokenverify.CheckAccessV3(ctx, ownerUserID)
|
return tokenverify.CheckAccessV3(ctx, ownerUserID)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
26
internal/common/check/msg.go
Normal file
26
internal/common/check/msg.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package check
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/config"
|
||||||
|
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||||
|
"Open_IM/pkg/proto/msg"
|
||||||
|
"context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MsgCheck struct {
|
||||||
|
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgCheck) getConn() (*grpc.ClientConn, error) {
|
||||||
|
return m.zk.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MsgCheck) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
|
||||||
|
cc, err := m.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
resp, err := msg.NewMsgClient(cc).SendMsg(ctx, req)
|
||||||
|
return resp, err
|
||||||
|
}
|
@ -4,8 +4,10 @@ import (
|
|||||||
"Open_IM/internal/common/check"
|
"Open_IM/internal/common/check"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/tracelog"
|
||||||
"Open_IM/pkg/proto/msg"
|
"Open_IM/pkg/proto/msg"
|
||||||
"Open_IM/pkg/proto/sdkws"
|
"Open_IM/pkg/proto/sdkws"
|
||||||
|
utils2 "Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
utils "github.com/OpenIMSDK/open_utils"
|
utils "github.com/OpenIMSDK/open_utils"
|
||||||
)
|
)
|
||||||
@ -13,6 +15,7 @@ import (
|
|||||||
type Check struct {
|
type Check struct {
|
||||||
user *check.UserCheck
|
user *check.UserCheck
|
||||||
group *check.GroupChecker
|
group *check.GroupChecker
|
||||||
|
msg *check.MsgCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationMsg struct {
|
type NotificationMsg struct {
|
||||||
@ -26,28 +29,33 @@ type NotificationMsg struct {
|
|||||||
SenderFaceURL string
|
SenderFaceURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Check) Notification(ctx context.Context, n *NotificationMsg) {
|
func (c *Check) Notification(ctx context.Context, notificationMsg *NotificationMsg) {
|
||||||
|
var err error
|
||||||
|
defer func() {
|
||||||
|
tracelog.SetCtxDebug(ctx, utils2.GetFuncName(1), err, "notificationMsg", notificationMsg)
|
||||||
|
}()
|
||||||
|
|
||||||
var req msg.SendMsgReq
|
var req msg.SendMsgReq
|
||||||
var msg sdkws.MsgData
|
var msg sdkws.MsgData
|
||||||
var offlineInfo sdkws.OfflinePushInfo
|
var offlineInfo sdkws.OfflinePushInfo
|
||||||
var title, desc, ex string
|
var title, desc, ex string
|
||||||
var pushSwitch, unReadCount bool
|
var pushSwitch, unReadCount bool
|
||||||
var reliabilityLevel int
|
var reliabilityLevel int
|
||||||
msg.SendID = n.SendID
|
msg.SendID = notificationMsg.SendID
|
||||||
msg.RecvID = n.RecvID
|
msg.RecvID = notificationMsg.RecvID
|
||||||
msg.Content = n.Content
|
msg.Content = notificationMsg.Content
|
||||||
msg.MsgFrom = n.MsgFrom
|
msg.MsgFrom = notificationMsg.MsgFrom
|
||||||
msg.ContentType = n.ContentType
|
msg.ContentType = notificationMsg.ContentType
|
||||||
msg.SessionType = n.SessionType
|
msg.SessionType = notificationMsg.SessionType
|
||||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||||
msg.ClientMsgID = utils.GetMsgID(n.SendID)
|
msg.ClientMsgID = utils.GetMsgID(notificationMsg.SendID)
|
||||||
msg.Options = make(map[string]bool, 7)
|
msg.Options = make(map[string]bool, 7)
|
||||||
msg.SenderNickname = n.SenderNickname
|
msg.SenderNickname = notificationMsg.SenderNickname
|
||||||
msg.SenderFaceURL = n.SenderFaceURL
|
msg.SenderFaceURL = notificationMsg.SenderFaceURL
|
||||||
switch n.SessionType {
|
switch notificationMsg.SessionType {
|
||||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||||
msg.RecvID = ""
|
msg.RecvID = ""
|
||||||
msg.GroupID = n.RecvID
|
msg.GroupID = notificationMsg.RecvID
|
||||||
}
|
}
|
||||||
offlineInfo.IOSBadgeCount = config.Config.IOSPush.BadgeCount
|
offlineInfo.IOSBadgeCount = config.Config.IOSPush.BadgeCount
|
||||||
offlineInfo.IOSPushSound = config.Config.IOSPush.PushSound
|
offlineInfo.IOSPushSound = config.Config.IOSPush.PushSound
|
||||||
@ -280,9 +288,5 @@ func (c *Check) Notification(ctx context.Context, n *NotificationMsg) {
|
|||||||
msg.OfflinePushInfo = &offlineInfo
|
msg.OfflinePushInfo = &offlineInfo
|
||||||
req.MsgData = &msg
|
req.MsgData = &msg
|
||||||
|
|
||||||
_, err := sendMsg(context.Background(), &req)
|
_, err = c.msg.SendMsg(ctx, &req)
|
||||||
}
|
|
||||||
|
|
||||||
func sendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -148,12 +148,6 @@ func (c *Check) BlackDeletedNotification(ctx context.Context, req *pbFriend.Remo
|
|||||||
c.friendNotification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
|
c.friendNotification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||||
}
|
}
|
||||||
|
|
||||||
// send to myself
|
|
||||||
func (c *Check) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
|
|
||||||
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
|
||||||
c.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Check) FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) {
|
func (c *Check) FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) {
|
||||||
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
||||||
c.friendNotification(ctx, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
|
c.friendNotification(ctx, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||||
|
13
internal/common/notification/user.go
Normal file
13
internal/common/notification/user.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/proto/sdkws"
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// send to myself
|
||||||
|
func (c *Check) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
|
||||||
|
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
||||||
|
c.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||||
|
}
|
@ -3,7 +3,7 @@ package friend
|
|||||||
import (
|
import (
|
||||||
"Open_IM/internal/common/check"
|
"Open_IM/internal/common/check"
|
||||||
"Open_IM/internal/common/convert"
|
"Open_IM/internal/common/convert"
|
||||||
chat "Open_IM/internal/common/notification"
|
"Open_IM/internal/common/notification"
|
||||||
"Open_IM/internal/common/rpcserver"
|
"Open_IM/internal/common/rpcserver"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
@ -26,6 +26,8 @@ type friendServer struct {
|
|||||||
*rpcserver.RpcServer
|
*rpcserver.RpcServer
|
||||||
controller.FriendInterface
|
controller.FriendInterface
|
||||||
controller.BlackInterface
|
controller.BlackInterface
|
||||||
|
notification *notification.Check
|
||||||
|
userCheck *check.UserCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFriendServer(port int) *friendServer {
|
func NewFriendServer(port int) *friendServer {
|
||||||
@ -105,7 +107,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbFriend.Apply
|
|||||||
if req.ToUserID == req.FromUserID {
|
if req.ToUserID == req.FromUserID {
|
||||||
return nil, constant.ErrCanNotAddYourself.Wrap()
|
return nil, constant.ErrCanNotAddYourself.Wrap()
|
||||||
}
|
}
|
||||||
if _, err := check.GetUsersInfo(ctx, req.ToUserID, req.FromUserID); err != nil {
|
if _, err := s.userCheck.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}, true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
in1, in2, err := s.FriendInterface.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
in1, in2, err := s.FriendInterface.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
||||||
@ -118,7 +120,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbFriend.Apply
|
|||||||
if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.FriendApplicationAddNotification(ctx, req)
|
s.notification.FriendApplicationAddNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ func (s *friendServer) ImportFriends(ctx context.Context, req *pbFriend.ImportFr
|
|||||||
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, err := check.NewUserCheck().GetUsersInfos(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...), true); err != nil {
|
if _, err := s.userCheck.GetUsersInfos(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...), true); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +159,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.FriendApplicationAgreedNotification(ctx, req)
|
s.notification.FriendApplicationAgreedNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
if req.HandleResult == constant.FriendResponseRefuse {
|
if req.HandleResult == constant.FriendResponseRefuse {
|
||||||
@ -165,7 +167,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.FriendApplicationRefusedNotification(ctx, req)
|
s.notification.FriendApplicationRefusedNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1")
|
return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1")
|
||||||
@ -184,7 +186,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
|||||||
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, []string{req.FriendUserID}); err != nil {
|
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, []string{req.FriendUserID}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.FriendDeletedNotification(ctx, req)
|
s.notification.FriendDeletedNotification(ctx, req)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +203,7 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
|||||||
if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
|
if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.FriendRemarkSetNotification(ctx, req.OwnerUserID, req.FriendUserID)
|
s.notification.FriendRemarkSetNotification(ctx, req.OwnerUserID, req.FriendUserID)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/internal/common/check"
|
||||||
"Open_IM/internal/common/convert"
|
"Open_IM/internal/common/convert"
|
||||||
chat "Open_IM/internal/common/notification"
|
"Open_IM/internal/common/notification"
|
||||||
"Open_IM/internal/common/rpcserver"
|
"Open_IM/internal/common/rpcserver"
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
@ -25,6 +26,8 @@ import (
|
|||||||
type userServer struct {
|
type userServer struct {
|
||||||
*rpcserver.RpcServer
|
*rpcserver.RpcServer
|
||||||
controller.UserInterface
|
controller.UserInterface
|
||||||
|
notification *notification.Check
|
||||||
|
userCheck *check.UserCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserServer(port int) *userServer {
|
func NewUserServer(port int) *userServer {
|
||||||
@ -226,11 +229,11 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
for _, v := range friends {
|
for _, v := range friends {
|
||||||
chat.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
|
s.notification.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v.FriendUser.UserID, tracelog.GetOpUserID(ctx))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chat.UserInfoUpdatedNotification(ctx, tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
|
s.notification.UserInfoUpdatedNotification(ctx, tracelog.GetOpUserID(ctx), req.UserInfo.UserID)
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
@ -246,7 +249,7 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Se
|
|||||||
if err := s.UpdateByMap(ctx, req.UserID, m); err != nil {
|
if err := s.UpdateByMap(ctx, req.UserID, m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
chat.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
|
s.notification.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user