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:
26
app/controllers/post_readers_controller.rb
Normal file
26
app/controllers/post_readers_controller.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PostReadersController < ApplicationController
|
||||
requires_login
|
||||
|
||||
def index
|
||||
post = Post.includes(topic: %i[allowed_groups]).find(params[:id])
|
||||
read_state = post.topic.allowed_groups.any? { |g| g.publish_read_state? && g.users.include?(current_user) }
|
||||
raise Discourse::InvalidAccess unless read_state
|
||||
|
||||
readers = User
|
||||
.joins(:topic_users)
|
||||
.where('topic_users.topic_id = ? AND COALESCE(topic_users.last_read_post_number, 1) >= ?', post.topic_id, post.post_number)
|
||||
.where.not(id: [current_user.id, post.user_id])
|
||||
|
||||
readers = readers.map do |r|
|
||||
{
|
||||
id: r.id, avatar_template: r.avatar_template,
|
||||
username: r.username,
|
||||
username_lower: r.username_lower
|
||||
}
|
||||
end
|
||||
|
||||
render_json_dump(post_readers: readers)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user