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.

127 lines
4.4 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
  1. # frozen_string_literal: true
  2. module AccountInteractions
  3. extend ActiveSupport::Concern
  4. class_methods do
  5. def following_map(target_account_ids, account_id)
  6. follow_mapping(Follow.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
  7. end
  8. def followed_by_map(target_account_ids, account_id)
  9. follow_mapping(Follow.where(account_id: target_account_ids, target_account_id: account_id), :account_id)
  10. end
  11. def blocking_map(target_account_ids, account_id)
  12. follow_mapping(Block.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
  13. end
  14. def muting_map(target_account_ids, account_id)
  15. follow_mapping(Mute.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
  16. end
  17. def requested_map(target_account_ids, account_id)
  18. follow_mapping(FollowRequest.where(target_account_id: target_account_ids, account_id: account_id), :target_account_id)
  19. end
  20. end
  21. included do
  22. # Follow relations
  23. has_many :follow_requests, dependent: :destroy
  24. has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy
  25. has_many :passive_relationships, class_name: 'Follow', foreign_key: 'target_account_id', dependent: :destroy
  26. has_many :following, -> { order('follows.id desc') }, through: :active_relationships, source: :target_account
  27. has_many :followers, -> { order('follows.id desc') }, through: :passive_relationships, source: :account
  28. # Block relationships
  29. has_many :block_relationships, class_name: 'Block', foreign_key: 'account_id', dependent: :destroy
  30. has_many :blocking, -> { order('blocks.id desc') }, through: :block_relationships, source: :target_account
  31. has_many :blocked_by_relationships, class_name: 'Block', foreign_key: :target_account_id, dependent: :destroy
  32. has_many :blocked_by, -> { order('blocks.id desc') }, through: :blocked_by_relationships, source: :account
  33. # Mute relationships
  34. has_many :mute_relationships, class_name: 'Mute', foreign_key: 'account_id', dependent: :destroy
  35. has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
  36. has_many :conversation_mutes, dependent: :destroy
  37. has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
  38. def follow!(other_account)
  39. active_relationships.find_or_create_by!(target_account: other_account)
  40. end
  41. def block!(other_account)
  42. block_relationships.find_or_create_by!(target_account: other_account)
  43. end
  44. def mute!(other_account)
  45. mute_relationships.find_or_create_by!(target_account: other_account)
  46. end
  47. def mute_conversation!(conversation)
  48. conversation_mutes.find_or_create_by!(conversation: conversation)
  49. end
  50. def block_domain!(other_domain)
  51. domain_blocks.find_or_create_by!(domain: other_domain)
  52. end
  53. def unfollow!(other_account)
  54. follow = active_relationships.find_by(target_account: other_account)
  55. follow&.destroy
  56. end
  57. def unblock!(other_account)
  58. block = block_relationships.find_by(target_account: other_account)
  59. block&.destroy
  60. end
  61. def unmute!(other_account)
  62. mute = mute_relationships.find_by(target_account: other_account)
  63. mute&.destroy
  64. end
  65. def unmute_conversation!(conversation)
  66. mute = conversation_mutes.find_by(conversation: conversation)
  67. mute&.destroy!
  68. end
  69. def unblock_domain!(other_domain)
  70. block = domain_blocks.find_by(domain: other_domain)
  71. block&.destroy
  72. end
  73. def following?(other_account)
  74. active_relationships.where(target_account: other_account).exists?
  75. end
  76. def blocking?(other_account)
  77. block_relationships.where(target_account: other_account).exists?
  78. end
  79. def domain_blocking?(other_domain)
  80. domain_blocks.where(domain: other_domain).exists?
  81. end
  82. def muting?(other_account)
  83. mute_relationships.where(target_account: other_account).exists?
  84. end
  85. def muting_conversation?(conversation)
  86. conversation_mutes.where(conversation: conversation).exists?
  87. end
  88. def requested?(other_account)
  89. follow_requests.where(target_account: other_account).exists?
  90. end
  91. def favourited?(status)
  92. status.proper.favourites.where(account: self).exists?
  93. end
  94. def reblogged?(status)
  95. status.proper.reblogs.where(account: self).exists?
  96. end
  97. end
  98. end