refactor: 重构消息发送模型
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user