mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-19 05:13:01 +00:00
Define instance method outside #included (#3128)
This commit is contained in:
parent
6e4c7d6211
commit
198ae3e366
|
@ -20,13 +20,13 @@ module AccountAvatar
|
||||||
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-quality 80 -strip' }
|
has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-quality 80 -strip' }
|
||||||
validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
|
validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
|
||||||
validates_attachment_size :avatar, less_than: 2.megabytes
|
validates_attachment_size :avatar, less_than: 2.megabytes
|
||||||
|
end
|
||||||
|
|
||||||
def avatar_original_url
|
def avatar_original_url
|
||||||
avatar.url(:original)
|
avatar.url(:original)
|
||||||
end
|
end
|
||||||
|
|
||||||
def avatar_static_url
|
def avatar_static_url
|
||||||
avatar_content_type == 'image/gif' ? avatar.url(:static) : avatar_original_url
|
avatar_content_type == 'image/gif' ? avatar.url(:static) : avatar_original_url
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,13 +20,13 @@ module AccountHeader
|
||||||
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-quality 80 -strip' }
|
has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-quality 80 -strip' }
|
||||||
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
|
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
|
||||||
validates_attachment_size :header, less_than: 2.megabytes
|
validates_attachment_size :header, less_than: 2.megabytes
|
||||||
|
end
|
||||||
|
|
||||||
def header_original_url
|
def header_original_url
|
||||||
header.url(:original)
|
header.url(:original)
|
||||||
end
|
end
|
||||||
|
|
||||||
def header_static_url
|
def header_static_url
|
||||||
header_content_type == 'image/gif' ? header.url(:static) : header_original_url
|
header_content_type == 'image/gif' ? header.url(:static) : header_original_url
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,82 +46,82 @@ module AccountInteractions
|
||||||
has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
|
has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
|
||||||
has_many :conversation_mutes, dependent: :destroy
|
has_many :conversation_mutes, dependent: :destroy
|
||||||
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
|
has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
|
||||||
|
end
|
||||||
|
|
||||||
def follow!(other_account)
|
def follow!(other_account)
|
||||||
active_relationships.find_or_create_by!(target_account: other_account)
|
active_relationships.find_or_create_by!(target_account: other_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def block!(other_account)
|
def block!(other_account)
|
||||||
block_relationships.find_or_create_by!(target_account: other_account)
|
block_relationships.find_or_create_by!(target_account: other_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mute!(other_account)
|
def mute!(other_account)
|
||||||
mute_relationships.find_or_create_by!(target_account: other_account)
|
mute_relationships.find_or_create_by!(target_account: other_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mute_conversation!(conversation)
|
def mute_conversation!(conversation)
|
||||||
conversation_mutes.find_or_create_by!(conversation: conversation)
|
conversation_mutes.find_or_create_by!(conversation: conversation)
|
||||||
end
|
end
|
||||||
|
|
||||||
def block_domain!(other_domain)
|
def block_domain!(other_domain)
|
||||||
domain_blocks.find_or_create_by!(domain: other_domain)
|
domain_blocks.find_or_create_by!(domain: other_domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfollow!(other_account)
|
def unfollow!(other_account)
|
||||||
follow = active_relationships.find_by(target_account: other_account)
|
follow = active_relationships.find_by(target_account: other_account)
|
||||||
follow&.destroy
|
follow&.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def unblock!(other_account)
|
def unblock!(other_account)
|
||||||
block = block_relationships.find_by(target_account: other_account)
|
block = block_relationships.find_by(target_account: other_account)
|
||||||
block&.destroy
|
block&.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmute!(other_account)
|
def unmute!(other_account)
|
||||||
mute = mute_relationships.find_by(target_account: other_account)
|
mute = mute_relationships.find_by(target_account: other_account)
|
||||||
mute&.destroy
|
mute&.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmute_conversation!(conversation)
|
def unmute_conversation!(conversation)
|
||||||
mute = conversation_mutes.find_by(conversation: conversation)
|
mute = conversation_mutes.find_by(conversation: conversation)
|
||||||
mute&.destroy!
|
mute&.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
def unblock_domain!(other_domain)
|
def unblock_domain!(other_domain)
|
||||||
block = domain_blocks.find_by(domain: other_domain)
|
block = domain_blocks.find_by(domain: other_domain)
|
||||||
block&.destroy
|
block&.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def following?(other_account)
|
def following?(other_account)
|
||||||
active_relationships.where(target_account: other_account).exists?
|
active_relationships.where(target_account: other_account).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def blocking?(other_account)
|
def blocking?(other_account)
|
||||||
block_relationships.where(target_account: other_account).exists?
|
block_relationships.where(target_account: other_account).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_blocking?(other_domain)
|
def domain_blocking?(other_domain)
|
||||||
domain_blocks.where(domain: other_domain).exists?
|
domain_blocks.where(domain: other_domain).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def muting?(other_account)
|
def muting?(other_account)
|
||||||
mute_relationships.where(target_account: other_account).exists?
|
mute_relationships.where(target_account: other_account).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def muting_conversation?(conversation)
|
def muting_conversation?(conversation)
|
||||||
conversation_mutes.where(conversation: conversation).exists?
|
conversation_mutes.where(conversation: conversation).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def requested?(other_account)
|
def requested?(other_account)
|
||||||
follow_requests.where(target_account: other_account).exists?
|
follow_requests.where(target_account: other_account).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def favourited?(status)
|
def favourited?(status)
|
||||||
status.proper.favourites.where(account: self).exists?
|
status.proper.favourites.where(account: self).exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def reblogged?(status)
|
def reblogged?(status)
|
||||||
status.proper.reblogs.where(account: self).exists?
|
status.proper.reblogs.where(account: self).exists?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,36 +6,38 @@ module Streamable
|
||||||
included do
|
included do
|
||||||
has_one :stream_entry, as: :activity
|
has_one :stream_entry, as: :activity
|
||||||
|
|
||||||
def title
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def content
|
|
||||||
title
|
|
||||||
end
|
|
||||||
|
|
||||||
def target
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_type
|
|
||||||
:activity
|
|
||||||
end
|
|
||||||
|
|
||||||
def thread
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def hidden?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def needs_stream_entry?
|
|
||||||
account.local?
|
|
||||||
end
|
|
||||||
|
|
||||||
after_create do
|
after_create do
|
||||||
account.stream_entries.create!(activity: self, hidden: hidden?) if needs_stream_entry?
|
account.stream_entries.create!(activity: self, hidden: hidden?) if needs_stream_entry?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def title
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def content
|
||||||
|
title
|
||||||
|
end
|
||||||
|
|
||||||
|
def target
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def object_type
|
||||||
|
:activity
|
||||||
|
end
|
||||||
|
|
||||||
|
def thread
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def hidden?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def needs_stream_entry?
|
||||||
|
account.local?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Targetable
|
module Targetable
|
||||||
extend ActiveSupport::Concern
|
def object_type
|
||||||
|
:object
|
||||||
included do
|
|
||||||
def object_type
|
|
||||||
:object
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue