Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/models/status.rb`: Upstream added lines close to a glitch-soc only line, not a real conflict. Applied upstream's changes (added hooks) while keeping glitch-soc's changes (`local_only` scope). - `config/environments/production.rb`: Upstream removed a header, while we have glitch-soc specific ones. Removed the header removed upstream.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
module Admin
|
||||
class DomainBlocksController < BaseController
|
||||
before_action :set_domain_block, only: [:show, :destroy, :edit, :update]
|
||||
before_action :set_domain_block, only: [:destroy, :edit, :update]
|
||||
|
||||
def batch
|
||||
authorize :domain_block, :create?
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
module Admin
|
||||
class EmailDomainBlocksController < BaseController
|
||||
before_action :set_email_domain_block, only: [:show, :destroy]
|
||||
|
||||
def index
|
||||
authorize :email_domain_block, :index?
|
||||
|
||||
@@ -59,10 +57,6 @@ module Admin
|
||||
|
||||
private
|
||||
|
||||
def set_email_domain_block
|
||||
@email_domain_block = EmailDomainBlock.find(params[:id])
|
||||
end
|
||||
|
||||
def set_resolved_records
|
||||
Resolv::DNS.open do |dns|
|
||||
dns.timeouts = 5
|
||||
|
@@ -187,7 +187,7 @@ module CacheConcern
|
||||
return [] if raw.empty?
|
||||
|
||||
cached_keys_with_value = begin
|
||||
Rails.cache.read_multi(*raw, namespace: 'v2').transform_keys(&:id).transform_values { |r| ActiveRecordCoder.load(r) }
|
||||
Rails.cache.read_multi(*raw).transform_keys(&:id).transform_values { |r| ActiveRecordCoder.load(r) }
|
||||
rescue ActiveRecordCoder::Error
|
||||
{} # The serialization format may have changed, let's pretend it's a cache miss.
|
||||
end
|
||||
@@ -200,7 +200,7 @@ module CacheConcern
|
||||
uncached = klass.where(id: uncached_ids).with_includes.index_by(&:id)
|
||||
|
||||
uncached.each_value do |item|
|
||||
Rails.cache.write(item, ActiveRecordCoder.dump(item), namespace: 'v2')
|
||||
Rails.cache.write(item, ActiveRecordCoder.dump(item))
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -8249,11 +8249,13 @@ noscript {
|
||||
img {
|
||||
margin-top: 2em;
|
||||
margin-bottom: 2em;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
video {
|
||||
margin-top: 2em;
|
||||
margin-bottom: 2em;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
figure {
|
||||
|
@@ -126,6 +126,8 @@ class Account < ApplicationRecord
|
||||
scope :not_excluded_by_account, ->(account) { where.not(id: account.excluded_from_timeline_account_ids) }
|
||||
scope :not_domain_blocked_by_account, ->(account) { where(arel_table[:domain].eq(nil).or(arel_table[:domain].not_in(account.excluded_from_timeline_domains))) }
|
||||
|
||||
after_update_commit :trigger_update_webhooks
|
||||
|
||||
delegate :email,
|
||||
:unconfirmed_email,
|
||||
:current_sign_in_at,
|
||||
@@ -591,4 +593,9 @@ class Account < ApplicationRecord
|
||||
|
||||
CanonicalEmailBlock.where(reference_account: self).delete_all
|
||||
end
|
||||
|
||||
# NOTE: the `account.created` webhook is triggered by the `User` model, not `Account`.
|
||||
def trigger_update_webhooks
|
||||
TriggerWebhookWorker.perform_async('account.updated', 'Account', id) if local?
|
||||
end
|
||||
end
|
||||
|
@@ -292,6 +292,21 @@ module AccountInteractions
|
||||
end
|
||||
end
|
||||
|
||||
def relations_map(account_ids, domains = nil, **options)
|
||||
relations = {
|
||||
blocked_by: Account.blocked_by_map(account_ids, id),
|
||||
following: Account.following_map(account_ids, id),
|
||||
}
|
||||
|
||||
return relations if options[:skip_blocking_and_muting]
|
||||
|
||||
relations.merge!({
|
||||
blocking: Account.blocking_map(account_ids, id),
|
||||
muting: Account.muting_map(account_ids, id),
|
||||
domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, id),
|
||||
})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_potential_friendship(other_account)
|
||||
|
@@ -79,7 +79,7 @@ module StatusThreadingConcern
|
||||
statuses = Status.with_accounts(ids).to_a
|
||||
account_ids = statuses.map(&:account_id).uniq
|
||||
domains = statuses.filter_map(&:account_domain).uniq
|
||||
relations = relations_map_for_account(account, account_ids, domains)
|
||||
relations = account&.relations_map(account_ids, domains) || {}
|
||||
|
||||
statuses.reject! { |status| StatusFilter.new(status, account, relations).filtered? }
|
||||
|
||||
@@ -108,16 +108,4 @@ module StatusThreadingConcern
|
||||
|
||||
arr
|
||||
end
|
||||
|
||||
def relations_map_for_account(account, account_ids, domains)
|
||||
return {} if account.nil?
|
||||
|
||||
{
|
||||
blocking: Account.blocking_map(account_ids, account.id),
|
||||
blocked_by: Account.blocked_by_map(account_ids, account.id),
|
||||
muting: Account.muting_map(account_ids, account.id),
|
||||
following: Account.following_map(account_ids, account.id),
|
||||
domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@@ -116,6 +116,9 @@ class Status < ApplicationRecord
|
||||
|
||||
scope :not_local_only, -> { where(local_only: [false, nil]) }
|
||||
|
||||
after_create_commit :trigger_create_webhooks
|
||||
after_update_commit :trigger_update_webhooks
|
||||
|
||||
cache_associated :application,
|
||||
:media_attachments,
|
||||
:conversation,
|
||||
@@ -142,6 +145,10 @@ class Status < ApplicationRecord
|
||||
|
||||
REAL_TIME_WINDOW = 6.hours
|
||||
|
||||
def cache_key
|
||||
"v2:#{super}"
|
||||
end
|
||||
|
||||
def searchable_by(preloaded = nil)
|
||||
ids = []
|
||||
|
||||
@@ -597,4 +604,12 @@ class Status < ApplicationRecord
|
||||
reblog&.decrement_count!(:reblogs_count) if reblog?
|
||||
thread&.decrement_count!(:replies_count) if in_reply_to_id.present? && distributable?
|
||||
end
|
||||
|
||||
def trigger_create_webhooks
|
||||
TriggerWebhookWorker.perform_async('status.created', 'Status', id) if local?
|
||||
end
|
||||
|
||||
def trigger_update_webhooks
|
||||
TriggerWebhookWorker.perform_async('status.updated', 'Status', id) if local?
|
||||
end
|
||||
end
|
||||
|
@@ -17,7 +17,10 @@ class Webhook < ApplicationRecord
|
||||
EVENTS = %w(
|
||||
account.approved
|
||||
account.created
|
||||
account.updated
|
||||
report.created
|
||||
status.created
|
||||
status.updated
|
||||
).freeze
|
||||
|
||||
scope :enabled, -> { where(enabled: true) }
|
||||
|
@@ -22,10 +22,6 @@ class InstancePresenter < ActiveModelSerializers::Model
|
||||
ContactPresenter.new
|
||||
end
|
||||
|
||||
def closed_registrations_message
|
||||
Setting.closed_registrations_message
|
||||
end
|
||||
|
||||
def description
|
||||
Setting.site_short_description
|
||||
end
|
||||
@@ -34,10 +30,6 @@ class InstancePresenter < ActiveModelSerializers::Model
|
||||
Setting.site_extended_description
|
||||
end
|
||||
|
||||
def privacy_policy
|
||||
Setting.site_terms
|
||||
end
|
||||
|
||||
def status_page_url
|
||||
Setting.status_page_url
|
||||
end
|
||||
|
@@ -120,7 +120,7 @@ class ImportService < BaseService
|
||||
end
|
||||
|
||||
account_ids = statuses.map(&:account_id)
|
||||
preloaded_relations = relations_map_for_account(@account, account_ids)
|
||||
preloaded_relations = @account.relations_map(account_ids, skip_blocking_and_muting: true)
|
||||
|
||||
statuses.keep_if { |status| StatusPolicy.new(@account, status, preloaded_relations).show? }
|
||||
|
||||
@@ -138,14 +138,4 @@ class ImportService < BaseService
|
||||
def import_data
|
||||
Paperclip.io_adapters.for(@import.data).read.force_encoding(Encoding::UTF_8)
|
||||
end
|
||||
|
||||
def relations_map_for_account(account, account_ids)
|
||||
{
|
||||
blocking: {},
|
||||
blocked_by: Account.blocked_by_map(account_ids, account.id),
|
||||
muting: {},
|
||||
following: Account.following_map(account_ids, account.id),
|
||||
domain_blocking_by_domain: {},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@@ -49,7 +49,7 @@ class SearchService < BaseService
|
||||
results = definition.limit(@limit).offset(@offset).objects.compact
|
||||
account_ids = results.map(&:account_id)
|
||||
account_domains = results.map(&:account_domain)
|
||||
preloaded_relations = relations_map_for_account(@account, account_ids, account_domains)
|
||||
preloaded_relations = @account.relations_map(account_ids, account_domains)
|
||||
|
||||
results.reject { |status| StatusFilter.new(status, @account, preloaded_relations).filtered? }
|
||||
rescue Faraday::ConnectionFailed, Parslet::ParseFailed
|
||||
@@ -111,16 +111,6 @@ class SearchService < BaseService
|
||||
@options[:type].blank? || @options[:type] == 'statuses'
|
||||
end
|
||||
|
||||
def relations_map_for_account(account, account_ids, domains)
|
||||
{
|
||||
blocking: Account.blocking_map(account_ids, account.id),
|
||||
blocked_by: Account.blocked_by_map(account_ids, account.id),
|
||||
muting: Account.muting_map(account_ids, account.id),
|
||||
following: Account.following_map(account_ids, account.id),
|
||||
domain_blocking_by_domain: Account.domain_blocking_map_by_domain(domains, account.id),
|
||||
}
|
||||
end
|
||||
|
||||
def parsed_query
|
||||
SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query))
|
||||
end
|
||||
|
@@ -19,7 +19,7 @@ class Webhooks::DeliveryWorker
|
||||
private
|
||||
|
||||
def perform_request
|
||||
request = Request.new(:post, @webhook.url, body: @body)
|
||||
request = Request.new(:post, @webhook.url, body: @body, allow_local: true)
|
||||
|
||||
request.add_headers(
|
||||
'Content-Type' => 'application/json',
|
||||
|
Reference in New Issue
Block a user