mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-07-13 00:21:10 +08:00
修改好友remark,通知群资料更新
This commit is contained in:
parent
2e39bd1d9c
commit
48a60ff266
@ -165,12 +165,36 @@ func (s *groupServer) NotificationFriendRemarkUpdate(ctx context.Context, req *p
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if len(commonMembers) == 0 {
|
||||||
|
return &pbgroup.NotificationFriendRemarkUpdateResp{}, nil
|
||||||
|
}
|
||||||
|
displayName, err := s.resolveFriendDisplayName(ctx, req.OwnerUserID, req.FriendUserID)
|
||||||
|
if err != nil {
|
||||||
|
log.ZWarn(ctx, "resolveFriendDisplayName", err, "ownerUserID", req.OwnerUserID, "friendUserID", req.FriendUserID)
|
||||||
|
}
|
||||||
for _, member := range commonMembers {
|
for _, member := range commonMembers {
|
||||||
s.notification.GroupMemberInfoSetNotification(ctx, member.GroupID, req.FriendUserID)
|
s.notification.GroupMemberRemarkUpdateNotification(ctx, member.GroupID, req.FriendUserID, req.OwnerUserID, displayName)
|
||||||
}
|
}
|
||||||
return &pbgroup.NotificationFriendRemarkUpdateResp{}, nil
|
return &pbgroup.NotificationFriendRemarkUpdateResp{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resolveFriendDisplayName returns the display name for friendUserID as seen by ownerUserID,
|
||||||
|
// following the priority: remark (if set) > firstName > nickname.
|
||||||
|
func (s *groupServer) resolveFriendDisplayName(ctx context.Context, ownerUserID, friendUserID string) (string, error) {
|
||||||
|
friendInfos, err := s.relationClient.GetFriendsInfo(ctx, ownerUserID, []string{friendUserID})
|
||||||
|
if err == nil && len(friendInfos) > 0 && friendInfos[0].GetRemark() != "" {
|
||||||
|
return friendInfos[0].GetRemark(), nil
|
||||||
|
}
|
||||||
|
users, err := s.userClient.GetUsersInfo(ctx, []string{friendUserID})
|
||||||
|
if err != nil || len(users) == 0 {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if users[0].FirstName != "" {
|
||||||
|
return users[0].FirstName, nil
|
||||||
|
}
|
||||||
|
return users[0].Nickname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *groupServer) NotificationUserInfoUpdate(ctx context.Context, req *pbgroup.NotificationUserInfoUpdateReq) (*pbgroup.NotificationUserInfoUpdateResp, error) {
|
func (s *groupServer) NotificationUserInfoUpdate(ctx context.Context, req *pbgroup.NotificationUserInfoUpdateReq) (*pbgroup.NotificationUserInfoUpdateResp, error) {
|
||||||
members, err := s.db.FindGroupMemberUser(ctx, nil, req.UserID)
|
members, err := s.db.FindGroupMemberUser(ctx, nil, req.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -803,6 +803,36 @@ func (g *NotificationSender) GroupCancelMutedNotification(ctx context.Context, g
|
|||||||
g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
|
g.Notification(ctx, mcontext.GetOpUserID(ctx), group.GroupID, constant.GroupCancelMutedNotification, tips)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupMemberRemarkUpdateNotification sends GroupMemberInfoSetNotification only to ownerUserID
|
||||||
|
// (as a single-chat notification), with ChangedUser.Nickname overridden by displayName
|
||||||
|
// (resolved as remark > firstName > nickname by the caller).
|
||||||
|
func (g *NotificationSender) GroupMemberRemarkUpdateNotification(ctx context.Context, groupID, friendUserID, ownerUserID, displayName string) {
|
||||||
|
var err error
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, stringutil.GetFuncName(1)+" failed", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
group, err := g.getGroupInfo(ctx, groupID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
changedUser, err := g.getGroupMember(ctx, groupID, friendUserID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if displayName != "" {
|
||||||
|
changedUser.Nickname = displayName
|
||||||
|
}
|
||||||
|
tips := &sdkws.GroupMemberInfoSetTips{
|
||||||
|
Group: group,
|
||||||
|
ChangedUser: changedUser,
|
||||||
|
}
|
||||||
|
g.setSortVersion(ctx, &tips.GroupMemberVersion, &tips.GroupMemberVersionID, database.GroupMemberVersionName, groupID, &tips.GroupSortVersion)
|
||||||
|
g.NotificationWithSessionType(ctx, ownerUserID, ownerUserID, constant.GroupMemberInfoSetNotification,
|
||||||
|
constant.SingleChatType, tips, notification.WithGroupID(groupID))
|
||||||
|
}
|
||||||
|
|
||||||
func (g *NotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
func (g *NotificationSender) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user