分组获取消息

pull/23/head
陶士涵 4 years ago
parent a603c88a07
commit cd6a2c9dad

@ -90,6 +90,13 @@ func NewChatServer(c *gin.Context) {
kefuConn.WriteMessage(websocket.TextMessage, str)
}
}
//新版
mKefuConns := ws.KefuList[visitor.to_id]
if mKefuConns != nil {
for _, kefu := range mKefuConns {
kefu.Conn.WriteMessage(websocket.TextMessage, str)
}
}
sendPingOnlineUsers()
}
}

@ -183,13 +183,19 @@ func GetVisitorMessage(c *gin.Context) {
// @Router /visitors_online [get]
func GetVisitorOnlines(c *gin.Context) {
users := make([]map[string]string, 0)
visitorIds := make([]string, 0)
for uid, visitor := range clientList {
userInfo := make(map[string]string)
userInfo["uid"] = uid
userInfo["name"] = visitor.name
userInfo["avator"] = visitor.avator
users = append(users, userInfo)
visitorIds = append(visitorIds, visitor.id)
}
//查询最新消息
messages := models.FindLastMessage(visitorIds)
log.Println(messages)
tcps := make([]string, 0)
for ip, _ := range clientTcpList {
tcps = append(tcps, ip)
@ -198,8 +204,9 @@ func GetVisitorOnlines(c *gin.Context) {
"code": 200,
"msg": "ok",
"result": gin.H{
"ws": users,
"tcp": tcps,
"ws": users,
"tcp": tcps,
"messages": messages,
},
})
}

@ -40,6 +40,13 @@ func FindUnreadMessageNumByVisitorId(visitor_id string) uint {
return count
}
//查询最后一条消息
func FindLastMessage(visitorIds []string) []Message {
var messages []Message
DB.Select("ANY_VALUE(visitor_id) visitor_id,ANY_VALUE(id) id,ANY_VALUE(Content) content").Where("visitor_id in (? )", visitorIds).Group("visitor_id").Find(&messages)
return messages
}
//查询条数
func CountMessage() uint {
var count uint

Loading…
Cancel
Save