diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index c07b1423c..4c528d1d1 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -246,7 +246,6 @@ func (s *friendServer) GetPaginationFriendsApplyTo( req *pbfriend.GetPaginationFriendsApplyToReq, ) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) { defer log.ZInfo(ctx, utils.GetFuncName()+" Return") - resp = &pbfriend.GetPaginationFriendsApplyToResp{} if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { return nil, err } @@ -255,6 +254,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo( if err != nil { return nil, err } + resp = &pbfriend.GetPaginationFriendsApplyToResp{} resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap) if err != nil { return nil, err diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index ef33b9867..2e5432b48 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -291,8 +291,9 @@ const ( GroupResponseAgree = 1 GroupResponseRefuse = -1 - FriendResponseAgree = 1 - FriendResponseRefuse = -1 + FriendResponseNotHandle = 0 + FriendResponseAgree = 1 + FriendResponseRefuse = -1 Male = 1 Female = 2 diff --git a/pkg/common/convert/black.go b/pkg/common/convert/black.go index 684a40d0d..ba0e2a5da 100644 --- a/pkg/common/convert/black.go +++ b/pkg/common/convert/black.go @@ -27,6 +27,9 @@ func BlackDB2Pb( blackDBs []*relation.BlackModel, f func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error), ) (blackPbs []*sdk.BlackInfo, err error) { + if len(blackDBs) == 0 { + return nil, nil + } var userIDs []string for _, blackDB := range blackDBs { userIDs = append(userIDs, blackDB.BlockUserID) diff --git a/pkg/common/convert/friend.go b/pkg/common/convert/friend.go index 018aee42f..0531ad195 100644 --- a/pkg/common/convert/friend.go +++ b/pkg/common/convert/friend.go @@ -54,6 +54,9 @@ func FriendsDB2Pb( friendsDB []*relation.FriendModel, getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error), ) (friendsPb []*sdkws.FriendInfo, err error) { + if len(friendsDB) == 0 { + return nil, nil + } var userID []string for _, friendDB := range friendsDB { userID = append(userID, friendDB.FriendUserID) @@ -80,6 +83,9 @@ func FriendRequestDB2Pb( friendRequests []*relation.FriendRequestModel, getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error), ) ([]*sdkws.FriendRequest, error) { + if len(friendRequests) == 0 { + return nil, nil + } userIDMap := make(map[string]struct{}) for _, friendRequest := range friendRequests { userIDMap[friendRequest.ToUserID] = struct{}{} diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 116345219..4d549efcf 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -221,6 +221,7 @@ func (f *friendDatabase) AgreeFriendRequest( friendRequest *relation.FriendRequestModel, ) (err error) { return f.tx.Transaction(func(tx any) error { + now := time.Now() fr, err := f.friendRequest.NewTx(tx).Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID) if err != nil { return err @@ -230,11 +231,25 @@ func (f *friendDatabase) AgreeFriendRequest( } friendRequest.HandlerUserID = mcontext.GetOpUserID(ctx) friendRequest.HandleResult = constant.FriendResponseAgree - friendRequest.HandleTime = time.Now() + friendRequest.HandleTime = now err = f.friendRequest.NewTx(tx).Update(ctx, friendRequest) if err != nil { return err } + + fr2, err := f.friendRequest.NewTx(tx).Take(ctx, friendRequest.ToUserID, friendRequest.FromUserID) + if err == nil && fr2.HandleResult == constant.FriendResponseNotHandle { + fr2.HandlerUserID = mcontext.GetOpUserID(ctx) + fr2.HandleResult = constant.FriendResponseAgree + fr2.HandleTime = now + err = f.friendRequest.NewTx(tx).Update(ctx, fr2) + if err != nil { + return err + } + } else if errs.Unwrap(err) != gorm.ErrRecordNotFound { + return err + } + exists, err := f.friend.NewTx(tx).FindUserState(ctx, friendRequest.FromUserID, friendRequest.ToUserID) if err != nil { return err diff --git a/pkg/proto/group/group.go b/pkg/proto/group/group.go index 64e7f0f61..5b387cb3a 100644 --- a/pkg/proto/group/group.go +++ b/pkg/proto/group/group.go @@ -23,9 +23,6 @@ func (x *CreateGroupReq) Check() error { if x.GroupInfo == nil { return errs.ErrArgs.Wrap("groupInfo is empty") } - if x.GroupInfo.OwnerUserID == "" { - return errs.ErrArgs.Wrap("GroupInfo.ownerUserID") - } if x.GroupInfo.GroupType > 2 || x.GroupInfo.GroupType < 0 { return errs.ErrArgs.Wrap("GroupType is invalid") } diff --git a/pkg/proto/msg/msg.go b/pkg/proto/msg/msg.go index aeb6deece..62b776856 100644 --- a/pkg/proto/msg/msg.go +++ b/pkg/proto/msg/msg.go @@ -133,9 +133,6 @@ func (x *MarkConversationAsReadReq) Check() error { if x.ConversationID == "" { return errs.ErrArgs.Wrap("conversationID is empty") } - if x.Seqs == nil { - return errs.ErrArgs.Wrap("seqs is empty") - } if x.UserID == "" { return errs.ErrArgs.Wrap("userID is empty") } @@ -165,9 +162,6 @@ func (x *ClearConversationsMsgReq) Check() error { if x.UserID == "" { return errs.ErrArgs.Wrap("userID is empty") } - if x.DeleteSyncOpt == nil { - return errs.ErrArgs.Wrap("deleteSyncOpt is empty") - } return nil } @@ -175,9 +169,6 @@ func (x *UserClearAllMsgReq) Check() error { if x.UserID == "" { return errs.ErrArgs.Wrap("userID is empty") } - if x.DeleteSyncOpt == nil { - return errs.ErrArgs.Wrap("deleteSyncOpt is empty") - } return nil } @@ -191,9 +182,6 @@ func (x *DeleteMsgsReq) Check() error { if x.Seqs == nil { return errs.ErrArgs.Wrap("seqs is empty") } - if x.DeleteSyncOpt == nil { - return errs.ErrArgs.Wrap("deleteSyncOpt is empty") - } return nil }