This commit is contained in:
苏尹岚
2020-12-04 15:24:39 +08:00
parent fb72d68235
commit 26ece732ff

View File

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