diff --git a/plugins/chat/app/services/chat/list_channel_messages.rb b/plugins/chat/app/services/chat/list_channel_messages.rb index 6c1f5155a49..affcfabbe07 100644 --- a/plugins/chat/app/services/chat/list_channel_messages.rb +++ b/plugins/chat/app/services/chat/list_channel_messages.rb @@ -158,7 +158,9 @@ module Chat end def update_membership_last_viewed_at(guardian:, **) - context.membership&.update!(last_viewed_at: Time.zone.now) + Scheduler::Defer.later "Chat::ListChannelMessages - defer update_membership_last_viewed_at" do + context.membership&.update!(last_viewed_at: Time.zone.now) + end end end end diff --git a/plugins/chat/spec/requests/chat/api/channel_messages_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channel_messages_controller_spec.rb index d91840d2342..a31ab9e5ce7 100644 --- a/plugins/chat/spec/requests/chat/api/channel_messages_controller_spec.rb +++ b/plugins/chat/spec/requests/chat/api/channel_messages_controller_spec.rb @@ -28,6 +28,19 @@ RSpec.describe Chat::Api::ChannelMessagesController do end end + context "when readonly mode" do + fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel) } + + before { Discourse.enable_readonly_mode } + after { Discourse.disable_readonly_mode } + + it "works" do + get "/chat/api/channels/#{channel.id}/messages" + + expect(response.status).to eq(200) + end + end + context "when channnel doesn’t exist" do it "returns a 404" do get "/chat/api/channels/-999/messages"