Merge pull request #25378 from nextcloud/bugfix/noid/mention-match-improvements
Improve mention matches
This commit is contained in:
commit
d5dea10517
|
@ -213,17 +213,11 @@ class Provider implements IProvider {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pattern = '/(^|\s)(' . '@' . $mention['id'] . ')(\b)/';
|
$message = str_replace('@"' . $mention['id'] . '"', '{mention' . $mentionCount . '}', $message);
|
||||||
if (strpos($mention['id'], ' ') !== false) {
|
if (strpos($mention['id'], ' ') === false && strpos($mention['id'], 'guest/') !== 0) {
|
||||||
$pattern = '/(^|\s)(' . '@"' . $mention['id'] . '"' . ')(\b)?/';
|
$message = str_replace('@' . $mention['id'], '{mention' . $mentionCount . '}', $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = preg_replace(
|
|
||||||
$pattern,
|
|
||||||
//'${1}' . $this->regexSafeUser($mention['id'], $displayName) . '${3}',
|
|
||||||
'${1}' . '{mention' . $mentionCount . '}' . '${3}',
|
|
||||||
$message
|
|
||||||
);
|
|
||||||
$mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']);
|
$mentions['mention' . $mentionCount] = $this->generateUserParameter($mention['id']);
|
||||||
$mentionCount++;
|
$mentionCount++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,11 @@ class Notifier implements INotifier {
|
||||||
// could contain characters like '@' for user IDs) but a one-based
|
// could contain characters like '@' for user IDs) but a one-based
|
||||||
// index of the mentions of that type.
|
// index of the mentions of that type.
|
||||||
$mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']];
|
$mentionParameterId = 'mention-' . $mention['type'] . $mentionTypeCount[$mention['type']];
|
||||||
|
$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('@' . $mention['id'], '{' . $mentionParameterId . '}', $message);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
|
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
|
||||||
} catch (\OutOfBoundsException $e) {
|
} catch (\OutOfBoundsException $e) {
|
||||||
|
|
|
@ -233,6 +233,9 @@ class Comment implements IComment {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$uids = array_unique($mentions[0]);
|
$uids = array_unique($mentions[0]);
|
||||||
|
usort($uids, static function ($uid1, $uid2) {
|
||||||
|
return mb_strlen($uid2) <=> mb_strlen($uid1);
|
||||||
|
});
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($uids as $uid) {
|
foreach ($uids as $uid) {
|
||||||
$cleanUid = trim(substr($uid, 1), '"');
|
$cleanUid = trim(substr($uid, 1), '"');
|
||||||
|
|
|
@ -149,7 +149,7 @@ class CommentTest extends TestCase {
|
||||||
' cc @23452-4333-54353-2342 @yolo!' .
|
' cc @23452-4333-54353-2342 @yolo!' .
|
||||||
' however the most important thing to know is that www.croissant.com/@oil is not valid' .
|
' however the most important thing to know is that www.croissant.com/@oil is not valid' .
|
||||||
' and won\'t match anything at all',
|
' and won\'t match anything at all',
|
||||||
['foobar', 'barfoo', 'foo@bar.com', 'bar@foo.org@foobar.io', '23452-4333-54353-2342', 'yolo']
|
['bar@foo.org@foobar.io', '23452-4333-54353-2342', 'foo@bar.com', 'foobar', 'barfoo', 'yolo']
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'@@chef is also a valid mention, no matter how strange it looks', ['@chef']
|
'@@chef is also a valid mention, no matter how strange it looks', ['@chef']
|
||||||
|
|
Loading…
Reference in New Issue