mirror of https://github.com/mastodon/mastodon
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - `app/models/form/admin_settings.rb`: New setting added upstream. Ported it. - `app/views/statuses/_simple_status.html.haml`: Upstream removed RTL classes. Did the same. - `config/settings.yml`: New setting added upstream. Ported it.pull/16342/head
commit
e4f8679eae
@ -1,32 +0,0 @@
|
|||||||
// U+0590 to U+05FF - Hebrew
|
|
||||||
// U+0600 to U+06FF - Arabic
|
|
||||||
// U+0700 to U+074F - Syriac
|
|
||||||
// U+0750 to U+077F - Arabic Supplement
|
|
||||||
// U+0780 to U+07BF - Thaana
|
|
||||||
// U+07C0 to U+07FF - N'Ko
|
|
||||||
// U+0800 to U+083F - Samaritan
|
|
||||||
// U+08A0 to U+08FF - Arabic Extended-A
|
|
||||||
// U+FB1D to U+FB4F - Hebrew presentation forms
|
|
||||||
// U+FB50 to U+FDFF - Arabic presentation forms A
|
|
||||||
// U+FE70 to U+FEFF - Arabic presentation forms B
|
|
||||||
|
|
||||||
const rtlChars = /[\u0590-\u083F]|[\u08A0-\u08FF]|[\uFB1D-\uFDFF]|[\uFE70-\uFEFF]/mg;
|
|
||||||
|
|
||||||
export function isRtl(text) {
|
|
||||||
if (text.length === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
text = text.replace(/(?:^|[^\/\w])@([a-z0-9_]+(@[a-z0-9\.\-]+)?)/ig, '');
|
|
||||||
text = text.replace(/(?:^|[^\/\w])#([\S]+)/ig, '');
|
|
||||||
text = text.replace(/\s+/g, '');
|
|
||||||
text = text.replace(/(\w\S+\.\w{2,}\S*)/g, '');
|
|
||||||
|
|
||||||
const matches = text.match(rtlChars);
|
|
||||||
|
|
||||||
if (!matches) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return matches.length / text.length > 0.3;
|
|
||||||
};
|
|
@ -0,0 +1,13 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module DomainMaterializable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
after_create_commit :refresh_instances_view
|
||||||
|
end
|
||||||
|
|
||||||
|
def refresh_instances_view
|
||||||
|
Instance.refresh unless domain.nil? || Instance.where(domain: domain).exists?
|
||||||
|
end
|
||||||
|
end
|
@ -1,26 +1,63 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: instances
|
||||||
|
#
|
||||||
|
# domain :string primary key
|
||||||
|
# accounts_count :bigint(8)
|
||||||
|
#
|
||||||
|
|
||||||
class Instance
|
class Instance < ApplicationRecord
|
||||||
include ActiveModel::Model
|
self.primary_key = :domain
|
||||||
|
|
||||||
attr_accessor :domain, :accounts_count, :domain_block
|
has_many :accounts, foreign_key: :domain, primary_key: :domain
|
||||||
|
|
||||||
def initialize(resource)
|
belongs_to :domain_block, foreign_key: :domain, primary_key: :domain
|
||||||
@domain = resource.domain
|
belongs_to :domain_allow, foreign_key: :domain, primary_key: :domain
|
||||||
@accounts_count = resource.respond_to?(:accounts_count) ? resource.accounts_count : nil
|
|
||||||
@domain_block = resource.is_a?(DomainBlock) ? resource : DomainBlock.rule_for(domain)
|
scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
|
||||||
@domain_allow = resource.is_a?(DomainAllow) ? resource : DomainAllow.rule_for(domain)
|
|
||||||
|
def self.refresh
|
||||||
|
Scenic.database.refresh_materialized_view(table_name, concurrently: true, cascade: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def countable?
|
def readonly?
|
||||||
@accounts_count.present?
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def delivery_failure_tracker
|
||||||
domain
|
@delivery_failure_tracker ||= DeliveryFailureTracker.new(domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
def following_count
|
||||||
|
@following_count ||= Follow.where(account: accounts).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def followers_count
|
||||||
|
@followers_count ||= Follow.where(target_account: accounts).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def reports_count
|
||||||
|
@reports_count ||= Report.where(target_account: accounts).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_key
|
def blocks_count
|
||||||
|
@blocks_count ||= Block.where(target_account: accounts).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def public_comment
|
||||||
|
domain_block&.public_comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def private_comment
|
||||||
|
domain_block&.private_comment
|
||||||
|
end
|
||||||
|
|
||||||
|
def media_storage
|
||||||
|
@media_storage ||= MediaAttachment.where(account: accounts).sum(:file_file_size)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_param
|
||||||
domain
|
domain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
.directory__tag
|
||||||
|
= link_to admin_instance_path(instance) do
|
||||||
|
%h4
|
||||||
|
= instance.domain
|
||||||
|
%small
|
||||||
|
- if instance.domain_block
|
||||||
|
- first_item = true
|
||||||
|
- if !instance.domain_block.noop?
|
||||||
|
= t("admin.domain_blocks.severity.#{instance.domain_block.severity}")
|
||||||
|
- first_item = false
|
||||||
|
- unless instance.domain_block.suspend?
|
||||||
|
- if instance.domain_block.reject_media?
|
||||||
|
- unless first_item
|
||||||
|
•
|
||||||
|
= t('admin.domain_blocks.rejecting_media')
|
||||||
|
- first_item = false
|
||||||
|
- if instance.domain_block.reject_reports?
|
||||||
|
- unless first_item
|
||||||
|
•
|
||||||
|
= t('admin.domain_blocks.rejecting_reports')
|
||||||
|
- elsif whitelist_mode?
|
||||||
|
= t('admin.accounts.whitelisted')
|
||||||
|
- else
|
||||||
|
= t('admin.accounts.no_limits_imposed')
|
||||||
|
.trends__item__current{ title: t('admin.instances.known_accounts', count: instance.accounts_count) }= number_to_human instance.accounts_count, strip_insignificant_zeros: true
|
@ -0,0 +1,11 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Scheduler::InstanceRefreshScheduler
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
sidekiq_options lock: :until_executed, retry: 0
|
||||||
|
|
||||||
|
def perform
|
||||||
|
Instance.refresh
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddForwardedToReports < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :reports, :forwarded, :boolean
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
class CreateInstances < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_view :instances, materialized: true
|
||||||
|
|
||||||
|
# To be able to refresh the view concurrently,
|
||||||
|
# at least one unique index is required
|
||||||
|
safety_assured { add_index :instances, :domain, unique: true }
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
WITH domain_counts(domain, accounts_count)
|
||||||
|
AS (
|
||||||
|
SELECT domain, COUNT(*) as accounts_count
|
||||||
|
FROM accounts
|
||||||
|
WHERE domain IS NOT NULL
|
||||||
|
GROUP BY domain
|
||||||
|
)
|
||||||
|
SELECT domain, accounts_count
|
||||||
|
FROM domain_counts
|
||||||
|
UNION
|
||||||
|
SELECT domain_blocks.domain, COALESCE(domain_counts.accounts_count, 0)
|
||||||
|
FROM domain_blocks
|
||||||
|
LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_blocks.domain
|
||||||
|
UNION
|
||||||
|
SELECT domain_allows.domain, COALESCE(domain_counts.accounts_count, 0)
|
||||||
|
FROM domain_allows
|
||||||
|
LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_allows.domain
|
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
Loading…
Reference in New Issue