修复了一些问题
This commit is contained in:
@@ -56,14 +56,19 @@ func SendHandler(c *gin.Context) {
|
||||
// 4. 构造临时的发送者客户端对象
|
||||
// 这个对象将传递给 Service 层,用于识别消息来源
|
||||
mockClient := &manager.Client{
|
||||
UserID: senderID,
|
||||
ID: clientID,
|
||||
UserID: senderID,
|
||||
ID: clientID,
|
||||
RemoteIP: utils.GetClientIP(c),
|
||||
}
|
||||
|
||||
// 5. 调用核心业务逻辑处理消息
|
||||
service.ChatSvc.HandleUserMessage(mockClient, &req)
|
||||
// 5. 调用核心业务逻辑处理消息,返回持久化后的消息体供前端对齐 ID
|
||||
savedMsg := service.ChatSvc.HandleUserMessage(mockClient, &req)
|
||||
|
||||
// 6. 返回成功响应
|
||||
// 6. 返回成功响应(含服务端消息 ID,避免前端重复展示)
|
||||
if savedMsg != nil {
|
||||
utils.SuccessWithData(c, savedMsg, "消息已发送")
|
||||
return
|
||||
}
|
||||
utils.Success(c, "消息已发送")
|
||||
}
|
||||
|
||||
@@ -169,6 +174,54 @@ func HistoryHandler(c *gin.Context) {
|
||||
}, "获取成功")
|
||||
}
|
||||
|
||||
/**
|
||||
* RecallMessageHandler
|
||||
* 功能:撤回消息(2 分钟内,仅发送者可撤回)
|
||||
* 路径:POST /api/messages/recall
|
||||
*/
|
||||
func RecallMessageHandler(c *gin.Context) {
|
||||
userID, exists := c.Get("user_id")
|
||||
if !exists {
|
||||
utils.Unauthorized(c, "未认证")
|
||||
return
|
||||
}
|
||||
|
||||
var req struct {
|
||||
MessageID uint `json:"message_id" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
utils.BadRequest(c, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
var msg model.ChatMessage
|
||||
if err := service.ChatSvc.DB.First(&msg, req.MessageID).Error; err != nil {
|
||||
utils.NotFound(c, "消息不存在")
|
||||
return
|
||||
}
|
||||
|
||||
if msg.SenderUserID != userID.(string) {
|
||||
utils.Forbidden(c, "无权撤回该消息")
|
||||
return
|
||||
}
|
||||
|
||||
if time.Since(msg.CreatedAt) > 2*time.Minute {
|
||||
utils.BadRequest(c, "超过2分钟,无法撤回")
|
||||
return
|
||||
}
|
||||
|
||||
msg.MessageType = model.MessageTypeSystem
|
||||
msg.Content = "撤回了一条消息"
|
||||
if err := service.ChatSvc.DB.Save(&msg).Error; err != nil {
|
||||
utils.InternalError(c, "撤回失败")
|
||||
return
|
||||
}
|
||||
|
||||
service.ChatSvc.BroadcastChatMessage(msg)
|
||||
|
||||
utils.SuccessWithData(c, msg, "撤回成功")
|
||||
}
|
||||
|
||||
/**
|
||||
* SyncMessagesHandler
|
||||
* 功能:全量同步消息 (V1 兼容)。
|
||||
@@ -178,7 +231,6 @@ func SyncMessagesHandler(c *gin.Context) {
|
||||
HistoryHandler(c)
|
||||
}
|
||||
|
||||
|
||||
// ==========================================
|
||||
// 系统与 WebRTC 接口
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user