FIX: Don't create a reviewable when sending PM to user in chat (#22914)
The change is mainly to improve the consistency between flagging a chat message and flagging a post. This, in particular skips creating a reviewable when sending a PM to the user using the option "Send @user a message" from the flag menu. Context: https://meta.discourse.org/t/send-message-to-user-flags-create-review-item-in-chat/272362
This commit is contained in:
parent
edb276b9a9
commit
b7953b2562
|
@ -46,36 +46,38 @@ module Chat
|
|||
|
||||
queued_for_review = !!ActiveRecord::Type::Boolean.new.deserialize(opts[:queue_for_review])
|
||||
|
||||
reviewable =
|
||||
Chat::ReviewableMessage.needs_review!(
|
||||
created_by: guardian.user,
|
||||
target: chat_message,
|
||||
reviewable_by_moderator: true,
|
||||
potential_spam: flag_type_id == ReviewableScore.types[:spam],
|
||||
payload: payload,
|
||||
)
|
||||
reviewable.update(target_created_by: chat_message.user)
|
||||
score =
|
||||
reviewable.add_score(
|
||||
guardian.user,
|
||||
flag_type_id,
|
||||
meta_topic_id: post&.topic_id,
|
||||
take_action: opts[:take_action],
|
||||
reason: queued_for_review ? "chat_message_queued_by_staff" : nil,
|
||||
force_review: queued_for_review,
|
||||
)
|
||||
if !is_notify_type
|
||||
reviewable =
|
||||
Chat::ReviewableMessage.needs_review!(
|
||||
created_by: guardian.user,
|
||||
target: chat_message,
|
||||
reviewable_by_moderator: true,
|
||||
potential_spam: flag_type_id == ReviewableScore.types[:spam],
|
||||
payload: payload,
|
||||
)
|
||||
reviewable.update(target_created_by: chat_message.user)
|
||||
score =
|
||||
reviewable.add_score(
|
||||
guardian.user,
|
||||
flag_type_id,
|
||||
meta_topic_id: post&.topic_id,
|
||||
take_action: opts[:take_action],
|
||||
reason: queued_for_review ? "chat_message_queued_by_staff" : nil,
|
||||
force_review: queued_for_review,
|
||||
)
|
||||
|
||||
if opts[:take_action]
|
||||
reviewable.perform(guardian.user, :agree_and_delete)
|
||||
Chat::Publisher.publish_delete!(chat_message.chat_channel, chat_message)
|
||||
else
|
||||
enforce_auto_silence_threshold(reviewable)
|
||||
Chat::Publisher.publish_flag!(chat_message, guardian.user, reviewable, score)
|
||||
if opts[:take_action]
|
||||
reviewable.perform(guardian.user, :agree_and_delete)
|
||||
Chat::Publisher.publish_delete!(chat_message.chat_channel, chat_message)
|
||||
else
|
||||
enforce_auto_silence_threshold(reviewable)
|
||||
Chat::Publisher.publish_flag!(chat_message, guardian.user, reviewable, score)
|
||||
end
|
||||
end
|
||||
|
||||
result.tap do |r|
|
||||
r[:success] = true
|
||||
r[:reviewable] = reviewable
|
||||
r[:reviewable] = reviewable if !is_notify_type
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -184,6 +184,13 @@ describe Chat::ReviewQueue do
|
|||
expect(pm_topic.title).to eq("Your chat message in \"#{chat_channel.title(message.user)}\"")
|
||||
end
|
||||
|
||||
it "doesn't create a reviewable" do
|
||||
queue.flag_message(message, guardian, ReviewableScore.types[:notify_user])
|
||||
|
||||
reviewable = Chat::ReviewableMessage.find_by(target: message)
|
||||
expect(reviewable).to be_nil
|
||||
end
|
||||
|
||||
it "doesn't create a PM if there is no message" do
|
||||
queue.flag_message(message, guardian, ReviewableScore.types[:notify_user])
|
||||
|
||||
|
|
Loading…
Reference in New Issue