FIX: Do not publish post for PM topic tracking if not new for user. (#14469)

This commit is contained in:
Alan Guo Xiang Tan 2021-09-29 13:54:24 +08:00 committed by GitHub
parent 9998090e5b
commit a1745e05ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -169,7 +169,7 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({
[INBOX_FILTER, ARCHIVE_FILTER].includes(this.filter) &&
(!message.payload.acting_user_id ||
message.payload.acting_user_id !== this.currentUser.id) &&
(this.inbox === "all" || this._displayMessageForGroupInbox(message))
this._displayMessageForGroupInbox(message)
) {
this._notifyIncoming(message.topic_id);
}
@ -187,7 +187,6 @@ const PrivateMessageTopicTrackingState = EmberObject.extend({
_shouldDisplayMessageForInbox(message) {
return (
this.inbox === "all" ||
this._displayMessageForGroupInbox(message) ||
(this.inbox === "user" &&
(message.payload.group_ids.length === 0 ||

View File

@ -98,13 +98,14 @@ class PrivateMessageTopicTrackingState
end
def self.publish_unread(post)
return unless post.topic.private_message?
topic = post.topic
return unless topic.private_message?
scope = TopicUser
.tracking(post.topic_id)
.includes(user: :user_stat)
.includes(user: [:user_stat, :user_option])
allowed_group_ids = post.topic.allowed_groups.pluck(:id)
allowed_group_ids = topic.allowed_groups.pluck(:id)
group_ids =
if post.post_type == Post.types[:whisper]
@ -123,6 +124,12 @@ class PrivateMessageTopicTrackingState
.select([:user_id, :last_read_post_number, :notification_level])
.each do |tu|
if tu.last_read_post_number.nil? &&
topic.created_at < tu.user.user_option.treat_as_new_topic_start_date
next
end
message = {
topic_id: post.topic_id,
message_type: UNREAD_MESSAGE_TYPE,

View File

@ -166,6 +166,17 @@ describe PrivateMessageTopicTrackingState do
.to eq(NotificationLevels.all[:watching])
expect(data['payload']['group_ids']).to eq([])
end
it 'does not publish message_bus message if post in topic is not new for user' do
group_message.update!(created_at: 3.days.ago)
user_2.user_option.update!(new_topic_duration_minutes: 2.days.minutes)
messages = MessageBus.track_publish do
described_class.publish_unread(group_message.first_post)
end
expect(messages).to eq([])
end
end
describe '.publish_group_archived' do