a
This commit is contained in:
@@ -69,12 +69,14 @@ func (c *EventController) TestWebsocket() {
|
|||||||
userID = c.GetString("userID")
|
userID = c.GetString("userID")
|
||||||
clientUser = make(map[string]*websocket.Conn)
|
clientUser = make(map[string]*websocket.Conn)
|
||||||
)
|
)
|
||||||
|
if userID == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
//将当前客户端放入map中
|
//将当前客户端放入map中
|
||||||
messageGroups, _ := dao.GetUserMessageGroups(dao.GetDB(), userID)
|
messageGroups, _ := dao.GetUserMessageGroups(dao.GetDB(), userID)
|
||||||
if len(messageGroups) == 0 {
|
if len(messageGroups) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("11111111111111111111111111111111111111111111111", userID)
|
|
||||||
clientUser[userID] = ws
|
clientUser[userID] = ws
|
||||||
clientsHeart[userID] = ws
|
clientsHeart[userID] = ws
|
||||||
for _, v := range messageGroups {
|
for _, v := range messageGroups {
|
||||||
@@ -114,23 +116,25 @@ func (c *EventController) TestWebsocket() {
|
|||||||
} else {
|
} else {
|
||||||
//接受消息 业务逻辑
|
//接受消息 业务逻辑
|
||||||
broadcast <- s
|
broadcast <- s
|
||||||
//发聊天消息时,这个组所有的成员包括创建者都在userIDs里
|
if s.GroupID != 0 {
|
||||||
userIDs := []string{}
|
//发聊天消息时,这个组所有的成员包括创建者都在userIDs里
|
||||||
if results, err := dao.GetMessageGroups(db, "", s.GroupID, 0, true, ""); err == nil {
|
userIDs := []string{}
|
||||||
for _, v := range results {
|
if results, err := dao.GetMessageGroups(db, "", s.GroupID, 0, true, ""); err == nil {
|
||||||
userIDs = append(userIDs, v.UserID)
|
for _, v := range results {
|
||||||
for _, vv := range v.MessageGroupMembers {
|
userIDs = append(userIDs, v.UserID)
|
||||||
userIDs = append(userIDs, vv.UserID)
|
for _, vv := range v.MessageGroupMembers {
|
||||||
|
userIDs = append(userIDs, vv.UserID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
//如果这些人不在这个组的ws池子里就打上未读标记
|
||||||
//如果这些人不在这个组的ws池子里就打上未读标记
|
for _, v := range userIDs {
|
||||||
for _, v := range userIDs {
|
if clientsHeart[v] == nil {
|
||||||
if clientsHeart[v] == nil {
|
messageGroupReads, _ := dao.GetMessageGroupRead(db, v, s.GroupID)
|
||||||
messageGroupReads, _ := dao.GetMessageGroupRead(db, v, s.GroupID)
|
for _, vv := range messageGroupReads {
|
||||||
for _, vv := range messageGroupReads {
|
vv.UnReadCount++
|
||||||
vv.UnReadCount++
|
dao.UpdateEntity(db, vv, "UnReadCount")
|
||||||
dao.UpdateEntity(db, vv, "UnReadCount")
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user