Improve mentions keyboard accessibility (#10173)

* Improve keyboard accessibility

* Add check for up down keys

* Add newline check for triggering

* Allow keyboard insertion of users

* Clear positional node errors on safari

* Add a little sanity check to please automated code checkers

* Use active instead of dashed

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
ian
2021-12-02 00:14:09 +08:00
committed by GitHub
parent 59c45c92e2
commit 32e0396b3e
4 changed files with 239 additions and 29 deletions

View File

@@ -10,6 +10,7 @@ import logger from '../logger';
import { userName } from '../utils/user-name';
import { uniq } from 'lodash';
import env from '../env';
import validateUUID from 'uuid-validate';
export class ActivityService extends ItemsService {
notificationsService: NotificationsService;
@@ -66,10 +67,13 @@ export class ActivityService extends ItemsService {
let comment = data.comment;
for (const mention of mentions) {
comment = comment.replace(mention, userPreviews[mention.substring(1)] ?? '@Unknown User');
const uuid = mention.substring(1);
// We only match on UUIDs in the first place. This is just an extra sanity check
if (validateUUID(uuid) === false) continue;
comment = comment.replace(new RegExp(mention, 'gm'), userPreviews[uuid] ?? '@Unknown User');
}
comment = `> ${comment}`;
comment = `> ${comment.replace(/\n+/gm, '\n> ')}`;
const message = `
Hello ${userName(user)},