Skip to content

Commit

Permalink
Turn custom emoji regexps into class level constants
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEssem authored and jordemort committed Sep 3, 2024
1 parent c925c67 commit e9b1a36
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/lib/activitypub/activity/emoji_react.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# frozen_string_literal: true

class ActivityPub::Activity::EmojiReact < ActivityPub::Activity
CUSTOM_EMOJI_REGEX = /^:[^:]+:$/

def perform
original_status = status_from_uri(object_uri)
name = @json['content']
return if original_status.nil? ||
!original_status.account.local? ||
delete_arrived_first?(@json['id'])

if /^:.*:$/.match?(name)
if CUSTOM_EMOJI_REGEX.match?(name)
name.delete! ':'
custom_emoji = process_emoji_tags(name, @json['tag'])

Expand Down
4 changes: 3 additions & 1 deletion app/lib/activitypub/activity/like.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ActivityPub::Activity::Like < ActivityPub::Activity
CUSTOM_EMOJI_REGEX = /^:[^:]+:$/

def perform
original_status = status_from_uri(object_uri)
return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id'])
Expand All @@ -23,7 +25,7 @@ def maybe_process_embedded_reaction
name = @json['content'] || @json['_misskey_reaction']
return false if name.nil?

if /^:.*:$/.match?(name)
if CUSTOM_EMOJI_REGEX.match?(name)
name.delete! ':'
custom_emoji = process_emoji_tags(name, @json['tag'])

Expand Down
4 changes: 3 additions & 1 deletion app/lib/activitypub/activity/undo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class ActivityPub::Activity::Undo < ActivityPub::Activity
CUSTOM_EMOJI_REGEX = /^:[^:]+:$/

def perform
case @object['type']
when 'Announce'
Expand Down Expand Up @@ -125,7 +127,7 @@ def undo_emoji_react

return if status.nil? || !status.account.local?

if /^:.*:$/.match?(name)
if CUSTOM_EMOJI_REGEX.match?(name)
name.delete! ':'
custom_emoji = process_emoji_tags(name, @object['tag'])

Expand Down

0 comments on commit e9b1a36

Please sign in to comment.