From 9843a76f80b9af6cc26eade53e51dff3e942c1ef Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Tue, 5 May 2020 13:18:47 +0100 Subject: [PATCH] Populate room, group, and direct message fields in channel presence events. --- CHANGELOG.md | 1 + server/tracker.go | 58 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97f870d1c..9a45d5ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ### Fixed - Ensure runtime environment values do not appear multiple times in the devconsole configuration view. +- Channel presence events now populate room, group, and direct message fields. ## [2.11.1] - 2020-03-29 ### Changed diff --git a/server/tracker.go b/server/tracker.go index 76ba7a055..943f69d62 100644 --- a/server/tracker.go +++ b/server/tracker.go @@ -778,9 +778,31 @@ func (t *LocalTracker) processEvent(e *PresenceEvent) { Leaves: leaves, }}} case StreamModeChannel: - fallthrough + channelID, err := StreamToChannelId(stream) + if err != nil { + // Should not happen thanks to previous validation, but guard just in case. + t.logger.Error("Error converting stream to channel identifier in presence event", zap.Error(err), zap.Any("stream", stream)) + continue + } + envelope = &rtapi.Envelope{Message: &rtapi.Envelope_ChannelPresenceEvent{ChannelPresenceEvent: &rtapi.ChannelPresenceEvent{ + ChannelId: channelID, + Joins: joins, + Leaves: leaves, + RoomName: streamWire.Label, + }}} case StreamModeGroup: - fallthrough + channelID, err := StreamToChannelId(stream) + if err != nil { + // Should not happen thanks to previous validation, but guard just in case. + t.logger.Error("Error converting stream to channel identifier in presence event", zap.Error(err), zap.Any("stream", stream)) + continue + } + envelope = &rtapi.Envelope{Message: &rtapi.Envelope_ChannelPresenceEvent{ChannelPresenceEvent: &rtapi.ChannelPresenceEvent{ + ChannelId: channelID, + Joins: joins, + Leaves: leaves, + GroupId: streamWire.Subject, + }}} case StreamModeDM: channelID, err := StreamToChannelId(stream) if err != nil { @@ -792,6 +814,8 @@ func (t *LocalTracker) processEvent(e *PresenceEvent) { ChannelId: channelID, Joins: joins, Leaves: leaves, + UserIdOne: streamWire.Subject, + UserIdTwo: streamWire.Subcontext, }}} case StreamModeMatchRelayed: fallthrough @@ -883,9 +907,31 @@ func (t *LocalTracker) processEvent(e *PresenceEvent) { Leaves: leaves, }}} case StreamModeChannel: - fallthrough + channelID, err := StreamToChannelId(stream) + if err != nil { + // Should not happen thanks to previous validation, but guard just in case. + t.logger.Error("Error converting stream to channel identifier in presence event", zap.Error(err), zap.Any("stream", stream)) + continue + } + envelope = &rtapi.Envelope{Message: &rtapi.Envelope_ChannelPresenceEvent{ChannelPresenceEvent: &rtapi.ChannelPresenceEvent{ + ChannelId: channelID, + // No joins. + Leaves: leaves, + RoomName: streamWire.Label, + }}} case StreamModeGroup: - fallthrough + channelID, err := StreamToChannelId(stream) + if err != nil { + // Should not happen thanks to previous validation, but guard just in case. + t.logger.Error("Error converting stream to channel identifier in presence event", zap.Error(err), zap.Any("stream", stream)) + continue + } + envelope = &rtapi.Envelope{Message: &rtapi.Envelope_ChannelPresenceEvent{ChannelPresenceEvent: &rtapi.ChannelPresenceEvent{ + ChannelId: channelID, + // No joins. + Leaves: leaves, + GroupId: streamWire.Subject, + }}} case StreamModeDM: channelID, err := StreamToChannelId(stream) if err != nil { @@ -896,7 +942,9 @@ func (t *LocalTracker) processEvent(e *PresenceEvent) { envelope = &rtapi.Envelope{Message: &rtapi.Envelope_ChannelPresenceEvent{ChannelPresenceEvent: &rtapi.ChannelPresenceEvent{ ChannelId: channelID, // No joins. - Leaves: leaves, + Leaves: leaves, + UserIdOne: streamWire.Subject, + UserIdTwo: streamWire.Subcontext, }}} case StreamModeMatchRelayed: fallthrough -- GitLab