FIX: fix notifications for flag PMs and show topics with moderator posts in inbox (#7331)

Some old moderator posts that were not correctly processed before this change and 993d8f34 are not listed under /u/username/messages
This commit is contained in:
Maja Komel 2019-04-25 11:15:13 +02:00 committed by Régis Hanol
parent 996e5e5dfa
commit 422237391e
3 changed files with 23 additions and 7 deletions

View File

@ -243,12 +243,16 @@ protected
trigger_spam = false
actions.each do |action|
action.agreed_at = Time.zone.now
action.agreed_by_id = performed_by.id
# so callback is called
action.save
action.add_moderator_post_if_needed(performed_by, :agreed, args[:post_was_deleted])
trigger_spam = true if action.post_action_type_id == PostActionType.types[:spam]
ActiveRecord::Base.transaction do
action.agreed_at = Time.zone.now
action.agreed_by_id = performed_by.id
# so callback is called
action.save
DB.after_commit do
action.add_moderator_post_if_needed(performed_by, :agreed, args[:post_was_deleted])
trigger_spam = true if action.post_action_type_id == PostActionType.types[:spam]
end
end
end
DiscourseEvent.trigger(:confirmed_spam_post, post) if trigger_spam

View File

@ -312,7 +312,7 @@ class TopicQuery
list = private_messages_for(user, :user)
list = not_archived(list, user)
.where('NOT (topics.participant_count = 1 AND topics.user_id = ?)', user.id)
.where('NOT (topics.participant_count = 1 AND topics.user_id = ? AND topics.moderator_posts_count = 0)', user.id)
create_list(:private_messages, {}, list)
end

View File

@ -1070,4 +1070,16 @@ describe TopicQuery do
end
end
end
describe '#list_private_messages' do
it "includes topics with moderator posts" do
private_message_topic = Fabricate(:private_message_post, user: user).topic
expect(TopicQuery.new(user).list_private_messages(user).topics).to be_empty
private_message_topic.add_moderator_post(admin, "Thank you for your flag")
expect(TopicQuery.new(user).list_private_messages(user).topics).to eq([private_message_topic])
end
end
end