mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
Add notes to blocks (#193)
In this commit, we also push note creation into the AccountInteractions concern, where we can: 1. create and persist model objects inside transactions without having to include job queuing inside the transaction 2. commonize the don't-add-a-blank-note check Finally, this commit resolves a invocation-on-nil in REST::RelationshipSerializer.
This commit is contained in:
@@ -82,21 +82,38 @@ module AccountInteractions
|
||||
rel
|
||||
end
|
||||
|
||||
def block!(other_account)
|
||||
block_relationships.find_or_create_by!(target_account: other_account)
|
||||
end
|
||||
|
||||
def mute!(other_account, notifications: nil)
|
||||
notifications = true if notifications.nil?
|
||||
mute = mute_relationships.create_with(hide_notifications: notifications).find_or_create_by!(target_account: other_account)
|
||||
# When toggling a mute between hiding and allowing notifications, the mute will already exist, so the find_or_create_by! call will return the existing Mute without updating the hide_notifications attribute. Therefore, we check that hide_notifications? is what we want and set it if it isn't.
|
||||
if mute.hide_notifications? != notifications
|
||||
mute.update!(hide_notifications: notifications)
|
||||
def block!(other_account, note: nil)
|
||||
transaction do
|
||||
block = block_relationships.find_or_create_by!(target_account: other_account)
|
||||
attach_note(block, note)
|
||||
block
|
||||
end
|
||||
|
||||
mute
|
||||
end
|
||||
|
||||
def mute!(other_account, notifications: nil, note: nil)
|
||||
notifications = true if notifications.nil?
|
||||
|
||||
transaction do
|
||||
mute = mute_relationships.create_with(hide_notifications: notifications).find_or_create_by!(target_account: other_account)
|
||||
attach_note(mute, note)
|
||||
|
||||
# When toggling a mute between hiding and allowing notifications, the mute will already exist, so the find_or_create_by! call will return the existing Mute without updating the hide_notifications attribute. Therefore, we check that hide_notifications? is what we want and set it if it isn't.
|
||||
if mute.hide_notifications? != notifications
|
||||
mute.update!(hide_notifications: notifications)
|
||||
end
|
||||
|
||||
mute
|
||||
end
|
||||
end
|
||||
|
||||
def attach_note(object, note)
|
||||
return if note.blank?
|
||||
|
||||
object.create_note!(note: note)
|
||||
end
|
||||
|
||||
private :attach_note
|
||||
|
||||
def mute_conversation!(conversation)
|
||||
conversation_mutes.find_or_create_by!(conversation: conversation)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user