From 0f192579ac9262ae07eeb0865a8565c37326e968 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 29 Oct 2014 17:43:18 +0000 Subject: [PATCH] SYWEB-48: Better regex for binging on usernames. This uses /\blocalpart\b|\bdisplayname\b/i which is overall a lot better than before. This specifically gets @localpart references which the bug was originally for. --- .../matrix/event-handler-service.js | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 373f18e8a..3b1354cde 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -58,14 +58,29 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) { var shouldBing = false; // case-insensitive name check for user_id OR display_name if they exist + var userRegex = ""; var myUserId = matrixService.config().user_id; if (myUserId) { - myUserId = myUserId.toLocaleLowerCase(); + var localpart = getLocalPartFromUserId(myUserId); + if (localpart) { + localpart = localpart.toLocaleLowerCase(); + userRegex += "\\b" + localpart + "\\b"; + } } var myDisplayName = matrixService.config().display_name; if (myDisplayName) { myDisplayName = myDisplayName.toLocaleLowerCase(); + if (userRegex.length > 0) { + userRegex += "|"; + } + userRegex += "\\b" + myDisplayName + "\\b"; } + + var r = new RegExp(userRegex, 'i'); + if (content.search(r) >= 0) { + shouldBing = true; + } + if ( (myDisplayName && content.toLocaleLowerCase().indexOf(myDisplayName) != -1) || (myUserId && content.toLocaleLowerCase().indexOf(myUserId) != -1) ) { shouldBing = true; @@ -84,6 +99,18 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) { return shouldBing; }; + var getLocalPartFromUserId = function(user_id) { + if (!user_id) { + return null; + } + var localpartRegex = /@(.*):\w+/i + var results = localpartRegex.exec(user_id); + if (results && results.length == 2) { + return results[1]; + } + return null; + }; + var initialSyncDeferred; var reset = function() {