fix bug: friend, args error (#534)

* fix bug: args error

* fix bug: args error

* fix bug: add friend need update both request

* fix bug: add friend need update both request
pull/526/head
WangchuXiao 1 year ago committed by GitHub
parent e5ab278be5
commit 4cacc3f621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -291,8 +291,9 @@ const (
GroupResponseAgree = 1
GroupResponseRefuse = -1
FriendResponseAgree = 1
FriendResponseRefuse = -1
FriendResponseNotHandle = 0
FriendResponseAgree = 1
FriendResponseRefuse = -1
Male = 1
Female = 2

@ -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)

@ -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{}{}

@ -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

@ -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")
}

@ -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
}

Loading…
Cancel
Save