pyq
This commit is contained in:
@@ -222,6 +222,9 @@ func (s *ChatService) HandleUserMessage(senderClient *manager.Client, req *model
|
||||
s.DispatchMessage(uid, msgBytes)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理@通知
|
||||
s.handleMentionNotification(senderClient.UserID, req.RoomID, extraData, msg)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -442,6 +445,71 @@ func (s *ChatService) SubscribeClusterMessages() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handleMentionNotification
|
||||
* 功能:处理群聊消息中的@通知
|
||||
* @param senderID 发送者ID
|
||||
* @param roomID 房间ID
|
||||
* @param extraData 消息的extra字段(JSON格式)
|
||||
* @param msg 消息对象
|
||||
*/
|
||||
func (s *ChatService) handleMentionNotification(senderID, roomID, extraData string, msg model.ChatMessage) {
|
||||
if extraData == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// 解析 extra 字段
|
||||
var extra struct {
|
||||
MentionUserIDs []string `json:"mention_user_ids"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(extraData), &extra); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(extra.MentionUserIDs) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取发送者信息
|
||||
var sender model.User
|
||||
if err := s.DB.Where("id = ?", senderID).First(&sender).Error; err != nil {
|
||||
return
|
||||
}
|
||||
sender.Password = ""
|
||||
|
||||
// 获取房间信息
|
||||
var room model.ChatRoom
|
||||
if err := s.DB.Where("room_id = ?", roomID).First(&room).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 为每个被@的用户发送通知
|
||||
for _, mentionUserID := range extra.MentionUserIDs {
|
||||
// 不通知自己
|
||||
if mentionUserID == senderID {
|
||||
continue
|
||||
}
|
||||
|
||||
// 构建@通知消息
|
||||
notifMsg := model.WsPayload{
|
||||
RequestType: "mention_notification",
|
||||
Data: map[string]interface{}{
|
||||
"type": "mention",
|
||||
"room_id": roomID,
|
||||
"room_name": room.RoomName,
|
||||
"sender": sender,
|
||||
"message": msg.Content,
|
||||
"message_id": msg.ID,
|
||||
"created_at": msg.CreatedAt,
|
||||
},
|
||||
}
|
||||
notifBytes, _ := json.Marshal(notifMsg)
|
||||
s.DispatchMessage(mentionUserID, notifBytes)
|
||||
|
||||
log.Printf("📢 [@通知] %s 在群 %s 中@了 %s", senderID, roomID, mentionUserID)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GetICEServers
|
||||
* 功能:获取 TURN 配置 (供 API 层调用)
|
||||
|
||||
@@ -294,6 +294,12 @@ func (s *RoomService) ListGroupMembers(roomID string) ([]model.RoomMember, error
|
||||
Find(&members).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 清除用户密码
|
||||
for i := range members {
|
||||
if members[i].User != nil {
|
||||
members[i].User.Password = ""
|
||||
}
|
||||
}
|
||||
return members, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user