-
-
Notifications
You must be signed in to change notification settings - Fork 668
Add support for mentions to the editor #815
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
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e87555f
wip
joedixon 1534a0b
Capture input
joedixon deac419
Add support for participants
joedixon 0df98b1
Apply fixes from StyleCI
StyleCIBot 8c089ea
Refactor user select
joedixon f86d46b
Apply fixes from StyleCI
StyleCIBot 1b794b9
Add keyboard navigation
joedixon f36de71
Apply fixes from StyleCI
StyleCIBot b1320a4
Fix user loading
joedixon ae2bc1a
Apply fixes from StyleCI
StyleCIBot 8dda827
Make mentions optional
joedixon 0a067e3
Tidy component
joedixon 94baead
Match backend regex
joedixon 9a3416b
wip
joedixon c646992
Apply fixes from StyleCI
StyleCIBot 056afe3
Handle mentions
joedixon b0601dd
Stub tests
joedixon 373d9f8
Apply fixes from StyleCI
StyleCIBot e620e3f
Add tests
joedixon ecbb450
Apply fixes from StyleCI
StyleCIBot 90a59ec
Update formatting
joedixon d8b1c0d
Update code selection
joedixon 6c9114f
Apply fixes from StyleCI
StyleCIBot 724bd4a
Fix article title format
joedixon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,26 @@ | ||
| <?php | ||
|
|
||
| namespace App\Concerns; | ||
|
|
||
| use App\Models\ReplyAble; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Collection; | ||
|
|
||
| trait HasMentions | ||
| { | ||
| public function mentionedIn(): ReplyAble | ||
| { | ||
| if ($this instanceof ReplyAble) { | ||
| return $this; | ||
| } | ||
|
|
||
| return $this->replyAble(); | ||
| } | ||
|
|
||
| public function getMentionedUsers(): Collection | ||
| { | ||
| preg_match_all('/@([a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w))/', $this->body(), $matches); | ||
|
|
||
| return User::whereIn('username', $matches[1])->get(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| <?php | ||
|
|
||
| namespace App\Events; | ||
|
|
||
| use App\Models\Thread; | ||
| use Illuminate\Queue\SerializesModels; | ||
|
|
||
| final class ThreadWasCreated | ||
| { | ||
| use SerializesModels; | ||
|
|
||
| public function __construct( | ||
| public Thread $thread | ||
| ) { | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Listeners; | ||
|
|
||
| use App\Events\ReplyWasCreated; | ||
| use App\Notifications\MentionNotification; | ||
|
|
||
| final class NotifyUsersMentionedInReply | ||
| { | ||
| public function handle(ReplyWasCreated $event): void | ||
| { | ||
| $event->reply->getMentionedUsers()->each(function ($user) use ($event) { | ||
| $user->notify(new MentionNotification($event->reply)); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Listeners; | ||
|
|
||
| use App\Events\ThreadWasCreated; | ||
| use App\Notifications\MentionNotification; | ||
|
|
||
| final class NotifyUsersMentionedInThread | ||
| { | ||
| public function handle(ThreadWasCreated $event): void | ||
| { | ||
| $event->thread->getMentionedUsers()->each(function ($user) use ($event) { | ||
| $user->notify(new MentionNotification($event->thread)); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Listeners; | ||
|
|
||
| use App\Events\ReplyWasCreated; | ||
| use App\Models\Thread; | ||
|
|
||
| final class SubscribeUsersMentionedInReply | ||
| { | ||
| public function handle(ReplyWasCreated $event): void | ||
| { | ||
| $event->reply->getMentionedUsers()->each(function ($user) use ($event) { | ||
| $replyAble = $event->reply->mentionedIn(); | ||
|
|
||
| if ($replyAble instanceof Thread && ! $replyAble->hasSubscriber($user)) { | ||
| $replyAble->subscribe($user); | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Listeners; | ||
|
|
||
| use App\Events\ThreadWasCreated; | ||
|
|
||
| final class SubscribeUsersMentionedInThread | ||
| { | ||
| public function handle(ThreadWasCreated $event): void | ||
| { | ||
| $event->thread->getMentionedUsers()->each(function ($user) use ($event) { | ||
| if (! $event->thread->hasSubscriber($user)) { | ||
| $event->thread->subscribe($user); | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| <?php | ||
|
|
||
| namespace App\Mail; | ||
|
|
||
| use App\Models\MentionAble; | ||
| use App\Models\User; | ||
| use Illuminate\Mail\Mailable; | ||
|
|
||
| final class MentionEmail extends Mailable | ||
| { | ||
| public function __construct( | ||
| public MentionAble $mentionAble, | ||
| public User $receiver | ||
| ) { | ||
| } | ||
|
|
||
| public function build() | ||
| { | ||
| return $this->subject("Mentioned: {$this->mentionAble->mentionedIn()->subject()}") | ||
| ->markdown('emails.mention'); | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| namespace App\Models; | ||
|
|
||
| use Illuminate\Support\Collection; | ||
|
|
||
| interface MentionAble | ||
| { | ||
| public function body(): string; | ||
|
|
||
| public function excerpt(): string; | ||
|
|
||
| public function author(): User; | ||
|
|
||
| public function mentionedIn(): ReplyAble; | ||
|
|
||
| public function getMentionedUsers(): Collection; | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.