mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
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
This commit is contained in:
parent
e5ab278be5
commit
4cacc3f621
@ -246,7 +246,6 @@ func (s *friendServer) GetPaginationFriendsApplyTo(
|
|||||||
req *pbfriend.GetPaginationFriendsApplyToReq,
|
req *pbfriend.GetPaginationFriendsApplyToReq,
|
||||||
) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) {
|
) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) {
|
||||||
defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
|
defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
|
||||||
resp = &pbfriend.GetPaginationFriendsApplyToResp{}
|
|
||||||
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -255,6 +254,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
resp = &pbfriend.GetPaginationFriendsApplyToResp{}
|
||||||
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
|
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -291,8 +291,9 @@ const (
|
|||||||
GroupResponseAgree = 1
|
GroupResponseAgree = 1
|
||||||
GroupResponseRefuse = -1
|
GroupResponseRefuse = -1
|
||||||
|
|
||||||
FriendResponseAgree = 1
|
FriendResponseNotHandle = 0
|
||||||
FriendResponseRefuse = -1
|
FriendResponseAgree = 1
|
||||||
|
FriendResponseRefuse = -1
|
||||||
|
|
||||||
Male = 1
|
Male = 1
|
||||||
Female = 2
|
Female = 2
|
||||||
|
@ -27,6 +27,9 @@ func BlackDB2Pb(
|
|||||||
blackDBs []*relation.BlackModel,
|
blackDBs []*relation.BlackModel,
|
||||||
f func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
f func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
||||||
) (blackPbs []*sdk.BlackInfo, err error) {
|
) (blackPbs []*sdk.BlackInfo, err error) {
|
||||||
|
if len(blackDBs) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
var userIDs []string
|
var userIDs []string
|
||||||
for _, blackDB := range blackDBs {
|
for _, blackDB := range blackDBs {
|
||||||
userIDs = append(userIDs, blackDB.BlockUserID)
|
userIDs = append(userIDs, blackDB.BlockUserID)
|
||||||
|
@ -54,6 +54,9 @@ func FriendsDB2Pb(
|
|||||||
friendsDB []*relation.FriendModel,
|
friendsDB []*relation.FriendModel,
|
||||||
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
||||||
) (friendsPb []*sdkws.FriendInfo, err error) {
|
) (friendsPb []*sdkws.FriendInfo, err error) {
|
||||||
|
if len(friendsDB) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
var userID []string
|
var userID []string
|
||||||
for _, friendDB := range friendsDB {
|
for _, friendDB := range friendsDB {
|
||||||
userID = append(userID, friendDB.FriendUserID)
|
userID = append(userID, friendDB.FriendUserID)
|
||||||
@ -80,6 +83,9 @@ func FriendRequestDB2Pb(
|
|||||||
friendRequests []*relation.FriendRequestModel,
|
friendRequests []*relation.FriendRequestModel,
|
||||||
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
getUsers func(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error),
|
||||||
) ([]*sdkws.FriendRequest, error) {
|
) ([]*sdkws.FriendRequest, error) {
|
||||||
|
if len(friendRequests) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
userIDMap := make(map[string]struct{})
|
userIDMap := make(map[string]struct{})
|
||||||
for _, friendRequest := range friendRequests {
|
for _, friendRequest := range friendRequests {
|
||||||
userIDMap[friendRequest.ToUserID] = struct{}{}
|
userIDMap[friendRequest.ToUserID] = struct{}{}
|
||||||
|
@ -221,6 +221,7 @@ func (f *friendDatabase) AgreeFriendRequest(
|
|||||||
friendRequest *relation.FriendRequestModel,
|
friendRequest *relation.FriendRequestModel,
|
||||||
) (err error) {
|
) (err error) {
|
||||||
return f.tx.Transaction(func(tx any) error {
|
return f.tx.Transaction(func(tx any) error {
|
||||||
|
now := time.Now()
|
||||||
fr, err := f.friendRequest.NewTx(tx).Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
|
fr, err := f.friendRequest.NewTx(tx).Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -230,11 +231,25 @@ func (f *friendDatabase) AgreeFriendRequest(
|
|||||||
}
|
}
|
||||||
friendRequest.HandlerUserID = mcontext.GetOpUserID(ctx)
|
friendRequest.HandlerUserID = mcontext.GetOpUserID(ctx)
|
||||||
friendRequest.HandleResult = constant.FriendResponseAgree
|
friendRequest.HandleResult = constant.FriendResponseAgree
|
||||||
friendRequest.HandleTime = time.Now()
|
friendRequest.HandleTime = now
|
||||||
err = f.friendRequest.NewTx(tx).Update(ctx, friendRequest)
|
err = f.friendRequest.NewTx(tx).Update(ctx, friendRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
exists, err := f.friend.NewTx(tx).FindUserState(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -23,9 +23,6 @@ func (x *CreateGroupReq) Check() error {
|
|||||||
if x.GroupInfo == nil {
|
if x.GroupInfo == nil {
|
||||||
return errs.ErrArgs.Wrap("groupInfo is empty")
|
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 {
|
if x.GroupInfo.GroupType > 2 || x.GroupInfo.GroupType < 0 {
|
||||||
return errs.ErrArgs.Wrap("GroupType is invalid")
|
return errs.ErrArgs.Wrap("GroupType is invalid")
|
||||||
}
|
}
|
||||||
|
@ -133,9 +133,6 @@ func (x *MarkConversationAsReadReq) Check() error {
|
|||||||
if x.ConversationID == "" {
|
if x.ConversationID == "" {
|
||||||
return errs.ErrArgs.Wrap("conversationID is empty")
|
return errs.ErrArgs.Wrap("conversationID is empty")
|
||||||
}
|
}
|
||||||
if x.Seqs == nil {
|
|
||||||
return errs.ErrArgs.Wrap("seqs is empty")
|
|
||||||
}
|
|
||||||
if x.UserID == "" {
|
if x.UserID == "" {
|
||||||
return errs.ErrArgs.Wrap("userID is empty")
|
return errs.ErrArgs.Wrap("userID is empty")
|
||||||
}
|
}
|
||||||
@ -165,9 +162,6 @@ func (x *ClearConversationsMsgReq) Check() error {
|
|||||||
if x.UserID == "" {
|
if x.UserID == "" {
|
||||||
return errs.ErrArgs.Wrap("userID is empty")
|
return errs.ErrArgs.Wrap("userID is empty")
|
||||||
}
|
}
|
||||||
if x.DeleteSyncOpt == nil {
|
|
||||||
return errs.ErrArgs.Wrap("deleteSyncOpt is empty")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,9 +169,6 @@ func (x *UserClearAllMsgReq) Check() error {
|
|||||||
if x.UserID == "" {
|
if x.UserID == "" {
|
||||||
return errs.ErrArgs.Wrap("userID is empty")
|
return errs.ErrArgs.Wrap("userID is empty")
|
||||||
}
|
}
|
||||||
if x.DeleteSyncOpt == nil {
|
|
||||||
return errs.ErrArgs.Wrap("deleteSyncOpt is empty")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +182,6 @@ func (x *DeleteMsgsReq) Check() error {
|
|||||||
if x.Seqs == nil {
|
if x.Seqs == nil {
|
||||||
return errs.ErrArgs.Wrap("seqs is empty")
|
return errs.ErrArgs.Wrap("seqs is empty")
|
||||||
}
|
}
|
||||||
if x.DeleteSyncOpt == nil {
|
|
||||||
return errs.ErrArgs.Wrap("deleteSyncOpt is empty")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user