refactor: 重构消息发送模型

This commit is contained in:
lixiangwuxian
2024-10-28 02:58:08 +08:00
parent fe863a9ac8
commit 7e28953a56
10 changed files with 196 additions and 16 deletions

View File

@@ -2,7 +2,6 @@ package wsclient
import (
"encoding/json"
"fmt"
"log"
"net/url"
@@ -38,6 +37,8 @@ func NewWebSocketClient(scheme, host, path string) (*WebSocketClient, error) {
}
}()
action.ActionManager.SetConn(conn)
go client.receiveMessages()
return client, nil
@@ -78,19 +79,7 @@ func (c *WebSocketClient) receiveMessages() {
go func() {
reply := handler.MsgInHandler(msg)
if reply.ReplyMsg != "" {
if reply.ReferOriginMsg {
reply.ReplyMsg = fmt.Sprintf("%s%s", action.GenReply(reply.FromMsg.OriginMsgId, "", 0, 0, 0), reply.ReplyMsg)
}
sendPkg := model.GenSendPkg(reply.FromMsg.UserId, reply.FromMsg.GroupInfo.GroupId, reply.ReplyMsg, false)
sendPkgJson, err := json.Marshal(sendPkg)
if err != nil {
log.Println("Error marshalling sendPkg:", err)
return
}
if err = c.SendMessage(websocket.TextMessage, sendPkgJson); err != nil {
log.Println("Error sending message:", err)
return
}
action.ActionManager.SendMsg(reply)
}
}()
}