mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Publish read topic tracking events for private messages. (#14274)
Follow-up to fc1fd1b416
This commit is contained in:
committed by
GitHub
parent
1e05175364
commit
412587f70a
32
app/models/concerns/topic_tracking_state_publishable.rb
Normal file
32
app/models/concerns/topic_tracking_state_publishable.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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.staff? ? "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
|
||||
Reference in New Issue
Block a user