Commit 868b8700 authored by Emma's avatar Emma 🦉

add settings for disabling notifications

parent 7d6c3cc9
Pipeline #53357728 passed with stages
in 14 minutes and 15 seconds
.form-help {
color: var(--text-muted);
font-size: 0.875rem;
margin-bottom: 0;
.form-row + .form-row > & {
// crappy hack
margin-top: -0.5rem;
}
}
......@@ -32,6 +32,7 @@
@import '_form/fieldset';
@import '_form/form-control';
@import '_form/form-row';
@import '_form/form-help';
@import '_form/required-indicator';
@import '_utilities/break-text';
......
......@@ -273,13 +273,29 @@ class Comment extends Votable {
}
public function addMention(User $mentioned) {
if (
!$mentioned->isBlocking($this->getUser()) &&
$mentioned !== $this->getUser() &&
$mentioned !== ($this->getParent() ?: $this->getSubmission())->getUser()
) {
$mentioned->sendNotification(new CommentMention($mentioned, $this));
if ($mentioned === $this->getUser()) {
// don't notify yourself
return;
}
if (!$mentioned->getNotifyOnMentions()) {
// don't notify users who've disabled mention notifications
return;
}
if ($mentioned->isBlocking($this->getUser())) {
// don't notify users blocking you
return;
}
$replyingTo = ($this->getParent() ?: $this->getSubmission())->getUser();
if ($replyingTo === $mentioned && $replyingTo->getNotifyOnReply()) {
// don't notify users who'll get a notification for the reply anyway
return;
}
$mentioned->sendNotification(new CommentMention($mentioned, $this));
}
protected function createVote(User $user, ?string $ip, int $choice): Vote {
......@@ -358,8 +374,13 @@ class Comment extends Votable {
private function notify() {
$receiver = ($this->parent ?: $this->submission)->getUser();
if ($this->user === $receiver || $receiver->isBlocking($this->user)) {
// don't send notification to oneself or to a blocking user
if (
$this->user === $receiver ||
!$receiver->getNotifyOnReply() ||
$receiver->isBlocking($this->user)
) {
// don't send notifications to oneself, to a user who's disabled
// them, or to a user who's blocked the user replying
return;
}
......
......@@ -345,12 +345,22 @@ class Submission extends Votable {
}
public function addMention(User $mentioned) {
if (
!$mentioned->isBlocking($this->getUser()) &&
$mentioned !== $this->getUser()
) {
$mentioned->sendNotification(new SubmissionMention($mentioned, $this));
if ($mentioned === $this->getUser()) {
// don't notify yourself
return;
}
if (!$mentioned->getNotifyOnMentions()) {
// don't notify users who've disabled mention notifications
return;
}
if ($mentioned->isBlocking($this->getUser())) {
// don't notify users blocking you
return;
}
$mentioned->sendNotification(new SubmissionMention($mentioned, $this));
}
public function getImage(): ?string {
......
......@@ -259,6 +259,20 @@ class User implements UserInterface, EquatableInterface {
*/
private $showThumbnails = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $notifyOnReply = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $notifyOnMentions = true;
public function __construct(string $username, string $password, \DateTime $created = null) {
$this->setUsername($username);
$this->password = $password;
......@@ -646,6 +660,22 @@ class User implements UserInterface, EquatableInterface {
$this->showThumbnails = $showThumbnails;
}
public function getNotifyOnReply(): bool {
return $this->notifyOnReply;
}
public function setNotifyOnReply(bool $notifyOnReply): void {
$this->notifyOnReply = $notifyOnReply;
}
public function getNotifyOnMentions(): bool {
return $this->notifyOnMentions;
}
public function setNotifyOnMentions(bool $notifyOnMentions): void {
$this->notifyOnMentions = $notifyOnMentions;
}
/**
* Returns the normalized form of the username.
*
......
......@@ -80,6 +80,10 @@ class UserData implements UserInterface {
private $showThumbnails;
private $notifyOnReply;
private $notifyOnMentions;
private $admin = false;
public static function fromUser(User $user): self {
......@@ -97,6 +101,8 @@ class UserData implements UserInterface {
$self->autoFetchSubmissionTitles = $user->autoFetchSubmissionTitles();
$self->enablePostPreviews = $user->enablePostPreviews();
$self->showThumbnails = $user->showThumbnails();
$self->notifyOnReply = $user->getNotifyOnReply();
$self->notifyOnMentions = $user->getNotifyOnMentions();
$self->admin = $user->isAdmin();
return $self;
......@@ -120,6 +126,8 @@ class UserData implements UserInterface {
$user->setAutoFetchSubmissionTitles($this->autoFetchSubmissionTitles);
$user->setEnablePostPreviews($this->enablePostPreviews);
$user->setShowThumbnails($this->showThumbnails);
$user->setNotifyOnReply($this->notifyOnReply);
$user->setNotifyOnMentions($this->notifyOnMentions);
$user->setAdmin($this->admin);
}
......@@ -139,6 +147,8 @@ class UserData implements UserInterface {
'autoFetchSubmissionTitles',
'enablePostPreviews',
'showThumbnails',
'notifyOnReply',
'notifyOnMentions',
];
foreach ($settings as $setting) {
......@@ -274,6 +284,22 @@ class UserData implements UserInterface {
$this->showThumbnails = $showThumbnails;
}
public function getNotifyOnReply(): ?bool {
return $this->notifyOnReply;
}
public function setNotifyOnReply(bool $notifyOnReply): void {
$this->notifyOnReply = $notifyOnReply;
}
public function getNotifyOnMentions(): ?bool {
return $this->notifyOnMentions;
}
public function setNotifyOnMentions(bool $notifyOnMentions): void {
$this->notifyOnMentions = $notifyOnMentions;
}
public function isAdmin(): bool {
return $this->admin;
}
......
......@@ -88,6 +88,16 @@ final class UserSettingsType extends AbstractType {
'label' => 'label.show_thumbnails',
'required' => false,
])
->add('notifyOnReply', CheckboxType::class, [
'help' => 'help.notify_on_reply',
'label' => 'label.notify_on_reply',
'required' => false,
])
->add('notifyOnMentions', CheckboxType::class, [
'help' => 'help.notify_on_mentions',
'label' => 'label.notify_on_mentions',
'required' => false,
])
->add('save', SubmitType::class);
}
......
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20190324150011 extends AbstractMigration {
public function getDescription(): string {
return 'Add notification preferences';
}
public function up(Schema $schema): void {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users ADD notify_on_reply BOOLEAN DEFAULT TRUE NOT NULL');
$this->addSql('ALTER TABLE users ADD notify_on_mentions BOOLEAN DEFAULT TRUE NOT NULL');
}
public function down(Schema $schema): void {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users DROP notify_on_reply');
$this->addSql('ALTER TABLE users DROP notify_on_mentions');
}
}
{% use '_forms/standard_form_theme.html.twig' with form_label as parent_form_label %}
{% use '_forms/standard_form_theme.html.twig' with
form_label as parent_form_label,
form_help as parent_form_help
%}
{% block checkbox_label %}
{{- block('parent_form_label') -}}
......@@ -8,7 +11,7 @@
<div>
{{ form_errors(form) }}
<div class="form-row form-row--single-line form-row--no-collapse">
<span class="form-row__align" role="presentation"></span>
<span class="form-row__align" aria-hidden="true"></span>
{{ form_widget(form) }}
{{ form_label(form) }}
</div>
......@@ -31,3 +34,12 @@
{{ form_help(form) }}
</div>
{%- endblock form_row %}
{%- block form_help -%}
{%- if help -%}
<div class="form-row form-row--single-line">
<div class="form-row__align" aria-hidden="true"></div>
{{ block('parent_form_help') }}
</div>
{%- endif -%}
{%- endblock form_help -%}
......@@ -43,6 +43,19 @@
</span>
{%- endblock checkbox_row %}
{% block form_help -%}
{%- if help is not empty -%}
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('') ~ ' form-help')|trim}) -%}
<p id="{{ id }}_help"{% with { attr: help_attr } %}{{ block('attributes') }}{% endwith %}>
{%- if translation_domain is same as(false) -%}
{{- help -}}
{%- else -%}
{{- help|trans({}, translation_domain) -}}
{%- endif -%}
</p>
{%- endif -%}
{%- endblock form_help %}
{%- block form_row -%}
{{- form_errors(form) -}}
<div class="form-row form__row">
......
......@@ -29,6 +29,14 @@
{{ form_row(form.enablePostPreviews) }}
</fieldset>
<fieldset class="fieldset form__group">
<legend class="form__group-header">{{ 'heading.notifications'|trans }}</legend>
{{ form_row(form.notifyOnReply) }}
{{ form_row(form.notifyOnMentions) }}
</fieldset>
<fieldset class="fieldset form__group">
<legend class="form__group-header">{{ 'label.appearance'|trans }}</legend>
......
......@@ -199,6 +199,7 @@ heading:
you_were_mentioned: You were mentioned by %user%
search: Search
search_results: '{0} No results for %query%|{1} 1 result for %query%:|]1,Inf[ %count% results for %query%:'
notifications: Notifications
help:
delete_forum_warning: All content on this forum will be irreversibly deleted!
......@@ -219,6 +220,8 @@ help:
still subscribe to and moderate forums you choose to hide.
hidden_forums_no_comment_hiding: Comments posted to hidden forums will still be displayed in the "recent comments" listing.
required_field: This field is required.
notify_on_reply: Get notifications when someone replies to your posts.
notify_on_mentions: Get notifications when someone links to your user profile.
inbox:
message_reply_head: 'Re: %title%'
......@@ -319,6 +322,8 @@ label:
search: Search for a post...
show_thumbnails: Show thumbnails
search_query: Search query
notify_on_reply: Notify on reply
notify_on_mentions: Notify on mentions
log:
comment_deletion: '%user% deleted comment by %author% in "%submission%"'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment