Add account_warning notification
This commit is contained in:
parent
af86c09824
commit
e7492e0745
9 changed files with 70 additions and 3 deletions
|
@ -30,6 +30,7 @@ const messages = defineMessages({
|
||||||
status: { id: 'notification.status', defaultMessage: '{name} just posted' },
|
status: { id: 'notification.status', defaultMessage: '{name} just posted' },
|
||||||
statusReference: { id: 'notification.status_reference', defaultMessage: '{name} refered' },
|
statusReference: { id: 'notification.status_reference', defaultMessage: '{name} refered' },
|
||||||
update: { id: 'notification.update', defaultMessage: '{name} edited a post' },
|
update: { id: 'notification.update', defaultMessage: '{name} edited a post' },
|
||||||
|
warning: { id: 'notification.warning', defaultMessage: 'You have been warned and "{action}" has been executed. Check your mailbox' },
|
||||||
adminSignUp: { id: 'notification.admin.sign_up', defaultMessage: '{name} signed up' },
|
adminSignUp: { id: 'notification.admin.sign_up', defaultMessage: '{name} signed up' },
|
||||||
adminReport: { id: 'notification.admin.report', defaultMessage: '{name} reported {target}' },
|
adminReport: { id: 'notification.admin.report', defaultMessage: '{name} reported {target}' },
|
||||||
});
|
});
|
||||||
|
@ -443,6 +444,31 @@ class Notification extends ImmutablePureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderWarning (notification) {
|
||||||
|
const { intl, unread } = this.props;
|
||||||
|
console.dir(notification);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HotKeys handlers={this.getHandlers()}>
|
||||||
|
<div className={classNames('notification notification-warning focusable', { unread })} tabIndex={0} aria-label={notificationForScreenReader(intl, intl.formatMessage(messages.statusReference, { name: notification.getIn(['account', 'acct']) }), notification.get('created_at'))}>
|
||||||
|
<div className='notification__message'>
|
||||||
|
<div className='notification__favourite-icon-wrapper'>
|
||||||
|
<Icon id='exclamation-triangle' className='star-icon' fixedWidth />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span title={notification.get('created_at')}>
|
||||||
|
<FormattedMessage id='notification.warning' defaultMessage='You have been warned and "{action}" has been executed. Check your mailbox' values={{action: notification.getIn(['account_warning', 'action'])}} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='notification__warning-text'>
|
||||||
|
{notification.getIn(['account_warning', 'text'])}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</HotKeys>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
renderAdminSignUp (notification, account, link) {
|
renderAdminSignUp (notification, account, link) {
|
||||||
const { intl, unread } = this.props;
|
const { intl, unread } = this.props;
|
||||||
|
|
||||||
|
@ -522,6 +548,8 @@ class Notification extends ImmutablePureComponent {
|
||||||
return this.renderUpdate(notification, link);
|
return this.renderUpdate(notification, link);
|
||||||
case 'poll':
|
case 'poll':
|
||||||
return this.renderPoll(notification, account);
|
return this.renderPoll(notification, account);
|
||||||
|
case 'warning':
|
||||||
|
return this.renderWarning(notification);
|
||||||
case 'admin.sign_up':
|
case 'admin.sign_up':
|
||||||
return this.renderAdminSignUp(notification, account, link);
|
return this.renderAdminSignUp(notification, account, link);
|
||||||
case 'admin.report':
|
case 'admin.report':
|
||||||
|
|
|
@ -439,6 +439,7 @@
|
||||||
"notification.status": "{name}さんが投稿しました",
|
"notification.status": "{name}さんが投稿しました",
|
||||||
"notification.status_reference": "{name}さんがあなたの投稿を参照しました",
|
"notification.status_reference": "{name}さんがあなたの投稿を参照しました",
|
||||||
"notification.update": "{name}さんが投稿を編集しました",
|
"notification.update": "{name}さんが投稿を編集しました",
|
||||||
|
"notification.warning": "あなたは警告を出され、「{action}」が実行されました。詳細はメールをご確認ください",
|
||||||
"notifications.clear": "通知を消去",
|
"notifications.clear": "通知を消去",
|
||||||
"notifications.clear_confirmation": "本当に通知を消去しますか?",
|
"notifications.clear_confirmation": "本当に通知を消去しますか?",
|
||||||
"notifications.column_settings.admin.report": "新しい通報:",
|
"notifications.column_settings.admin.report": "新しい通報:",
|
||||||
|
|
|
@ -52,10 +52,11 @@ const notificationToMap = notification => ImmutableMap({
|
||||||
id: notification.id,
|
id: notification.id,
|
||||||
type: notification.type,
|
type: notification.type,
|
||||||
account: notification.account.id,
|
account: notification.account.id,
|
||||||
emoji_reaction: ImmutableMap(notification.emoji_reaction),
|
|
||||||
created_at: notification.created_at,
|
created_at: notification.created_at,
|
||||||
|
emoji_reaction: ImmutableMap(notification.emoji_reaction),
|
||||||
status: notification.status ? notification.status.id : null,
|
status: notification.status ? notification.status.id : null,
|
||||||
report: notification.report ? fromJS(notification.report) : null,
|
report: notification.report ? fromJS(notification.report) : null,
|
||||||
|
account_warning: notification.account_warning ? ImmutableMap(notification.account_warning) : null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const normalizeNotification = (state, notification, usePendingItems) => {
|
const normalizeNotification = (state, notification, usePendingItems) => {
|
||||||
|
|
|
@ -1848,6 +1848,11 @@ a.account__display-name {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification__warning-text {
|
||||||
|
padding: 16px 16px 16px 48px;
|
||||||
|
color: $darker-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
.notification__display-name {
|
.notification__display-name {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Admin::AccountAction
|
||||||
|
|
||||||
process_email!
|
process_email!
|
||||||
process_queue!
|
process_queue!
|
||||||
|
notify!
|
||||||
end
|
end
|
||||||
|
|
||||||
def report
|
def report
|
||||||
|
@ -107,6 +108,10 @@ class Admin::AccountAction
|
||||||
log_action(:create, @warning) if @warning.text.present? && type == 'none'
|
log_action(:create, @warning) if @warning.text.present? && type == 'none'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify!
|
||||||
|
LocalNotificationWorker.perform_async(target_account.id, @warning.id, 'AccountWarning', 'warning') if @warning && %w(none sensitive silence).include?(type)
|
||||||
|
end
|
||||||
|
|
||||||
def process_reports!
|
def process_reports!
|
||||||
# If we're doing "mark as resolved" on a single report,
|
# If we're doing "mark as resolved" on a single report,
|
||||||
# then we want to keep other reports open in case they
|
# then we want to keep other reports open in case they
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Admin::StatusBatchAction
|
||||||
|
|
||||||
def save!
|
def save!
|
||||||
process_action!
|
process_action!
|
||||||
|
notify!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -157,6 +158,10 @@ class Admin::StatusBatchAction
|
||||||
report.save!
|
report.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify!
|
||||||
|
LocalNotificationWorker.perform_async(target_account.id, @warning.id, 'AccountWarning', 'warning') if warnable? && @warning
|
||||||
|
end
|
||||||
|
|
||||||
def report
|
def report
|
||||||
@report ||= Report.find(report_id) if report_id.present?
|
@report ||= Report.find(report_id) if report_id.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,7 @@ class Notification < ApplicationRecord
|
||||||
'EmojiReaction' => :emoji_reaction,
|
'EmojiReaction' => :emoji_reaction,
|
||||||
'StatusReference' => :status_reference,
|
'StatusReference' => :status_reference,
|
||||||
'Poll' => :poll,
|
'Poll' => :poll,
|
||||||
|
'AccountWarning' => :warning,
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
TYPES = %i(
|
TYPES = %i(
|
||||||
|
@ -42,6 +43,7 @@ class Notification < ApplicationRecord
|
||||||
reaction
|
reaction
|
||||||
poll
|
poll
|
||||||
update
|
update
|
||||||
|
warning
|
||||||
admin.sign_up
|
admin.sign_up
|
||||||
admin.report
|
admin.report
|
||||||
).freeze
|
).freeze
|
||||||
|
@ -73,6 +75,7 @@ class Notification < ApplicationRecord
|
||||||
belongs_to :status_reference, inverse_of: :notification
|
belongs_to :status_reference, inverse_of: :notification
|
||||||
belongs_to :poll, inverse_of: false
|
belongs_to :poll, inverse_of: false
|
||||||
belongs_to :report, inverse_of: false
|
belongs_to :report, inverse_of: false
|
||||||
|
belongs_to :account_warning, inverse_of: false
|
||||||
end
|
end
|
||||||
|
|
||||||
validates :type, inclusion: { in: TYPES }
|
validates :type, inclusion: { in: TYPES }
|
||||||
|
@ -159,6 +162,15 @@ class Notification < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_account_web
|
||||||
|
case activity_type
|
||||||
|
when 'AccountWarning'
|
||||||
|
account_warning&.target_account
|
||||||
|
else
|
||||||
|
from_account
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
after_initialize :set_from_account
|
after_initialize :set_from_account
|
||||||
before_validation :set_from_account
|
before_validation :set_from_account
|
||||||
|
|
||||||
|
@ -168,7 +180,7 @@ class Notification < ApplicationRecord
|
||||||
return unless new_record?
|
return unless new_record?
|
||||||
|
|
||||||
case activity_type
|
case activity_type
|
||||||
when 'Status', 'Follow', 'Favourite', 'EmojiReaction', 'EmojiReact', 'FollowRequest', 'Poll', 'Report'
|
when 'Status', 'Follow', 'Favourite', 'EmojiReaction', 'EmojiReact', 'FollowRequest', 'Poll', 'Report', 'AccountWarning'
|
||||||
self.from_account_id = activity&.account_id
|
self.from_account_id = activity&.account_id
|
||||||
when 'Mention', 'StatusReference'
|
when 'Mention', 'StatusReference'
|
||||||
self.from_account_id = activity&.status&.account_id
|
self.from_account_id = activity&.status&.account_id
|
||||||
|
|
5
app/serializers/rest/account_warning_serializer.rb
Normal file
5
app/serializers/rest/account_warning_serializer.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class REST::AccountWarningSerializer < ActiveModel::Serializer
|
||||||
|
attributes :id, :action, :text, :status_ids
|
||||||
|
end
|
|
@ -3,10 +3,11 @@
|
||||||
class REST::NotificationSerializer < ActiveModel::Serializer
|
class REST::NotificationSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :type, :created_at
|
attributes :id, :type, :created_at
|
||||||
|
|
||||||
belongs_to :from_account, key: :account, serializer: REST::AccountSerializer
|
belongs_to :from_account_web, key: :account, serializer: REST::AccountSerializer
|
||||||
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
|
belongs_to :target_status, key: :status, if: :status_type?, serializer: REST::StatusSerializer
|
||||||
belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
|
belongs_to :report, if: :report_type?, serializer: REST::ReportSerializer
|
||||||
belongs_to :emoji_reaction, if: :emoji_reaction_type?, serializer: REST::NotifyEmojiReactionSerializer
|
belongs_to :emoji_reaction, if: :emoji_reaction_type?, serializer: REST::NotifyEmojiReactionSerializer
|
||||||
|
belongs_to :account_warning, if: :warning_type?, serializer: REST::AccountWarningSerializer
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object.id.to_s
|
object.id.to_s
|
||||||
|
@ -20,6 +21,10 @@ class REST::NotificationSerializer < ActiveModel::Serializer
|
||||||
object.type == :'admin.report'
|
object.type == :'admin.report'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def warning_type?
|
||||||
|
object.type == :warning
|
||||||
|
end
|
||||||
|
|
||||||
def emoji_reaction_type?
|
def emoji_reaction_type?
|
||||||
object.type == :emoji_reaction
|
object.type == :emoji_reaction
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue