about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-15 13:34:05 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-15 14:12:24 -0500
commitcf3ec71aa564c7fe47ec79f8dd5f14e3bce0b85c (patch)
tree49a3356c4177157b377aeca223a7d1c1e2e3dc17 /app/lib
parent0a5eba734e6aa6a6e7e8f64b022af8ea129c9f5d (diff)
local visibility scope, chat scope+tags, unlisted tags
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activitypub/activity/create.rb14
-rw-r--r--app/lib/activitypub/tag_manager.rb8
-rw-r--r--app/lib/bangtags.rb25
3 files changed, 37 insertions, 10 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 263dbbb87..2b267c0d7 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -153,7 +153,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
   def attach_tags(status)
     @tags.each do |tag|
       status.tags << tag
-      TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?
+      tag.chatters.find_or_create_by(account_id: status.account) if tag.chat?
+      next unless status.distributable? && !tag.chat?
+      TrendingTags.record_use!(tag, status.account, status.created_at)
     end
 
     @mentions.each do |mention|
@@ -181,7 +183,15 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
 
     hashtag = tag['name'].gsub(/\A#/, '').gsub(':', '.').mb_chars.downcase
 
-    return if !@options[:imported] && hashtag.starts_with?('self.', '_self.', 'local.', '_local.')
+    return if !@options[:imported] && (
+      hashtag.in?(%w(self .self local .local chat.local .chat.local)) ||
+      hashtag.starts_with?('self.', '.self', 'local.', '.local', 'chat.local.', '.chat.local.')
+    )
+
+    if tag['name'].starts_with?('chat.', '.chat.')
+      @params[:visibility] = :chat
+      @params[:thread] = nil
+    end
 
     hashtag = Tag.where(name: hashtag).first_or_create!(name: hashtag)
 
diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb
index 595291342..baec9da21 100644
--- a/app/lib/activitypub/tag_manager.rb
+++ b/app/lib/activitypub/tag_manager.rb
@@ -62,9 +62,9 @@ class ActivityPub::TagManager
     case status.visibility
     when 'public'
       [COLLECTIONS[:public]]
-    when 'unlisted', 'private'
+    when 'unlisted', 'private', 'local'
       [account_followers_url(status.account)]
-    when 'direct', 'limited'
+    when 'direct', 'limited', 'chat'
       if status.account.silenced?
         # Only notify followers if the account is locally silenced
         account_ids = status.active_mentions.pluck(:account_id)
@@ -89,11 +89,11 @@ class ActivityPub::TagManager
     case status.visibility
     when 'public'
       cc << account_followers_url(status.account)
-    when 'unlisted'
+    when 'unlisted', 'local'
       cc << COLLECTIONS[:public]
     end
 
-    unless status.direct_visibility? || status.limited_visibility?
+    unless status.direct_visibility? || status.limited_visibility? || status.chat_visibility?
       if status.account.silenced?
         # Only notify followers if the account is locally silenced
         account_ids = status.active_mentions.pluck(:account_id)
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 4f4452486..e106dc582 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -452,8 +452,9 @@ class Bangtags
             'group'       => :private,
 
             'unlisted'    => :unlisted,
-            'local'       => :unlisted,
-            'monsterpit'  => :unlisted,
+
+            'local'       => :local,
+            'monsterpit'  => :local,
 
             'public'      => :public,
             'world'       => :public,
@@ -552,9 +553,25 @@ class Bangtags
   end
 
   def add_tags(to_status, *tags)
-    records = []
-    valid_name = /^[[:word:]:_\-]*[[:alpha:]:_·\-][[:word:]:_\-]*$/
+    valid_name = /^[[:word:]:._\-]*[[:alpha:]:._·\-][[:word:]:._\-]*$/
     tags = tags.select {|t| t.present? && valid_name.match?(t)}.uniq
     ProcessHashtagsService.new.call(to_status, tags)
+    to_status.save
+  end
+
+  def del_tags(from_status, *tags)
+    valid_name = /^[[:word:]:._\-]*[[:alpha:]:._·\-][[:word:]:._\-]*$/
+    tags = tags.select {|t| t.present? && valid_name.match?(t)}.uniq
+    tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
+      name.gsub!(/[:.]+/, '.')
+      next if name.blank? || name == '.'
+      if name.ends_with?('.')
+        filtered_tags = from_status.tags.select { |t| t.name == name || t.name.starts_with?(name) }
+      else
+        filtered_tags = from_status.tags.select { |t| t.name == name }
+      end
+      from_status.tags.destroy(filtered_tags)
+    end
+    from_status.save
   end
 end