mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
1630dae2db
* Enable or disable read state based on group attribute * When read state needs to be published, the minimum unread count is calculated in the topic query. This way, we can know if someone reads the last post * The option can be enabled/disabled from the UI * The read indicator will live-updated using message bus * Show read indicator on every post * The read indicator now shows read count and can be expanded to see user avatars * Read count gets updated everytime someone reads a message * Simplify topic-list read indicator logic * Unsubscribe from message bus on willDestroyElement, removed unnecesarry values from post-menu, and added a comment to explain where does minimum_unread_count comes from
27 lines
817 B
Ruby
27 lines
817 B
Ruby
# 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
|