diff --git a/plugins/chat/app/serializers/base_chat_channel_membership_serializer.rb b/plugins/chat/app/serializers/base_chat_channel_membership_serializer.rb index ce7d2dab9c..25d10a0197 100644 --- a/plugins/chat/app/serializers/base_chat_channel_membership_serializer.rb +++ b/plugins/chat/app/serializers/base_chat_channel_membership_serializer.rb @@ -9,10 +9,9 @@ class BaseChatChannelMembershipSerializer < ApplicationSerializer :last_read_message_id, :unread_count, :unread_mentions, - :can_join_chat_channel + :meta - def can_join_chat_channel - chat_channel = ChatChannel.find_by(id: object[:chat_channel_id]) - scope.can_join_chat_channel?(chat_channel) if chat_channel + def meta + { can_join_chat_channel: scope.can_join_chat_channel?(object.chat_channel) } end end diff --git a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js index 792b42c4f7..b7006708c3 100644 --- a/plugins/chat/assets/javascripts/discourse/models/chat-channel.js +++ b/plugins/chat/assets/javascripts/discourse/models/chat-channel.js @@ -120,7 +120,7 @@ export default class ChatChannel extends RestModel { } get canJoin() { - return this.currentUserMembership.can_join_chat_channel; + return this.currentUserMembership.meta?.can_join_chat_channel; } canModifyMessages(user) { diff --git a/plugins/chat/spec/support/api/schemas/user_chat_channel_membership.json b/plugins/chat/spec/support/api/schemas/user_chat_channel_membership.json index 30725b7d44..17907f0e53 100644 --- a/plugins/chat/spec/support/api/schemas/user_chat_channel_membership.json +++ b/plugins/chat/spec/support/api/schemas/user_chat_channel_membership.json @@ -26,6 +26,9 @@ "avatar_template": { "type": "string" }, "username": { "type": "string" } } + }, + "meta": { + "can_join_chat_channel": { "type": "boolean" } } } }