2017-08-09 04:52:15 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Activity::Like < ActivityPub::Activity
|
|
|
|
def perform
|
|
|
|
original_status = status_from_uri(object_uri)
|
2022-11-29 14:21:53 +09:00
|
|
|
return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id'])
|
2017-08-09 04:52:15 +09:00
|
|
|
|
2023-05-17 21:53:11 +09:00
|
|
|
return if maybe_process_misskey_reaction
|
2022-11-29 14:21:53 +09:00
|
|
|
|
|
|
|
return if @account.favourited?(original_status)
|
2017-08-09 04:52:15 +09:00
|
|
|
|
2017-08-20 23:53:47 +09:00
|
|
|
favourite = original_status.favourites.create!(account: @account)
|
2022-02-25 08:34:14 +09:00
|
|
|
|
2022-03-04 09:06:33 +09:00
|
|
|
LocalNotificationWorker.perform_async(original_status.account_id, favourite.id, 'Favourite', 'favourite')
|
2022-02-25 08:34:14 +09:00
|
|
|
Trends.statuses.register(original_status)
|
2017-08-09 04:52:15 +09:00
|
|
|
end
|
2022-12-03 02:02:06 +09: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-17 21:53:11 +09:00
|
|
|
def maybe_process_misskey_reaction
|
|
|
|
original_status = status_from_uri(object_uri)
|
2022-12-03 02:02:06 +09:00
|
|
|
name = @json['_misskey_reaction']
|
|
|
|
return false if name.nil?
|
|
|
|
|
2023-05-10 06:41:48 +09:00
|
|
|
if /^:.*:$/.match?(name)
|
2022-12-03 02:02:06 +09:00
|
|
|
name.delete! ':'
|
2023-05-27 20:09:48 +09:00
|
|
|
custom_emoji = process_emoji_tags(name, @json['tag'])
|
2023-05-17 21:53:11 +09:00
|
|
|
|
2022-12-03 02:02:06 +09:00
|
|
|
return false if custom_emoji.nil? # invalid custom emoji, treat it as a regular like
|
|
|
|
end
|
2023-05-15 06:49:18 +09:00
|
|
|
return true if @account.reacted?(original_status, name, custom_emoji)
|
2022-12-03 02:02:06 +09: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 19:22:15 +09:00
|
|
|
true
|
2023-05-15 06:53:57 +09:00
|
|
|
# account tried to react with disabled custom emoji. Returning true to discard activity.
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
true
|
2022-12-03 02:02:06 +09:00
|
|
|
end
|
2017-08-09 04:52:15 +09:00
|
|
|
end
|