|
|
|
@ -16,7 +16,6 @@ package user
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/internal/rpc/friend"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/redis"
|
|
|
|
@ -24,12 +23,9 @@ import (
|
|
|
|
|
tablerelation "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/localcache"
|
|
|
|
|
friendpb "github.com/openimsdk/protocol/friend"
|
|
|
|
|
"github.com/openimsdk/protocol/group"
|
|
|
|
|
"github.com/openimsdk/tools/db/redisutil"
|
|
|
|
|
"math/rand"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
|
|
@ -135,29 +131,26 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
|
|
|
|
|
if err := s.webhookBeforeUpdateUserInfo(ctx, &s.config.WebhooksConfig.BeforeUpdateUserInfo, req); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := convert.UserPb2DBMap(req.UserInfo)
|
|
|
|
|
oldUser, err := s.db.GetUserByID(ctx, req.UserInfo.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if err := s.db.UpdateByMap(ctx, req.UserInfo.UserID, data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if err := s.db.UpdateByMap(ctx, req.UserInfo.UserID, data); err != nil {
|
|
|
|
|
s.friendNotificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID)
|
|
|
|
|
friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
//s.friendNotificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID)
|
|
|
|
|
//friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID)
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// return nil, err
|
|
|
|
|
//}
|
|
|
|
|
//if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" {
|
|
|
|
|
// if err = s.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID,oldUser); err != nil {
|
|
|
|
|
// return nil, err
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//for _, friendID := range friends {
|
|
|
|
|
// s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
|
|
|
|
//}
|
|
|
|
|
if req.UserInfo.Nickname != "" || req.UserInfo.FaceURL != "" {
|
|
|
|
|
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, friendID := range friends {
|
|
|
|
|
s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
|
|
|
|
}
|
|
|
|
|
s.webhookAfterUpdateUserInfo(ctx, &s.config.WebhooksConfig.AfterUpdateUserInfo, req)
|
|
|
|
|
if err = s.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID, oldUser); err != nil {
|
|
|
|
|
if err = s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp, nil
|
|
|
|
@ -171,29 +164,25 @@ func (s *userServer) UpdateUserInfoEx(ctx context.Context, req *pbuser.UpdateUse
|
|
|
|
|
if err = s.webhookBeforeUpdateUserInfoEx(ctx, &s.config.WebhooksConfig.BeforeUpdateUserInfoEx, req); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
oldUser, err := s.db.GetUserByID(ctx, req.UserInfo.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
data := convert.UserPb2DBMapEx(req.UserInfo)
|
|
|
|
|
if err = s.db.UpdateByMap(ctx, req.UserInfo.UserID, data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
//s.friendNotificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID)
|
|
|
|
|
//friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID)
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// return nil, err
|
|
|
|
|
//}
|
|
|
|
|
//if req.UserInfo.Nickname != nil || req.UserInfo.FaceURL != nil {
|
|
|
|
|
// if err := s.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
|
|
|
|
// return nil, err
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//for _, friendID := range friends {
|
|
|
|
|
// s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
|
|
|
|
//}
|
|
|
|
|
s.friendNotificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID)
|
|
|
|
|
friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if req.UserInfo.Nickname != nil || req.UserInfo.FaceURL != nil {
|
|
|
|
|
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, friendID := range friends {
|
|
|
|
|
s.friendNotificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID)
|
|
|
|
|
}
|
|
|
|
|
s.webhookAfterUpdateUserInfoEx(ctx, &s.config.WebhooksConfig.AfterUpdateUserInfoEx, req)
|
|
|
|
|
if err := s.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID, oldUser); err != nil {
|
|
|
|
|
if err := s.groupRpcClient.NotificationUserInfoUpdate(ctx, req.UserInfo.UserID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return resp, nil
|
|
|
|
@ -695,40 +684,10 @@ func (s *userServer) userModelToResp(users []*tablerelation.User, pagination pag
|
|
|
|
|
return &pbuser.SearchNotificationAccountResp{Total: total, NotificationAccounts: notificationAccounts}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *userServer) NotificationUserInfoUpdate(ctx context.Context, userID string, oldUser *tablerelation.User) error {
|
|
|
|
|
user, err := s.db.GetUserByID(ctx, userID)
|
|
|
|
|
func (s *userServer) SortQuery(ctx context.Context, req *pbuser.SortQueryReq) (*pbuser.SortQueryResp, error) {
|
|
|
|
|
users, err := s.db.SortQuery(ctx, req.UserIDName, req.Asc)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if *user == *oldUser {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
s.friendNotificationSender.UserInfoUpdatedNotification(ctx, userID)
|
|
|
|
|
if user.Nickname == oldUser.Nickname && user.FaceURL == oldUser.FaceURL {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
oldUserInfo := convert.UserDB2Pb(oldUser)
|
|
|
|
|
newUserInfo := convert.UserDB2Pb(user)
|
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
var es [2]error
|
|
|
|
|
wg.Add(len(es))
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
_, es[0] = s.groupRpcClient.Client.NotificationUserInfoUpdate(ctx, &group.NotificationUserInfoUpdateReq{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
OldUserInfo: oldUserInfo,
|
|
|
|
|
NewUserInfo: newUserInfo,
|
|
|
|
|
})
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
_, es[1] = s.friendRpcClient.Client.NotificationUserInfoUpdate(ctx, &friendpb.NotificationUserInfoUpdateReq{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
OldUserInfo: oldUserInfo,
|
|
|
|
|
NewUserInfo: newUserInfo,
|
|
|
|
|
})
|
|
|
|
|
}()
|
|
|
|
|
wg.Wait()
|
|
|
|
|
return errors.Join(es[:]...)
|
|
|
|
|
return &pbuser.SortQueryResp{Users: convert.UsersDB2Pb(users)}, nil
|
|
|
|
|
}
|
|
|
|
|