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.

187 lines
5.4 KiB

Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
6 years ago
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::AccountsController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow read') }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'GET #show' do
  10. it 'returns http success' do
  11. get :show, params: { id: user.account.id }
  12. expect(response).to have_http_status(200)
  13. end
  14. end
  15. describe 'POST #follow' do
  16. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', locked: locked)).account }
  17. before do
  18. post :follow, params: { id: other_account.id }
  19. end
  20. context 'with unlocked account' do
  21. let(:locked) { false }
  22. it 'returns http success' do
  23. expect(response).to have_http_status(200)
  24. end
  25. it 'returns JSON with following=true and requested=false' do
  26. json = body_as_json
  27. expect(json[:following]).to be true
  28. expect(json[:requested]).to be false
  29. end
  30. it 'creates a following relation between user and target user' do
  31. expect(user.account.following?(other_account)).to be true
  32. end
  33. end
  34. context 'with locked account' do
  35. let(:locked) { true }
  36. it 'returns http success' do
  37. expect(response).to have_http_status(200)
  38. end
  39. it 'returns JSON with following=false and requested=true' do
  40. json = body_as_json
  41. expect(json[:following]).to be false
  42. expect(json[:requested]).to be true
  43. end
  44. it 'creates a follow request relation between user and target user' do
  45. expect(user.account.requested?(other_account)).to be true
  46. end
  47. end
  48. end
  49. describe 'POST #unfollow' do
  50. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  51. before do
  52. user.account.follow!(other_account)
  53. post :unfollow, params: { id: other_account.id }
  54. end
  55. it 'returns http success' do
  56. expect(response).to have_http_status(200)
  57. end
  58. it 'removes the following relation between user and target user' do
  59. expect(user.account.following?(other_account)).to be false
  60. end
  61. end
  62. describe 'POST #block' do
  63. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  64. before do
  65. user.account.follow!(other_account)
  66. post :block, params: { id: other_account.id }
  67. end
  68. it 'returns http success' do
  69. expect(response).to have_http_status(200)
  70. end
  71. it 'removes the following relation between user and target user' do
  72. expect(user.account.following?(other_account)).to be false
  73. end
  74. it 'creates a blocking relation' do
  75. expect(user.account.blocking?(other_account)).to be true
  76. end
  77. end
  78. describe 'POST #unblock' do
  79. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  80. before do
  81. user.account.block!(other_account)
  82. post :unblock, params: { id: other_account.id }
  83. end
  84. it 'returns http success' do
  85. expect(response).to have_http_status(200)
  86. end
  87. it 'removes the blocking relation between user and target user' do
  88. expect(user.account.blocking?(other_account)).to be false
  89. end
  90. end
  91. describe 'POST #mute' do
  92. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  93. before do
  94. user.account.follow!(other_account)
  95. post :mute, params: {id: other_account.id }
  96. end
  97. it 'returns http success' do
  98. expect(response).to have_http_status(200)
  99. end
  100. it 'does not remove the following relation between user and target user' do
  101. expect(user.account.following?(other_account)).to be true
  102. end
  103. it 'creates a muting relation' do
  104. expect(user.account.muting?(other_account)).to be true
  105. end
  106. it 'mutes notifications' do
  107. expect(user.account.muting_notifications?(other_account)).to be true
  108. end
  109. end
  110. describe 'POST #mute with notifications set to false' do
  111. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  112. before do
  113. user.account.follow!(other_account)
  114. post :mute, params: {id: other_account.id, notifications: false }
  115. end
  116. it 'returns http success' do
  117. expect(response).to have_http_status(200)
  118. end
  119. it 'does not remove the following relation between user and target user' do
  120. expect(user.account.following?(other_account)).to be true
  121. end
  122. it 'creates a muting relation' do
  123. expect(user.account.muting?(other_account)).to be true
  124. end
  125. it 'does not mute notifications' do
  126. expect(user.account.muting_notifications?(other_account)).to be false
  127. end
  128. end
  129. describe 'POST #unmute' do
  130. let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  131. before do
  132. user.account.mute!(other_account)
  133. post :unmute, params: { id: other_account.id }
  134. end
  135. it 'returns http success' do
  136. expect(response).to have_http_status(200)
  137. end
  138. it 'removes the muting relation between user and target user' do
  139. expect(user.account.muting?(other_account)).to be false
  140. end
  141. end
  142. end