From 87055819b994226d45876da44003e8763b26ff51 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Apr 2026 20:52:02 +0000 Subject: [PATCH] wire pub/sub channel subscriptions into channel_focus handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a client focuses a channel, subscribe to its pub/sub topic. When switching channels, unsubscribe from the old topic first. This completes the pub/sub integration — channel broadcasts now route only to clients subscribed to the relevant topic. https://claude.ai/code/session_01CBFF3r84ywkJRWwuqw8zD8 --- Server/ws/export_test.go | 6 ++++++ Server/ws/handlers.go | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/Server/ws/export_test.go b/Server/ws/export_test.go index f246be60..b8ce0c46 100644 --- a/Server/ws/export_test.go +++ b/Server/ws/export_test.go @@ -94,9 +94,15 @@ func (p *LiveKitProcess) SetProcessStoppedForTest() { func NewHubForTest() *Hub { return &Hub{ clients: make(map[int64]*Client), + pubsub: NewPubSub(), } } +// PubSubForTest exposes the hub's PubSub for external tests. +func (h *Hub) PubSubForTest() *PubSub { + return h.pubsub +} + // BuildAuthOKForTest exposes Hub.buildAuthOK for external tests. func (h *Hub) BuildAuthOKForTest(user *db.User, roleName string) []byte { return h.buildAuthOK(user, roleName) diff --git a/Server/ws/handlers.go b/Server/ws/handlers.go index 3edbde4e..559da71d 100644 --- a/Server/ws/handlers.go +++ b/Server/ws/handlers.go @@ -160,9 +160,20 @@ func (h *Hub) handleMessage(c *Client, raw []byte) { } // Apply client state mutations. if result.SetChannelID != nil { + oldChID := c.getChannelID() c.mu.Lock() c.channelID = *result.SetChannelID c.mu.Unlock() + // Update pub/sub channel topic subscriptions. + newChID := *result.SetChannelID + if oldChID != newChID { + if oldChID > 0 { + c.hub.pubsub.Unsubscribe(c, ChannelTopic(oldChID)) + } + if newChID > 0 { + c.hub.pubsub.Subscribe(c, ChannelTopic(newChID)) + } + } } if result.SetE2EEPubKey != nil { c.setE2EEPubKey(*result.SetE2EEPubKey)