DEV: When deleting a chat message, do not delete mention records (#21486)
A chat message may be restored later, so we shouldn't be deleting `chat_mentions` records for it.
But we still have to remove notifications (see 082cd139
).
This commit is contained in:
parent
92bb845db2
commit
f4fde4e49b
|
@ -22,7 +22,7 @@ module Chat
|
|||
policy :invalid_access
|
||||
transaction do
|
||||
step :trash_message
|
||||
step :destroy_mentions
|
||||
step :destroy_notifications
|
||||
step :update_tracking_state
|
||||
step :update_thread_reply_cache
|
||||
end
|
||||
|
@ -53,8 +53,10 @@ module Chat
|
|||
message.trash!
|
||||
end
|
||||
|
||||
def destroy_mentions(message:, **)
|
||||
Chat::Mention.where(chat_message: message).destroy_all
|
||||
def destroy_notifications(message:, **)
|
||||
ids = Chat::Mention.where(chat_message: message).pluck(:notification_id)
|
||||
Notification.where(id: ids).destroy_all
|
||||
Chat::Mention.where(chat_message: message).update_all(notification_id: nil)
|
||||
end
|
||||
|
||||
def update_tracking_state(message:, **)
|
||||
|
|
|
@ -43,10 +43,15 @@ RSpec.describe Chat::TrashMessage do
|
|||
expect(Chat::Message.find_by(id: message.id)).to be_nil
|
||||
end
|
||||
|
||||
it "destroys associated mentions" do
|
||||
mention = Fabricate(:chat_mention, chat_message: message)
|
||||
it "destroys notifications for mentions" do
|
||||
notification = Fabricate(:notification)
|
||||
mention = Fabricate(:chat_mention, chat_message: message, notification: notification)
|
||||
|
||||
result
|
||||
expect(Chat::Mention.find_by(id: mention.id)).to be_nil
|
||||
|
||||
mention = Chat::Mention.find_by(id: mention.id)
|
||||
expect(mention).to be_present
|
||||
expect(mention.notification_id).to be_nil
|
||||
end
|
||||
|
||||
it "publishes associated Discourse and MessageBus events" do
|
||||
|
|
Loading…
Reference in New Issue