From 48a60ff266d301d75f64e1a5c248c09fd88a0f8d Mon Sep 17 00:00:00 2001 From: hawklin2017 <32898629+hawklin2017@users.noreply.github.com> Date: Wed, 20 May 2026 22:31:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A5=BD=E5=8F=8Bremark?= =?UTF-8?q?=EF=BC=8C=E9=80=9A=E7=9F=A5=E7=BE=A4=E8=B5=84=E6=96=99=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/rpc/group/group.go | 26 +++++++++++++++++++++++++- internal/rpc/group/notification.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 47f860ca1..639e20070 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -165,12 +165,36 @@ func (s *groupServer) NotificationFriendRemarkUpdate(ctx context.Context, req *p if err != nil { 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 { - s.notification.GroupMemberInfoSetNotification(ctx, member.GroupID, req.FriendUserID) + s.notification.GroupMemberRemarkUpdateNotification(ctx, member.GroupID, req.FriendUserID, req.OwnerUserID, displayName) } 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) { members, err := s.db.FindGroupMemberUser(ctx, nil, req.UserID) if err != nil { diff --git a/internal/rpc/group/notification.go b/internal/rpc/group/notification.go index 71daa3a16..8b2094883 100644 --- a/internal/rpc/group/notification.go +++ b/internal/rpc/group/notification.go @@ -803,6 +803,36 @@ func (g *NotificationSender) GroupCancelMutedNotification(ctx context.Context, g 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) { var err error defer func() {