about summary refs log tree commit diff
path: root/app/services/activitypub/process_status_update_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/activitypub/process_status_update_service.rb')
-rw-r--r--app/services/activitypub/process_status_update_service.rb26
1 files changed, 7 insertions, 19 deletions
diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb
index 977928127..7438a7c53 100644
--- a/app/services/activitypub/process_status_update_service.rb
+++ b/app/services/activitypub/process_status_update_service.rb
@@ -95,10 +95,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
 
       # If for some reasons the options were changed, it invalidates all previous
       # votes, so we need to remove them
-      if poll_parser.significantly_changes?(poll)
-        @poll_changed = true
-        poll.votes.delete_all unless poll.new_record?
-      end
+      @poll_changed = true if poll_parser.significantly_changes?(poll)
 
       poll.last_fetched_at = Time.now.utc
       poll.options         = poll_parser.options
@@ -106,6 +103,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
       poll.expires_at      = poll_parser.expires_at
       poll.voters_count    = poll_parser.voters_count
       poll.cached_tallies  = poll_parser.cached_tallies
+      poll.reset_votes! if @poll_changed
       poll.save!
 
       @status.poll_id = poll.id
@@ -120,7 +118,7 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
     @status.text         = @status_parser.text || ''
     @status.spoiler_text = @status_parser.spoiler_text || ''
     @status.sensitive    = @account.sensitized? || @status_parser.sensitive || false
-    @status.language     = @status_parser.language || detected_language
+    @status.language     = @status_parser.language
     @status.edited_at    = @status_parser.edited_at || Time.now.utc if significant_changes?
 
     @status.save!
@@ -210,10 +208,6 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
     { redis: Redis.current, key: "create:#{@uri}", autorelease: 15.minutes.seconds }
   end
 
-  def detected_language
-    LanguageDetector.instance.detect(@status_parser.text, @account)
-  end
-
   def create_previous_edit!
     # We only need to create a previous edit when no previous edits exist, e.g.
     # when the status has never been edited. For other cases, we always create
@@ -221,24 +215,18 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
 
     return if @status.edits.any?
 
-    @status.edits.create(
-      text: @status.text,
-      spoiler_text: @status.spoiler_text,
+    @status.snapshot!(
       media_attachments_changed: false,
-      account_id: @account.id,
-      created_at: @status.created_at
+      at_time: @status.created_at
     )
   end
 
   def create_edit!
     return unless significant_changes?
 
-    @status_edit = @status.edits.create(
-      text: @status.text,
-      spoiler_text: @status.spoiler_text,
+    @status.snapshot!(
       media_attachments_changed: @media_attachments_changed || @poll_changed,
-      account_id: @account.id,
-      created_at: @status.edited_at
+      account_id: @account.id
     )
   end