discourse/app/models/concerns/topic_tracking_state_publishable.rb
Krzysztof Kotlarek 09932738e5
FEATURE: whispers available for groups (#17170)
Before, whispers were only available for staff members.

Config has been changed to allow to configure privileged groups with access to whispers. Post migration was added to move from the old setting into the new one.

I considered having a boolean column `whisperer` on user model similar to `admin/moderator` for performance reason. Finally, I decided to keep looking for groups as queries are only done for current user and didn't notice any N+1 queries.
2022-06-30 10:18:12 +10:00

33 lines
957 B
Ruby

# frozen_string_literal: true
module TopicTrackingStatePublishable
extend ActiveSupport::Concern
class_methods do
def publish_read_message(message_type:,
channel_name:,
topic_id:,
user:,
last_read_post_number:,
notification_level: nil)
highest_post_number = DB.query_single(
"SELECT #{user.whisperer? ? "highest_staff_post_number" : "highest_post_number"} FROM topics WHERE id = ?",
topic_id
).first
message = {
message_type: message_type,
topic_id: topic_id,
payload: {
last_read_post_number: last_read_post_number,
notification_level: notification_level,
highest_post_number: highest_post_number
}
}.as_json
MessageBus.publish(channel_name, message, user_ids: [user.id])
end
end
end