mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 07:07:43 +08:00
FIX: Delete associated notifications when trashing chat messages. (#20144)
Deleting a message with a mention doesn't clear the associated notification, confusing the mentioned user. There are different chat notification types, but we only care about `chat_mentioned` since `chat_quoted` is associated with a post, and `chat_message` is only for push notifications. Unfortunately, this change doesn't fix the chat bubble getting out of sync when a message gets deleted since we track unread/mentions count with an integer, making it a bit hard to manipulate. We can follow up later if we consider it necessary.
This commit is contained in:
@ -260,13 +260,9 @@ class Chat::ChatController < Chat::ChatBaseController
|
||||
def delete
|
||||
guardian.ensure_can_delete_chat!(@message, @chatable)
|
||||
|
||||
updated = @message.trash!(current_user)
|
||||
if updated
|
||||
ChatPublisher.publish_delete!(@chat_channel, @message)
|
||||
render json: success_json
|
||||
else
|
||||
render_json_error(@message)
|
||||
end
|
||||
ChatMessageDestroyer.new.trash_message(@message, current_user)
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
def restore
|
||||
|
@ -3,7 +3,7 @@
|
||||
class ChatMention < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :chat_message
|
||||
belongs_to :notification
|
||||
belongs_to :notification, dependent: :destroy
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
@ -11,6 +11,18 @@ class ChatMessageDestroyer
|
||||
end
|
||||
end
|
||||
|
||||
def trash_message(message, actor)
|
||||
ChatMessage.transaction do
|
||||
message.trash!(actor)
|
||||
ChatMention.where(chat_message: message).destroy_all
|
||||
|
||||
# FIXME: We should do something to prevent the blue/green bubble
|
||||
# of other channel members from getting out of sync when a message
|
||||
# gets deleted.
|
||||
ChatPublisher.publish_delete!(message.chat_channel, message)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reset_last_read(message_ids)
|
||||
|
Reference in New Issue
Block a user