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. # silenced :boolean default(FALSE), not null
  32. # suspended :boolean default(FALSE), not null
  33. # locked :boolean default(FALSE), not null
  34. # header_remote_url :string default(""), not null
  35. # last_webfingered_at :datetime
  36. # inbox_url :string default(""), not null
  37. # outbox_url :string default(""), not null
  38. # shared_inbox_url :string default(""), not null
  39. # followers_url :string default(""), not null
  40. # protocol :integer default("ostatus"), not null
  41. # memorial :boolean default(FALSE), not null
  42. # moved_to_account_id :bigint(8)
  43. # featured_collection_url :string
  44. # fields :jsonb
  45. # actor_type :string
  46. # discoverable :boolean
  47. #
  48. class Account < ApplicationRecord
  49. USERNAME_RE = /[a-z0-9_]+([a-z0-9_\.-]+[a-z0-9_]+)?/i
  50. MENTION_RE = /(?<=^|[^\/[:word:]])@((#{USERNAME_RE})(?:@[a-z0-9\.\-]+[a-z0-9]+)?)/i
  51. MIN_FOLLOWERS_DISCOVERY = 10
  52. include AccountAssociations
  53. include AccountAvatar
  54. include AccountFinderConcern
  55. include AccountHeader
  56. include AccountInteractions
  57. include Attachmentable
  58. include Paginable
  59. include AccountCounters
  60. include DomainNormalizable
  61. MAX_DISPLAY_NAME_LENGTH = (ENV['MAX_DISPLAY_NAME_CHARS'] || 30).to_i
  62. MAX_NOTE_LENGTH = (ENV['MAX_BIO_CHARS'] || 500).to_i
  63. MAX_FIELDS = (ENV['MAX_PROFILE_FIELDS'] || 4).to_i
  64. enum protocol: [:ostatus, :activitypub]
  65. validates :username, presence: true
  66. # Remote user validations
  67. validates :username, uniqueness: { scope: :domain, case_sensitive: true }, if: -> { !local? && will_save_change_to_username? }
  68. validates :username, format: { with: /\A#{USERNAME_RE}\z/i }, if: -> { !local? && will_save_change_to_username? }
  69. # Local user validations
  70. validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? }
  71. validates_with UniqueUsernameValidator, if: -> { local? && will_save_change_to_username? }
  72. validates_with UnreservedUsernameValidator, if: -> { local? && will_save_change_to_username? }
  73. validates :display_name, length: { maximum: MAX_DISPLAY_NAME_LENGTH }, if: -> { local? && will_save_change_to_display_name? }
  74. validate :note_length_does_not_exceed_length_limit, if: -> { local? && will_save_change_to_note? }
  75. validates :fields, length: { maximum: MAX_FIELDS }, if: -> { local? && will_save_change_to_fields? }
  76. scope :remote, -> { where.not(domain: nil) }
  77. scope :local, -> { where(domain: nil) }
  78. scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
  79. scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
  80. scope :silenced, -> { where(silenced: true) }
  81. scope :suspended, -> { where(suspended: true) }
  82. scope :without_suspended, -> { where(suspended: false) }
  83. scope :without_silenced, -> { where(silenced: false) }
  84. scope :recent, -> { reorder(id: :desc) }
  85. scope :bots, -> { where(actor_type: %w(Application Service)) }
  86. scope :alphabetic, -> { order(domain: :asc, username: :asc) }
  87. scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
  88. scope :matches_username, ->(value) { where(arel_table[:username].matches("#{value}%")) }
  89. scope :matches_display_name, ->(value) { where(arel_table[:display_name].matches("#{value}%")) }
  90. scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
  91. scope :searchable, -> { without_suspended.where(moved_to_account_id: nil) }
  92. scope :discoverable, -> { searchable.without_silenced.where(discoverable: true).joins(:account_stat).where(AccountStat.arel_table[:followers_count].gteq(MIN_FOLLOWERS_DISCOVERY)).by_recent_status }
  93. scope :tagged_with, ->(tag) { joins(:accounts_tags).where(accounts_tags: { tag_id: tag }) }
  94. 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')) }
  95. scope :popular, -> { order('account_stats.followers_count desc') }
  96. delegate :email,
  97. :unconfirmed_email,
  98. :current_sign_in_ip,
  99. :current_sign_in_at,
  100. :confirmed?,
  101. :admin?,
  102. :moderator?,
  103. :staff?,
  104. :locale,
  105. :hides_network?,
  106. to: :user,
  107. prefix: true,
  108. allow_nil: true
  109. delegate :chosen_languages, to: :user, prefix: false, allow_nil: true
  110. def local?
  111. domain.nil?
  112. end
  113. def moved?
  114. moved_to_account_id.present?
  115. end
  116. def bot?
  117. %w(Application Service).include? actor_type
  118. end
  119. alias bot bot?
  120. def bot=(val)
  121. self.actor_type = ActiveModel::Type::Boolean.new.cast(val) ? 'Service' : 'Person'
  122. end
  123. def acct
  124. local? ? username : "#{username}@#{domain}"
  125. end
  126. def local_username_and_domain
  127. "#{username}@#{Rails.configuration.x.local_domain}"
  128. end
  129. def local_followers_count
  130. Follow.where(target_account_id: id).count
  131. end
  132. def to_webfinger_s
  133. "acct:#{local_username_and_domain}"
  134. end
  135. def subscribed?
  136. subscription_expires_at.present?
  137. end
  138. def possibly_stale?
  139. last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
  140. end
  141. def refresh!
  142. return if local?
  143. ResolveAccountService.new.call(acct)
  144. end
  145. def silence!
  146. update!(silenced: true)
  147. end
  148. def unsilence!
  149. update!(silenced: false)
  150. end
  151. def suspend!
  152. transaction do
  153. user&.disable! if local?
  154. update!(suspended: true)
  155. end
  156. end
  157. def unsuspend!
  158. transaction do
  159. user&.enable! if local?
  160. update!(suspended: false)
  161. end
  162. end
  163. def memorialize!
  164. transaction do
  165. user&.disable! if local?
  166. update!(memorial: true)
  167. end
  168. end
  169. def keypair
  170. @keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key)
  171. end
  172. def tags_as_strings=(tag_names)
  173. tag_names.map! { |name| name.mb_chars.downcase.to_s }
  174. tag_names.uniq!
  175. # Existing hashtags
  176. hashtags_map = Tag.where(name: tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag }
  177. # Initialize not yet existing hashtags
  178. tag_names.each do |name|
  179. next if hashtags_map.key?(name)
  180. hashtags_map[name] = Tag.new(name: name)
  181. end
  182. # Remove hashtags that are to be deleted
  183. tags.each do |tag|
  184. if hashtags_map.key?(tag.name)
  185. hashtags_map.delete(tag.name)
  186. else
  187. transaction do
  188. tags.delete(tag)
  189. tag.decrement_count!(:accounts_count)
  190. end
  191. end
  192. end
  193. # Add hashtags that were so far missing
  194. hashtags_map.each_value do |tag|
  195. transaction do
  196. tags << tag
  197. tag.increment_count!(:accounts_count)
  198. end
  199. end
  200. end
  201. def fields
  202. (self[:fields] || []).map { |f| Field.new(self, f) }
  203. end
  204. def fields_attributes=(attributes)
  205. fields = []
  206. old_fields = self[:fields] || []
  207. if attributes.is_a?(Hash)
  208. attributes.each_value do |attr|
  209. next if attr[:name].blank?
  210. previous = old_fields.find { |item| item['value'] == attr[:value] }
  211. if previous && previous['verified_at'].present?
  212. attr[:verified_at] = previous['verified_at']
  213. end
  214. fields << attr
  215. end
  216. end
  217. self[:fields] = fields
  218. end
  219. def build_fields
  220. return if fields.size >= MAX_FIELDS
  221. tmp = self[:fields] || []
  222. (MAX_FIELDS - tmp.size).times do
  223. tmp << { name: '', value: '' }
  224. end
  225. self.fields = tmp
  226. end
  227. def magic_key
  228. modulus, exponent = [keypair.public_key.n, keypair.public_key.e].map do |component|
  229. result = []
  230. until component.zero?
  231. result << [component % 256].pack('C')
  232. component >>= 8
  233. end
  234. result.reverse.join
  235. end
  236. (['RSA'] + [modulus, exponent].map { |n| Base64.urlsafe_encode64(n) }).join('.')
  237. end
  238. def subscription(webhook_url)
  239. @subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url)
  240. end
  241. def save_with_optional_media!
  242. save!
  243. rescue ActiveRecord::RecordInvalid
  244. self.avatar = nil
  245. self.header = nil
  246. self[:avatar_remote_url] = ''
  247. self[:header_remote_url] = ''
  248. save!
  249. end
  250. def object_type
  251. :person
  252. end
  253. def to_param
  254. username
  255. end
  256. def excluded_from_timeline_account_ids
  257. Rails.cache.fetch("exclude_account_ids_for:#{id}") { blocking.pluck(:target_account_id) + blocked_by.pluck(:account_id) + muting.pluck(:target_account_id) }
  258. end
  259. def excluded_from_timeline_domains
  260. Rails.cache.fetch("exclude_domains_for:#{id}") { domain_blocks.pluck(:domain) }
  261. end
  262. def preferred_inbox_url
  263. shared_inbox_url.presence || inbox_url
  264. end
  265. class Field < ActiveModelSerializers::Model
  266. attributes :name, :value, :verified_at, :account, :errors
  267. def initialize(account, attributes)
  268. @account = account
  269. @attributes = attributes
  270. @name = attributes['name'].strip[0, string_limit]
  271. @value = attributes['value'].strip[0, string_limit]
  272. @verified_at = attributes['verified_at']&.to_datetime
  273. @errors = {}
  274. end
  275. def verified?
  276. verified_at.present?
  277. end
  278. def value_for_verification
  279. @value_for_verification ||= begin
  280. if account.local?
  281. value
  282. else
  283. ActionController::Base.helpers.strip_tags(value)
  284. end
  285. end
  286. end
  287. def verifiable?
  288. value_for_verification.present? && value_for_verification.start_with?('http://', 'https://')
  289. end
  290. def mark_verified!
  291. @verified_at = Time.now.utc
  292. @attributes['verified_at'] = @verified_at
  293. end
  294. def to_h
  295. { name: @name, value: @value, verified_at: @verified_at }
  296. end
  297. private
  298. def string_limit
  299. if account.local?
  300. 255
  301. else
  302. 2047
  303. end
  304. end
  305. end
  306. class << self
  307. def readonly_attributes
  308. super - %w(statuses_count following_count followers_count)
  309. end
  310. def domains
  311. reorder(nil).pluck(Arel.sql('distinct accounts.domain'))
  312. end
  313. def inboxes
  314. urls = reorder(nil).where(protocol: :activitypub).pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)"))
  315. DeliveryFailureTracker.filter(urls)
  316. end
  317. def search_for(terms, limit = 10)
  318. textsearch, query = generate_query_for_search(terms)
  319. sql = <<-SQL.squish
  320. SELECT
  321. accounts.*,
  322. ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  323. FROM accounts
  324. WHERE #{query} @@ #{textsearch}
  325. AND accounts.suspended = false
  326. AND accounts.moved_to_account_id IS NULL
  327. ORDER BY rank DESC
  328. LIMIT ?
  329. SQL
  330. records = find_by_sql([sql, limit])
  331. ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
  332. records
  333. end
  334. def advanced_search_for(terms, account, limit = 10, following = false)
  335. textsearch, query = generate_query_for_search(terms)
  336. if following
  337. sql = <<-SQL.squish
  338. WITH first_degree AS (
  339. SELECT target_account_id
  340. FROM follows
  341. WHERE account_id = ?
  342. )
  343. SELECT
  344. accounts.*,
  345. (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  346. FROM accounts
  347. 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 = ?)
  348. WHERE accounts.id IN (SELECT * FROM first_degree)
  349. AND #{query} @@ #{textsearch}
  350. AND accounts.suspended = false
  351. AND accounts.moved_to_account_id IS NULL
  352. GROUP BY accounts.id
  353. ORDER BY rank DESC
  354. LIMIT ?
  355. SQL
  356. records = find_by_sql([sql, account.id, account.id, account.id, limit])
  357. else
  358. sql = <<-SQL.squish
  359. SELECT
  360. accounts.*,
  361. (count(f.id) + 1) * ts_rank_cd(#{textsearch}, #{query}, 32) AS rank
  362. FROM accounts
  363. 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 = ?)
  364. WHERE #{query} @@ #{textsearch}
  365. AND accounts.suspended = false
  366. AND accounts.moved_to_account_id IS NULL
  367. GROUP BY accounts.id
  368. ORDER BY rank DESC
  369. LIMIT ?
  370. SQL
  371. records = find_by_sql([sql, account.id, account.id, limit])
  372. end
  373. ActiveRecord::Associations::Preloader.new.preload(records, :account_stat)
  374. records
  375. end
  376. private
  377. def generate_query_for_search(terms)
  378. terms = Arel.sql(connection.quote(terms.gsub(/['?\\:]/, ' ')))
  379. textsearch = "(setweight(to_tsvector('simple', accounts.display_name), 'A') || setweight(to_tsvector('simple', accounts.username), 'B') || setweight(to_tsvector('simple', coalesce(accounts.domain, '')), 'C'))"
  380. query = "to_tsquery('simple', ''' ' || #{terms} || ' ''' || ':*')"
  381. [textsearch, query]
  382. end
  383. end
  384. def emojis
  385. @emojis ||= CustomEmoji.from_text(emojifiable_text, domain)
  386. end
  387. before_create :generate_keys
  388. before_validation :prepare_contents, if: :local?
  389. before_destroy :clean_feed_manager
  390. private
  391. def prepare_contents
  392. display_name&.strip!
  393. note&.strip!
  394. end
  395. def generate_keys
  396. return unless local? && !Rails.env.test?
  397. keypair = OpenSSL::PKey::RSA.new(2048)
  398. self.private_key = keypair.to_pem
  399. self.public_key = keypair.public_key.to_pem
  400. end
  401. YAML_START = "---\r\n"
  402. YAML_END = "\r\n...\r\n"
  403. def note_length_does_not_exceed_length_limit
  404. note_without_metadata = note
  405. if note.start_with? YAML_START
  406. idx = note.index YAML_END
  407. unless idx.nil?
  408. note_without_metadata = note[(idx + YAML_END.length) .. -1]
  409. end
  410. end
  411. if note_without_metadata.mb_chars.grapheme_length > MAX_NOTE_LENGTH
  412. errors.add(:note, "can't be longer than 500 graphemes")
  413. end
  414. end
  415. def normalize_domain
  416. return if local?
  417. super
  418. end
  419. def emojifiable_text
  420. [note, display_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