2017-08-08 21:52:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Activity::Like < ActivityPub::Activity
|
|
|
|
def perform
|
|
|
|
original_status = status_from_uri(object_uri)
|
2024-01-18 19:39:59 +01:00
|
|
|
return if original_status.nil? || delete_arrived_first?(@json['id'])
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2024-01-14 03:57:44 +01:00
|
|
|
return if maybe_process_embedded_reaction
|
2023-11-08 01:43:47 +01:00
|
|
|
|
|
|
|
return if @account.favourited?(original_status)
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2017-08-20 16:53:47 +02:00
|
|
|
favourite = original_status.favourites.create!(account: @account)
|
2022-02-25 00:34:14 +01:00
|
|
|
|
2022-03-04 01:06:33 +01:00
|
|
|
LocalNotificationWorker.perform_async(original_status.account_id, favourite.id, 'Favourite', 'favourite')
|
2022-02-25 00:34:14 +01:00
|
|
|
Trends.statuses.register(original_status)
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|
2023-11-08 01:43:47 +01:00
|
|
|
|
2024-01-14 03:57:44 +01:00
|
|
|
# Some servers deliver reactions as likes with the emoji in content
|
|
|
|
# Versions of Misskey before 12.1.0 specify emojis in _misskey_reaction instead, so we check both
|
2023-12-26 21:04:53 +01:00
|
|
|
# See https://misskey-hub.net/ns.html#misskey-reaction for details
|
2024-01-14 03:57:44 +01:00
|
|
|
def maybe_process_embedded_reaction
|
2023-11-08 01:43:47 +01:00
|
|
|
original_status = status_from_uri(object_uri)
|
2023-12-26 21:04:53 +01:00
|
|
|
name = @json['content'] || @json['_misskey_reaction']
|
2023-11-08 01:43:47 +01:00
|
|
|
return false if name.nil?
|
|
|
|
|
|
|
|
if /^:.*:$/.match?(name)
|
|
|
|
name.delete! ':'
|
|
|
|
custom_emoji = process_emoji_tags(name, @json['tag'])
|
|
|
|
|
|
|
|
return false if custom_emoji.nil? # invalid custom emoji, treat it as a regular like
|
|
|
|
end
|
|
|
|
return true if @account.reacted?(original_status, name, custom_emoji)
|
|
|
|
|
|
|
|
reaction = original_status.status_reactions.create!(account: @account, name: name, custom_emoji: custom_emoji)
|
|
|
|
LocalNotificationWorker.perform_async(original_status.account_id, reaction.id, 'StatusReaction', 'reaction')
|
|
|
|
true
|
|
|
|
# account tried to react with disabled custom emoji. Returning true to discard activity.
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
true
|
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|