Skip to content
Merged
Changes from 1 commit
Commits
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
Next Next commit
Fix mentioning users with subnames
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Jan 29, 2021
commit 152fd2ffe5907c9ab3d3901fbc54c340e4e8eece
13 changes: 8 additions & 5 deletions lib/Chat/Parser/UserMention.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public function parseMessage(Message $chatMessage): void {
$mentionTypeCount = [];

$mentions = $comment->getMentions();
// TODO This can be removed once getMentions() returns sorted results (Nextcloud 21+)
usort($mentions, static function ($m1, $m2) {
return mb_strlen($m2['id']) <=> mb_strlen($m1['id']);
});

foreach ($mentions as $mention) {
if ($mention['type'] === 'user' && $mention['id'] === 'all') {
$mention['type'] = 'call';
Expand All @@ -101,12 +106,10 @@ public function parseMessage(Message $chatMessage): void {
// index of the mentions of that type.
$mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']];

if (strpos($mention['id'], ' ') !== false || strpos($mention['id'], 'guest/') === 0) {
$placeholder = '@"' . $mention['id'] . '"';
} else {
$placeholder = '@' . $mention['id'];
$message = str_replace('@"' . $mention['id'] . '"', '{' . $mentionParameterId . '}', $message);
if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) {
$message = str_replace('@' . $mention['id'], '{' . $mentionParameterId . '}', $message);
}
$message = str_replace($placeholder, '{' . $mentionParameterId . '}', $message);

if ($mention['type'] === 'call') {
$messageParameters[$mentionParameterId] = [
Expand Down