discourse/plugins/chat/app/jobs/regular/update_channel_user_count.rb
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

19 lines
458 B
Ruby

# frozen_string_literal: true
module Jobs
class UpdateChannelUserCount < Jobs::Base
def execute(args = {})
channel = ChatChannel.find_by(id: args[:chat_channel_id])
return if channel.blank?
return if !channel.user_count_stale
channel.update!(
user_count: ChatChannelMembershipsQuery.count(channel),
user_count_stale: false,
)
ChatPublisher.publish_chat_channel_metadata(channel)
end
end
end