Skip to content

Commit

Permalink
[mentions] feat: group mentions (#3658)
Browse files Browse the repository at this point in the history
* wip: group mentions

* Apply fixes from StyleCI

* chore: format

* group mention autocomplete

* chore: format

* remove console.log

* implement notifications

* prevent guest and member groups from being mentioned

* Update extensions/mentions/less/forum.less

Co-authored-by: Sami Mazouz <[email protected]>

* rename displayname to groupname

* Update extensions/mentions/src/Formatter/FormatGroupMentions.php

Co-authored-by: Sami Mazouz <[email protected]>

* remove redundant unparse

* simplify migrations

* add group deleted translation

* Apply fixes from StyleCI

* handle everything falsy

* Include icon in group mention preview

* remove box-shadow from autocomplete group results

* Add color to preview

* chore: format

* Remove box shadow from group autocomplete results

* Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php

Co-authored-by: Sami Mazouz <[email protected]>

* remove unneeded migration

* prevent former group icon from beingdisplayed

* add group searcher with permissions

* Apply fixes from StyleCI

* Search groups based on canSearchGroups permission

* Don't include virtual groups in results

* Add search groups translation

* Revert "remove unneeded migration"

This reverts commit 9347665baa1820ed0875c6b2dd22b14fbc2768e7.

* Revert "Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php"

This reverts commit 8406d51df276d8f14917bfdc45a86e6b847784b7.

* add searchGroups permission to tests

* Apply fixes from StyleCI

* Add default searchGroups permission

* Apply fixes from StyleCI

* Update extensions/mentions/js/src/forum/addComposerAutocomplete.js

Co-authored-by: Sami Mazouz <[email protected]>

* Update extensions/mentions/migrations/2022_10_21_000000_create_post_mentions_groups_table.php

Co-authored-by: Sami Mazouz <[email protected]>

* remove unneeded migration, correct table table

* correct table name in down migration

* Remove group searcher

* Apply fixes from StyleCI

* Remove group searching from composer autocomplete

* Add mentionGroups permission

* Apply fixes from StyleCI

* prevent post preview from rendering a group mention when user does not have permission

* remove test changes

* wip: expose ServerRequestInterface to textformatter parse()

* Apply fixes from StyleCI

* Set post content properly

* php 7.x compatibility

* begin adding groupmention tests

* Apply fixes from StyleCI

* test virtual groups don't mention

* Apply fixes from StyleCI

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update extensions/mentions/extend.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update extensions/mentions/extend.php

Co-authored-by: Sami Mazouz <[email protected]>

* requested changes

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/tests/integration/api/groups/ListTest.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/src/Search/SearchServiceProvider.php

Co-authored-by: Sami Mazouz <[email protected]>

* Update framework/core/src/Extend/Formatter.php

Co-authored-by: Sami Mazouz <[email protected]>

* remove default permission migration

* try using datetime column instead of timestamp

* Apply fixes from StyleCI

* chore: remove commented code

* add tests

* Apply fixes from StyleCI

* Pass actor to parser instead of ServerRequest

* Allow for  to be null

* Update framework/core/src/Extend/Formatter.php

Co-authored-by: Sami Mazouz <[email protected]>

* pass actor instead of request

* Apply fixes from StyleCI

* actor instead of request

* remove serverrequest

* Apply fixes from StyleCI

* remove dupe actor

* Update extensions/mentions/src/Formatter/CheckPermissions.php

Co-authored-by: Sami Mazouz <[email protected]>

* fix type in comment

* group does not have the relation, post does

* test: invalid, deleted, fresh data mentions

Signed-off-by: Sami Mazouz <[email protected]>

* Apply fixes from StyleCI

* fix: group mentions don't work when editing posts

Signed-off-by: Sami Mazouz <[email protected]>

Signed-off-by: Sami Mazouz <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: Sami Mazouz <[email protected]>
  • Loading branch information
3 people authored Nov 5, 2022
1 parent 1ebf4b6 commit f54bd6f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Extend/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function configure($callback): self
* - \s9e\TextFormatter\Parser $parser
* - mixed $context
* - string $text: The text to be parsed.
* - \Flarum\User\User|null $actor. This argument MUST either be nullable, or omitted entirely.
*
* The callback should return:
* - string $text: The text to be parsed.
Expand Down
6 changes: 4 additions & 2 deletions src/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Flarum\Formatter;

use Flarum\User\User;
use Illuminate\Contracts\Cache\Repository;
use Psr\Http\Message\ServerRequestInterface;
use s9e\TextFormatter\Configurator;
Expand Down Expand Up @@ -83,14 +84,15 @@ public function addRenderingCallback($callback)
*
* @param string $text
* @param mixed $context
* @param User|null $user
* @return string
*/
public function parse($text, $context = null)
public function parse($text, $context = null, User $user = null)
{
$parser = $this->getParser($context);

foreach ($this->parsingCallbacks as $callback) {
$text = $callback($parser, $context, $text);
$text = $callback($parser, $context, $text, $user);
}

return $parser->parse($text);
Expand Down
3 changes: 2 additions & 1 deletion src/Post/Command/PostReplyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function handle(PostReply $command)
$discussion->id,
Arr::get($command->data, 'attributes.content'),
$actor->id,
$command->ipAddress
$command->ipAddress,
$command->actor,
);

if ($actor->isAdmin() && ($time = Arr::get($command->data, 'attributes.createdAt'))) {
Expand Down
12 changes: 7 additions & 5 deletions src/Post/CommentPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class CommentPost extends Post
* @param string $content
* @param int $userId
* @param string $ipAddress
* @param User|null $actor
* @return static
*/
public static function reply($discussionId, $content, $userId, $ipAddress)
public static function reply($discussionId, $content, $userId, $ipAddress, User $actor = null)
{
$post = new static;

Expand All @@ -57,7 +58,7 @@ public static function reply($discussionId, $content, $userId, $ipAddress)
$post->ip_address = $ipAddress;

// Set content last, as the parsing may rely on other post attributes.
$post->content = $content;
$post->setContentAttribute($content, $actor);

$post->raise(new Posted($post));

Expand All @@ -74,7 +75,7 @@ public static function reply($discussionId, $content, $userId, $ipAddress)
public function revise($content, User $actor)
{
if ($this->content !== $content) {
$this->content = $content;
$this->setContentAttribute($content, $actor);

$this->edited_at = Carbon::now();
$this->edited_user_id = $actor->id;
Expand Down Expand Up @@ -145,10 +146,11 @@ public function getParsedContentAttribute()
* Parse the content before it is saved to the database.
*
* @param string $value
* @param User $actor
*/
public function setContentAttribute($value)
public function setContentAttribute($value, User $actor = null)
{
$this->attributes['content'] = $value ? static::$formatter->parse($value, $this) : null;
$this->attributes['content'] = $value ? static::$formatter->parse($value, $this, $actor ?? $this->user) : null;
}

/**
Expand Down

0 comments on commit f54bd6f

Please sign in to comment.