]> cat aescling's git repositories - mastodon.git/commitdiff
Feature conversations muting (#3017)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 15 May 2017 01:04:13 +0000 (03:04 +0200)
committerGitHub <noreply@github.com>
Mon, 15 May 2017 01:04:13 +0000 (03:04 +0200)
* 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

52 files changed:
app/controllers/api/v1/statuses_controller.rb
app/controllers/api_controller.rb
app/javascript/mastodon/actions/statuses.js
app/javascript/mastodon/components/status_action_bar.js
app/javascript/mastodon/containers/status_container.js
app/javascript/mastodon/features/notifications/components/notification.js
app/javascript/mastodon/features/status/components/action_bar.js
app/javascript/mastodon/features/status/index.js
app/javascript/mastodon/locales/ar.json
app/javascript/mastodon/locales/bg.json
app/javascript/mastodon/locales/de.json
app/javascript/mastodon/locales/defaultMessages.json
app/javascript/mastodon/locales/en.json
app/javascript/mastodon/locales/eo.json
app/javascript/mastodon/locales/es.json
app/javascript/mastodon/locales/fa.json
app/javascript/mastodon/locales/fi.json
app/javascript/mastodon/locales/fr.json
app/javascript/mastodon/locales/he.json
app/javascript/mastodon/locales/hr.json
app/javascript/mastodon/locales/hu.json
app/javascript/mastodon/locales/id.json
app/javascript/mastodon/locales/io.json
app/javascript/mastodon/locales/it.json
app/javascript/mastodon/locales/ja.json
app/javascript/mastodon/locales/nl.json
app/javascript/mastodon/locales/no.json
app/javascript/mastodon/locales/oc.json
app/javascript/mastodon/locales/pl.json
app/javascript/mastodon/locales/pt-BR.json
app/javascript/mastodon/locales/pt.json
app/javascript/mastodon/locales/ru.json
app/javascript/mastodon/locales/tr.json
app/javascript/mastodon/locales/uk.json
app/javascript/mastodon/locales/zh-CN.json
app/javascript/mastodon/locales/zh-HK.json
app/javascript/mastodon/reducers/statuses.js
app/models/account.rb
app/models/conversation.rb
app/models/conversation_mute.rb [new file with mode: 0644]
app/models/status.rb
app/services/notify_service.rb
app/views/api/v1/statuses/show.rabl
config/routes.rb
db/migrate/20170301222600_create_mutes.rb
db/migrate/20170508230434_create_conversation_mutes.rb [new file with mode: 0644]
db/schema.rb
spec/controllers/api/v1/statuses_controller_spec.rb
spec/fabricators/conversation_mute_fabricator.rb [new file with mode: 0644]
spec/models/conversation_mute_spec.rb [new file with mode: 0644]
spec/models/status_spec.rb
spec/services/notify_service_spec.rb

index 77bdaa49436d4c9e4fdebf414f8733f315f6b7c2..9312282ed6a315441b6003939ece70c945721f9a 100644 (file)
@@ -1,10 +1,11 @@
 # frozen_string_literal: true
 
 class Api::V1::StatusesController < ApiController
-  before_action :authorize_if_got_token, except:            [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
-  before_action -> { doorkeeper_authorize! :write }, only:  [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
-  before_action :require_user!, except: [:show, :context, :card, :reblogged_by, :favourited_by]
-  before_action :set_status, only:      [:show, :context, :card, :reblogged_by, :favourited_by]
+  before_action :authorize_if_got_token, except:            [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite, :mute, :unmute]
+  before_action -> { doorkeeper_authorize! :write }, only:  [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite, :mute, :unmute]
+  before_action :require_user!, except:  [:show, :context, :card, :reblogged_by, :favourited_by]
+  before_action :set_status, only:       [:show, :context, :card, :reblogged_by, :favourited_by, :mute, :unmute]
+  before_action :set_conversation, only: [:mute, :unmute]
 
   respond_to :json
 
@@ -105,6 +106,22 @@ class Api::V1::StatusesController < ApiController
     render :show
   end
 
+  def mute
+    current_account.mute_conversation!(@conversation)
+
+    @mutes_map = { @conversation.id => true }
+
+    render :show
+  end
+
+  def unmute
+    current_account.unmute_conversation!(@conversation)
+
+    @mutes_map = { @conversation.id => false }
+
+    render :show
+  end
+
   private
 
   def set_status
@@ -112,6 +129,11 @@ class Api::V1::StatusesController < ApiController
     raise ActiveRecord::RecordNotFound unless @status.permitted?(current_account)
   end
 
+  def set_conversation
+    @conversation = @status.conversation
+    raise Mastodon::ValidationError if @conversation.nil?
+  end
+
   def status_params
     params.permit(:status, :in_reply_to_id, :sensitive, :spoiler_text, :visibility, media_ids: [])
   end
index 957e3c3152348bd207327769859bb89300752a0f..1c67b6fdc61d71663c4d302eb91c09391b45119f 100644 (file)
@@ -93,11 +93,14 @@ class ApiController < ApplicationController
     if current_account.nil?
       @reblogs_map    = {}
       @favourites_map = {}
+      @mutes_map      = {}
       return
     end
 
-    status_ids      = statuses.compact.flat_map { |s| [s.id, s.reblog_of_id] }.uniq
-    @reblogs_map    = Status.reblogs_map(status_ids, current_account)
-    @favourites_map = Status.favourites_map(status_ids, current_account)
+    status_ids       = statuses.compact.flat_map { |s| [s.id, s.reblog_of_id] }.uniq
+    conversation_ids = statuses.compact.map(&:conversation_id).compact.uniq
+    @reblogs_map     = Status.reblogs_map(status_ids, current_account)
+    @favourites_map  = Status.favourites_map(status_ids, current_account)
+    @mutes_map       = Status.mutes_map(conversation_ids, current_account)
   end
 end
index 19df2c36ccbaec1ec20406af0a2aedfee0dfb53b..5eb9bf8171ba3307dbea3a2e3818d3563e244cd9 100644 (file)
@@ -15,6 +15,14 @@ export const CONTEXT_FETCH_REQUEST = 'CONTEXT_FETCH_REQUEST';
 export const CONTEXT_FETCH_SUCCESS = 'CONTEXT_FETCH_SUCCESS';
 export const CONTEXT_FETCH_FAIL    = 'CONTEXT_FETCH_FAIL';
 
+export const STATUS_MUTE_REQUEST = 'STATUS_MUTE_REQUEST';
+export const STATUS_MUTE_SUCCESS = 'STATUS_MUTE_SUCCESS';
+export const STATUS_MUTE_FAIL    = 'STATUS_MUTE_FAIL';
+
+export const STATUS_UNMUTE_REQUEST = 'STATUS_UNMUTE_REQUEST';
+export const STATUS_UNMUTE_SUCCESS = 'STATUS_UNMUTE_SUCCESS';
+export const STATUS_UNMUTE_FAIL    = 'STATUS_UNMUTE_FAIL';
+
 export function fetchStatusRequest(id, skipLoading) {
   return {
     type: STATUS_FETCH_REQUEST,
@@ -139,3 +147,71 @@ export function fetchContextFail(id, error) {
     skipAlert: true
   };
 };
+
+export function muteStatus(id) {
+  return (dispatch, getState) => {
+    dispatch(muteStatusRequest(id));
+
+    api(getState).post(`/api/v1/statuses/${id}/mute`).then(response => {
+      dispatch(muteStatusSuccess(id));
+    }).catch(error => {
+      dispatch(muteStatusFail(id, error));
+    });
+  };
+};
+
+export function muteStatusRequest(id) {
+  return {
+    type: STATUS_MUTE_REQUEST,
+    id
+  };
+};
+
+export function muteStatusSuccess(id) {
+  return {
+    type: STATUS_MUTE_SUCCESS,
+    id
+  };
+};
+
+export function muteStatusFail(id, error) {
+  return {
+    type: STATUS_MUTE_FAIL,
+    id,
+    error
+  };
+};
+
+export function unmuteStatus(id) {
+  return (dispatch, getState) => {
+    dispatch(unmuteStatusRequest(id));
+
+    api(getState).post(`/api/v1/statuses/${id}/unmute`).then(response => {
+      dispatch(unmuteStatusSuccess(id));
+    }).catch(error => {
+      dispatch(unmuteStatusFail(id, error));
+    });
+  };
+};
+
+export function unmuteStatusRequest(id) {
+  return {
+    type: STATUS_UNMUTE_REQUEST,
+    id
+  };
+};
+
+export function unmuteStatusSuccess(id) {
+  return {
+    type: STATUS_UNMUTE_SUCCESS,
+    id
+  };
+};
+
+export function unmuteStatusFail(id, error) {
+  return {
+    type: STATUS_UNMUTE_FAIL,
+    id,
+    error
+  };
+};
index b3d5e442cf9a01715a4c55f1d34a26155c63f57b..4d077fb9876d0f065496df8d739c075359742d56 100644 (file)
@@ -16,7 +16,9 @@ const messages = defineMessages({
   cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
   favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
   open: { id: 'status.open', defaultMessage: 'Expand this status' },
-  report: { id: 'status.report', defaultMessage: 'Report @{name}' }
+  report: { id: 'status.report', defaultMessage: 'Report @{name}' },
+  muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
+  unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
 });
 
 class StatusActionBar extends React.PureComponent {
@@ -35,7 +37,9 @@ class StatusActionBar extends React.PureComponent {
     onMute: PropTypes.func,
     onBlock: PropTypes.func,
     onReport: PropTypes.func,
+    onMuteConversation: PropTypes.func,
     me: PropTypes.number.isRequired,
+    withDismiss: PropTypes.bool,
     intl: PropTypes.object.isRequired
   };
 
@@ -76,9 +80,14 @@ class StatusActionBar extends React.PureComponent {
     this.context.router.push('/report');
   }
 
+  handleConversationMuteClick = () => {
+    this.props.onMuteConversation(this.props.status);
+  }
+
   render () {
-    const { status, me, intl } = this.props;
+    const { status, me, intl, withDismiss } = this.props;
     const reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
+    const mutingConversation = status.get('muted');
 
     let menu = [];
     let reblogIcon = 'retweet';
@@ -88,6 +97,11 @@ class StatusActionBar extends React.PureComponent {
     menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
     menu.push(null);
 
+    if (withDismiss) {
+      menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
+      menu.push(null);
+    }
+
     if (status.getIn(['account', 'id']) === me) {
       menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
     } else {
index eb1f1ab79187d1c5a2f41ca46845f0f37847e548..8b7d6dc53d012a783486abb269274cb8f0e622f1 100644 (file)
@@ -16,7 +16,7 @@ import {
   blockAccount,
   muteAccount
 } from '../actions/accounts';
-import { deleteStatus } from '../actions/statuses';
+import { muteStatus, unmuteStatus, deleteStatus } from '../actions/statuses';
 import { initReport } from '../actions/reports';
 import { openModal } from '../actions/modal';
 import { createSelector } from 'reselect'
@@ -113,6 +113,14 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
     }));
   },
 
+  onMuteConversation (status) {
+    if (status.get('muted')) {
+      dispatch(unmuteStatus(status.get('id')));
+    } else {
+      dispatch(muteStatus(status.get('id')));
+    }
+  },
+
 });
 
 export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Status));
index 48a0e0381094c60377f0d26d911f9c997e6428f4..e20be99eaaa3e33c0a7d7e1fcfbdcb97b53a1fe9 100644 (file)
@@ -32,7 +32,7 @@ class Notification extends ImmutablePureComponent {
   }
 
   renderMention (notification) {
-    return <StatusContainer id={notification.get('status')} />;
+    return <StatusContainer id={notification.get('status')} withDismiss />;
   }
 
   renderFavourite (notification, link) {
@@ -45,7 +45,7 @@ class Notification extends ImmutablePureComponent {
           <FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
         </div>
 
-        <StatusContainer id={notification.get('status')} account={notification.get('account')} muted={true} />
+        <StatusContainer id={notification.get('status')} account={notification.get('account')} muted={true} withDismiss />
       </div>
     );
   }
@@ -60,7 +60,7 @@ class Notification extends ImmutablePureComponent {
           <FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
         </div>
 
-        <StatusContainer id={notification.get('status')} account={notification.get('account')} muted={true} />
+        <StatusContainer id={notification.get('status')} account={notification.get('account')} muted={true} withDismiss />
       </div>
     );
   }
index 0ed149f8063bfc5e310a5a85cad241ae0b649333..9779f496555a1ceae1987b4b992b67e4b254db26 100644 (file)
@@ -12,7 +12,7 @@ const messages = defineMessages({
   reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
   cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
   favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
-  report: { id: 'status.report', defaultMessage: 'Report @{name}' }
+  report: { id: 'status.report', defaultMessage: 'Report @{name}' },
 });
 
 class ActionBar extends React.PureComponent {
index 3ce55e68e93d4fb0b86e8ba0a9860997e6df2e0b..e2ba1c5b90ecdf896ad7e0f8f0f4155f35c6fc8a 100644 (file)
@@ -171,8 +171,24 @@ class Status extends ImmutablePureComponent {
           <div className='scrollable detailed-status__wrapper'>
             {ancestors}
 
-            <DetailedStatus status={status} autoPlayGif={autoPlayGif} me={me} onOpenVideo={this.handleOpenVideo} onOpenMedia={this.handleOpenMedia} />
-            <ActionBar status={status} me={me} onReply={this.handleReplyClick} onFavourite={this.handleFavouriteClick} onReblog={this.handleReblogClick} onDelete={this.handleDeleteClick} onMention={this.handleMentionClick} onReport={this.handleReport} />
+            <DetailedStatus
+              status={status}
+              autoPlayGif={autoPlayGif}
+              me={me}
+              onOpenVideo={this.handleOpenVideo}
+              onOpenMedia={this.handleOpenMedia}
+            />
+
+            <ActionBar
+              status={status}
+              me={me}
+              onReply={this.handleReplyClick}
+              onFavourite={this.handleFavouriteClick}
+              onReblog={this.handleReblogClick}
+              onDelete={this.handleDeleteClick}
+              onMention={this.handleMentionClick}
+              onReport={this.handleReport}
+            />
 
             {descendants}
           </div>
index e6f6d8c512007c2b9db08ada22fd63d2c49e0d6d..539b1c81f24a86a6890457506cf14783ed1b9e94 100644 (file)
   "status.load_more": "حمّل المزيد",
   "status.media_hidden": "الصورة مستترة",
   "status.mention": "أذكُر @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "وسع هذه المشاركة",
   "status.reblog": "رَقِّي",
   "status.reblogged_by": "{name} رقى",
   "status.sensitive_warning": "محتوى حساس",
   "status.show_less": "إعرض أقلّ",
   "status.show_more": "أظهر المزيد",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "تحرير",
   "tabs_bar.federated_timeline": "الموحَّد",
   "tabs_bar.home": "الرئيسية",
index 7d0660c25dff8d207cf1addd180bbc0957ebb60d..5101a8b76f38b424eab1ef0eebbd58ed3e5c2e55 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Споменаване",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expand this status",
   "status.reblog": "Споделяне",
   "status.reblogged_by": "{name} сподели",
   "status.sensitive_warning": "Деликатно съдържание",
   "status.show_less": "Show less",
   "status.show_more": "Show more",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Съставяне",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Начало",
index 1c3a8b6560c91f799c9f26fcf4fe84f1e66b8f4a..bdef9153790d512f7493857c49551358a5ac2dc5 100644 (file)
   "status.load_more": "Weitere laden",
   "status.media_hidden": "Medien versteckt",
   "status.mention": "Erwähnen",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Öffnen",
   "status.reblog": "Teilen",
   "status.reblogged_by": "{name} teilte",
   "status.sensitive_warning": "Heikle Inhalte",
   "status.show_less": "Weniger anzeigen",
   "status.show_more": "Mehr anzeigen",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Schreiben",
   "tabs_bar.federated_timeline": "Föderation",
   "tabs_bar.home": "Home",
index 9163a3563d70c060209ccebc1ab4cbeb8ab493f6..94a5d456ddc4d63e4328333f8561e1958ffcbffc 100644 (file)
       {
         "defaultMessage": "Report @{name}",
         "id": "status.report"
+      },
+      {
+        "defaultMessage": "Mute conversation",
+        "id": "status.mute_conversation"
+      },
+      {
+        "defaultMessage": "Unmute conversation",
+        "id": "status.unmute_conversation"
       }
     ],
     "path": "app/javascript/mastodon/components/status_action_bar.json"
         "defaultMessage": "Expand video",
         "id": "video_player.expand"
       },
-      {
-        "defaultMessage": "Video could not be played",
-        "id": "video_player.video_error"
-      },
       {
         "defaultMessage": "Sensitive content",
         "id": "status.sensitive_warning"
       {
         "defaultMessage": "Media hidden",
         "id": "status.media_hidden"
+      },
+      {
+        "defaultMessage": "Video could not be played",
+        "id": "video_player.video_error"
       }
     ],
     "path": "app/javascript/mastodon/components/video_player.json"
index 4dd59b88313455a2a09e2772d666edfa1ad67d01..bb86e813ab19debb17e5035ab9cf55b3fb7d1dc9 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Mention @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expand this status",
   "status.reblog": "Boost",
   "status.reblogged_by": "{name} boosted",
   "status.sensitive_warning": "Sensitive content",
   "status.show_less": "Show less",
   "status.show_more": "Show more",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Compose",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Home",
index 205af27e18dc42bd0f18b0276fd4784cc0e565f2..2e846cd2add4efcb0097dc4546157089e8f45435 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Mencii @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expand this status",
   "status.reblog": "Diskonigi",
   "status.reblogged_by": "{name} diskonigita",
   "status.sensitive_warning": "Tikla enhavo",
   "status.show_less": "Show less",
   "status.show_more": "Show more",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Ekskribi",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Hejmo",
index fec4b391e7bf53ccc2295ec31712655c96b20139..447b384e4599b39bf5393a4e2cae1cf626e00dae 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Mencionar",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expandir estado",
   "status.reblog": "Retoot",
   "status.reblogged_by": "Retooteado por {name}",
   "status.sensitive_warning": "Contenido sensible",
   "status.show_less": "Mostrar menos",
   "status.show_more": "Mostrar más",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Redactar",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Inicio",
index 7820da5f6c05d35cb9f6152f4c599283840e1a71..68033284584920625d75e2e682f737ae4064e186 100644 (file)
   "status.load_more": "بیشتر نشان بده",
   "status.media_hidden": "تصویر پنهان شده",
   "status.mention": "نام‌بردن از @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "این نوشته را باز کن",
   "status.reblog": "بازبوقیدن",
   "status.reblogged_by": "{name} بازبوقید",
   "status.sensitive_warning": "محتوای حساس",
   "status.show_less": "نهفتن",
   "status.show_more": "نمایش",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "بنویسید",
   "tabs_bar.federated_timeline": "همگانی",
   "tabs_bar.home": "خانه",
index 2621baa518171d70fe059867a63aad00f436109c..dc453e42ed93a40b0deee94ec9f3c8304f5bb654 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Mainitse @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expand this status",
   "status.reblog": "Buustaa",
   "status.reblogged_by": "{name} buustasi",
   "status.sensitive_warning": "Arkaluontoista sisältöä",
   "status.show_less": "Show less",
   "status.show_more": "Show more",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Luo",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Koti",
index f80cf5a716d51126daee63086ff18f0388bf4f9f..6a840fc3ec881e8922aefc43fb56da5bcd1d9cd2 100644 (file)
   "status.load_more": "Charger plus",
   "status.media_hidden": "Média caché",
   "status.mention": "Mentionner",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Déplier ce statut",
   "status.reblog": "Partager",
   "status.reblogged_by": "{name} a partagé :",
   "status.sensitive_warning": "Contenu délicat",
   "status.show_less": "Replier",
   "status.show_more": "Déplier",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Composer",
   "tabs_bar.federated_timeline": "Fil public global",
   "tabs_bar.home": "Accueil",
index e428dfdf286de174e97623775e4f1f52bcdc953f..0cc5f45664dad4e4153179d5b4a92d51db0c58b4 100644 (file)
   "status.load_more": "עוד",
   "status.media_hidden": "מדיה מוסתרת",
   "status.mention": "פניה אל @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "הרחבת הודעה",
   "status.reblog": "הדהוד",
   "status.reblogged_by": "הודהד על ידי {name}",
   "status.sensitive_warning": "תוכן רגיש",
   "status.show_less": "הראה פחות",
   "status.show_more": "הראה יותר",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "חיבור",
   "tabs_bar.federated_timeline": "ציר זמן בין-קהילתי",
   "tabs_bar.home": "בבית",
index 726ad960999a574dbe36b3bb452cb117af6ed912..7f068b2a2ce1dbd3e2c9b3848d8a8df81c45741d 100644 (file)
   "status.load_more": "Učitaj više",
   "status.media_hidden": "Sakriven media sadržaj",
   "status.mention": "Spomeni @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Proširi ovaj status",
   "status.reblog": "Podigni",
   "status.reblogged_by": "{name} je podigao",
   "status.sensitive_warning": "Osjetljiv sadržaj",
   "status.show_less": "Pokaži manje",
   "status.show_more": "Pokaži više",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Sastavi",
   "tabs_bar.federated_timeline": "Federalni",
   "tabs_bar.home": "Dom",
index dd283d736ea0e04cafded373474d2ec43a3b4a38..0dbe2dabb69b672bf1ff4d6c25a906bd311955be 100644 (file)
   "status.load_more": "Load more",
   "status.media_hidden": "Media hidden",
   "status.mention": "Említés",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expand this status",
   "status.reblog": "Reblog",
   "status.reblogged_by": "{name} reblogolta",
   "status.sensitive_warning": "Érzékeny tartalom",
   "status.show_less": "Show less",
   "status.show_more": "Show more",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Összeállítás",
   "tabs_bar.federated_timeline": "Federated",
   "tabs_bar.home": "Kezdőlap",
index ce0399a65f6dc1a97acf651dadf9a963d3068293..bdba4b5a8d4f141c69cc303cb7e710dda7e00054 100644 (file)
   "status.load_more": "Tampilkan semua",
   "status.media_hidden": "Media disembunyikan",
   "status.mention": "Balasan @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Tampilkan status ini",
   "status.reblog": "Boost",
   "status.reblogged_by": "di-boost {name}",
   "status.sensitive_warning": "Konten sensitif",
   "status.show_less": "Tampilkan lebih sedikit",
   "status.show_more": "Tampilkan semua",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Tulis",
   "tabs_bar.federated_timeline": "Gabungan",
   "tabs_bar.home": "Beranda",
index 5f63f2a8999928462def99b31352f56a322eb9e4..5b4391688c515b23e056217294ea32b6c991157b 100644 (file)
   "status.load_more": "Kargar pluse",
   "status.media_hidden": "Kontenajo celita",
   "status.mention": "Mencionar @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Detaligar ca mesajo",
   "status.reblog": "Repetar",
   "status.reblogged_by": "{name} repetita",
   "status.sensitive_warning": "Trubliva kontenajo",
   "status.show_less": "Montrar mine",
   "status.show_more": "Montrar plue",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Kompozar",
   "tabs_bar.federated_timeline": "Federata",
   "tabs_bar.home": "Hemo",
index 38d23f44c9d53cd531177252ad63ed448674957b..17b77757928badebfaffb9737ade5667cff0cb48 100644 (file)
   "status.load_more": "Mostra di più",
   "status.media_hidden": "Allegato nascosto",
   "status.mention": "Nomina @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Espandi questo post",
   "status.reblog": "Condividi",
   "status.reblogged_by": "{name} ha condiviso",
   "status.sensitive_warning": "Materiale sensibile",
   "status.show_less": "Mostra meno",
   "status.show_more": "Mostra di più",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Scrivi",
   "tabs_bar.federated_timeline": "Federazione",
   "tabs_bar.home": "Home",
index 0c252535f96a3cbae37bce403cdd7dd2deb04053..ee836a98669cd4b151b4e52337f27cfd0a561f42 100644 (file)
   "status.load_more": "もっと見る",
   "status.media_hidden": "非表示のメデイア",
   "status.mention": "返信",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "詳細を表示",
   "status.reblog": "ブースト",
   "status.reblogged_by": "{name} さんにブーストされました",
   "status.sensitive_warning": "閲覧注意",
   "status.show_less": "隠す",
   "status.show_more": "もっと見る",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "投稿",
   "tabs_bar.federated_timeline": "連合",
   "tabs_bar.home": "ホーム",
index 76e47e46ace9bc3835edb5b92c6ffe6d5ab17c78..82164d4ea77d7bfe1c65fef5e74b42f8a8cdb359 100644 (file)
   "status.load_more": "Meer laden",
   "status.media_hidden": "Media verborgen",
   "status.mention": "Vermeld @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Toot volledig tonen",
   "status.reblog": "Boost",
   "status.reblogged_by": "{name} boostte",
   "status.sensitive_warning": "Gevoelige inhoud",
   "status.show_less": "Minder tonen",
   "status.show_more": "Meer tonen",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Schrijven",
   "tabs_bar.federated_timeline": "Globaal",
   "tabs_bar.home": "Jouw tijdlijn",
index 4254dd2d442cfa6c925ac91414fb4b170cb2fd5b..9fcf7dadeaf7188851e2d36d9bc5b93af0b2b535 100644 (file)
   "status.load_more": "Last mer",
   "status.media_hidden": "Media skjult",
   "status.mention": "Nevn @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Utvid denne statusen",
   "status.reblog": "Fremhev",
   "status.reblogged_by": "Fremhevd av {name}",
   "status.sensitive_warning": "Følsomt innhold",
   "status.show_less": "Vis mindre",
   "status.show_more": "Vis mer",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Komponer",
   "tabs_bar.federated_timeline": "Felles",
   "tabs_bar.home": "Hjem",
index 6830bc0930b5ab48f9b7dd20cfd414c9b5fa82e6..26b44af71b07fab60e8375c8f40d5eb814378cb1 100644 (file)
   "status.load_more": "Cargar mai",
   "status.media_hidden": "Mèdia rescondut",
   "status.mention": "Mencionar",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Desplegar aqueste estatut",
   "status.reblog": "Partejar",
   "status.reblogged_by": "{name} a partejat :",
   "status.sensitive_warning": "Contengut embarrassant",
   "status.show_less": "Tornar plegar",
   "status.show_more": "Desplegar",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Compausar",
   "tabs_bar.federated_timeline": "Fil public global",
   "tabs_bar.home": "Acuèlh",
index 65c7443d3020ea998ec8aaf547eea8af0c26395e..4c4d17b53a8c5fa635399948b241e7d6ab84a10e 100644 (file)
   "status.load_more": "Załaduj więcej",
   "status.media_hidden": "Zawartość multimedialna ukryta",
   "status.mention": "Wspomnij o @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Rozszerz ten status",
   "status.reblog": "Podbij",
   "status.reblogged_by": "{name} podbił",
   "status.sensitive_warning": "Wrażliwa zawartość",
   "status.show_less": "Pokaż mniej",
   "status.show_more": "Pokaż więcej",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Napisz",
   "tabs_bar.federated_timeline": "Globalne",
   "tabs_bar.home": "Strona główna",
index 999742e5b9f8eff876298161f278a6746adac4f2..74856015b8ee6d7905e08b6a581f082c79cbb8e3 100644 (file)
   "status.load_more": "Carregar mais",
   "status.media_hidden": "Media escondida",
   "status.mention": "Mencionar @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expandir",
   "status.reblog": "Partilhar",
   "status.reblogged_by": "{name} partilhou",
   "status.sensitive_warning": "Conteúdo sensível",
   "status.show_less": "Mostrar menos",
   "status.show_more": "Mostrar mais",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Criar",
   "tabs_bar.federated_timeline": "Global",
   "tabs_bar.home": "Home",
index 999742e5b9f8eff876298161f278a6746adac4f2..74856015b8ee6d7905e08b6a581f082c79cbb8e3 100644 (file)
   "status.load_more": "Carregar mais",
   "status.media_hidden": "Media escondida",
   "status.mention": "Mencionar @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Expandir",
   "status.reblog": "Partilhar",
   "status.reblogged_by": "{name} partilhou",
   "status.sensitive_warning": "Conteúdo sensível",
   "status.show_less": "Mostrar menos",
   "status.show_more": "Mostrar mais",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Criar",
   "tabs_bar.federated_timeline": "Global",
   "tabs_bar.home": "Home",
index fc73a280cc457e70cd1c3efc60b679b0190b5b77..3ae78cd0131398070b4498b1e5d23e10a0e93979 100644 (file)
   "status.load_more": "Показать еще",
   "status.media_hidden": "Медиаконтент скрыт",
   "status.mention": "Упомянуть @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Развернуть статус",
   "status.reblog": "Продвинуть",
   "status.reblogged_by": "{name} продвинул(а)",
   "status.sensitive_warning": "Чувствительный контент",
   "status.show_less": "Свернуть",
   "status.show_more": "Развернуть",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Написать",
   "tabs_bar.federated_timeline": "Глобальная",
   "tabs_bar.home": "Главная",
index f483762b46b004413492af008cd2191aaa13ddb9..b2c4036d6a8c651d70ee75427dc002b07d2bc9c3 100644 (file)
   "status.load_more": "Daha fazla",
   "status.media_hidden": "Gizli görsel",
   "status.mention": "Bahset @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Bu gönderiyi genişlet",
   "status.reblog": "Boost'la",
   "status.reblogged_by": "{name} boost etti",
   "status.sensitive_warning": "Hassas içerik",
   "status.show_less": "Daha azı",
   "status.show_more": "Daha fazlası",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Oluştur",
   "tabs_bar.federated_timeline": "Federe",
   "tabs_bar.home": "Ana sayfa",
index e4c4cf2eb01201f4104e52ccc65d3c1a1f34ea29..a2c50e9e0a18952d1a7f64cb70ac82c227f895df 100644 (file)
   "status.load_more": "Завантажити більше",
   "status.media_hidden": "Медіаконтент приховано",
   "status.mention": "Згадати",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "Розгорнути допис",
   "status.reblog": "Передмухнути",
   "status.reblogged_by": "{name} передмухнув(-ла)",
   "status.sensitive_warning": "Непристойний зміст",
   "status.show_less": "Згорнути",
   "status.show_more": "Розгорнути",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "Написати",
   "tabs_bar.federated_timeline": "Глобальна",
   "tabs_bar.home": "Головна",
index fa32ebc5ee47c28c195487f49706e8c8051bbe6f..741689968547334b959c1530562b93f0cbc83cab 100644 (file)
   "status.load_more": "加载更多",
   "status.media_hidden": "隐藏媒体内容",
   "status.mention": "提及 @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "展开嘟文",
   "status.reblog": "转嘟",
   "status.reblogged_by": "{name} 转嘟",
   "status.sensitive_warning": "敏感内容",
   "status.show_less": "减少显示",
   "status.show_more": "显示更多",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "撰写",
   "tabs_bar.federated_timeline": "跨站",
   "tabs_bar.home": "主页",
index 157fca27f2e102a0bbae826586c87e11eef715d1..f55fd8806b8fc7170343ab8d6b85f3f8fd37a5d8 100644 (file)
   "status.load_more": "載入更多",
   "status.media_hidden": "隱藏媒體內容",
   "status.mention": "提及 @{name}",
+  "status.mute_conversation": "Mute conversation",
   "status.open": "展開文章",
   "status.reblog": "轉推",
   "status.reblogged_by": "{name} 轉推",
   "status.sensitive_warning": "敏感內容",
   "status.show_less": "減少顯示",
   "status.show_more": "顯示更多",
+  "status.unmute_conversation": "Unmute conversation",
   "tabs_bar.compose": "撰寫",
   "tabs_bar.federated_timeline": "跨站",
   "tabs_bar.home": "主頁",
index 3ad924c694be22870ec9d73c0cf210467037a38c..282380c3782ca8523de461a632c00a29954950a1 100644 (file)
@@ -10,7 +10,9 @@ import {
 } from '../actions/interactions';
 import {
   STATUS_FETCH_SUCCESS,
-  CONTEXT_FETCH_SUCCESS
+  CONTEXT_FETCH_SUCCESS,
+  STATUS_MUTE_SUCCESS,
+  STATUS_UNMUTE_SUCCESS
 } from '../actions/statuses';
 import {
   TIMELINE_REFRESH_SUCCESS,
@@ -103,6 +105,10 @@ export default function statuses(state = initialState, action) {
     return state.setIn([action.status.get('id'), 'reblogged'], true);
   case REBLOG_FAIL:
     return state.setIn([action.status.get('id'), 'reblogged'], false);
+  case STATUS_MUTE_SUCCESS:
+    return state.setIn([action.id, 'muted'], true);
+  case STATUS_UNMUTE_SUCCESS:
+    return state.setIn([action.id, 'muted'], false);
   case TIMELINE_REFRESH_SUCCESS:
   case TIMELINE_EXPAND_SUCCESS:
   case ACCOUNT_TIMELINE_FETCH_SUCCESS:
index d43cae038ffaec6e22bc88417210444d0be0997b..bf3d92a5109a439a2536b7912b576c467ba98a0c 100644 (file)
@@ -84,6 +84,7 @@ class Account < ApplicationRecord
   # Mute relationships
   has_many :mute_relationships, class_name: 'Mute', foreign_key: 'account_id', dependent: :destroy
   has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
+  has_many :conversation_mutes
 
   # Media
   has_many :media_attachments, dependent: :destroy
@@ -130,6 +131,10 @@ class Account < ApplicationRecord
     mute_relationships.find_or_create_by!(target_account: other_account)
   end
 
+  def mute_conversation!(conversation)
+    conversation_mutes.find_or_create_by!(conversation: conversation)
+  end
+
   def unfollow!(other_account)
     follow = active_relationships.find_by(target_account: other_account)
     follow&.destroy
@@ -145,6 +150,11 @@ class Account < ApplicationRecord
     mute&.destroy
   end
 
+  def unmute_conversation!(conversation)
+    mute = conversation_mutes.find_by(conversation: conversation)
+    mute&.destroy!
+  end
+
   def following?(other_account)
     following.include?(other_account)
   end
@@ -157,6 +167,10 @@ class Account < ApplicationRecord
     muting.include?(other_account)
   end
 
+  def muting_conversation?(conversation)
+    conversation_mutes.where(conversation: conversation).exists?
+  end
+
   def requested?(other_account)
     follow_requests.where(target_account: other_account).exists?
   end
index fbec961c74afbfb7631f5f6dbff46260e9fb2b35..3715e1049d8c7cbf8521e61503c54f74126f57d9 100644 (file)
@@ -10,7 +10,7 @@
 #
 
 class Conversation < ApplicationRecord
-  validates :uri, uniqueness: true
+  validates :uri, uniqueness: true, if: :uri
 
   has_many :statuses
 
diff --git a/app/models/conversation_mute.rb b/app/models/conversation_mute.rb
new file mode 100644 (file)
index 0000000..79299b9
--- /dev/null
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+# == Schema Information
+#
+# Table name: conversation_mutes
+#
+#  id              :integer          not null, primary key
+#  account_id      :integer          not null
+#  conversation_id :integer          not null
+#
+
+class ConversationMute < ApplicationRecord
+  belongs_to :account, required: true
+  belongs_to :conversation, required: true
+end
index 772cef238fa4243e41ab495739ed6a5bd28278f5..7c39a273a6cc8274685f68360a7a42afaa8625cd 100644 (file)
@@ -181,6 +181,10 @@ class Status < ApplicationRecord
       select('reblog_of_id').where(reblog_of_id: status_ids).where(account_id: account_id).map { |s| [s.reblog_of_id, true] }.to_h
     end
 
+    def mutes_map(conversation_ids, account_id)
+      ConversationMute.select('conversation_id').where(conversation_id: conversation_ids).where(account_id: account_id).map { |m| [m.conversation_id, true] }.to_h
+    end
+
     def reload_stale_associations!(cached_items)
       account_ids = []
 
index 9c7eb26ef489e73796c537b668889051f1cac4d8..7b377f6a8be4b5df7e7ae93b80613310f2e6313d 100644 (file)
@@ -43,10 +43,19 @@ class NotifyService < BaseService
     blocked ||= (@notification.from_account.silenced? && !@recipient.following?(@notification.from_account))                       # Hellban
     blocked ||= (@recipient.user.settings.interactions['must_be_follower']  && !@notification.from_account.following?(@recipient)) # Options
     blocked ||= (@recipient.user.settings.interactions['must_be_following'] && !@recipient.following?(@notification.from_account)) # Options
+    blocked ||= conversation_muted?
     blocked ||= send("blocked_#{@notification.type}?")                                                                             # Type-dependent filters
     blocked
   end
 
+  def conversation_muted?
+    if @notification.target_status
+      @recipient.muting_conversation?(@notification.target_status.conversation)
+    else
+      false
+    end
+  end
+
   def create_notification
     @notification.save!
     return unless @notification.browserable?
index 41e8983efff687b902c15c6b8cca118c9b27ce0c..4b33fb2c316774fc12fc0f44e289485d12a47313 100644 (file)
@@ -2,12 +2,14 @@ object @status
 
 extends 'api/v1/statuses/_show'
 
-node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? @favourites_map[status.id] : current_account.favourited?(status) }
-node(:reblogged,  if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map)    ? @reblogs_map[status.id]    : current_account.reblogged?(status) }
+node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? @favourites_map[status.id]         : current_account.favourited?(status) }
+node(:reblogged,  if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map)    ? @reblogs_map[status.id]            : current_account.reblogged?(status) }
+node(:muted,      if: proc { !current_account.nil? }) { |status| defined?(@mutes_map)      ? @mutes_map[status.conversation_id] : current_account.muting_conversation?(status.conversation) }
 
 child reblog: :reblog do
   extends 'api/v1/statuses/_show'
 
   node(:favourited, if: proc { !current_account.nil? }) { |status| defined?(@favourites_map) ? @favourites_map[status.id] : current_account.favourited?(status) }
   node(:reblogged,  if: proc { !current_account.nil? }) { |status| defined?(@reblogs_map)    ? @reblogs_map[status.id]    : current_account.reblogged?(status) }
+  node(:muted,      if: proc { !current_account.nil? }) { false }
 end
index 37b3895fd564d64072f7138ed14cad71f57dc4a7..9ff6a13bba6cc308b079efebf3bb55889ff681de 100644 (file)
@@ -131,6 +131,8 @@ Rails.application.routes.draw do
           post :unreblog
           post :favourite
           post :unfavourite
+          post :mute
+          post :unmute
         end
       end
 
index 8f1bb22f5b915f60cf869c170faa4dab708f9683..4c27eca1e3850e77e8958c09aae4920d1ea3117e 100644 (file)
@@ -7,6 +7,5 @@ class CreateMutes < ActiveRecord::Migration[5.0]
     end
 
     add_index :mutes, [:account_id, :target_account_id], unique: true
-
   end
 end
diff --git a/db/migrate/20170508230434_create_conversation_mutes.rb b/db/migrate/20170508230434_create_conversation_mutes.rb
new file mode 100644 (file)
index 0000000..81edf27
--- /dev/null
@@ -0,0 +1,10 @@
+class CreateConversationMutes < ActiveRecord::Migration[5.0]
+  def change
+    create_table :conversation_mutes do |t|
+      t.integer :account_id, null: false
+      t.bigint :conversation_id, null: false
+    end
+
+    add_index :conversation_mutes, [:account_id, :conversation_id], unique: true
+  end
+end
index 7f7fc597808c76636ea0fec6ccf0b41fcb85b04e..76624f07a3a980eb282882c5ed4c50e3cf471afd 100644 (file)
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20170507141759) do
+ActiveRecord::Schema.define(version: 20170508230434) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -62,6 +62,12 @@ ActiveRecord::Schema.define(version: 20170507141759) do
     t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true, using: :btree
   end
 
+  create_table "conversation_mutes", force: :cascade do |t|
+    t.integer "account_id",      null: false
+    t.bigint  "conversation_id", null: false
+    t.index ["account_id", "conversation_id"], name: "index_conversation_mutes_on_account_id_and_conversation_id", unique: true, using: :btree
+  end
+
   create_table "conversations", id: :bigserial, force: :cascade do |t|
     t.string   "uri"
     t.datetime "created_at", null: false
index 74faed269e89f0114759a7381bd97b113cd344e0..ac3b2dc7d6f12697c2bfae1f368fe0ab8cb06598 100644 (file)
@@ -183,6 +183,39 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
         expect(user.account.favourited?(status)).to be false
       end
     end
+
+    describe 'POST #mute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'creates a conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to_not be_nil
+      end
+    end
+
+    describe 'POST #unmute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute,   params: { id: status.id }
+        post :unmute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'destroys the conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to be_nil
+      end
+    end
   end
 
   context 'without an oauth token' do
diff --git a/spec/fabricators/conversation_mute_fabricator.rb b/spec/fabricators/conversation_mute_fabricator.rb
new file mode 100644 (file)
index 0000000..84f131c
--- /dev/null
@@ -0,0 +1,2 @@
+Fabricator(:conversation_mute) do
+end
diff --git a/spec/models/conversation_mute_spec.rb b/spec/models/conversation_mute_spec.rb
new file mode 100644 (file)
index 0000000..b602e80
--- /dev/null
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ConversationMute, type: :model do
+
+end
index f9f5c160375cf161e854db5a53552ec275c5d4be..d280525fca07fee053ba9249057b0ab7891ebe55 100644 (file)
@@ -196,6 +196,54 @@ RSpec.describe Status, type: :model do
     pending
   end
 
+  describe '.mutes_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.mutes_map([status.conversation.id], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      account.mute_conversation!(status.conversation)
+      expect(subject[status.conversation.id]).to be true
+    end
+  end
+
+  describe '.favourites_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.favourites_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:favourite, status: status, account: account)
+      expect(subject[status.id]).to be true
+    end
+  end
+
+  describe '.reblogs_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.reblogs_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:status, account: account, reblog: status)
+      expect(subject[status.id]).to be true
+    end
+  end
+
   describe '.local_only' do
     it 'returns only statuses from local accounts' do
       local_account = Fabricate(:account, domain: nil)
index 86848e1ffccc51192cd258a5376304a0466a9f1f..032c37a28b9d039d3f54e5260d4645fd0c2aaafd 100644 (file)
@@ -7,10 +7,50 @@ RSpec.describe NotifyService do
 
   let(:user) { Fabricate(:user) }
   let(:recipient) { user.account }
-  let(:activity) { Fabricate(:follow, target_account: recipient) }
+  let(:sender) { Fabricate(:account) }
+  let(:activity) { Fabricate(:follow, account: sender, target_account: recipient) }
 
   it { is_expected.to change(Notification, :count).by(1) }
 
+  it 'does not notify when sender is blocked' do
+    recipient.block!(sender)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when sender is silenced and not followed' do
+    sender.update(silenced: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when recipient is suspended' do
+    recipient.update(suspended: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  context do
+    let(:asshole)  { Fabricate(:account, username: 'asshole') }
+    let(:reply_to) { Fabricate(:status, account: asshole) }
+    let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, thread: reply_to)) }
+
+    it 'does not notify when conversation is muted' do
+      recipient.mute_conversation!(activity.status.conversation)
+      is_expected.to_not change(Notification, :count)
+    end
+
+    it 'does not notify when it is a reply to a blocked user' do
+      recipient.block!(asshole)
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
+  context do
+    let(:sender) { recipient }
+
+    it 'does not notify when recipient is the sender' do
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
   describe 'email' do
     before do
       ActionMailer::Base.deliveries.clear