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.

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