FEATURE: Publish read state on group messages. (#7989) [Undo revert] (#8024)

* Reenable: "FEATURE: Publish read state on group messages. (#7989)"

This reverts commit 67f5cc1ce8.

* FIX: Read indicator only appears when the group setting is enabled
This commit is contained in:
Roman Rizzi
2019-08-20 11:57:25 -03:00
committed by GitHub
parent 67f5cc1ce8
commit 5dda5c2f7c
35 changed files with 531 additions and 21 deletions

View File

@@ -153,7 +153,8 @@ class Admin::GroupsController < Admin::AdminController
:default_notification_level,
:membership_request_template,
:owner_usernames,
:usernames
:usernames,
:publish_read_state
]
custom_fields = Group.editable_group_custom_fields
permitted << { custom_fields: custom_fields } unless custom_fields.blank?

View File

@@ -552,7 +552,8 @@ class GroupsController < ApplicationController
:name,
:grant_trust_level,
:automatic_membership_email_domains,
:automatic_membership_retroactive
:automatic_membership_retroactive,
:publish_read_state
])
custom_fields = Group.editable_group_custom_fields

View 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