From b800f2d484e87cecf1f1c327d3fdb0c83d04eabd Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com> Date: Tue, 12 Mar 2024 17:53:37 +0800 Subject: [PATCH] fix: fix make lint --- internal/push/offlinepush/getui/push.go | 3 +-- internal/push/push_rpc_server.go | 3 +-- internal/push/tools.go | 3 +-- internal/rpc/friend/black.go | 7 ++++++- internal/rpc/friend/friend.go | 16 ++++++++++++++-- pkg/rpcclient/notification/friend.go | 5 +---- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/internal/push/offlinepush/getui/push.go b/internal/push/offlinepush/getui/push.go index 67f6292db..1a95727e5 100644 --- a/internal/push/offlinepush/getui/push.go +++ b/internal/push/offlinepush/getui/push.go @@ -90,9 +90,8 @@ func (g *Client) Push(ctx context.Context, userIDs []string, title, content stri for i, v := range s.GetSplitResult() { go func(index int, userIDs []string) { defer wg.Done() - if err := g.batchPush(ctx, token, userIDs, pushReq); err != nil { + if err = g.batchPush(ctx, token, userIDs, pushReq); err != nil { log.ZError(ctx, "batchPush failed", err, "index", index, "token", token, "req", pushReq) - err = err } }(i, v.Item) } diff --git a/internal/push/push_rpc_server.go b/internal/push/push_rpc_server.go index a8bb18974..b68b06666 100644 --- a/internal/push/push_rpc_server.go +++ b/internal/push/push_rpc_server.go @@ -90,9 +90,8 @@ func (r *pushServer) PushMsg(ctx context.Context, pbData *pbpush.PushMsgReq) (re if err != nil { if err != errNoOfflinePusher { return nil, err - } else { - log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String()) } + log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String()) } return &pbpush.PushMsgResp{}, nil } diff --git a/internal/push/tools.go b/internal/push/tools.go index 3242767b1..760c8c95b 100644 --- a/internal/push/tools.go +++ b/internal/push/tools.go @@ -26,7 +26,6 @@ func GetContent(msg *sdkws.MsgData) string { _ = proto.Unmarshal(msg.Content, &tips) content := tips.JsonDetail return content - } else { - return string(msg.Content) } + return string(msg.Content) } diff --git a/internal/rpc/friend/black.go b/internal/rpc/friend/black.go index 64c63eb73..4bb0d9f58 100644 --- a/internal/rpc/friend/black.go +++ b/internal/rpc/friend/black.go @@ -79,9 +79,14 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbfriend.AddBlackReq) CreateTime: time.Now(), Ex: req.Ex, } + if err := s.blackDatabase.Create(ctx, []*relation.BlackModel{&black}); err != nil { return nil, err } - s.notificationSender.BlackAddedNotification(ctx, req) + + if err := s.notificationSender.BlackAddedNotification(ctx, req); err != nil { + return nil, err + } + return &pbfriend.AddBlackResp{}, nil } diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 6403a4159..4df4085a9 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -114,26 +114,36 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply if err := authverify.CheckAccessV3(ctx, req.FromUserID, s.config); err != nil { return nil, err } + if req.ToUserID == req.FromUserID { return nil, errs.ErrCanNotAddYourself.Wrap("req.ToUserID", req.ToUserID) } + if err = CallbackBeforeAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue { return nil, err } + if _, err := s.userRpcClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil { return nil, err } + in1, in2, err := s.friendDatabase.CheckIn(ctx, req.FromUserID, req.ToUserID) if err != nil { return nil, err } + if in1 && in2 { return nil, errs.ErrRelationshipAlready.Wrap() } + if err = s.friendDatabase.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil { return nil, err } - s.notificationSender.FriendApplicationAddNotification(ctx, req) + + if err = s.notificationSender.FriendApplicationAddNotification(ctx, req); err != nil { + return nil, err + } + if err = CallbackAfterAddFriend(ctx, s.config, req); err != nil && err != errs.ErrCallbackContinue { return nil, err } @@ -197,7 +207,9 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbfriend.Res if err != nil { return nil, err } - s.notificationSender.FriendApplicationAgreedNotification(ctx, req) + if err := s.notificationSender.FriendApplicationAgreedNotification(ctx, req); err != nil { + return nil, err + } return resp, nil } if req.HandleResult == constant.FriendResponseRefuse { diff --git a/pkg/rpcclient/notification/friend.go b/pkg/rpcclient/notification/friend.go index dafca055a..751bdf475 100644 --- a/pkg/rpcclient/notification/friend.go +++ b/pkg/rpcclient/notification/friend.go @@ -126,10 +126,7 @@ func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Conte return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips) } -func (f *FriendNotificationSender) FriendApplicationAddNotification( - ctx context.Context, - req *pbfriend.ApplyToAddFriendReq, -) error { +func (f *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error { tips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{ FromUserID: req.FromUserID, ToUserID: req.ToUserID,