You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 lines
16 KiB

Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
Fix Account model deprecation warnings (#3689) ``` DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:61) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:62) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:63) ``` Here's PR describing changes to Dirty API https://github.com/rails/rails/pull/25337
7 years ago
Fix Account model deprecation warnings (#3689) ``` DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:60) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:61) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:62) DEPRECATION WARNING: The behavior of `attribute_changed?` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute?` instead. (called from block in <class:Account> at /Users/rene/Workspace/personal/ruby/mastodon/app/models/account.rb:63) ``` Here's PR describing changes to Dirty API https://github.com/rails/rails/pull/25337
7 years ago
8 years ago
8 years ago
Account domain blocks (#2381) * Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Conversation muting - prevents notifications that reference a conversation (including replies, favourites, reblogs) from being created. API endpoints /api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute Currently no way to tell when a status/conversation is muted, so the web UI only has a "disable notifications" button, doesn't work as a toggle * Display "Dismiss notifications" on all statuses in notifications column, not just own * Add "muted" as a boolean attribute on statuses JSON For now always false on contained reblogs, since it's only relevant for statuses returned from the notifications endpoint, which are not nested Remove "Disable notifications" from detailed status view, since it's only relevant in the notifications column * Up max class length * Remove pending test for conversation mute * Add tests, clean up * Rename to "mute conversation" and "unmute conversation" * Raise validation error when trying to mute/unmute status without conversation * Adding account domain blocks that filter notifications and public timelines * Add tests for domain blocks in notifications, public timelines Filter reblogs of blocked domains from home * Add API for listing and creating account domain blocks * API for creating/deleting domain blocks, tests for Status#ancestors and Status#descendants, filter domain blocks from them * Filter domains in streaming API * Update account_domain_block_spec.rb
7 years ago
8 years ago
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: accounts
  5. #
  6. # id :bigint(8) not null, primary key
  7. # username :string default(""), not null
  8. # domain :string
  9. # secret :string default(""), not null
  10. # private_key :text
  11. # public_key :text default(""), not null
  12. # remote_url :string default(""), not null
  13. # salmon_url :string default(""), not null
  14. # hub_url :string default(""), not null
  15. # created_at :datetime not null
  16. # updated_at :datetime not null
  17. # note :text default(""), not null
  18. # display_name :string default(""), not null
  19. # uri :string default(""), not null
  20. # url :string
  21. # avatar_file_name :string
  22. # avatar_content_type :string
  23. # avatar_file_size :integer
  24. # avatar_updated_at :datetime
  25. # header_file_name :string
  26. # header_content_type :string
  27. # header_file_size :integer
  28. # header_updated_at :datetime
  29. # avatar_remote_url :string
  30. # subscription_expires_at :datetime
  31. # locked :boolean default(FALSE), not null
  32. # header_remote_url :string default(""), not null
  33. # last_webfingered_at :datetime
  34. # inbox_url :string default(""), not null
  35. # outbox_url :string default(""), not null
  36. # shared_inbox_url :string default(""), not null
  37. # followers_url :string default(""), not null
  38. # protocol :integer default("ostatus"), not null
  39. # memorial :boolean default(FALSE), not null
  40. # moved_to_account_id :bigint(8)
  41. # featured_collection_url :string
  42. # fields :jsonb
  43. # actor_type :string
  44. # discoverable :boolean
  45. # also_known_as :string is an Array
  46. # silenced_at :datetime
  47. # suspended_at :datetime
  48. # trust_level :integer
  49. #
  50. class Account < ApplicationRecord
  51. USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
  52. MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
  53. MIN_FOLLOWERS_DISCOVERY = 10
  54. include AccountAssociations
  55. include AccountAvatar
  56. include AccountFinderConcern
  57. include AccountHeader
  58. include AccountInteractions
  59. include Attachmentable
  60. include Paginable
  61. include AccountCounters
  62. include DomainNormalizable
  63. TRUST_LEVELS = {
  64. untrusted: 0,
  65. trusted: 1,
  66. }.freeze
  67. enum protocol: [:ostatus, :activitypub]
  68. validates :username, presence: true
  69. # Remote user validations
  70. validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: -> { !local? && will_save_change_to_username? }
  71. validates :username, format: { with: /\A#{USERNAME_RE}\z/i }, if: -> { !local? && will_save_change_to_username? }
  72. # Local user validations
  73. validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' }
  74. validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? }
  75. validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
  76. validates :display_name, length: { maximum: 30 }, if: -> { local? && will_save_change_to_display_name? }
  77. validates :note, note_length: { maximum: 500 }, if: -> { local? && will_save_change_to_note? }
  78. validates :fields, length: { maximum: 4 }, if: -> { local? && will_save_change_to_fields? }
  79. scope :remote, -> { where.not(domain: nil) }
  80. scope :local, -> { where(domain: nil) }
  81. scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
  82. scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
  83. scope :silenced, -> { where.not(silenced_at: nil) }
  84. scope :suspended, -> { where.not(suspended_at: nil) }
  85. scope :without_suspended, -> { where(suspended_at: nil) }
  86. scope :without_silenced, -> { where(silenced_at: nil) }
  87. scope :recent, -> { reorder(id: :desc) }
  88. scope :bots, -> { where(actor_type: %w(Application Service)) }
  89. scope :alphabetic, -> { order(domain: :asc, username: :asc) }
  90. scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
  91. scope :matches_username, ->(value) { where(arel_table[:username].matches("#{value}%")) }
  92. scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) }
  93. scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
  94. scope :searchable, -> { without_suspended.where(moved_to_account_id: nil) }
  95. scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat).where(AccountStat.arel_table[:followers_count].gteq(MIN_FOLLOWERS_DISCOVERY)) }
  96. scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) }
  97. scope :by_recent_status, -> { order(Arel.sql('(case when account_stats.last_status_at is null then 1 else 0 end) asc, account_stats.last_status_at desc')) }
  98. scope :popular, -> { order('account_stats.followers_count desc') }
  99. scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
  100. delegate :email,
  101. :unconfirmed_email,
  102. :current_sign_in_ip,
  103. :current_sign_in_at,
  104. :confirmed?,
  105. :approved?,
  106. :pending?,
  107. :disabled?,
  108. :role,
  109. :admin?,
  110. :moderator?,
  111. :staff?,
  112. :locale,
  113. :hides_network?,
  114. :shows_application?,
  115. to: :user,
  116. prefix: true,
  117. allow_nil: true
  118. delegate :chosen_languages, to: :user, prefix: false, allow_nil: true
  119. def local?
  120. domain.nil?
  121. end
  122. def moved?
  123. moved_to_account_id.present?
  124. end
  125. def bot?
  126. %w(Application Service).include? actor_type
  127. end
  128. def instance_actor?
  129. id == -99
  130. end
  131. alias bot bot?
  132. def bot=(val)
  133. self.actor_type = ActiveModel::Type::Boolean.new.cast(val) ? 'Service' : 'Person'
  134. end
  135. def acct
  136. local? ? username : "#{username}@#{domain}"
  137. end
  138. def local_username_and_domain
  139. "#{username}@#{Rails.configuration.x.local_domain}"
  140. end
  141. def local_followers_count
  142. Follow.where(target_account_id: id).count
  143. end
  144. def to_webfinger_s
  145. "acct:#{local_username_and_domain}"
  146. end
  147. def subscribed?
  148. subscription_expires_at.present?
  149. end
  150. def possibly_stale?
  151. last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
  152. end
  153. def trust_level
  154. self[:trust_level] || 0
  155. end
  156. def refresh!
  157. ResolveAccountService.new.call(acct) unless local?
  158. end
  159. def silenced?
  160. silenced_at.present?
  161. end
  162. def silence!(date = Time.now.utc)
  163. update!(silenced_at: date)
  164. end
  165. def unsilence!
  166. update!(silenced_at: nil, trust_level: trust_level == TRUST_LEVELS[:untrusted] ? TRUST_LEVELS[:trusted] : trust_level)
  167. end
  168. def suspended?
  169. suspended_at.present?
  170. end
  171. def suspend!(date = Time.now.utc)
  172. transaction do
  173. user&.disable! if local?
  174. update!(suspended_at: date)
  175. end
  176. end
  177. def unsuspend!
  178. transaction do
  179. user&.enable! if local?
  180. update!(suspended_at: nil)
  181. end
  182. end
  183. def memorialize!
  184. transaction do
  185. user&.disable! if local?
  186. update!(memorial: true)
  187. end
  188. end
  189. def sign?
  190. true
  191. end
  192. def keypair
  193. @keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
  194. end
  195. def tags_as_strings=(tag_names)
  196. hashtags_map = Tag.find_or_create_by_names(tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag }
  197. # Remove hashtags that are to be deleted
  198. tags.each do |tag|
  199. if hashtags_map.key?(tag.name)
  200. hashtags_map.delete(tag.name)
  201. else
  202. transaction do
  203. tags.delete(tag)
  204. tag.decrement_count!(:accounts_count)
  205. end
  206. end
  207. end
  208. # Add hashtags that were so far missing
  209. hashtags_map.each_value do |tag|
  210. transaction do
  211. tags << tag
  212. tag.increment_count!(:accounts_count)
  213. end
  214. end
  215. end
  216. def also_known_as
  217. self[:also_known_as] || []
  218. end
  219. def fields
  220. (self[:fields] || []).map { |f| Field.new(self, f) }
  221. end
  222. def fields_attributes=(attributes)
  223. fields = []
  224. old_fields = self[:fields] || []
  225. old_fields = [] if old_fields.is_a?(Hash)
  226. if attributes.is_a?(Hash)
  227. attributes.each_value do |attr|
  228. next if attr[:name].blank?
  229. previous = old_fields.find { |item| item['value'] == attr[:value] }
  230. if previous && previous['verified_at'].present?
  231. attr[:verified_at] = previous['verified_at']
  232. end
  233. fields << attr
  234. end
  235. end
  236. self[:fields] = fields
  237. end
  238. DEFAULT_FIELDS_SIZE = 4
  239. def build_fields
  240. return if fields.size >= DEFAULT_FIELDS_SIZE
  241. tmp = self[:fields] || []
  242. tmp = [] if tmp.is_a?(Hash)
  243. (DEFAULT_FIELDS_SIZE - tmp.size).times do
  244. tmp << { name: '', value: '' }
  245. end
  246. self.fields = tmp
  247. end
  248. def subscription(webhook_url)
  249. @subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url)
  250. end
  251. def save_with_optional_media!
  252. save!
  253. rescue ActiveRecord::RecordInvalid
  254. self.avatar = nil
  255. self.header = nil
  256. self[:avatar_remote_url] = ''
  257. self[:header_remote_url] = ''
  258. save!
  259. end
  260. def object_type
  261. :person
  262. end
  263. def to_param
  264. username
  265. end
  266. def excluded_from_timeline_account_ids
  267. Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) }
  268. end
  269. def excluded_from_timeline_domains
  270. Rails.cache.fetch("exclude_domains_for:#{id}") { domain_blocks.pluck(:domain) }
  271. end
  272. def preferred_inbox_url
  273. shared_inbox_url.presence || inbox_url
  274. end
  275. class Field < ActiveModelSerializers::Model
  276. attributes :name, :value, :verified_at, :account, :errors
  277. def initialize(account, attributes)
  278. @account = account
  279. @attributes = attributes
  280. @name = attributes['name'].strip[0, string_limit]
  281. @value = attributes['value'].strip[0, string_limit]
  282. @verified_at = attributes['verified_at']&.to_datetime
  283. @errors = {}
  284. end
  285. def verified?
  286. verified_at.present?
  287. end
  288. def value_for_verification
  289. @value_for_verification ||= begin
  290. if account.local?
  291. value
  292. else
  293. ActionController::Base.helpers.strip_tags(value)
  294. end
  295. end
  296. end
  297. def verifiable?
  298. value_for_verification.present? && value_for_verification.start_with?('http://', 'https://')
  299. end
  300. def mark_verified!
  301. @verified_at = Time.now.utc
  302. @attributes['verified_at'] = @verified_at
  303. end
  304. def to_h
  305. { name: @name, value: @value, verified_at: @verified_at }
  306. end
  307. private
  308. def string_limit
  309. if account.local?
  310. 255
  311. else
  312. 2047
  313. end
  314. end
  315. end
  316. class << self
  317. def readonly_attributes
  318. super - %w(statuses_count following_count followers_count)
  319. end
  320. def domains
  321. reorder(nil).pluck(Arel.sql('distinct accounts.domain'))
  322. end
  323. def inboxes
  324. urls = reorder(nil).where(protocol: :activitypub).pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)"))
  325. DeliveryFailureTracker.filter(urls)
  326. end
  327. def search_for(terms, limit = 10, offset = 0)
  328. textsearch, query = generate_query_for_search(terms)
  329. sql = <<-SQL.squish
  330. SELECT
  331. accounts.*,
  332. ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  333. FROM accounts
  334. WHERE #{query} @@ #{textsearch}
  335. AND accounts.suspended_at IS NULL
  336. AND accounts.moved_to_account_id IS NULL
  337. ORDER BY rank DESC
  338. LIMIT ? OFFSET ?
  339. SQL
  340. records = find_by_sql([sql, limit, offset])
  341. ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
  342. records
  343. end
  344. def advanced_search_for(terms, account, limit = 10, following = false, offset = 0)
  345. textsearch, query = generate_query_for_search(terms)
  346. if following
  347. sql = <<-SQL.squish
  348. WITH first_degree AS (
  349. SELECT target_account_id
  350. FROM follows
  351. WHERE account_id = ?
  352. )
  353. SELECT
  354. accounts.*,
  355. (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  356. FROM accounts
  357. LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
  358. WHERE accounts.id IN (SELECT * FROM first_degree)
  359. AND #{query} @@ #{textsearch}
  360. AND accounts.suspended_at IS NULL
  361. AND accounts.moved_to_account_id IS NULL
  362. GROUP BY accounts.id
  363. ORDER BY rank DESC
  364. LIMIT ? OFFSET ?
  365. SQL
  366. records = find_by_sql([sql, account.id, account.id, account.id, limit, offset])
  367. else
  368. sql = <<-SQL.squish
  369. SELECT
  370. accounts.*,
  371. (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  372. FROM accounts
  373. LEFT OUTER JOIN follows AS f ON (accounts.id = f.account_id AND f.target_account_id = ?) OR (accounts.id = f.target_account_id AND f.account_id = ?)
  374. WHERE #{query} @@ #{textsearch}
  375. AND accounts.suspended_at IS NULL
  376. AND accounts.moved_to_account_id IS NULL
  377. GROUP BY accounts.id
  378. ORDER BY rank DESC
  379. LIMIT ? OFFSET ?
  380. SQL
  381. records = find_by_sql([sql, account.id, account.id, limit, offset])
  382. end
  383. ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
  384. records
  385. end
  386. private
  387. def generate_query_for_search(terms)
  388. terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' ')))
  389. textsearch = "(setweight(to_tsvector('simple', accounts.display_name), 'A') || setweight(to_tsvector('simple', accounts.username), 'B') || setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C'))"
  390. query = "to_tsquery('simple', ''' ' || #{terms} || ' ''' || ':*')"
  391. [textsearch, query]
  392. end
  393. end
  394. def emojis
  395. @emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
  396. end
  397. before_create :generate_keys
  398. before_validation :prepare_contents, if: :local?
  399. before_validation :prepare_username, on: :create
  400. before_destroy :clean_feed_manager
  401. private
  402. def prepare_contents
  403. display_name&.strip!
  404. note&.strip!
  405. end
  406. def prepare_username
  407. username&.squish!
  408. end
  409. def generate_keys
  410. return unless local? && private_key.blank? && public_key.blank?
  411. keypair = OpenSSL::PKey::RSA.new(2048)
  412. self.private_key = keypair.to_pem
  413. self.public_key = keypair.public_key.to_pem
  414. end
  415. def normalize_domain
  416. return if local?
  417. super
  418. end
  419. def emojifiable_text
  420. [note, display_name, fields.map(&:name), fields.map(&:value)].join(' ')
  421. end
  422. def clean_feed_manager
  423. reblog_key = FeedManager.instance.key(:home, id, 'reblogs')
  424. reblogged_id_set = Redis.current.zrange(reblog_key, 0, -1)
  425. Redis.current.pipelined do
  426. Redis.current.del(FeedManager.instance.key(:home, id))
  427. Redis.current.del(reblog_key)
  428. reblogged_id_set.each do |reblogged_id|
  429. reblog_set_key = FeedManager.instance.key(:home, id, "reblogs:#{reblogged_id}")
  430. Redis.current.del(reblog_set_key)
  431. end
  432. end
  433. end
  434. end