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)
|
2022-11-29 06:21:53 +01:00
|
|
|
return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id'])
|
2017-08-08 21:52:15 +02:00
|
|
|
|
2023-05-27 12:19:29 +02:00
|
|
|
return if maybe_process_misskey_reaction
|
2022-11-29 06:21:53 +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
|
2022-12-02 18:02:06 +01:00
|
|
|
|
|
|
|
# Misskey delivers reactions as likes with the emoji in _misskey_reaction
|
|
|
|
# see https://misskey-hub.net/ns.html#misskey-reaction for details
|
2023-05-27 12:19:29 +02:00
|
|
|
def maybe_process_misskey_reaction
|
|
|
|
original_status = status_from_uri(object_uri)
|
2022-12-02 18:02:06 +01:00
|
|
|
name = @json['_misskey_reaction']
|
|
|
|
return false if name.nil?
|
|
|
|
|
2023-05-08 19:37:56 +02:00
|
|
|
if /^:.*:$/.match?(name)
|
2022-12-02 18:02:06 +01:00
|
|
|
name.delete! ':'
|
2023-05-27 12:19:29 +02:00
|
|
|
custom_emoji = process_emoji_tags(@json['tag'])
|
|
|
|
|
2022-12-02 18:02:06 +01:00
|
|
|
return false if custom_emoji.nil? # invalid custom emoji, treat it as a regular like
|
|
|
|
end
|
2023-05-27 12:19:29 +02:00
|
|
|
return true if @account.reacted?(original_status, name, custom_emoji)
|
2022-12-02 18:02:06 +01:00
|
|
|
|
|
|
|
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')
|
2022-12-03 11:22:15 +01:00
|
|
|
true
|
2023-05-27 12:19:29 +02:00
|
|
|
# account tried to react with disabled custom emoji. Returning true to discard activity.
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
true
|
2022-12-02 18:02:06 +01:00
|
|
|
end
|
2017-08-08 21:52:15 +02:00
|
|
|
end
|