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") 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,6 +116,7 @@ func (c *EventController) TestWebsocket() {
} else { } else {
//接受消息 业务逻辑 //接受消息 业务逻辑
broadcast <- s broadcast <- s
if s.GroupID != 0 {
//发聊天消息时这个组所有的成员包括创建者都在userIDs里 //发聊天消息时这个组所有的成员包括创建者都在userIDs里
userIDs := []string{} userIDs := []string{}
if results, err := dao.GetMessageGroups(db, "", s.GroupID, 0, true, ""); err == nil { if results, err := dao.GetMessageGroups(db, "", s.GroupID, 0, true, ""); err == nil {
@@ -134,6 +137,7 @@ func (c *EventController) TestWebsocket() {
} }
} }
} }
}
utils.CallFuncAsync(func() { utils.CallFuncAsync(func() {
if s.GroupID != 0 { if s.GroupID != 0 {
dao.WrapAddIDCULDEntity(s, "") dao.WrapAddIDCULDEntity(s, "")