diff options
author | Kegan Dougal <kegan@matrix.org> | 2014-10-29 17:43:18 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2014-10-29 17:44:57 +0000 |
commit | 0f192579ac9262ae07eeb0865a8565c37326e968 (patch) | |
tree | 2654ec7a7f25402aff8c8b6b85bf3f974c093305 /webclient/components | |
parent | Use floating-point rather than integer division to handle timeouts so that no... (diff) | |
download | synapse-0f192579ac9262ae07eeb0865a8565c37326e968.tar.xz |
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.
Diffstat (limited to 'webclient/components')
-rw-r--r-- | webclient/components/matrix/event-handler-service.js | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 373f18e8a5..3b1354cdef 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() { |