From 422e312b951a0b951a4292c6b902c829f20397be Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 16 Jul 2024 16:17:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9im=E7=9A=84=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/im.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/handler/im.go b/handler/im.go index 7340624..b1c2398 100644 --- a/handler/im.go +++ b/handler/im.go @@ -196,15 +196,15 @@ func SRMessage(c *gin.Context) { res3, _ = json.Marshal(msg) } //判断对方是否在线,若不在线则发送离线消息,否则正常发送消息 - if worker.IsContainKey(to_user_id+"_status") == true { - if worker.GetRedis(to_user_id+"_status") == "0" { - msg.Type = "offline" - msg.Msg = "offline" - msg.From_user_id = -1 - msg.Session = res - res3, _ = json.Marshal(msg) - } - } + //if worker.IsContainKey(to_user_id+"_status") == true { + // if worker.GetRedis(to_user_id+"_status") == "0" { + // msg.Type = "offline" + // msg.Msg = "offline" + // msg.From_user_id = -1 + // msg.Session = res + // res3, _ = json.Marshal(msg) + // } + //} err2 := ws.WriteMessage(websocket.TextMessage, res3) if err2 != nil { worker.SetRedisWithExpire("user_"+id.(string)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期 From 63b5b968b4631e84b4d4f8b579e62d9f6ea62629 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 17 Jul 2024 18:12:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DIm=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E5=8F=91=E9=80=81Bug=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E6=96=B9=E7=A6=BB=E7=BA=BF=E8=87=AA=E5=8A=A8=E6=96=AD=E5=BC=80?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/im.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/handler/im.go b/handler/im.go index 0afec6b..4fc96ee 100644 --- a/handler/im.go +++ b/handler/im.go @@ -144,7 +144,7 @@ func SRMessage(c *gin.Context) { } defer ws.Close() res := worker.GetRedis(redis_key + "_connection") - worker.SetRedisWithExpire("user_"+id.(string)+"_status", "1", time.Second*5) + worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "1", time.Second*5) if res == "" { return } @@ -197,8 +197,8 @@ func SRMessage(c *gin.Context) { res3, _ = json.Marshal(msg) } //判断对方是否在线,若不在线则发送离线消息,否则正常发送消息 - if worker.IsContainKey(to_user_id+"_status") == true { - if worker.GetRedis(to_user_id+"_status") == "0" { + if worker.IsContainKey("user_"+to_user_id+"_status") == true { + if worker.GetRedis("user_"+to_user_id+"_status") == "0" { msg.Type = "offline" msg.Msg = "offline" msg.From_user_id = -1 @@ -208,9 +208,9 @@ func SRMessage(c *gin.Context) { } err2 := ws.WriteMessage(websocket.TextMessage, res3) if err2 != nil { - worker.SetRedisWithExpire("user_"+id.(string)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期 + worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期 } else { - worker.SetRedisWithExpire("user_"+id.(string)+"_status", "1", time.Second*5) //设置用户在线状态,1为在线,0为离线,5秒后过期 + worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "1", time.Second*5) //设置用户在线状态,1为在线,0为离线,5秒后过期 } time.Sleep(time.Second * 1) // 每1秒查询一次 } else {