From 94a618778b46285f74a191caa4bd1a94d95c1373 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Tue, 27 Oct 2020 13:42:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=85=B6=E4=BB=96=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E7=9A=84=E8=B4=A6=E6=88=B7=E8=BF=9E=E6=8E=A5=E5=8F=91=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/chat.go | 2 +- controller/message.go | 34 ++++++++++++++++++---------------- static/js/chat-main.js | 32 ++++++++++++++++++-------------- ws/ws.go | 21 ++++++++++++++++++++- 4 files changed, 57 insertions(+), 32 deletions(-) diff --git a/controller/chat.go b/controller/chat.go index b468c97..7f0de86 100644 --- a/controller/chat.go +++ b/controller/chat.go @@ -53,7 +53,7 @@ func init() { ReadBufferSize: 1024, WriteBufferSize: 1024, } - go UpdateVisitorStatusCron() + //go UpdateVisitorStatusCron() go singleBroadcaster() //go sendPingOnlineUsers() //sendPingToClient() diff --git a/controller/message.go b/controller/message.go index 445b01d..fea27db 100644 --- a/controller/message.go +++ b/controller/message.go @@ -159,31 +159,32 @@ func SendMessageV2(c *gin.Context) { msg = TypeMessage{ Type: "message", - Data: ClientMessage{ + Data: ws.ClientMessage{ Name: kefuInfo.Nickname, Avator: kefuInfo.Avator, Id: kefuInfo.Name, Time: time.Now().Format("2006-01-02 15:04:05"), ToId: vistorInfo.VisitorId, Content: content, + IsKefu: "no", }, } str, _ := json.Marshal(msg) conn.WriteMessage(websocket.TextMessage, str) - //msg = TypeMessage{ - // Type: "message", - // Data: ClientMessage{ - // Name: kefuInfo.Nickname, - // Avator: kefuInfo.Avator, - // Id: vistorInfo.VisitorId, - // Time: time.Now().Format("2006-01-02 15:04:05"), - // ToId: vistorInfo.VisitorId, - // Content: content, - // }, - //} - //str2, _ := json.Marshal(msg) - //ws.SuperAdminMessage(str2) - + msg = TypeMessage{ + Type: "message", + Data: ws.ClientMessage{ + Name: kefuInfo.Nickname, + Avator: kefuInfo.Avator, + Id: vistorInfo.VisitorId, + Time: time.Now().Format("2006-01-02 15:04:05"), + ToId: vistorInfo.VisitorId, + Content: content, + IsKefu: "yes", + }, + } + str2, _ := json.Marshal(msg) + ws.OneKefuMessage(kefuInfo.Name, str2) } if cType == "visitor" { //kefuConns, ok := ws.KefuList[kefuInfo.Name] @@ -196,13 +197,14 @@ func SendMessageV2(c *gin.Context) { //} msg = TypeMessage{ Type: "message", - Data: ClientMessage{ + Data: ws.ClientMessage{ Avator: vistorInfo.Avator, Id: vistorInfo.VisitorId, Name: vistorInfo.Name, ToId: kefuInfo.Name, Content: content, Time: time.Now().Format("2006-01-02 15:04:05"), + IsKefu: "no", }, } str, _ := json.Marshal(msg) diff --git a/static/js/chat-main.js b/static/js/chat-main.js index 3cc0a3f..24491c3 100644 --- a/static/js/chat-main.js +++ b/static/js/chat-main.js @@ -129,11 +129,21 @@ var app=new Vue({ content.avator = msg.avator; content.name = msg.name; content.content = replaceContent(msg.content); - content.is_kefu = false; + content.is_kefu = msg.is_kefu=="yes"? true:false; content.time = msg.time; if (msg.id == this.currentGuest) { this.msgList.push(content); } + + for(let i=0;i