聊天增加图片功能
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
@@ -312,13 +313,13 @@ func (r *Repository) SendMessage(principal Principal, conversationID uint64, req
|
||||
SenderRole: participant.Role,
|
||||
ContentType: "text",
|
||||
Content: req.Content,
|
||||
AttachmentURLS: emptyJSONList(),
|
||||
AttachmentURLS: encodeStringList(req.AttachmentURLS),
|
||||
}
|
||||
if err := tx.Create(&message).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
conversation.LastMessageID = &message.ID
|
||||
conversation.LastMessagePreview = truncatePreview(message.Content)
|
||||
conversation.LastMessagePreview = messagePreview(message.Content, req.AttachmentURLS)
|
||||
conversation.LastMessageAt = &message.CreatedAt
|
||||
if err := tx.Save(&conversation).Error; err != nil {
|
||||
return err
|
||||
@@ -708,6 +709,17 @@ func truncatePreview(content string) string {
|
||||
return string(runes[:80])
|
||||
}
|
||||
|
||||
func messagePreview(content string, attachments []string) string {
|
||||
content = strings.TrimSpace(content)
|
||||
if content != "" {
|
||||
return truncatePreview(content)
|
||||
}
|
||||
if len(attachments) > 0 {
|
||||
return "[图片]"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// TransferConversation 转接会话给其他客服
|
||||
func (r *Repository) TransferConversation(principal Principal, conversationID uint64, toAdminID uint64) error {
|
||||
return r.db.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -908,6 +920,11 @@ func emptyJSONList() datatypes.JSON {
|
||||
return datatypes.JSON(raw)
|
||||
}
|
||||
|
||||
func encodeStringList(items []string) datatypes.JSON {
|
||||
raw, _ := json.Marshal(items)
|
||||
return datatypes.JSON(raw)
|
||||
}
|
||||
|
||||
// UpdateRemark 更新会话备注
|
||||
func (r *Repository) UpdateRemark(principal Principal, conversationID uint64, remark string) error {
|
||||
return r.db.Model(&model.ChatParticipant{}).
|
||||
|
||||
Reference in New Issue
Block a user