FIX: Add MessageBust.last_id to chat channel subscriptions (#19255)

This commit adds variousMessageBus.last_ids to serializer payloads
for chat channels and the chat view (for chat live pane) so
we can use those IDs when subscribing to MessageBus channels
from chat.

This allows us to ensure that any messages created between the
server being hit and the UI loaded and subscribing end up being
delivered to the client, rather than just silently dropped.

This commit also fixes an issue where we were subscribing to
the new-messages and new-mentions MessageBus channels multiple
times when following/unfollowing a channel multiple times.
This commit is contained in:
Martin Brennan
2022-12-02 10:57:53 +10:00
committed by GitHub
parent a2cec6366f
commit 8437081d94
25 changed files with 448 additions and 96 deletions

View File

@@ -18,7 +18,8 @@ class ChatChannelSerializer < ApplicationSerializer
:total_messages,
:archive_topic_id,
:memberships_count,
:current_user_membership
:current_user_membership,
:message_bus_last_ids
def initialize(object, opts)
super(object, opts)
@@ -94,6 +95,13 @@ class ChatChannelSerializer < ApplicationSerializer
).as_json
end
def message_bus_last_ids
{
new_messages: MessageBus.last_id("/chat/#{object.id}/new-messages"),
new_mentions: MessageBus.last_id("/chat/#{object.id}/new-mentions"),
}
end
alias_method :include_archive_topic_id?, :include_archive_status?
alias_method :include_total_messages?, :include_archive_status?
alias_method :include_archived_messages?, :include_archive_status?

View File

@@ -22,6 +22,7 @@ class ChatViewSerializer < ApplicationSerializer
can_moderate: scope.can_moderate_chat?(object.chat_channel.chatable),
can_delete_self: scope.can_delete_own_chats?(object.chat_channel.chatable),
can_delete_others: scope.can_delete_other_chats?(object.chat_channel.chatable),
channel_message_bus_last_id: MessageBus.last_id("/chat/#{object.chat_channel.id}"),
}
meta_hash[:can_load_more_past] = object.can_load_more_past unless object.can_load_more_past.nil?
meta_hash[

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class StructuredChannelSerializer < ApplicationSerializer
attributes :public_channels, :direct_message_channels
attributes :public_channels, :direct_message_channels, :message_bus_last_ids
def public_channels
object[:public_channels].map do |channel|
@@ -29,4 +29,19 @@ class StructuredChannelSerializer < ApplicationSerializer
return if scope.anonymous?
object[:memberships].find { |membership| membership.chat_channel_id == channel_id }
end
def message_bus_last_ids
last_ids = {
channel_metadata: MessageBus.last_id("/chat/channel-metadata"),
channel_edits: MessageBus.last_id("/chat/channel-edits"),
channel_status: MessageBus.last_id("/chat/channel-status"),
new_channel: MessageBus.last_id("/chat/new-channel"),
}
if !scope.anonymous?
last_ids[:user_tracking_state] = MessageBus.last_id(
"/chat/user-tracking-state/#{scope.user.id}",
)
end
last_ids
end
end