From db533d9f4eebc8a5ff035d074ec9bf1cdcc80131 Mon Sep 17 00:00:00 2001 From: cncsmonster Date: Mon, 23 Oct 2023 00:08:55 +0800 Subject: [PATCH] fix: fix lint erros in pkg/authverify,pkg/rpcclien --- pkg/authverify/token.go | 3 + pkg/callbackstruct/common.go | 1 + pkg/rpcclient/auth.go | 1 + pkg/rpcclient/conversation.go | 10 ++ pkg/rpcclient/friend.go | 5 + pkg/rpcclient/group.go | 14 +++ pkg/rpcclient/msg.go | 11 +- .../{conevrsation.go => conversation.go} | 3 + pkg/rpcclient/notification/friend.go | 33 +++-- pkg/rpcclient/notification/group.go | 118 ++++++++++-------- pkg/rpcclient/notification/msg.go | 2 + pkg/rpcclient/notification/user.go | 52 ++++---- pkg/rpcclient/push.go | 1 + pkg/rpcclient/third.go | 9 +- pkg/rpcclient/user.go | 12 ++ 15 files changed, 183 insertions(+), 92 deletions(-) rename pkg/rpcclient/notification/{conevrsation.go => conversation.go} (99%) mode change 100644 => 100755 pkg/rpcclient/notification/group.go mode change 100644 => 100755 pkg/rpcclient/third.go diff --git a/pkg/authverify/token.go b/pkg/authverify/token.go index a8e577fde..724d4934f 100644 --- a/pkg/authverify/token.go +++ b/pkg/authverify/token.go @@ -41,6 +41,7 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) { if opUserID == ownerUserID { return nil } + return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName()) } @@ -52,6 +53,7 @@ func CheckAdmin(ctx context.Context) error { if utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) { return nil } + return errs.ErrNoPermission.Wrap(fmt.Sprintf("user %s is not admin userID", mcontext.GetOpUserID(ctx))) } @@ -74,5 +76,6 @@ func WsVerifyToken(token, userID string, platformID int) error { if claim.PlatformID != platformID { return errs.ErrTokenInvalid.Wrap(fmt.Sprintf("token platform %d != %d", claim.PlatformID, platformID)) } + return nil } diff --git a/pkg/callbackstruct/common.go b/pkg/callbackstruct/common.go index ef84d52b9..8b320a04f 100644 --- a/pkg/callbackstruct/common.go +++ b/pkg/callbackstruct/common.go @@ -61,6 +61,7 @@ func (c CommonCallbackResp) Parse() error { if c.ActionCode != errs.NoError || c.ErrCode != errs.NoError { return errs.NewCodeError(int(c.ErrCode), c.ErrMsg).WithDetail(c.ErrDlt) } + return nil } diff --git a/pkg/rpcclient/auth.go b/pkg/rpcclient/auth.go index 0ee021de1..4859e541d 100644 --- a/pkg/rpcclient/auth.go +++ b/pkg/rpcclient/auth.go @@ -31,6 +31,7 @@ func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth { panic(err) } client := auth.NewAuthClient(conn) + return &Auth{discov: discov, conn: conn, Client: client} } diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index 60ca53351..30b0b4b77 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -39,6 +39,7 @@ func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversatio panic(err) } client := pbconversation.NewConversationClient(conn) + return &Conversation{discov: discov, conn: conn, Client: client} } @@ -56,26 +57,31 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont if err != nil { return 0, err } + return conversation.GetConversation().RecvMsgOpt, err } func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error { _, err := c.Client.CreateSingleChatConversations(ctx, &pbconversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID}) + return err } func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error { _, err := c.Client.CreateGroupChatConversations(ctx, &pbconversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID}) + return err } func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error { _, err := c.Client.SetConversationMaxSeq(ctx, &pbconversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq}) + return err } func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbconversation.ConversationReq) error { _, err := c.Client.SetConversations(ctx, &pbconversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation}) + return err } @@ -84,6 +90,7 @@ func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUse if err != nil { return nil, err } + return resp.ConversationIDs, nil } @@ -92,6 +99,7 @@ func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID if err != nil { return nil, err } + return resp.Conversation, nil } @@ -106,6 +114,7 @@ func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Con if len(resp.Conversations) == 0 { return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("conversationIDs: %v not found", conversationIDs)) } + return resp.Conversations, nil } @@ -124,5 +133,6 @@ func (c *ConversationRpcClient) GetConversations( if err != nil { return nil, err } + return resp.Conversations, nil } diff --git a/pkg/rpcclient/friend.go b/pkg/rpcclient/friend.go index b84db40d4..6b214aaf2 100644 --- a/pkg/rpcclient/friend.go +++ b/pkg/rpcclient/friend.go @@ -38,6 +38,7 @@ func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend { panic(err) } client := friend.NewFriendClient(conn) + return &Friend{discov: discov, conn: conn, Client: client} } @@ -59,6 +60,7 @@ func (f *FriendRpcClient) GetFriendsInfo( return nil, err } resp = r.FriendsInfo[0] + return } @@ -68,6 +70,7 @@ func (f *FriendRpcClient) IsFriend(ctx context.Context, possibleFriendUserID, us if err != nil { return false, err } + return resp.InUser1Friends, nil } @@ -77,6 +80,7 @@ func (f *FriendRpcClient) GetFriendIDs(ctx context.Context, ownerUserID string) if err != nil { return nil, err } + return resp.FriendIDs, nil } @@ -85,5 +89,6 @@ func (b *FriendRpcClient) IsBlocked(ctx context.Context, possibleBlackUserID, us if err != nil { return false, err } + return r.InUser2Blacks, nil } diff --git a/pkg/rpcclient/group.go b/pkg/rpcclient/group.go index bf0efe60c..5a340875b 100644 --- a/pkg/rpcclient/group.go +++ b/pkg/rpcclient/group.go @@ -42,6 +42,7 @@ func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group { panic(err) } client := group.NewGroupClient(conn) + return &Group{discov: discov, conn: conn, Client: client} } @@ -69,6 +70,7 @@ func (g *GroupRpcClient) GetGroupInfos( return nil, errs.ErrGroupIDNotFound.Wrap(strings.Join(ids, ",")) } } + return resp.GroupInfos, nil } @@ -77,6 +79,7 @@ func (g *GroupRpcClient) GetGroupInfo(ctx context.Context, groupID string) (*sdk if err != nil { return nil, err } + return groups[0], nil } @@ -89,6 +92,7 @@ func (g *GroupRpcClient) GetGroupInfoMap( if err != nil { return nil, err } + return utils.SliceToMap(groups, func(e *sdkws.GroupInfo) string { return e.GroupID }), nil @@ -114,6 +118,7 @@ func (g *GroupRpcClient) GetGroupMemberInfos( return nil, errs.ErrNotInGroupYet.Wrap(strings.Join(ids, ",")) } } + return resp.Members, nil } @@ -126,6 +131,7 @@ func (g *GroupRpcClient) GetGroupMemberInfo( if err != nil { return nil, err } + return members[0], nil } @@ -139,6 +145,7 @@ func (g *GroupRpcClient) GetGroupMemberInfoMap( if err != nil { return nil, err } + return utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string { return e.UserID }), nil @@ -155,6 +162,7 @@ func (g *GroupRpcClient) GetOwnerAndAdminInfos( if err != nil { return nil, err } + return resp.Members, nil } @@ -163,6 +171,7 @@ func (g *GroupRpcClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdk GroupID: groupID, RoleLevels: []int32{constant.GroupOwner}, }) + return resp.Members[0], err } @@ -173,6 +182,7 @@ func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string) if err != nil { return nil, err } + return resp.UserIDs, nil } @@ -183,6 +193,7 @@ func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string) if err != nil { return nil, err } + return resp.GroupInfo, nil } @@ -198,6 +209,7 @@ func (g *GroupRpcClient) GetGroupMemberCache( if err != nil { return nil, err } + return resp.Member, nil } @@ -206,6 +218,7 @@ func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error GroupID: groupID, DeleteMember: true, }) + return err } @@ -213,5 +226,6 @@ func (g *GroupRpcClient) NotificationUserInfoUpdate(ctx context.Context, userID _, err := g.Client.NotificationUserInfoUpdate(ctx, &group.NotificationUserInfoUpdateReq{ UserID: userID, }) + return err } diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index e3dad874e..51e29c7d8 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -136,6 +136,7 @@ func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message { panic(err) } client := msg.NewMsgClient(conn) + return &Message{discov: discov, conn: conn, Client: client} } @@ -147,16 +148,19 @@ func NewMessageRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) MessageR func (m *MessageRpcClient) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) { resp, err := m.Client.SendMsg(ctx, req) + return resp, err } func (m *MessageRpcClient) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sdkws.GetMaxSeqResp, error) { resp, err := m.Client.GetMaxSeq(ctx, req) + return resp, err } func (m *MessageRpcClient) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) { resp, err := m.Client.PullMessageBySeqs(ctx, req) + return resp, err } @@ -165,6 +169,7 @@ func (m *MessageRpcClient) GetConversationMaxSeq(ctx context.Context, conversati if err != nil { return 0, err } + return resp.MaxSeq, nil } @@ -200,6 +205,7 @@ func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSende for _, opt := range opts { opt(notificationSender) } + return notificationSender } @@ -220,6 +226,7 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s content, err := json.Marshal(&n) if err != nil { log.ZError(ctx, "MsgClient Notification json.Marshal failed", err, "sendID", sendID, "recvID", recvID, "contentType", contentType, "msg", m) + return err } notificationOpt := ¬ificationOpt{} @@ -229,7 +236,8 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s var req msg.SendMsgReq var msg sdkws.MsgData if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil { - userInfo, err := s.getUserInfo(ctx, sendID) + var userInfo *sdkws.UserInfo + userInfo, err = s.getUserInfo(ctx, sendID) if err != nil { log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID) } else { @@ -267,6 +275,7 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s } else { log.ZError(ctx, "MsgClient Notification SendMsg failed", err, "req", &req) } + return err } diff --git a/pkg/rpcclient/notification/conevrsation.go b/pkg/rpcclient/notification/conversation.go similarity index 99% rename from pkg/rpcclient/notification/conevrsation.go rename to pkg/rpcclient/notification/conversation.go index 77fc623e4..0fefb147e 100644 --- a/pkg/rpcclient/notification/conevrsation.go +++ b/pkg/rpcclient/notification/conversation.go @@ -41,6 +41,7 @@ func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx IsPrivate: isPrivateChat, ConversationID: conversationID, } + return c.Notification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, tips) } @@ -50,6 +51,7 @@ func (c *ConversationNotificationSender) ConversationChangeNotification(ctx cont UserID: userID, ConversationIDList: conversationIDs, } + return c.Notification(ctx, userID, userID, constant.ConversationChangeNotification, tips) } @@ -65,5 +67,6 @@ func (c *ConversationNotificationSender) ConversationUnreadChangeNotification( HasReadSeq: hasReadSeq, UnreadCountTime: unreadCountTime, } + return c.Notification(ctx, userID, userID, constant.ConversationUnreadNotification, tips) } diff --git a/pkg/rpcclient/notification/friend.go b/pkg/rpcclient/notification/friend.go index b061a24ae..9dae27c6e 100644 --- a/pkg/rpcclient/notification/friend.go +++ b/pkg/rpcclient/notification/friend.go @@ -57,6 +57,7 @@ func WithDBFunc( for _, user := range users { result = append(result, user) } + return result, nil } s.getUsersInfo = f @@ -75,6 +76,7 @@ func WithRpcFunc( for _, user := range users { result = append(result, user) } + return result, err } s.getUsersInfo = f @@ -91,6 +93,7 @@ func NewFriendNotificationSender( for _, opt := range opts { opt(f) } + return f } @@ -106,22 +109,13 @@ func (f *FriendNotificationSender) getUsersInfoMap( for _, user := range users { result[user.GetUserID()] = user.(*sdkws.UserInfo) } - return result, nil -} -func (f *FriendNotificationSender) getFromToUserNickname( - ctx context.Context, - fromUserID, toUserID string, -) (string, string, error) { - users, err := f.getUsersInfoMap(ctx, []string{fromUserID, toUserID}) - if err != nil { - return "", "", nil - } - return users[fromUserID].Nickname, users[toUserID].Nickname, nil + return result, nil } func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, changedUserID string) error { tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID} + return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips) } @@ -133,6 +127,7 @@ func (f *FriendNotificationSender) FriendApplicationAddNotification( FromUserID: req.FromUserID, ToUserID: req.ToUserID, }} + return f.Notification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &tips) } @@ -144,6 +139,7 @@ func (f *FriendNotificationSender) FriendApplicationAgreedNotification( FromUserID: req.FromUserID, ToUserID: req.ToUserID, }, HandleMsg: req.HandleMsg} + return f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &tips) } @@ -155,6 +151,7 @@ func (f *FriendNotificationSender) FriendApplicationRefusedNotification( FromUserID: req.FromUserID, ToUserID: req.ToUserID, }, HandleMsg: req.HandleMsg} + return f.Notification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &tips) } @@ -179,6 +176,7 @@ func (f *FriendNotificationSender) FriendAddedNotification( if err != nil { return err } + return f.Notification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &tips) } @@ -187,6 +185,7 @@ func (f *FriendNotificationSender) FriendDeletedNotification(ctx context.Context FromUserID: req.OwnerUserID, ToUserID: req.FriendUserID, }} + return f.Notification(ctx, req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &tips) } @@ -194,6 +193,7 @@ func (f *FriendNotificationSender) FriendRemarkSetNotification(ctx context.Conte tips := sdkws.FriendInfoChangedTips{FromToUserID: &sdkws.FromToUserID{}} tips.FromToUserID.FromUserID = fromUserID tips.FromToUserID.ToUserID = toUserID + return f.Notification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &tips) } @@ -201,6 +201,7 @@ func (f *FriendNotificationSender) BlackAddedNotification(ctx context.Context, r tips := sdkws.BlackAddedTips{FromToUserID: &sdkws.FromToUserID{}} tips.FromToUserID.FromUserID = req.OwnerUserID tips.FromToUserID.ToUserID = req.BlackUserID + return f.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &tips) } @@ -209,7 +210,10 @@ func (f *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, FromUserID: req.OwnerUserID, ToUserID: req.BlackUserID, }} - f.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips) + err := f.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips) + if err != nil { + panic(err) + } } func (f *FriendNotificationSender) FriendInfoUpdatedNotification( @@ -218,5 +222,8 @@ func (f *FriendNotificationSender) FriendInfoUpdatedNotification( needNotifiedUserID string, ) { tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID} - f.Notification(ctx, mcontext.GetOpUserID(ctx), needNotifiedUserID, constant.FriendInfoUpdatedNotification, &tips) + err := f.Notification(ctx, mcontext.GetOpUserID(ctx), needNotifiedUserID, constant.FriendInfoUpdatedNotification, &tips) + if err != nil { + panic(err) + } } diff --git a/pkg/rpcclient/notification/group.go b/pkg/rpcclient/notification/group.go old mode 100644 new mode 100755 index 8e71f61c3..23341af70 --- a/pkg/rpcclient/notification/group.go +++ b/pkg/rpcclient/notification/group.go @@ -60,6 +60,7 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (* if len(users) == 0 { return nil, errs.ErrUserIDNotFound.Wrap(fmt.Sprintf("user %s not found", userID)) } + return &sdkws.PublicUserInfo{ UserID: users[0].GetUserID(), Nickname: users[0].GetNickname(), @@ -68,6 +69,23 @@ func (g *GroupNotificationSender) getUser(ctx context.Context, userID string) (* }, nil } +func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo { + return &sdkws.GroupMemberFullInfo{ + GroupID: member.GroupID, + UserID: member.UserID, + RoleLevel: member.RoleLevel, + JoinTime: member.JoinTime.UnixMilli(), + Nickname: member.Nickname, + FaceURL: member.FaceURL, + AppMangerLevel: appMangerLevel, + JoinSource: member.JoinSource, + OperatorUserID: member.OperatorUserID, + Ex: member.Ex, + MuteEndTime: member.MuteEndTime.UnixMilli(), + InviterUserID: member.InviterUserID, + } +} + func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) { gm, err := g.db.TakeGroup(ctx, groupID) if err != nil { @@ -81,6 +99,7 @@ func (g *GroupNotificationSender) getGroupInfo(ctx context.Context, groupID stri if err != nil { return nil, err } + return &sdkws.GroupInfo{ GroupID: gm.GroupID, GroupName: gm.GroupName, @@ -148,6 +167,7 @@ func (g *GroupNotificationSender) getGroupMemberMap(ctx context.Context, groupID for i, member := range members { m[member.UserID] = members[i] } + return m, nil } @@ -159,6 +179,7 @@ func (g *GroupNotificationSender) getGroupMember(ctx context.Context, groupID st if len(members) == 0 { return nil, errs.ErrInternalServer.Wrap(fmt.Sprintf("group %s member %s not found", groupID, userID)) } + return members[0], nil } @@ -168,46 +189,8 @@ func (g *GroupNotificationSender) getGroupOwnerAndAdminUserID(ctx context.Contex return nil, err } fn := func(e *relation.GroupMemberModel) string { return e.UserID } - return utils.Slice(members, fn), nil -} - -func (g *GroupNotificationSender) groupDB2PB(group *relation.GroupModel, ownerUserID string, memberCount uint32) *sdkws.GroupInfo { - return &sdkws.GroupInfo{ - GroupID: group.GroupID, - GroupName: group.GroupName, - Notification: group.Notification, - Introduction: group.Introduction, - FaceURL: group.FaceURL, - OwnerUserID: ownerUserID, - CreateTime: group.CreateTime.UnixMilli(), - MemberCount: memberCount, - Ex: group.Ex, - Status: group.Status, - CreatorUserID: group.CreatorUserID, - GroupType: group.GroupType, - NeedVerification: group.NeedVerification, - LookMemberInfo: group.LookMemberInfo, - ApplyMemberFriend: group.ApplyMemberFriend, - NotificationUpdateTime: group.NotificationUpdateTime.UnixMilli(), - NotificationUserID: group.NotificationUserID, - } -} -func (g *GroupNotificationSender) groupMemberDB2PB(member *relation.GroupMemberModel, appMangerLevel int32) *sdkws.GroupMemberFullInfo { - return &sdkws.GroupMemberFullInfo{ - GroupID: member.GroupID, - UserID: member.UserID, - RoleLevel: member.RoleLevel, - JoinTime: member.JoinTime.UnixMilli(), - Nickname: member.Nickname, - FaceURL: member.FaceURL, - AppMangerLevel: appMangerLevel, - JoinSource: member.JoinSource, - OperatorUserID: member.OperatorUserID, - Ex: member.Ex, - MuteEndTime: member.MuteEndTime.UnixMilli(), - InviterUserID: member.InviterUserID, - } + return utils.Slice(members, fn), nil } func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) { @@ -219,6 +202,7 @@ func (g *GroupNotificationSender) getUsersInfoMap(ctx context.Context, userIDs [ for _, user := range users { result[user.GetUserID()] = user.(*sdkws.UserInfo) } + return result, nil } @@ -236,21 +220,31 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws return nil } userID := mcontext.GetOpUserID(ctx) - if groupID != "" { + getOpUser := func(g *GroupNotificationSender, groupID, userID string) (opUser *sdkws.GroupMemberFullInfo, err error) { if authverify.IsManagerUserID(userID) { - *opUser = &sdkws.GroupMemberFullInfo{ + opUser = &sdkws.GroupMemberFullInfo{ GroupID: groupID, UserID: userID, RoleLevel: constant.GroupAdmin, AppMangerLevel: constant.AppAdmin, } - } else { - member, err := g.db.TakeGroupMember(ctx, groupID, userID) - if err == nil { - *opUser = g.groupMemberDB2PB(member, 0) - } else if !errs.ErrRecordNotFound.Is(err) { - return err - } + + return opUser, nil + } + var member *relation.GroupMemberModel + member, err = g.db.TakeGroupMember(ctx, groupID, userID) + if err == nil { + opUser = g.groupMemberDB2PB(member, 0) + } else if !errs.ErrRecordNotFound.Is(err) { + return nil, err + } + + return opUser, nil + } + if groupID != "" { + *opUser, err = getOpUser(g, groupID, userID) + if err != nil { + return err } } user, err := g.getUser(ctx, userID) @@ -273,6 +267,7 @@ func (g *GroupNotificationSender) fillOpUser(ctx context.Context, opUser **sdkws (*opUser).FaceURL = user.FaceURL } } + return nil } @@ -286,6 +281,7 @@ func (g *GroupNotificationSender) GroupCreatedNotification(ctx context.Context, if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupCreatedNotification, tips) } @@ -299,6 +295,7 @@ func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context, if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName()) } @@ -312,6 +309,7 @@ func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Conte if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNameNotification, tips) } @@ -325,6 +323,7 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName()) } @@ -355,6 +354,7 @@ func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.C log.ZError(ctx, "JoinGroupApplicationNotification failed", err, "group", req.GroupID, "userID", userID) } } + return nil } @@ -370,6 +370,7 @@ func (g *GroupNotificationSender) MemberQuitNotification(ctx context.Context, me return err } tips := &sdkws.MemberQuitTips{Group: group, QuitUser: member} + return g.Notification(ctx, mcontext.GetOpUserID(ctx), member.GroupID, constant.MemberQuitNotification, tips) } @@ -389,7 +390,8 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte return err } tips := &sdkws.GroupApplicationAcceptedTips{Group: group, HandleMsg: req.HandledMsg, ReceiverAs: 1} - if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { + err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID) + if err != nil { return err } for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) { @@ -398,6 +400,7 @@ func (g *GroupNotificationSender) GroupApplicationAcceptedNotification(ctx conte log.ZError(ctx, "failed", err) } } + return nil } @@ -417,7 +420,8 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte return err } tips := &sdkws.GroupApplicationRejectedTips{Group: group, HandleMsg: req.HandledMsg} - if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { + err = g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID) + if err != nil { return err } for _, userID := range append(userIDs, mcontext.GetOpUserID(ctx)) { @@ -426,6 +430,7 @@ func (g *GroupNotificationSender) GroupApplicationRejectedNotification(ctx conte log.ZError(ctx, "failed", err) } } + return nil } @@ -449,6 +454,7 @@ func (g *GroupNotificationSender) GroupOwnerTransferredNotification(ctx context. if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupOwnerTransferredNotification, tips) } @@ -462,6 +468,7 @@ func (g *GroupNotificationSender) MemberKickedNotification(ctx context.Context, if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.MemberKickedNotification, tips) } @@ -487,6 +494,7 @@ func (g *GroupNotificationSender) MemberInvitedNotification(ctx context.Context, if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberInvitedNotification, tips) } @@ -506,6 +514,7 @@ func (g *GroupNotificationSender) MemberEnterNotification(ctx context.Context, g return err } tips := &sdkws.MemberEnterTips{Group: group, EntrantUser: user} + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.MemberEnterNotification, tips) } @@ -519,6 +528,7 @@ func (g *GroupNotificationSender) GroupDismissedNotification(ctx context.Context if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupDismissedNotification, tips) } @@ -544,6 +554,7 @@ func (g *GroupNotificationSender) GroupMemberMutedNotification(ctx context.Conte if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberMutedNotification, tips) } @@ -566,6 +577,7 @@ func (g *GroupNotificationSender) GroupMemberCancelMutedNotification(ctx context if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberCancelMutedNotification, tips) } @@ -591,6 +603,7 @@ func (g *GroupNotificationSender) GroupMutedNotification(ctx context.Context, gr if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMutedNotification, tips) } @@ -616,6 +629,7 @@ func (g *GroupNotificationSender) GroupCancelMutedNotification(ctx context.Conte if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips) } @@ -638,6 +652,7 @@ func (g *GroupNotificationSender) GroupMemberInfoSetNotification(ctx context.Con if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberInfoSetNotification, tips) } @@ -660,6 +675,7 @@ func (g *GroupNotificationSender) GroupMemberSetToAdminNotification(ctx context. if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToAdminNotification, tips) } @@ -682,6 +698,7 @@ func (g *GroupNotificationSender) GroupMemberSetToOrdinaryUserNotification(ctx c if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { return err } + return g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupMemberSetToOrdinaryUserNotification, tips) } @@ -693,5 +710,6 @@ func (g *GroupNotificationSender) SuperGroupNotification(ctx context.Context, se } }() err = g.Notification(ctx, sendID, recvID, constant.SuperGroupUpdateNotification, nil) + return err } diff --git a/pkg/rpcclient/notification/msg.go b/pkg/rpcclient/notification/msg.go index 60fa64f40..6e367ac04 100644 --- a/pkg/rpcclient/notification/msg.go +++ b/pkg/rpcclient/notification/msg.go @@ -37,6 +37,7 @@ func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context, ConversationID: conversationID, Seqs: seqs, } + return m.Notification(ctx, userID, userID, constant.DeleteMsgsNotification, &tips) } @@ -47,5 +48,6 @@ func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conv Seqs: seqs, HasReadSeq: hasReadSeq, } + return m.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips) } diff --git a/pkg/rpcclient/notification/user.go b/pkg/rpcclient/notification/user.go index 4feebf7b9..f6e592d18 100644 --- a/pkg/rpcclient/notification/user.go +++ b/pkg/rpcclient/notification/user.go @@ -52,6 +52,7 @@ func WithUserFunc( for _, user := range users { result = append(result, user) } + return result, nil } u.getUsersInfo = f @@ -68,34 +69,37 @@ func NewUserNotificationSender( for _, opt := range opts { opt(f) } + return f } -func (u *UserNotificationSender) getUsersInfoMap( - ctx context.Context, - userIDs []string, -) (map[string]*sdkws.UserInfo, error) { - users, err := u.getUsersInfo(ctx, userIDs) - if err != nil { - return nil, err - } - result := make(map[string]*sdkws.UserInfo) - for _, user := range users { - result[user.GetUserID()] = user.(*sdkws.UserInfo) - } - return result, nil -} +// func (u *UserNotificationSender) getUsersInfoMap( +// ctx context.Context, +// userIDs []string, +// ) (map[string]*sdkws.UserInfo, error) { +// users, err := u.getUsersInfo(ctx, userIDs) +// if err != nil { +// return nil, err +// } +// result := make(map[string]*sdkws.UserInfo) +// for _, user := range users { +// result[user.GetUserID()] = user.(*sdkws.UserInfo) +// } -func (u *UserNotificationSender) getFromToUserNickname( - ctx context.Context, - fromUserID, toUserID string, -) (string, string, error) { - users, err := u.getUsersInfoMap(ctx, []string{fromUserID, toUserID}) - if err != nil { - return "", "", nil - } - return users[fromUserID].Nickname, users[toUserID].Nickname, nil -} +// return result, nil +// } + +// func (u *UserNotificationSender) getFromToUserNickname( +// ctx context.Context, +// fromUserID, toUserID string, +// ) (string, string, error) { +// users, err := u.getUsersInfoMap(ctx, []string{fromUserID, toUserID}) +// if err != nil { +// return "", "", err +// } + +// return users[fromUserID].Nickname, users[toUserID].Nickname, nil +// } func (u *UserNotificationSender) UserStatusChangeNotification( ctx context.Context, diff --git a/pkg/rpcclient/push.go b/pkg/rpcclient/push.go index 6d0876972..7733572bf 100644 --- a/pkg/rpcclient/push.go +++ b/pkg/rpcclient/push.go @@ -36,6 +36,7 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push { if err != nil { panic(err) } + return &Push{ discov: discov, conn: conn, diff --git a/pkg/rpcclient/third.go b/pkg/rpcclient/third.go old mode 100644 new mode 100755 index 48a537112..2bb761450 --- a/pkg/rpcclient/third.go +++ b/pkg/rpcclient/third.go @@ -42,14 +42,13 @@ func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { panic(err) } client := third.NewThirdClient(conn) - minioClient, err := minioInit() + minioClient, _ := minioInit() + return &Third{discov: discov, Client: client, conn: conn, MinioClient: minioClient} } func minioInit() (*minio.Client, error) { - minioClient := &minio.Client{} - var initUrl string - initUrl = config.Config.Object.Minio.Endpoint + initUrl := config.Config.Object.Minio.Endpoint minioUrl, err := url.Parse(initUrl) if err != nil { return nil, err @@ -63,9 +62,11 @@ func minioInit() (*minio.Client, error) { } else if minioUrl.Scheme == "https" { opts.Secure = true } + var minioClient *minio.Client minioClient, err = minio.New(minioUrl.Host, opts) if err != nil { return nil, err } + return minioClient, nil } diff --git a/pkg/rpcclient/user.go b/pkg/rpcclient/user.go index c40d95727..dfd93fb0b 100644 --- a/pkg/rpcclient/user.go +++ b/pkg/rpcclient/user.go @@ -45,6 +45,7 @@ func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User { panic(err) } client := user.NewUserClient(conn) + return &User{Discov: discov, Client: client, conn: conn} } @@ -54,6 +55,7 @@ type UserRpcClient User // NewUserRpcClientByUser initializes a UserRpcClient based on the provided User instance. func NewUserRpcClientByUser(user *User) *UserRpcClient { rpc := UserRpcClient(*user) + return &rpc } @@ -75,6 +77,7 @@ func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]* })); len(ids) > 0 { return nil, errs.ErrUserIDNotFound.Wrap(strings.Join(ids, ",")) } + return resp.UsersInfo, nil } @@ -84,6 +87,7 @@ func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws. if err != nil { return nil, err } + return users[0], nil } @@ -93,6 +97,7 @@ func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) ( if err != nil { return nil, err } + return utils.SliceToMap(users, func(e *sdkws.UserInfo) string { return e.UserID }), nil @@ -108,6 +113,7 @@ func (u *UserRpcClient) GetPublicUserInfos( if err != nil { return nil, err } + return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo { return &sdkws.PublicUserInfo{ UserID: e.UserID, @@ -124,6 +130,7 @@ func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (* if err != nil { return nil, err } + return users[0], nil } @@ -137,6 +144,7 @@ func (u *UserRpcClient) GetPublicUserInfoMap( if err != nil { return nil, err } + return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string { return e.UserID }), nil @@ -150,6 +158,7 @@ func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri if err != nil { return 0, err } + return resp.GlobalRecvMsgOpt, nil } @@ -159,6 +168,7 @@ func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error { if err != nil { return err } + return authverify.CheckAccessV3(ctx, ownerUserID) } @@ -168,6 +178,7 @@ func (u *UserRpcClient) GetAllUserIDs(ctx context.Context, pageNumber, showNumbe if err != nil { return nil, err } + return resp.UserIDs, nil } @@ -177,5 +188,6 @@ func (u *UserRpcClient) SetUserStatus(ctx context.Context, userID string, status UserID: userID, Status: status, PlatformID: int32(platformID), }) + return err }