Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notification unsubscribe & email overhaul with HTML multipart #3872

Merged
merged 61 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2e09b45
feat: notification unsubscribe links
imorland Aug 19, 2023
d247b40
Apply fixes from StyleCI
StyleCIBot Aug 19, 2023
cb1ccb7
use PHPStan array shape
imorland Aug 20, 2023
76604bb
remove docblocks
imorland Aug 20, 2023
79928b0
docblock types for UnsubscibeToken model
imorland Aug 20, 2023
5df7197
typo
imorland Aug 20, 2023
e1ab8e5
create setNotificationPreference on the User model
imorland Aug 20, 2023
ad4fc00
attempt to fix phpstan error
imorland Aug 20, 2023
c3ce914
Rename getEmailView to getEmailViews to better reflect the function. …
imorland Aug 20, 2023
c81c16e
check both plain and html views are provided to the mailer
imorland Aug 20, 2023
7bdb956
Apply fixes from StyleCI
StyleCIBot Aug 20, 2023
aed4336
add translations to UnsubscribeController
imorland Aug 20, 2023
500b726
remove commented code
imorland Aug 20, 2023
3b1b08b
phpstan possible fix?
imorland Aug 20, 2023
14c9284
unsubscribe via confirmation page and POST request
imorland Aug 21, 2023
7944a31
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
556544b
back to forum is now a hyperlink rather than button
imorland Aug 21, 2023
93441b7
remove commented code
imorland Aug 21, 2023
ace1804
refactor templates into either notification or informational
imorland Aug 21, 2023
c4c86a2
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
670a323
update path
imorland Aug 21, 2023
900cd73
extract greeting and handle globally
imorland Aug 21, 2023
b977caa
no need to pass displayname to translation anymore
imorland Aug 21, 2023
c281005
dont get the forum title twice!
imorland Aug 21, 2023
989624a
make displayname available to informational emails
imorland Aug 21, 2023
1325e0f
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
ecd99ca
format
imorland Aug 21, 2023
aa55d10
introduce translations to the plain templates (wip)
imorland Aug 21, 2023
f1e553e
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
0911f7a
fix typo of plain email view
imorland Aug 21, 2023
629eb9b
improve html email output readability
imorland Aug 21, 2023
98242c6
Begin breaking down html templates to allow for better control of the…
imorland Aug 21, 2023
0ea64f7
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
4171a02
allow config.php to specify outgoing mail format
imorland Aug 21, 2023
2971e01
Apply fixes from StyleCI
StyleCIBot Aug 21, 2023
cb7b302
add email signoff translation
imorland Aug 21, 2023
d2f3977
fix renderer issues
imorland Aug 21, 2023
87d4111
Include forum logo in html base template, if it's available
imorland Sep 13, 2023
feff34c
Update html notification templates
imorland Sep 13, 2023
bac74a7
Apply fixes from StyleCI
StyleCIBot Sep 13, 2023
3eac530
feedback: use formatter in blade templates, use post content renderer
imorland Sep 18, 2023
48224ff
chore: remove wip code
imorland Sep 18, 2023
c20540d
Apply fixes from StyleCI
StyleCIBot Sep 18, 2023
b0d688e
Update framework/core/src/Forum/Controller/UnsubscribeActionControlle…
imorland Sep 18, 2023
d3f4b5f
use markdown in email footer translations
imorland Sep 18, 2023
a3d6127
use markdown
imorland Sep 18, 2023
8356497
move mailer to mail namespace
imorland Sep 18, 2023
a60410b
Use combined type MailableInterface&BlueprintInterface
imorland Sep 18, 2023
6a1786f
Mail format config
imorland Sep 18, 2023
2b0352a
extract mail settings to ItemList
imorland Sep 18, 2023
9350518
use hasSection
imorland Sep 18, 2023
86b6089
phpstan error
imorland Sep 18, 2023
b31780b
stan, again
imorland Sep 18, 2023
0185c34
Merge branch '2.x' into im/unsubscribe-links
imorland Sep 18, 2023
6197de3
fix suspension not rendering the reason in html view
imorland Sep 18, 2023
b77e0a8
remove recipient_display_name
imorland Sep 18, 2023
55680c4
add mail_format to install step
imorland Sep 26, 2023
412a207
allow greeting or signoff to be disabled per template, or globally
imorland Sep 28, 2023
c4901f7
chore: re-use the existing information email job
SychO9 Sep 29, 2023
499f203
fix: allow disabling greeting from email blade template
SychO9 Sep 29, 2023
91da308
fix: error
SychO9 Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions extensions/mentions/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,43 @@ flarum-mentions:
# These translations are used in emails sent when a post is replied to
post_mentioned:
subject: "{replier_display_name} replied to your post in {title}"
body: |
Hey {recipient_display_name}!
plain:
body: |
{replier_display_name} replied to your post (#{post_number}) in {title}.

{replier_display_name} replied to your post (#{post_number}) in {title}.
{url}

{url}
---

---

{content}
{content}
html:
body: "{replier_display_name} replied to your post (#{post_number}) in [{title}]({url})."

# These translations are used in emails sent when a user is mentioned
user_mentioned:
subject: "{mentioner_display_name} mentioned you in {title}"
body: |
Hey {recipient_display_name}!

{mentioner_display_name} mentioned you in a post in {title}.
plain:
body: |
{mentioner_display_name} mentioned you in a post in {title}.

{url}
{url}

---
---

{content}
{content}
html:
body: "{mentioner_display_name} mentioned you in a post in [{title}]({url})."
# These translations are used in emails sent when a group is mentioned
group_mentioned:
subject: "{mentioner_display_name} mentioned a group you're a member of in {title}"
body: |
Hey {recipient_display_name}!

{mentioner_display_name} mentioned a group you're a member of in {title}.
plain:
body: |
{mentioner_display_name} mentioned a group you're a member of in {title}.

{url}
{url}

---
---

{content}
{content}
html:
body: "{mentioner_display_name} mentioned a group you're a member of in [{title}]({url})."
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public function getData(): mixed
return null;
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-mentions::emails.groupMentioned'];
return [
'text' => 'flarum-mentions::emails.plain.groupMentioned',
'html' => 'flarum-mentions::emails.html.groupMentioned', ];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public function getData(): array
return ['replyNumber' => (int) $this->reply->number];
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-mentions::emails.postMentioned'];
return [
'text' => 'flarum-mentions::emails.plain.postMentioned',
'html' => 'flarum-mentions::emails.html.postMentioned',
];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ public function getData(): mixed
return null;
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-mentions::emails.userMentioned'];
return [
'text' => 'flarum-mentions::emails.plain.userMentioned',
'html' => 'flarum-mentions::emails.html.userMentioned'
];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
13 changes: 13 additions & 0 deletions extensions/mentions/views/emails/html/groupMentioned.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $formatter->convert($translator->trans('flarum-mentions.email.group_mentioned.html.body', [
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number])
])) !!}
@endsection

@section('contentPreview')
{!! $blueprint->post->formatContent() !!}
@endsection
14 changes: 14 additions & 0 deletions extensions/mentions/views/emails/html/postMentioned.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $formatter->convert($translator->trans('flarum-mentions.email.post_mentioned.html.body', [
'{replier_display_name}' => $blueprint->reply->user->display_name,
'{post_number}' => $blueprint->post->number,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->reply->discussion_id, 'near' => $blueprint->reply->number])
])) !!}
@endsection

@section('contentPreview')
{!! $blueprint->reply->formatContent() !!}
@endsection
13 changes: 13 additions & 0 deletions extensions/mentions/views/emails/html/userMentioned.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $formatter->convert($translator->trans('flarum-mentions.email.user_mentioned.html.body', [
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number])
])) !!}
@endsection

@section('contentPreview')
{!! $blueprint->post->formatContent() !!}
@endsection
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{!! $translator->trans('flarum-mentions.email.group_mentioned.body', [
'{recipient_display_name}' => $user->display_name,
@extends('flarum.forum::email.plain.notification.base')

@section('content')
{!! $translator->trans('flarum-mentions.email.group_mentioned.plain.body', [
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
'{content}' => $blueprint->post->content
]) !!}
@endsection
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{!! $translator->trans('flarum-mentions.email.post_mentioned.body', [
'{recipient_display_name}' => $user->display_name,
@extends('flarum.forum::email.plain.notification.base')

@section('content')
{!! $translator->trans('flarum-mentions.email.post_mentioned.plain.body', [
'{replier_display_name}' => $blueprint->reply->user->display_name,
'{post_number}' => $blueprint->post->number,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->reply->discussion_id, 'near' => $blueprint->reply->number]),
'{content}' => $blueprint->reply->content
]) !!}
@endsection
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{!! $translator->trans('flarum-mentions.email.user_mentioned.body', [
'{recipient_display_name}' => $user->display_name,
@extends('flarum.forum::email.plain.notification.base')

@section('content')
{!! $translator->trans('flarum-mentions.email.user_mentioned.plain.body', [
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
'{content}' => $blueprint->post->content
]) !!}
@endsection
22 changes: 13 additions & 9 deletions extensions/subscriptions/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,25 @@ flarum-subscriptions:
# These translations are used in emails sent when a post is made in a subscribed discussion
new_post:
subject: "[New Post] {title}"
body: |
Hey {recipient_display_name}!
plain:
body: |
{poster_display_name} just posted in a discussion you're following: {title}.

{poster_display_name} made a post in a discussion you're following: {title}.
To view the new activity, check out the following link:
{url}

To view the new activity, check out the following link:
{url}
---

---
{content}

{content}
---

---
You won't receive any more notifications about this discussion until you're up-to-date.
html:
body: |
{poster_display_name} just posted in a discussion you're following: [{title}]({url}).

You won't receive any more notifications about this discussion until you're up-to-date.
You won't recieve any more notifications about this discussion until you're up-to-date.

##
# REUSED TRANSLATIONS - These keys should not be used directly in code!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public function getData(): array
return ['postNumber' => (int) $this->post->number];
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-subscriptions::emails.newPost'];
return [
'text' => 'flarum-subscriptions::emails.plain.newPost',
'html' => 'flarum-subscriptions::emails.html.newPost', ];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
13 changes: 13 additions & 0 deletions extensions/subscriptions/views/emails/html/newPost.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $formatter->convert($translator->trans('flarum-subscriptions.email.new_post.html.body', [
'{poster_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number])
])) !!}
@endsection

@section('contentPreview')
{!! $blueprint->post->formatContent() !!}
@endsection
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{!! $translator->trans('flarum-subscriptions.email.new_post.body', [
'{recipient_display_name}' => $user->display_name,
@extends('flarum.forum::email.plain.notification.base')

@section('content')
{!! $translator->trans('flarum-subscriptions.email.new_post.plain.body', [
'{poster_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number]),
'{content}' => $blueprint->post->content
]) !!}
@endsection
26 changes: 14 additions & 12 deletions extensions/suspend/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,22 @@ flarum-suspend:
no_reason_given: No reason was given for this suspension.
suspended:
subject: Your account has been suspended
body: |
Hey {recipient_display_name},
plain:
body: |
You have been suspended for the following reason:

You have been suspended for the following reason:

---
{suspension_message}
---
---
{suspension_message}
---
html:
body: "You have been suspended from {forumTitle} for the following reason:"

unsuspended:
subject: Your account has been unsuspended
body: |
Hey {recipient_display_name},

You have been unsuspended. You can head back to the forum by clicking on the following link:
plain:
body: |
You have been unsuspended. You can head back to the forum by clicking on the following link:

{forum_url}
{forum_url}
html:
body: "You have been unsuspended. You can head back to [{forumTitle}]({forum_url}) when you are ready."
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Flarum\Suspend\Notification;

use Carbon\Carbon;
use Carbon\CarbonInterface;
use Flarum\Database\AbstractModel;
use Flarum\Locale\TranslatorInterface;
Expand All @@ -35,7 +36,7 @@ public function getFromUser(): ?User

public function getData(): CarbonInterface
{
return $this->user->suspended_until;
return Carbon::now();
}

public static function getType(): string
Expand All @@ -48,9 +49,11 @@ public static function getSubjectModel(): string
return User::class;
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-suspend::emails.suspended'];
return [
'text' => 'flarum-suspend::emails.plain.suspended',
'html' => 'flarum-suspend::emails.html.suspended', ];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ public static function getSubjectModel(): string
return User::class;
}

public function getEmailView(): string|array
public function getEmailViews(): array
{
return ['text' => 'flarum-suspend::emails.unsuspended'];
return [
'text' => 'flarum-suspend::emails.plain.unsuspended',
'html' => 'flarum-suspend::emails.html.unsuspended', ];
}

public function getEmailSubject(TranslatorInterface $translator): string
Expand Down
11 changes: 11 additions & 0 deletions extensions/suspend/views/emails/html/suspended.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@extends('flarum.forum::email.html.information.base')

@section('informationContent')
{!! $formatter->convert($translator->trans('flarum-suspend.email.suspended.html.body', [
'{forumTitle}' => $settings->get('forum_title')
])) !!}
@endsection

@section('contentPreview')
{!! $formatter->convert($blueprint->user->suspend_message ?? $translator->trans('flarum-suspend.email.no_reason_given')) !!}
@endsection
8 changes: 8 additions & 0 deletions extensions/suspend/views/emails/html/unsuspended.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@extends('flarum.forum::email.html.information.base')

@section('content')
{!! $formatter->convert($translator->trans('flarum-suspend.email.unsuspended.html.body', [
'{forumTitle}' => $settings->get('forum_title'),
'{forum_url}' => $url->to('forum')->base(),
])) !!}
@endsection
7 changes: 7 additions & 0 deletions extensions/suspend/views/emails/plain/suspended.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('flarum.forum::email.plain.information.base')

@section('content')
{!! $translator->trans('flarum-suspend.email.suspended.plain.body', [
'{suspension_message}' => $blueprint->user->suspend_message ?? $translator->trans('flarum-suspend.email.no_reason_given'),
]) !!}
@endsection
7 changes: 7 additions & 0 deletions extensions/suspend/views/emails/plain/unsuspended.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@extends('flarum.forum::email.plain.information.base')

@section('content')
{!! $translator->trans('flarum-suspend.email.unsuspended.plain.body', [
'{forum_url}' => $url->to('forum')->base(),
]) !!}
@endsection
4 changes: 0 additions & 4 deletions extensions/suspend/views/emails/suspended.blade.php

This file was deleted.

4 changes: 0 additions & 4 deletions extensions/suspend/views/emails/unsuspended.blade.php

This file was deleted.

Loading
Loading