mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
* Revert "Revert "FEATURE: Publish read state on group messages. (#7989) [Undo revert] (#8024)""
This reverts commit 36425eb9f0.
* Fix: Show who read only if the attribute is enabled
* PERF: Precalculate the last post readed by a group member
* Use book-reader icon instear of far-eye
* FIX: update topic groups correctly
* DEV: Tidy up read indicator update on write
This commit is contained in:
@@ -344,11 +344,13 @@ class TopicQuery
|
||||
|
||||
def list_private_messages_group(user)
|
||||
list = private_messages_for(user, :group)
|
||||
group_id = Group.where('name ilike ?', @options[:group_name]).pluck(:id).first
|
||||
group = Group.where('name ilike ?', @options[:group_name]).select(:id, :publish_read_state).first
|
||||
publish_read_state = !!group&.publish_read_state
|
||||
list = list.joins("LEFT JOIN group_archived_messages gm ON gm.topic_id = topics.id AND
|
||||
gm.group_id = #{group_id.to_i}")
|
||||
gm.group_id = #{group&.id&.to_i}")
|
||||
list = list.where("gm.id IS NULL")
|
||||
create_list(:private_messages, {}, list)
|
||||
list = append_read_state(list, group) if publish_read_state
|
||||
create_list(:private_messages, { publish_read_state: publish_read_state }, list)
|
||||
end
|
||||
|
||||
def list_private_messages_group_archive(user)
|
||||
@@ -1057,4 +1059,16 @@ class TopicQuery
|
||||
def sanitize_sql_array(input)
|
||||
ActiveRecord::Base.public_send(:sanitize_sql_array, input.join(','))
|
||||
end
|
||||
|
||||
def append_read_state(list, group)
|
||||
group_id = group&.id
|
||||
return list if group_id.nil?
|
||||
|
||||
selected_values = list.select_values.empty? ? ['topics.*'] : list.select_values
|
||||
selected_values << "COALESCE(tg.last_read_post_number, 0) AS last_read_post_number"
|
||||
|
||||
list
|
||||
.joins("LEFT OUTER JOIN topic_groups tg ON topics.id = tg.topic_id AND tg.group_id = #{group_id}")
|
||||
.select(*selected_values)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user