修改im的在线检测

This commit is contained in:
junleea 2024-07-16 16:27:31 +08:00
parent 22d0bffdf3
commit 8e894b003f
1 changed files with 9 additions and 9 deletions

View File

@ -197,15 +197,15 @@ func SRMessage(c *gin.Context) {
res3, _ = json.Marshal(msg) res3, _ = json.Marshal(msg)
} }
//判断对方是否在线,若不在线则发送离线消息,否则正常发送消息 //判断对方是否在线,若不在线则发送离线消息,否则正常发送消息
if worker.IsContainKey(to_user_id+"_status") == true { //if worker.IsContainKey(to_user_id+"_status") == true {
if worker.GetRedis(to_user_id+"_status") == "0" { // if worker.GetRedis(to_user_id+"_status") == "0" {
msg.Type = "offline" // msg.Type = "offline"
msg.Msg = "offline" // msg.Msg = "offline"
msg.From_user_id = -1 // msg.From_user_id = -1
msg.Session = res // msg.Session = res
res3, _ = json.Marshal(msg) // res3, _ = json.Marshal(msg)
} // }
} //}
err2 := ws.WriteMessage(websocket.TextMessage, res3) err2 := ws.WriteMessage(websocket.TextMessage, res3)
if err2 != nil { if err2 != nil {
worker.SetRedisWithExpire("user_"+id.(string)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期 worker.SetRedisWithExpire("user_"+id.(string)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期