From 3c67c5fd59705d49470ab87ad4cd0783469158db Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 30 Jan 2024 17:19:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ws=E5=90=8C=E7=BB=84=E5=A4=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws/service/ws.impl.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/ws/service/ws.impl.go b/src/modules/ws/service/ws.impl.go index 447438b0..36409894 100644 --- a/src/modules/ws/service/ws.impl.go +++ b/src/modules/ws/service/ws.impl.go @@ -85,7 +85,17 @@ func (s *WSImpl) NewClient(uid string, groupIDs []string, conn *websocket.Conn) for _, groupID := range groupIDs { if v, ok := WsGroup.Load(groupID); ok { groupUIDs := v.(*[]string) - *groupUIDs = append(*groupUIDs, uid) + // 避免同组内相同用户 + hasUid := false + for _, uidv := range *groupUIDs { + if uidv == uid { + hasUid = true + break + } + } + if !hasUid { + *groupUIDs = append(*groupUIDs, uid) + } } else { WsGroup.Store(groupID, &[]string{uid}) } @@ -145,6 +155,7 @@ func (s *WSImpl) clientWrite(wsClient *model.WSClient) { s.CloseClient(wsClient.ID) return } + wsClient.LastHeartbeat = time.Now().UnixMilli() } }