闭社主体 forked from https://github.com/tootsuite/mastodon
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.

154 lines
6.3 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
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. require 'rails_helper'
  2. RSpec.describe FeedManager do
  3. describe '#key' do
  4. subject { FeedManager.instance.key(:home, 1) }
  5. it 'returns a string' do
  6. expect(subject).to be_a String
  7. end
  8. end
  9. describe '#filter?' do
  10. let(:alice) { Fabricate(:account, username: 'alice') }
  11. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  12. let(:jeff) { Fabricate(:account, username: 'jeff') }
  13. context 'for home feed' do
  14. it 'returns false for followee\'s status' do
  15. status = Fabricate(:status, text: 'Hello world', account: alice)
  16. bob.follow!(alice)
  17. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false
  18. end
  19. it 'returns false for reblog by followee' do
  20. status = Fabricate(:status, text: 'Hello world', account: jeff)
  21. reblog = Fabricate(:status, reblog: status, account: alice)
  22. bob.follow!(alice)
  23. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be false
  24. end
  25. it 'returns true for reblog by followee of blocked account' do
  26. status = Fabricate(:status, text: 'Hello world', account: jeff)
  27. reblog = Fabricate(:status, reblog: status, account: alice)
  28. bob.follow!(alice)
  29. bob.block!(jeff)
  30. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  31. end
  32. it 'returns true for reblog by followee of muted account' do
  33. status = Fabricate(:status, text: 'Hello world', account: jeff)
  34. reblog = Fabricate(:status, reblog: status, account: alice)
  35. bob.follow!(alice)
  36. bob.mute!(jeff)
  37. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  38. end
  39. it 'returns true for reblog by followee of someone who is blocking recipient' do
  40. status = Fabricate(:status, text: 'Hello world', account: jeff)
  41. reblog = Fabricate(:status, reblog: status, account: alice)
  42. bob.follow!(alice)
  43. jeff.block!(bob)
  44. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  45. end
  46. it 'returns false for reply by followee to another followee' do
  47. status = Fabricate(:status, text: 'Hello world', account: jeff)
  48. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  49. bob.follow!(alice)
  50. bob.follow!(jeff)
  51. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  52. end
  53. it 'returns false for reply by followee to recipient' do
  54. status = Fabricate(:status, text: 'Hello world', account: bob)
  55. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  56. bob.follow!(alice)
  57. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  58. end
  59. it 'returns false for reply by followee to self' do
  60. status = Fabricate(:status, text: 'Hello world', account: alice)
  61. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  62. bob.follow!(alice)
  63. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  64. end
  65. it 'returns true for reply by followee to non-followed account' do
  66. status = Fabricate(:status, text: 'Hello world', account: jeff)
  67. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  68. bob.follow!(alice)
  69. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be true
  70. end
  71. it 'returns true for the second reply by followee to a non-federated status' do
  72. reply = Fabricate(:status, text: 'Reply 1', reply: true, account: alice)
  73. second_reply = Fabricate(:status, text: 'Reply 2', thread: reply, account: alice)
  74. bob.follow!(alice)
  75. expect(FeedManager.instance.filter?(:home, second_reply, bob.id)).to be true
  76. end
  77. it 'returns false for status by followee mentioning another account' do
  78. bob.follow!(alice)
  79. status = PostStatusService.new.call(alice, 'Hey @jeff')
  80. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false
  81. end
  82. it 'returns true for status by followee mentioning blocked account' do
  83. bob.block!(jeff)
  84. bob.follow!(alice)
  85. status = PostStatusService.new.call(alice, 'Hey @jeff')
  86. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
  87. end
  88. it 'returns true for reblog of a personally blocked domain' do
  89. alice.block_domain!('example.com')
  90. alice.follow!(jeff)
  91. status = Fabricate(:status, text: 'Hello world', account: bob)
  92. reblog = Fabricate(:status, reblog: status, account: jeff)
  93. expect(FeedManager.instance.filter?(:home, reblog, alice.id)).to be true
  94. end
  95. end
  96. context 'for mentions feed' do
  97. it 'returns true for status that mentions blocked account' do
  98. bob.block!(jeff)
  99. status = PostStatusService.new.call(alice, 'Hey @jeff')
  100. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
  101. end
  102. it 'returns true for status that replies to a blocked account' do
  103. status = Fabricate(:status, text: 'Hello world', account: jeff)
  104. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  105. bob.block!(jeff)
  106. expect(FeedManager.instance.filter?(:mentions, reply, bob.id)).to be true
  107. end
  108. it 'returns true for status by silenced account who recipient is not following' do
  109. status = Fabricate(:status, text: 'Hello world', account: alice)
  110. alice.update(silenced: true)
  111. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
  112. end
  113. it 'returns false for status by followed silenced account' do
  114. status = Fabricate(:status, text: 'Hello world', account: alice)
  115. alice.update(silenced: true)
  116. bob.follow!(alice)
  117. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be false
  118. end
  119. end
  120. end
  121. describe '#push' do
  122. it 'trims timelines if they will have more than FeedManager::MAX_ITEMS' do
  123. account = Fabricate(:account)
  124. status = Fabricate(:status)
  125. members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] }
  126. Redis.current.zadd("feed:type:#{account.id}", members)
  127. FeedManager.instance.push('type', account, status)
  128. expect(Redis.current.zcard("feed:type:#{account.id}")).to eq FeedManager::MAX_ITEMS
  129. end
  130. end
  131. end