Commit b5f5c408eeec8e4d6acb1ec5a7513de5b1f7cd70
1 parent
b0221c21
✨ feat(im):好友申请通知 payload 补 fromNickname/fromAvatar,前端按 requestId 直推不再回拉
Showing
2 changed files
with
17 additions
and
2 deletions
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/friend/ImFriendRequestServiceImpl.java
| ... | ... | @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.im.service.websocket.dto.notification.friend.Frie |
| 20 | 20 | import cn.iocoder.yudao.module.im.service.websocket.dto.notification.friend.FriendRequestNotification; |
| 21 | 21 | import cn.iocoder.yudao.module.im.service.websocket.dto.notification.friend.FriendRequestRejectedNotification; |
| 22 | 22 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 23 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 23 | 24 | import jakarta.annotation.Resource; |
| 24 | 25 | import lombok.extern.slf4j.Slf4j; |
| 25 | 26 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -98,9 +99,12 @@ public class ImFriendRequestServiceImpl implements ImFriendRequestService { |
| 98 | 99 | friendRequestMapper.insert(request); |
| 99 | 100 | } |
| 100 | 101 | |
| 101 | - // 3. 推送 FRIEND_REQUEST_RECEIVED 给 toUser 多端 | |
| 102 | + // 3. 推送 FRIEND_REQUEST_RECEIVED 给 toUser 多端;payload 携带申请方昵称 / 头像,前端按 requestId 直推 push 进列表 | |
| 103 | + AdminUserRespDTO fromUser = adminUserApi.getUser(fromUserId); | |
| 102 | 104 | FriendRequestNotification payload = (FriendRequestNotification) new FriendRequestNotification() |
| 103 | 105 | .setRequestId(request.getId()).setApplyContent(request.getApplyContent()).setAddSource(request.getAddSource()) |
| 106 | + .setFromNickname(fromUser != null ? fromUser.getNickname() : null) | |
| 107 | + .setFromAvatar(fromUser != null ? fromUser.getAvatar() : null) | |
| 104 | 108 | .setOperatorUserId(fromUserId).setFriendUserId(fromUserId); |
| 105 | 109 | websocketService.sendPrivateMessageAsync(toUserId, ImPrivateMessageDTO.ofFriendNotification( |
| 106 | 110 | ImMessageTypeEnum.FRIEND_REQUEST_RECEIVED.getType(), fromUserId, toUserId, payload)); | ... | ... |
yudao-module-im/src/main/java/cn/iocoder/yudao/module/im/service/websocket/dto/notification/friend/FriendRequestNotification.java
| ... | ... | @@ -5,7 +5,7 @@ import lombok.Data; |
| 5 | 5 | /** |
| 6 | 6 | * 收到新的好友申请通知 |
| 7 | 7 | * <p> |
| 8 | - * 推送给申请的接收方多端;前端拿到 requestId 后按需 fetch 完整申请记录,避免 payload 体积过大 | |
| 8 | + * 推送给申请的接收方多端;payload 已携带 fromUser 聚合字段,前端按 requestId 直接 push 进列表,无需回拉 | |
| 9 | 9 | */ |
| 10 | 10 | @Data |
| 11 | 11 | public class FriendRequestNotification extends BaseFriendNotification { |
| ... | ... | @@ -23,4 +23,15 @@ public class FriendRequestNotification extends BaseFriendNotification { |
| 23 | 23 | */ |
| 24 | 24 | private Integer addSource; |
| 25 | 25 | |
| 26 | + // ========== 聚合自 AdminUser,避免前端再调 system 接口 ========== | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 申请方昵称 | |
| 30 | + */ | |
| 31 | + private String fromNickname; | |
| 32 | + /** | |
| 33 | + * 申请方头像 | |
| 34 | + */ | |
| 35 | + private String fromAvatar; | |
| 36 | + | |
| 26 | 37 | } | ... | ... |