wire pub/sub channel subscriptions into channel_focus handler

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
This commit is contained in:
Claude
2026-04-05 20:52:02 +00:00
parent 075ef28e29
commit 87055819b9
2 changed files with 17 additions and 0 deletions
+6
View File
@@ -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)
+11
View File
@@ -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)