about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/domains_cli.rb5
-rw-r--r--lib/mastodon/snowflake.rb13
-rw-r--r--lib/mastodon/version.rb41
-rw-r--r--lib/tasks/monsterfork.rake43
4 files changed, 87 insertions, 15 deletions
diff --git a/lib/mastodon/domains_cli.rb b/lib/mastodon/domains_cli.rb
index 5433ddd9d..8a507b44e 100644
--- a/lib/mastodon/domains_cli.rb
+++ b/lib/mastodon/domains_cli.rb
@@ -41,6 +41,11 @@ module Mastodon
         end
       end
 
+      say('Scheduling account defederation messages to be sent to target domains...')
+      DefederateDomainService.new.call(scope.pluck(:domain).uniq)
+      say('Done!', :green)
+
+      say('Deleting accounts from target domains...')
       processed, = parallelize_with_progress(scope) do |account|
         DeleteAccountService.new.call(account, reserve_username: false, skip_side_effects: true) unless options[:dry_run]
       end
diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb
index 9e5bc7383..10ed51f0c 100644
--- a/lib/mastodon/snowflake.rb
+++ b/lib/mastodon/snowflake.rb
@@ -120,21 +120,10 @@ module Mastodon::Snowflake
 
         seq_name = data[:seq_prefix] + '_id_seq'
 
-        # If we were on Postgres 9.5+, we could do CREATE SEQUENCE IF
-        # NOT EXISTS, but we can't depend on that. Instead, catch the
-        # possible exception and ignore it.
         # Note that seq_name isn't a column name, but it's a
         # relation, like a column, and follows the same quoting rules
         # in Postgres.
-        connection.execute(<<~SQL)
-          DO $$
-            BEGIN
-              CREATE SEQUENCE #{connection.quote_column_name(seq_name)};
-            EXCEPTION WHEN duplicate_table THEN
-              -- Do nothing, we have the sequence already.
-            END
-          $$ LANGUAGE plpgsql;
-        SQL
+        connection.execute("CREATE SEQUENCE IF NOT EXISTS #{connection.quote_column_name(seq_name)};")
       end
     end
 
diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb
index 429bcb8a5..448518884 100644
--- a/lib/mastodon/version.rb
+++ b/lib/mastodon/version.rb
@@ -21,7 +21,7 @@ module Mastodon
     end
 
     def suffix
-      '+glitch'
+      '+glitch+monsterpit'
     end
 
     def to_a
@@ -33,11 +33,11 @@ module Mastodon
     end
 
     def repository
-      ENV.fetch('GITHUB_REPOSITORY', 'glitch-soc/mastodon')
+      ENV.fetch('GITHUB_REPOSITORY') { 'monsterpit/monsterpit-mastodon' }
     end
 
     def source_base_url
-      ENV.fetch('SOURCE_BASE_URL', "https://github.com/#{repository}")
+      ENV.fetch('SOURCE_BASE_URL') { "https://monsterware.dev/#{repository}" }
     end
 
     # specify git tag or commit hash here
@@ -56,5 +56,40 @@ module Mastodon
     def user_agent
       @user_agent ||= "#{HTTP::Request::USER_AGENT} (Mastodon/#{Version}; +http#{Rails.configuration.x.use_https ? 's' : ''}://#{Rails.configuration.x.web_domain}/)"
     end
+
+    def server_metadata_json
+      @server_metadata_json ||= [
+        {
+          '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' },
+          type: 'PropertyValue',
+          name: 'version',
+          value: to_s,
+        },
+        {
+          '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' },
+          type: 'PropertyValue',
+          name: 'monsterpit:extensions',
+          value: '2020.09.05.1',
+        },
+        {
+          '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' },
+          type: 'PropertyValue',
+          name: 'comment:0',
+          value: "big tails can't fail",
+        },
+        {
+          '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' },
+          type: 'PropertyValue',
+          name: 'comment:1',
+          value: 'trans rights!',
+        },
+        {
+          '@context': { 'schema': 'http://schema.org/', name: 'schema:name', value: 'schema:value' },
+          type: 'PropertyValue',
+          name: 'comment:2',
+          value: 'gently the kobolds',
+        },
+      ]
+    end
   end
 end
diff --git a/lib/tasks/monsterfork.rake b/lib/tasks/monsterfork.rake
new file mode 100644
index 000000000..02ed97a9a
--- /dev/null
+++ b/lib/tasks/monsterfork.rake
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+namespace :monsterfork do
+  desc 'Compute post nesting levels (this may take a very long time!)'
+  task compute_nesting_levels: :environment do
+    Rails.logger.info('Setting post nesting level for orphaned replies...')
+    Status.select(:id, :account_id).where(reply: true, in_reply_to_id: nil).reorder(nil).in_batches.update_all(nest_level: 1)
+
+    count = 1.0
+    total = Conversation.count
+
+    Conversation.reorder('conversations.id DESC').find_each do |conversation|
+      Rails.logger.info("(#{(count / total * 100).to_i}%) Computing post nesting levels for all threads...")
+
+      conversation.statuses.where(reply: true).reorder('statuses.id ASC').find_each do |status|
+        level = [status.thread&.account_id == status.account_id ? status.thread&.nest_level.to_i : status.thread&.nest_level.to_i + 1, 127].min
+        status.update(nest_level: level) if level != status.nest_level
+      end
+
+      count += 1
+    end
+  end
+
+  desc '(Re-)announce instance actor to allow-listed servers'
+  task announce_instance_actor: :environment  do
+    Rails.logger.info('Announcing instance actor to all allowed servers...')
+    ActivityPub::UpdateDistributionWorker.new.perform(Account.representative.id)
+    Rails.logger.info('Done!')
+  end
+
+  desc 'Update the accounts of allow-listed application and instance actors'
+  task refresh_application_actors: :environment  do
+    Account.remote.without_suspended.where(actor_type: 'Application').find_each do |account|
+      Rails.logger.info("Refetching application actor: #{account.acct}")
+      account.update!(last_webfingered_at: nil)
+      begin
+        ResolveAccountService.new.call(account)
+      rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError, Mastodon::UnexpectedResponseError => e
+        Rails.logger.info("  Failed: #{e.class} (#{e.message})")
+      end
+    end
+    Rails.logger.info('Done!')
+  end
+end