diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-12-02 14:14:49 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-12-02 14:14:49 +0100 |
commit | 58b3f4fd674d29c444b236ad3936dbd04c6e175e (patch) | |
tree | c5d32fb2f38256cc116338def4d2e408e6d20624 /app/models | |
parent | 2b2797d6a5902af63c3362b5abca03578f567761 (diff) |
Fix #329 - avatar errors no longer prevent remote accounts from being saved
(without avatar). Also improved search position of exact matches
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 19 | ||||
-rw-r--r-- | app/models/status.rb | 3 |
2 files changed, 14 insertions, 8 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index 0f3d0dda2..105b77e04 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -50,15 +50,14 @@ class Account < ApplicationRecord # PuSH subscriptions has_many :subscriptions, dependent: :destroy - pg_search_scope :search_for, against: { username: 'A', domain: 'B' }, using: { tsearch: { prefix: true } } + pg_search_scope :search_for, against: { username: 'A', domain: 'B' }, + using: { tsearch: { prefix: true } } scope :remote, -> { where.not(domain: nil) } scope :local, -> { where(domain: nil) } scope :without_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0') } scope :with_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) > 0') } - scope :expiring, -> (time) { where(subscription_expires_at: nil).or(where('subscription_expires_at < ?', time)).remote.with_followers } - - scope :with_counters, -> { select('accounts.*, (select count(f.id) from follows as f where f.target_account_id = accounts.id) as followers_count, (select count(f.id) from follows as f where f.account_id = accounts.id) as following_count, (select count(s.id) from statuses as s where s.account_id = accounts.id) as statuses_count') } + scope :expiring, ->(time) { where(subscription_expires_at: nil).or(where('subscription_expires_at < ?', time)).remote.with_followers } def follow!(other_account) active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) @@ -114,9 +113,15 @@ class Account < ApplicationRecord OStatus2::Subscription.new(remote_url, secret: secret, lease_seconds: 86_400 * 30, webhook: webhook_url, hub: hub_url) end - def ping!(atom_url, hubs) - return unless local? && !Rails.env.development? - OStatus2::Publication.new(atom_url, hubs).publish + def save_with_optional_avatar! + save! + rescue ActiveRecord::RecordInvalid => invalid + if invalid.record.errors[:avatar_file_size] || invalid[:avatar_content_type] + self.avatar = nil + retry + end + + raise invalid end def avatar_remote_url=(url) diff --git a/app/models/status.rb b/app/models/status.rb index 87d8249b1..1a37ea86f 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -29,7 +29,8 @@ class Status < ApplicationRecord default_scope { order('id desc') } - scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') } + scope :remote, -> { where.not(uri: nil) } + scope :local, -> { where(uri: nil) } cache_associated :account, :media_attachments, :tags, :stream_entry, mentions: :account, reblog: [:account, :stream_entry, :tags, :media_attachments, mentions: :account], thread: :account |