about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-05-07 18:21:59 +0200
committerClaire <claire.github-309c@sitedethib.com>2021-05-07 18:21:59 +0200
commit50b430d9a2857edf8ab44e9b94c7bcb14ecd2117 (patch)
tree4932ca1d8e52f6ce9b8b9fbb304b6bfce4027e54 /app/lib
parenta346912030012dc1451249373ff7ef1a61016517 (diff)
parentd8e0c8a89e1f1dd1c4ce1513deaeb3c85c6e4a42 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
- `app/views/statuses/_simple_status.html.haml`:
  Small markup change in glitch-soc, on a line that has been modified by
  upstream. Ported upstream changes.
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/activitypub/activity/announce.rb4
-rw-r--r--app/lib/activitypub/activity/create.rb2
-rw-r--r--app/lib/delivery_failure_tracker.rb26
-rw-r--r--app/lib/potential_friendship_tracker.rb10
-rw-r--r--app/lib/status_reach_finder.rb6
-rw-r--r--app/lib/video_metadata_extractor.rb54
6 files changed, 90 insertions, 12 deletions
diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb
index a1081522e..9f778ffb9 100644
--- a/app/lib/activitypub/activity/announce.rb
+++ b/app/lib/activitypub/activity/announce.rb
@@ -22,6 +22,10 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
         visibility: visibility_from_audience
       )
 
+      original_status.tags.each do |tag|
+        tag.use!(@account)
+      end
+
       distribute(@status)
     end
 
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 98c587399..763c417f9 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -164,7 +164,7 @@ 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.public_visibility?
+      tag.use!(@account, status: status, at_time: status.created_at) if status.public_visibility?
     end
 
     @mentions.each do |mention|
diff --git a/app/lib/delivery_failure_tracker.rb b/app/lib/delivery_failure_tracker.rb
index 2cd6ef7ad..8907ade4c 100644
--- a/app/lib/delivery_failure_tracker.rb
+++ b/app/lib/delivery_failure_tracker.rb
@@ -17,6 +17,10 @@ class DeliveryFailureTracker
     UnavailableDomain.find_by(domain: @host)&.destroy
   end
 
+  def clear_failures!
+    Redis.current.del(exhausted_deliveries_key)
+  end
+
   def days
     Redis.current.scard(exhausted_deliveries_key) || 0
   end
@@ -25,6 +29,10 @@ class DeliveryFailureTracker
     !UnavailableDomain.where(domain: @host).exists?
   end
 
+  def exhausted_deliveries_days
+    Redis.current.smembers(exhausted_deliveries_key).sort.map { |date| Date.new(date.slice(0, 4).to_i, date.slice(4, 2).to_i, date.slice(6, 2).to_i) }
+  end
+
   alias reset! track_success!
 
   class << self
@@ -44,6 +52,24 @@ class DeliveryFailureTracker
     def reset!(url)
       new(url).reset!
     end
+
+    def warning_domains
+      domains = Redis.current.keys(exhausted_deliveries_key_by('*')).map do |key|
+        key.delete_prefix(exhausted_deliveries_key_by(''))
+      end
+
+      domains - UnavailableDomain.all.pluck(:domain)
+    end
+
+    def warning_domains_map
+      warning_domains.index_with { |domain| Redis.current.scard(exhausted_deliveries_key_by(domain)) }
+    end
+
+    private
+
+    def exhausted_deliveries_key_by(host)
+      "exhausted_deliveries:#{host}"
+    end
   end
 
   private
diff --git a/app/lib/potential_friendship_tracker.rb b/app/lib/potential_friendship_tracker.rb
index e72d454b6..f5bc20346 100644
--- a/app/lib/potential_friendship_tracker.rb
+++ b/app/lib/potential_friendship_tracker.rb
@@ -27,15 +27,5 @@ class PotentialFriendshipTracker
     def remove(account_id, target_account_id)
       redis.zrem("interactions:#{account_id}", target_account_id)
     end
-
-    def get(account, limit)
-      account_ids = redis.zrevrange("interactions:#{account.id}", 0, limit)
-
-      return [] if account_ids.empty? || limit < 1
-
-      accounts = Account.searchable.where(id: account_ids).index_by(&:id)
-
-      account_ids.map { |id| accounts[id.to_i] }.compact
-    end
   end
 end
diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb
index 3aab3bde0..735d66a4f 100644
--- a/app/lib/status_reach_finder.rb
+++ b/app/lib/status_reach_finder.rb
@@ -62,7 +62,11 @@ class StatusReachFinder
   end
 
   def followers_inboxes
-    @status.account.followers.inboxes
+    if @status.in_reply_to_local_account? && @status.distributable?
+      @status.account.followers.or(@status.thread.account.followers).inboxes
+    else
+      @status.account.followers.inboxes
+    end
   end
 
   def relay_inboxes
diff --git a/app/lib/video_metadata_extractor.rb b/app/lib/video_metadata_extractor.rb
new file mode 100644
index 000000000..03e40f923
--- /dev/null
+++ b/app/lib/video_metadata_extractor.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+class VideoMetadataExtractor
+  attr_reader :duration, :bitrate, :video_codec, :audio_codec,
+              :colorspace, :width, :height, :frame_rate
+
+  def initialize(path)
+    @path     = path
+    @metadata = Oj.load(ffmpeg_command_output, mode: :strict, symbol_keys: true)
+
+    parse_metadata
+  rescue Terrapin::ExitStatusError, Oj::ParseError
+    @invalid = true
+  rescue Terrapin::CommandNotFoundError
+    raise Paperclip::Errors::CommandNotFoundError, 'Could not run the `ffprobe` command. Please install ffmpeg.'
+  end
+
+  def valid?
+    !@invalid
+  end
+
+  private
+
+  def ffmpeg_command_output
+    command = Terrapin::CommandLine.new('ffprobe', '-i :path -print_format :format -show_format -show_streams -show_error -loglevel :loglevel')
+    command.run(path: @path, format: 'json', loglevel: 'fatal')
+  end
+
+  def parse_metadata
+    if @metadata.key?(:format)
+      @duration = @metadata[:format][:duration].to_f
+      @bitrate  = @metadata[:format][:bit_rate].to_i
+    end
+
+    if @metadata.key?(:streams)
+      video_streams = @metadata[:streams].select { |stream| stream[:codec_type] == 'video' }
+      audio_streams = @metadata[:streams].select { |stream| stream[:codec_type] == 'audio' }
+
+      if (video_stream = video_streams.first)
+        @video_codec = video_stream[:codec_name]
+        @colorspace  = video_stream[:pix_fmt]
+        @width       = video_stream[:width]
+        @height      = video_stream[:height]
+        @frame_rate  = video_stream[:avg_frame_rate] == '0/0' ? nil : Rational(video_stream[:avg_frame_rate])
+      end
+
+      if (audio_stream = audio_streams.first)
+        @audio_codec = audio_stream[:codec_name]
+      end
+    end
+
+    @invalid = true if @metadata.key?(:error)
+  end
+end