mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-25 03:32:41 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
71cec2d153
922 changed files with 9431 additions and 4194 deletions
|
|
@ -3,50 +3,52 @@
|
|||
#
|
||||
# Table name: accounts
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# username :string default(""), not null
|
||||
# domain :string
|
||||
# secret :string default(""), not null
|
||||
# private_key :text
|
||||
# public_key :text default(""), not null
|
||||
# remote_url :string default(""), not null
|
||||
# salmon_url :string default(""), not null
|
||||
# hub_url :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# note :text default(""), not null
|
||||
# display_name :string default(""), not null
|
||||
# uri :string default(""), not null
|
||||
# url :string
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# header_file_name :string
|
||||
# header_content_type :string
|
||||
# header_file_size :integer
|
||||
# header_updated_at :datetime
|
||||
# avatar_remote_url :string
|
||||
# subscription_expires_at :datetime
|
||||
# locked :boolean default(FALSE), not null
|
||||
# header_remote_url :string default(""), not null
|
||||
# last_webfingered_at :datetime
|
||||
# inbox_url :string default(""), not null
|
||||
# outbox_url :string default(""), not null
|
||||
# shared_inbox_url :string default(""), not null
|
||||
# followers_url :string default(""), not null
|
||||
# protocol :integer default("ostatus"), not null
|
||||
# memorial :boolean default(FALSE), not null
|
||||
# moved_to_account_id :bigint(8)
|
||||
# featured_collection_url :string
|
||||
# fields :jsonb
|
||||
# actor_type :string
|
||||
# discoverable :boolean
|
||||
# also_known_as :string is an Array
|
||||
# silenced_at :datetime
|
||||
# suspended_at :datetime
|
||||
# trust_level :integer
|
||||
# hide_collections :boolean
|
||||
# id :bigint(8) not null, primary key
|
||||
# username :string default(""), not null
|
||||
# domain :string
|
||||
# secret :string default(""), not null
|
||||
# private_key :text
|
||||
# public_key :text default(""), not null
|
||||
# remote_url :string default(""), not null
|
||||
# salmon_url :string default(""), not null
|
||||
# hub_url :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# note :text default(""), not null
|
||||
# display_name :string default(""), not null
|
||||
# uri :string default(""), not null
|
||||
# url :string
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# header_file_name :string
|
||||
# header_content_type :string
|
||||
# header_file_size :integer
|
||||
# header_updated_at :datetime
|
||||
# avatar_remote_url :string
|
||||
# subscription_expires_at :datetime
|
||||
# locked :boolean default(FALSE), not null
|
||||
# header_remote_url :string default(""), not null
|
||||
# last_webfingered_at :datetime
|
||||
# inbox_url :string default(""), not null
|
||||
# outbox_url :string default(""), not null
|
||||
# shared_inbox_url :string default(""), not null
|
||||
# followers_url :string default(""), not null
|
||||
# protocol :integer default("ostatus"), not null
|
||||
# memorial :boolean default(FALSE), not null
|
||||
# moved_to_account_id :bigint(8)
|
||||
# featured_collection_url :string
|
||||
# fields :jsonb
|
||||
# actor_type :string
|
||||
# discoverable :boolean
|
||||
# also_known_as :string is an Array
|
||||
# silenced_at :datetime
|
||||
# suspended_at :datetime
|
||||
# trust_level :integer
|
||||
# hide_collections :boolean
|
||||
# avatar_storage_schema_version :integer
|
||||
# header_storage_schema_version :integer
|
||||
#
|
||||
|
||||
class Account < ApplicationRecord
|
||||
|
|
@ -413,7 +415,7 @@ class Account < ApplicationRecord
|
|||
|
||||
def inboxes
|
||||
urls = reorder(nil).where(protocol: :activitypub).pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)"))
|
||||
DeliveryFailureTracker.filter(urls)
|
||||
DeliveryFailureTracker.without_unavailable(urls)
|
||||
end
|
||||
|
||||
def search_for(terms, limit = 10, offset = 0)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ class AccountAlias < ApplicationRecord
|
|||
belongs_to :account
|
||||
|
||||
validates :acct, presence: true, domain: { acct: true }
|
||||
validates :uri, presence: true
|
||||
validates :uri, uniqueness: { scope: :account_id }
|
||||
validate :validate_target_account
|
||||
|
||||
before_validation :set_uri
|
||||
after_create :add_to_account
|
||||
|
|
@ -44,4 +44,12 @@ class AccountAlias < ApplicationRecord
|
|||
def remove_from_account
|
||||
account.update(also_known_as: account.also_known_as.reject { |x| x == uri })
|
||||
end
|
||||
|
||||
def validate_target_account
|
||||
if uri.blank?
|
||||
errors.add(:acct, I18n.t('migrations.errors.not_found'))
|
||||
elsif ActivityPub::TagManager.instance.uri_for(account) == uri
|
||||
errors.add(:acct, I18n.t('migrations.errors.move_to_self'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# published_at :datetime
|
||||
# status_ids :bigint is an Array
|
||||
# status_ids :bigint(8) is an Array
|
||||
#
|
||||
|
||||
class Announcement < ApplicationRecord
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ module Omniauthable
|
|||
username = starting_username
|
||||
i = 0
|
||||
|
||||
while Account.exists?(username: username)
|
||||
while Account.exists?(username: username, domain: nil)
|
||||
i += 1
|
||||
username = "#{starting_username}_#{i}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,20 +3,21 @@
|
|||
#
|
||||
# Table name: custom_emojis
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# shortcode :string default(""), not null
|
||||
# domain :string
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# disabled :boolean default(FALSE), not null
|
||||
# uri :string
|
||||
# image_remote_url :string
|
||||
# visible_in_picker :boolean default(TRUE), not null
|
||||
# category_id :bigint(8)
|
||||
# id :bigint(8) not null, primary key
|
||||
# shortcode :string default(""), not null
|
||||
# domain :string
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# disabled :boolean default(FALSE), not null
|
||||
# uri :string
|
||||
# image_remote_url :string
|
||||
# visible_in_picker :boolean default(TRUE), not null
|
||||
# category_id :bigint(8)
|
||||
# image_storage_schema_version :integer
|
||||
#
|
||||
|
||||
class CustomEmoji < ApplicationRecord
|
||||
|
|
|
|||
|
|
@ -3,23 +3,24 @@
|
|||
#
|
||||
# Table name: media_attachments
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8)
|
||||
# file_file_name :string
|
||||
# file_content_type :string
|
||||
# file_file_size :integer
|
||||
# file_updated_at :datetime
|
||||
# remote_url :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# shortcode :string
|
||||
# type :integer default("image"), not null
|
||||
# file_meta :json
|
||||
# account_id :bigint(8)
|
||||
# description :text
|
||||
# scheduled_status_id :bigint(8)
|
||||
# blurhash :string
|
||||
# processing :integer
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8)
|
||||
# file_file_name :string
|
||||
# file_content_type :string
|
||||
# file_file_size :integer
|
||||
# file_updated_at :datetime
|
||||
# remote_url :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# shortcode :string
|
||||
# type :integer default("image"), not null
|
||||
# file_meta :json
|
||||
# account_id :bigint(8)
|
||||
# description :text
|
||||
# scheduled_status_id :bigint(8)
|
||||
# blurhash :string
|
||||
# processing :integer
|
||||
# file_storage_schema_version :integer
|
||||
#
|
||||
|
||||
class MediaAttachment < ApplicationRecord
|
||||
|
|
|
|||
|
|
@ -3,25 +3,26 @@
|
|||
#
|
||||
# Table name: preview_cards
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# url :string default(""), not null
|
||||
# title :string default(""), not null
|
||||
# description :string default(""), not null
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# type :integer default("link"), not null
|
||||
# html :text default(""), not null
|
||||
# author_name :string default(""), not null
|
||||
# author_url :string default(""), not null
|
||||
# provider_name :string default(""), not null
|
||||
# provider_url :string default(""), not null
|
||||
# width :integer default(0), not null
|
||||
# height :integer default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# embed_url :string default(""), not null
|
||||
# id :bigint(8) not null, primary key
|
||||
# url :string default(""), not null
|
||||
# title :string default(""), not null
|
||||
# description :string default(""), not null
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# type :integer default("link"), not null
|
||||
# html :text default(""), not null
|
||||
# author_name :string default(""), not null
|
||||
# author_url :string default(""), not null
|
||||
# provider_name :string default(""), not null
|
||||
# provider_url :string default(""), not null
|
||||
# width :integer default(0), not null
|
||||
# height :integer default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# embed_url :string default(""), not null
|
||||
# image_storage_schema_version :integer
|
||||
#
|
||||
|
||||
class PreviewCard < ApplicationRecord
|
||||
|
|
@ -47,6 +48,10 @@ class PreviewCard < ApplicationRecord
|
|||
|
||||
before_save :extract_dimensions, if: :link?
|
||||
|
||||
def local?
|
||||
false
|
||||
end
|
||||
|
||||
def missing_image?
|
||||
width.present? && height.present? && image_file_name.blank?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class RelationshipFilter
|
|||
scope = scope_for('relationship', params['relationship'].to_s.strip)
|
||||
|
||||
params.each do |key, value|
|
||||
next if key.to_s == 'page'
|
||||
next if %w(relationship page).include?(key)
|
||||
|
||||
scope.merge!(scope_for(key.to_s, value.to_s.strip)) if value.present?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class Relay < ApplicationRecord
|
|||
payload = Oj.dump(follow_activity(activity_id))
|
||||
|
||||
update!(state: :pending, follow_activity_id: activity_id)
|
||||
DeliveryFailureTracker.new(inbox_url).track_success!
|
||||
DeliveryFailureTracker.reset!(inbox_url)
|
||||
ActivityPub::DeliveryWorker.perform_async(payload, some_local_account.id, inbox_url)
|
||||
end
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class Relay < ApplicationRecord
|
|||
payload = Oj.dump(unfollow_activity(activity_id))
|
||||
|
||||
update!(state: :idle, follow_activity_id: nil)
|
||||
DeliveryFailureTracker.new(inbox_url).track_success!
|
||||
DeliveryFailureTracker.reset!(inbox_url)
|
||||
ActivityPub::DeliveryWorker.perform_async(payload, some_local_account.id, inbox_url)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
class RemoteFollow
|
||||
include ActiveModel::Validations
|
||||
include RoutingHelper
|
||||
include WebfingerHelper
|
||||
|
||||
attr_accessor :acct, :addressable_template
|
||||
|
||||
|
|
@ -71,7 +72,7 @@ class RemoteFollow
|
|||
end
|
||||
|
||||
def acct_resource
|
||||
@acct_resource ||= Goldfinger.finger("acct:#{acct}")
|
||||
@acct_resource ||= webfinger!("acct:#{acct}")
|
||||
rescue Goldfinger::Error, HTTP::ConnectionError
|
||||
nil
|
||||
end
|
||||
|
|
|
|||
|
|
@ -197,18 +197,6 @@ class Status < ApplicationRecord
|
|||
preview_cards.first
|
||||
end
|
||||
|
||||
def title
|
||||
if destroyed?
|
||||
"#{account.acct} deleted status"
|
||||
elsif reblog?
|
||||
preview = sensitive ? '<sensitive>' : text.slice(0, 10).split("\n")[0]
|
||||
"#{account.acct} shared #{reblog.account.acct}'s: #{preview}"
|
||||
else
|
||||
preview = sensitive ? '<sensitive>' : text.slice(0, 20).split("\n")[0]
|
||||
"#{account.acct}: #{preview}"
|
||||
end
|
||||
end
|
||||
|
||||
def hidden?
|
||||
!distributable?
|
||||
end
|
||||
|
|
@ -296,7 +284,7 @@ class Status < ApplicationRecord
|
|||
def as_public_timeline(account = nil, local_only = false)
|
||||
query = timeline_scope(local_only).without_replies
|
||||
|
||||
apply_timeline_filters(query, account, local_only)
|
||||
apply_timeline_filters(query, account, [:local, true].include?(local_only))
|
||||
end
|
||||
|
||||
def as_tag_timeline(tag, account = nil, local_only = false)
|
||||
|
|
@ -354,7 +342,7 @@ class Status < ApplicationRecord
|
|||
|
||||
if account.nil?
|
||||
where(visibility: visibility)
|
||||
elsif target_account.blocking?(account) # get rid of blocked peeps
|
||||
elsif target_account.blocking?(account) || (account.domain.present? && target_account.domain_blocking?(account.domain)) # get rid of blocked peeps
|
||||
none
|
||||
elsif account.id == target_account.id # author can see own stuff
|
||||
all
|
||||
|
|
@ -388,8 +376,16 @@ class Status < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def timeline_scope(local_only = false)
|
||||
starting_scope = local_only ? Status.local : Status
|
||||
def timeline_scope(scope = false)
|
||||
starting_scope = case scope
|
||||
when :local, true
|
||||
Status.local
|
||||
when :remote
|
||||
Status.remote
|
||||
else
|
||||
Status
|
||||
end
|
||||
|
||||
starting_scope
|
||||
.with_public_visibility
|
||||
.without_reblogs
|
||||
|
|
|
|||
22
app/models/unavailable_domain.rb
Normal file
22
app/models/unavailable_domain.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: unavailable_domains
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# domain :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class UnavailableDomain < ApplicationRecord
|
||||
include DomainNormalizable
|
||||
|
||||
after_commit :reset_cache!
|
||||
|
||||
private
|
||||
|
||||
def reset_cache!
|
||||
Rails.cache.delete('unavailable_domains')
|
||||
end
|
||||
end
|
||||
|
|
@ -98,6 +98,7 @@ class User < ApplicationRecord
|
|||
|
||||
before_validation :sanitize_languages
|
||||
before_create :set_approved
|
||||
after_commit :send_pending_devise_notifications
|
||||
|
||||
# This avoids a deprecation warning from Rails 5.1
|
||||
# It seems possible that a future release of devise-two-factor will
|
||||
|
|
@ -306,11 +307,38 @@ class User < ApplicationRecord
|
|||
protected
|
||||
|
||||
def send_devise_notification(notification, *args)
|
||||
devise_mailer.send(notification, self, *args).deliver_later
|
||||
# This method can be called in `after_update` and `after_commit` hooks,
|
||||
# but we must make sure the mailer is actually called *after* commit,
|
||||
# otherwise it may work on stale data. To do this, figure out if we are
|
||||
# within a transaction.
|
||||
if ActiveRecord::Base.connection.current_transaction.try(:records)&.include?(self)
|
||||
pending_devise_notifications << [notification, args]
|
||||
else
|
||||
render_and_send_devise_message(notification, *args)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send_pending_devise_notifications
|
||||
pending_devise_notifications.each do |notification, args|
|
||||
render_and_send_devise_message(notification, *args)
|
||||
end
|
||||
|
||||
# Empty the pending notifications array because the
|
||||
# after_commit hook can be called multiple times which
|
||||
# could cause multiple emails to be sent.
|
||||
pending_devise_notifications.clear
|
||||
end
|
||||
|
||||
def pending_devise_notifications
|
||||
@pending_devise_notifications ||= []
|
||||
end
|
||||
|
||||
def render_and_send_devise_message(notification, *args)
|
||||
devise_mailer.send(notification, self, *args).deliver_later
|
||||
end
|
||||
|
||||
def set_approved
|
||||
self.approved = open_registrations? || valid_invitation? || external?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -94,11 +94,11 @@ class Web::PushSubscription < ApplicationRecord
|
|||
|
||||
def find_or_create_access_token
|
||||
Doorkeeper::AccessToken.find_or_create_for(
|
||||
Doorkeeper::Application.find_by(superapp: true),
|
||||
session_activation.user_id,
|
||||
Doorkeeper::OAuth::Scopes.from_string('read write follow push'),
|
||||
Doorkeeper.configuration.access_token_expires_in,
|
||||
Doorkeeper.configuration.refresh_token_enabled?
|
||||
application: Doorkeeper::Application.find_by(superapp: true),
|
||||
resource_owner: session_activation.user_id,
|
||||
scopes: Doorkeeper::OAuth::Scopes.from_string('read write follow push'),
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue