Skip to content

Commit

Permalink
fix: improve batchUserFaceURLandName logic. (#756)
Browse files Browse the repository at this point in the history
* refactor: update ServerAPI method name.

* feat: improve batchUserFaceURLandName logic.

* update logic.
  • Loading branch information
mo3et authored Oct 25, 2024
1 parent 476b148 commit e2389f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 10 additions & 3 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback"
"math"
"sync"

sdk "github.com/openimsdk/openim-sdk-core/v3/pkg/sdk_params_callback"

"github.com/openimsdk/openim-sdk-core/v3/pkg/api"
"github.com/openimsdk/openim-sdk-core/v3/pkg/cache"
"github.com/openimsdk/tools/utils/stringutil"
Expand Down Expand Up @@ -924,6 +925,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
if err != nil {
return err
}

groups := datautil.SliceToMap(groupInfoList, func(groupInfo *model_struct.LocalGroup) string {
return groupInfo.GroupID
})
Expand All @@ -935,8 +937,10 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations
conversation.FaceURL = v.FaceURL
conversation.ShowName = v.Nickname
} else {
log.ZWarn(ctx, "user info not found", errors.New("user not found"),
"userID", conversation.UserID)
log.ZWarn(ctx, "user info not found", errors.New("user not found"),"userID", conversation.UserID)

conversation.FaceURL = ""
conversation.ShowName = "UserNotFound"
}
} else if conversation.ConversationType == constant.ReadGroupChatType {
if v, ok := groups[conversation.GroupID]; ok {
Expand All @@ -949,6 +953,7 @@ func (c *Conversation) batchAddFaceURLAndName(ctx context.Context, conversations

}
}

return nil
}

Expand Down Expand Up @@ -979,10 +984,12 @@ func (c *Conversation) batchGetUserNameAndFaceURL(ctx context.Context, userIDs .
}
m[localFriend.FriendUserID] = userInfo
}

usersInfo, err := c.user.GetUsersInfoWithCache(ctx, notInFriend)
if err != nil {
return nil, err
}

for _, userInfo := range usersInfo {
m[userInfo.UserID] = userInfo
}
Expand Down
20 changes: 14 additions & 6 deletions internal/user/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/openimsdk/tools/utils/datautil"
)

// GetSingleUserFromSvr retrieves user information from the server.
func (u *User) GetSingleUserFromSvr(ctx context.Context, userID string) (*model_struct.LocalUser, error) {
users, err := u.GetUsersInfoFromSvr(ctx, []string{userID})
// GetSingleUserFromServer retrieves user information from the server.
func (u *User) GetSingleUserFromServer(ctx context.Context, userID string) (*model_struct.LocalUser, error) {
users, err := u.GetUsersInfoFromServer(ctx, []string{userID})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -125,10 +125,18 @@ func (u *User) ProcessUserCommandUpdate(ctx context.Context, userCommand *userPb

// GetUserInfoFromServer retrieves user information from the server.
func (u *User) GetUserInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
var err error

serverUsersInfo, err := u.getUsersInfo(ctx, userIDs)
if err != nil {
return nil, err
}

if len(serverUsersInfo) == 0 {
log.ZError(ctx, "serverUsersInfo is empty", err, "userIDs", userIDs)
return nil, err
}

return datautil.Batch(ServerUserToLocalUser, serverUsersInfo), nil
}

Expand Down Expand Up @@ -171,11 +179,11 @@ func (u *User) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdk_struc
return res, nil
}

// GetUsersInfoFromSvr retrieves user information from the server.
func (u *User) GetUsersInfoFromSvr(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
// GetUsersInfoFromServer retrieves user information from the server.
func (u *User) GetUsersInfoFromServer(ctx context.Context, userIDs []string) ([]*model_struct.LocalUser, error) {
users, err := u.getUsersInfo(ctx, userIDs)
if err != nil {
return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromSvr failed")
return nil, sdkerrs.WrapMsg(err, "GetUsersInfoFromServer failed")
}
return datautil.Batch(ServerUserToLocalUser, users), nil
}
5 changes: 3 additions & 2 deletions internal/user/full_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user
import (
"context"
"errors"

"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
userPb "github.com/openimsdk/protocol/user"
"github.com/openimsdk/tools/errs"
Expand All @@ -11,7 +12,7 @@ import (
)

func (u *User) SyncLoginUserInfo(ctx context.Context) error {
remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID)
remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID)
if err != nil {
return err
}
Expand All @@ -28,7 +29,7 @@ func (u *User) SyncLoginUserInfo(ctx context.Context) error {
}

func (u *User) SyncLoginUserInfoWithoutNotice(ctx context.Context) error {
remoteUser, err := u.GetSingleUserFromSvr(ctx, u.loginUserID)
remoteUser, err := u.GetSingleUserFromServer(ctx, u.loginUserID)
if err != nil {
return err
}
Expand Down

0 comments on commit e2389f1

Please sign in to comment.