-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notifications of severed relationships (#27511)
- Loading branch information
1 parent
8a1423a
commit 44bf7b8
Showing
39 changed files
with
780 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
class SeveredRelationshipsController < ApplicationController | ||
layout 'admin' | ||
|
||
before_action :authenticate_user! | ||
before_action :set_body_classes | ||
before_action :set_cache_headers | ||
|
||
before_action :set_event, only: [:following, :followers] | ||
|
||
def index | ||
@events = AccountRelationshipSeveranceEvent.where(account: current_account) | ||
end | ||
|
||
def following | ||
respond_to do |format| | ||
format.csv { send_data following_data, filename: "following-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" } | ||
end | ||
end | ||
|
||
def followers | ||
respond_to do |format| | ||
format.csv { send_data followers_data, filename: "followers-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" } | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_event | ||
@event = AccountRelationshipSeveranceEvent.find(params[:id]) | ||
end | ||
|
||
def following_data | ||
CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv| | ||
@event.severed_relationships.active.where(local_account: current_account).includes(:remote_account).reorder(id: :desc).each do |follow| | ||
csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')] | ||
end | ||
end | ||
end | ||
|
||
def followers_data | ||
CSV.generate(headers: ['Account address'], write_headers: true) do |csv| | ||
@event.severed_relationships.passive.where(local_account: current_account).includes(:remote_account).reorder(id: :desc).each do |follow| | ||
csv << [acct(follow.account)] | ||
end | ||
end | ||
end | ||
|
||
def acct(account) | ||
account.local? ? account.local_username_and_domain : account.acct | ||
end | ||
|
||
def set_body_classes | ||
@body_classes = 'admin' | ||
end | ||
|
||
def set_cache_headers | ||
response.cache_control.replace(private: true, no_store: true) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/javascript/mastodon/features/notifications/components/relationships_severance_event.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; | ||
|
||
import ImmutablePropTypes from 'react-immutable-proptypes'; | ||
|
||
import { RelativeTimestamp } from 'mastodon/components/relative_timestamp'; | ||
|
||
// This needs to be kept in sync with app/models/relationship_severance_event.rb | ||
const messages = defineMessages({ | ||
account_suspension: { id: 'relationship_severance_notification.types.account_suspension', defaultMessage: 'Account has been suspended' }, | ||
domain_block: { id: 'relationship_severance_notification.types.domain_block', defaultMessage: 'Domain has been suspended' }, | ||
user_domain_block: { id: 'relationship_severance_notification.types.user_domain_block', defaultMessage: 'You blocked this domain' }, | ||
}); | ||
|
||
const RelationshipsSeveranceEvent = ({ event, hidden }) => { | ||
const intl = useIntl(); | ||
|
||
if (hidden || !event) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className='notification__report'> | ||
<div className='notification__report__details'> | ||
<div> | ||
<RelativeTimestamp timestamp={event.get('created_at')} short={false} /> | ||
{' · '} | ||
{ event.get('purged') ? ( | ||
<FormattedMessage | ||
id='relationship_severance_notification.purged_data' | ||
defaultMessage='purged by administrators' | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id='relationship_severance_notification.relationships' | ||
defaultMessage='{count, plural, one {# relationship} other {# relationships}}' | ||
values={{ count: event.get('relationships_count', 0) }} | ||
/> | ||
)} | ||
<br /> | ||
<strong>{intl.formatMessage(messages[event.get('type')])}</strong> | ||
</div> | ||
|
||
<div className='notification__report__actions'> | ||
<a href='/severed_relationships' className='button' target='_blank' rel='noopener noreferrer'> | ||
<FormattedMessage id='relationship_severance_notification.view' defaultMessage='View' /> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
}; | ||
|
||
RelationshipsSeveranceEvent.propTypes = { | ||
event: ImmutablePropTypes.map.isRequired, | ||
hidden: PropTypes.bool, | ||
}; | ||
|
||
export default RelationshipsSeveranceEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# | ||
# == Schema Information | ||
# | ||
# Table name: account_relationship_severance_events | ||
# | ||
# id :bigint(8) not null, primary key | ||
# account_id :bigint(8) not null | ||
# relationship_severance_event_id :bigint(8) not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class AccountRelationshipSeveranceEvent < ApplicationRecord | ||
belongs_to :account | ||
belongs_to :relationship_severance_event | ||
|
||
delegate :severed_relationships, :type, :target_name, :purged, to: :relationship_severance_event, prefix: false | ||
|
||
before_create :set_relationships_count! | ||
|
||
private | ||
|
||
def set_relationships_count! | ||
self.relationships_count = severed_relationships.where(local_account: account).count | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: relationship_severance_events | ||
# | ||
# id :bigint(8) not null, primary key | ||
# type :integer not null | ||
# target_name :string not null | ||
# purged :boolean default(FALSE), not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class RelationshipSeveranceEvent < ApplicationRecord | ||
self.inheritance_column = nil | ||
|
||
has_many :severed_relationships, inverse_of: :relationship_severance_event, dependent: :delete_all | ||
|
||
enum type: { | ||
domain_block: 0, | ||
user_domain_block: 1, | ||
account_suspension: 2, | ||
} | ||
|
||
scope :about_local_account, ->(account) { where(id: SeveredRelationship.about_local_account(account).select(:relationship_severance_event_id)) } | ||
|
||
def import_from_active_follows!(follows) | ||
import_from_follows!(follows, true) | ||
end | ||
|
||
def import_from_passive_follows!(follows) | ||
import_from_follows!(follows, false) | ||
end | ||
|
||
def affected_local_accounts | ||
Account.where(id: severed_relationships.select(:local_account_id)) | ||
end | ||
|
||
private | ||
|
||
def import_from_follows!(follows, active) | ||
SeveredRelationship.insert_all( | ||
follows.pluck(:account_id, :target_account_id, :show_reblogs, :notify, :languages).map do |account_id, target_account_id, show_reblogs, notify, languages| | ||
{ | ||
local_account_id: active ? account_id : target_account_id, | ||
remote_account_id: active ? target_account_id : account_id, | ||
show_reblogs: show_reblogs, | ||
notify: notify, | ||
languages: languages, | ||
relationship_severance_event_id: id, | ||
direction: active ? :active : :passive, | ||
} | ||
end | ||
) | ||
end | ||
end |
Oops, something went wrong.