From 512f2cc9c49d585b566b3f5200b85748359b4b1e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 23 Sep 2014 12:22:14 +0100 Subject: Fix SYWEB-8 : Buggy tab-complete. The first red blink was caused by an uninitialised search index. There is no caching of entries, since this then wouldn't update if someone joined/left during the tab. Instead, set to search index to MAX_VALUE then fix it to a valid index AFTER the search is complete. Also ditched trailing space on ": ". --- webclient/room/room-directive.js | 59 +++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'webclient') diff --git a/webclient/room/room-directive.js b/webclient/room/room-directive.js index e033b003e1..8db4cb5d9a 100644 --- a/webclient/room/room-directive.js +++ b/webclient/room/room-directive.js @@ -21,39 +21,53 @@ angular.module('RoomController') return function (scope, element, attrs) { element.bind("keydown keypress", function (event) { // console.log("event: " + event.which); - if (event.which === 9) { + var TAB = 9; + var SHIFT = 16; + var keypressCode = event.which; + if (keypressCode === TAB) { if (!scope.tabCompleting) { // cache our starting text - // console.log("caching " + element[0].value); scope.tabCompleteOriginal = element[0].value; scope.tabCompleting = true; + scope.tabCompleteIndex = 0; } + // loop in the right direction if (event.shiftKey) { scope.tabCompleteIndex--; if (scope.tabCompleteIndex < 0) { - scope.tabCompleteIndex = 0; + // wrap to the last search match, and fix up to a real + // index value after we've matched + scope.tabCompleteIndex = Number.MAX_VALUE; } } else { scope.tabCompleteIndex++; } + var searchIndex = 0; var targetIndex = scope.tabCompleteIndex; var text = scope.tabCompleteOriginal; - // console.log("targetIndex: " + targetIndex + ", text=" + text); + // console.log("targetIndex: " + targetIndex + ", + // text=" + text); // FIXME: use the correct regexp to recognise userIDs + // XXX: I don't really know what the point of this is. You + // WANT to match freeform text given you want to match display + // names AND user IDs. Surely you just want to get the last + // word out of the input text and that's that? + // Am I missing something here? -- Kegan var search = /@?([a-zA-Z0-9_\-:\.]+)$/.exec(text); - if (targetIndex === 0) { - element[0].value = text; - - // Force angular to wake up and update the input ng-model by firing up input event + + if (targetIndex === 0) { // 0 is always the original text + element[0].value = text; + // Force angular to wake up and update the input ng-model + // by firing up input event angular.element(element[0]).triggerHandler('input'); } else if (search && search[1]) { - // console.log("search found: " + search); + // console.log("search found: " + search+" from "+text); var expansion; // FIXME: could do better than linear search here @@ -68,6 +82,7 @@ angular.module('RoomController') if (searchIndex < targetIndex) { // then search raw mxids angular.forEach(scope.members, function(item, name) { if (searchIndex < targetIndex) { + // === 1 because mxids are @username if (name.toLowerCase().indexOf(search[1].toLowerCase()) === 1) { expansion = name; searchIndex++; @@ -76,18 +91,22 @@ angular.module('RoomController') }); } - if (searchIndex === targetIndex) { - // xchat-style tab complete + if (searchIndex === targetIndex || + targetIndex === Number.MAX_VALUE) { + // xchat-style tab complete, add a colon if tab + // completing at the start of the text if (search[0].length === text.length) - expansion += " : "; + expansion += ": "; else expansion += " "; element[0].value = text.replace(/@?([a-zA-Z0-9_\-:\.]+)$/, expansion); // cancel blink element[0].className = ""; - - // Force angular to wake up and update the input ng-model by firing up input event - angular.element(element[0]).triggerHandler('input'); + if (targetIndex === Number.MAX_VALUE) { + // wrap the index around to the last index found + scope.tabCompleteIndex = searchIndex; + targetIndex = searchIndex; + } } else { // console.log("wrapped!"); @@ -97,17 +116,19 @@ angular.module('RoomController') }, 150); element[0].value = text; scope.tabCompleteIndex = 0; - - // Force angular to wake up and update the input ng-model by firing up input event - angular.element(element[0]).triggerHandler('input'); } + + // Force angular to wak up and update the input ng-model by + // firing up input event + angular.element(element[0]).triggerHandler('input'); } else { scope.tabCompleteIndex = 0; } + // prevent the default TAB operation (typically focus shifting) event.preventDefault(); } - else if (event.which !== 16 && scope.tabCompleting) { + else if (keypressCode !== SHIFT && scope.tabCompleting) { scope.tabCompleting = false; scope.tabCompleteIndex = 0; } -- cgit 1.4.1 From 997a016122218dd51ee0d2fb2ddac1c61fce455b Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 23 Sep 2014 13:01:12 +0100 Subject: fix NPE --- webclient/components/matrix/event-handler-service.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'webclient') diff --git a/webclient/components/matrix/event-handler-service.js b/webclient/components/matrix/event-handler-service.js index 21066e3d9f..9c19f306c0 100644 --- a/webclient/components/matrix/event-handler-service.js +++ b/webclient/components/matrix/event-handler-service.js @@ -260,8 +260,7 @@ function(matrixService, $rootScope, $q, $timeout, mPresence) { if (event.content.prev !== event.content.membership) { memberChanges = "membership"; } - else if (event.prev_content.displayname !== - event.content.displayname) { + else if (event.prev_content && (event.prev_content.displayname !== event.content.displayname)) { memberChanges = "displayname"; } -- cgit 1.4.1 From 4847045259a631a2f1e03fd9751df301e6589560 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 23 Sep 2014 13:36:58 +0100 Subject: send messages to users from the home page (SYWEB-19) --- webclient/home/home-controller.js | 30 ++++++++++++++++++++++++++++++ webclient/home/home.html | 13 ++++++++++--- webclient/user/user-controller.js | 3 ++- 3 files changed, 42 insertions(+), 4 deletions(-) (limited to 'webclient') diff --git a/webclient/home/home-controller.js b/webclient/home/home-controller.js index e35219bebb..a535d439d3 100644 --- a/webclient/home/home-controller.js +++ b/webclient/home/home-controller.js @@ -42,6 +42,10 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen displayName: "", avatarUrl: "" }; + + $scope.newChat = { + user: "" + }; var refresh = function() { @@ -112,6 +116,32 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen } ); }; + + // FIXME: factor this out between user-controller and home-controller etc. + $scope.messageUser = function() { + + // FIXME: create a new room every time, for now + + matrixService.create(null, 'private').then( + function(response) { + // This room has been created. Refresh the rooms list + var room_id = response.data.room_id; + console.log("Created room with id: "+ room_id); + + matrixService.invite(room_id, $scope.newChat.user).then( + function() { + $scope.feedback = "Invite sent successfully"; + $scope.$parent.goToPage("/room/" + room_id); + }, + function(reason) { + $scope.feedback = "Failure: " + JSON.stringify(reason); + }); + }, + function(error) { + $scope.feedback = "Failure: " + JSON.stringify(error.data); + }); + }; + $scope.onInit = function() { // Load profile data diff --git a/webclient/home/home.html b/webclient/home/home.html index 5a1e18e1de..0af382916e 100644 --- a/webclient/home/home.html +++ b/webclient/home/home.html @@ -17,7 +17,7 @@
{{ config.user_id }}
- +

Recent conversations


@@ -52,17 +52,24 @@
- + private
- +
+
+
+ + +
+
+
{{ feedback }} diff --git a/webclient/user/user-controller.js b/webclient/user/user-controller.js index 3940db6683..0dbfa325d0 100644 --- a/webclient/user/user-controller.js +++ b/webclient/user/user-controller.js @@ -38,7 +38,8 @@ angular.module('UserController', ['matrixService']) $scope.user.avatar_url = response.data.avatar_url; } ); - + + // FIXME: factor this out between user-controller and home-controller etc. $scope.messageUser = function() { // FIXME: create a new room every time, for now -- cgit 1.4.1 From e9c88ae4f42ad520814b139474a876706da22037 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Tue, 23 Sep 2014 15:18:45 +0200 Subject: Partial fix of SYWEB-28: If members do not have last_active_ago, compare their presence state to order them --- webclient/app-filter.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'webclient') diff --git a/webclient/app-filter.js b/webclient/app-filter.js index ee9374668b..0d059e1621 100644 --- a/webclient/app-filter.js +++ b/webclient/app-filter.js @@ -70,7 +70,23 @@ angular.module('matrixWebClient') }); filtered.sort(function (a, b) { - return ((a["last_active_ago"] || 10e10) > (b["last_active_ago"] || 10e10) ? 1 : -1); + // Sort members on their last_active_ago value + if (undefined !== a.last_active_ago || undefined !== b.last_active_ago) { + return ((a.last_active_ago || 10e10) > (b.last_active_ago || 10e10) ? 1 : -1); + } + else { + // If they do not have last_active_ago, sort them according to their presence state + // Online users go first amongs members who do not have last_active_ago + var presenceLevels = { + offline: 1, + unavailable: 2, + online: 4, + free_for_chat: 3 + }; + var aPresence = (a.presence in presenceLevels) ? presenceLevels[a.presence] : 0; + var bPresence = (b.presence in presenceLevels) ? presenceLevels[b.presence] : 0; + return bPresence - aPresence; + } }); return filtered; }; -- cgit 1.4.1 From c9f73bd3258e40f5728a9910f9f5051240ca682e Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 23 Sep 2014 16:11:12 +0100 Subject: fix one cause of SYWEB-53 --- webclient/components/matrix/matrix-filter.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'webclient') diff --git a/webclient/components/matrix/matrix-filter.js b/webclient/components/matrix/matrix-filter.js index 328e3a7086..1a64dc126c 100644 --- a/webclient/components/matrix/matrix-filter.js +++ b/webclient/components/matrix/matrix-filter.js @@ -49,15 +49,12 @@ angular.module('matrixFilter', []) if (member.state_key !== user_id) { if (member.state_key in $rootScope.presence) { - // If the user is available in presence, use the displayname there + // If the user is listed in presence, use the displayname there // as it is the most uptodate - roomName = $rootScope.presence[member.state_key].content.displayname; + roomName = $rootScope.presence[member.state_key].content.displayname || member.state_key; } - else if (member.content.displayname) { - roomName = member.content.displayname; - } - else { - roomName = member.state_key; + else { + roomName = member.content.displayname || member.state_key; } } } -- cgit 1.4.1 From 7d94913efb799654a8e51676bcb9813f2e453514 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 23 Sep 2014 16:12:06 +0100 Subject: remove old commented-out code --- webclient/components/matrix/matrix-service.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'webclient') diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index 069e02e939..79781f5d86 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -697,11 +697,10 @@ angular.module('matrixService', []) createRoomIdToAliasMapping: function(roomId, alias) { roomIdToAlias[roomId] = alias; aliasToRoomId[alias] = roomId; - // localStorage.setItem(MAPPING_PREFIX+roomId, alias); }, getRoomIdToAliasMapping: function(roomId) { - var alias = roomIdToAlias[roomId]; // was localStorage.getItem(MAPPING_PREFIX+roomId) + var alias = roomIdToAlias[roomId]; //console.log("looking for alias for " + roomId + "; found: " + alias); return alias; }, -- cgit 1.4.1 From e4e8ad6780abd63f766db13974ddc3d3c4f7528f Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Tue, 23 Sep 2014 17:25:37 +0200 Subject: SYWEB-28: Fixed weird members list ordering: sort members on their last activity absolute time --- webclient/app-filter.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'webclient') diff --git a/webclient/app-filter.js b/webclient/app-filter.js index 0d059e1621..9443446c9f 100644 --- a/webclient/app-filter.js +++ b/webclient/app-filter.js @@ -70,9 +70,16 @@ angular.module('matrixWebClient') }); filtered.sort(function (a, b) { - // Sort members on their last_active_ago value - if (undefined !== a.last_active_ago || undefined !== b.last_active_ago) { - return ((a.last_active_ago || 10e10) > (b.last_active_ago || 10e10) ? 1 : -1); + // Sort members on their last_active absolute time + var aLastActiveTS = 0, bLastActiveTS = 0; + if (undefined !== a.last_active_ago) { + aLastActiveTS = a.last_updated - a.last_active_ago; + } + if (undefined !== b.last_active_ago) { + bLastActiveTS = b.last_updated - b.last_active_ago; + } + if (aLastActiveTS || bLastActiveTS) { + return bLastActiveTS - aLastActiveTS; } else { // If they do not have last_active_ago, sort them according to their presence state -- cgit 1.4.1 From a7420ff2b5b2880bded6d13b548607028113397f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 23 Sep 2014 16:53:27 +0100 Subject: Fix SYWEB-72 : Improve performance when typing. Swapped ng-keydown to a directive, which does the same thing (check if up/down arrow then call history.goUp/goDown). This has *dramatically* improved performance when typing in rooms which have lots (>100) of messages loaded. --- webclient/room/room-directive.js | 15 +++++++++++++++ webclient/room/room.html | 3 +-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'webclient') diff --git a/webclient/room/room-directive.js b/webclient/room/room-directive.js index 8db4cb5d9a..d5108b5f1c 100644 --- a/webclient/room/room-directive.js +++ b/webclient/room/room-directive.js @@ -135,6 +135,21 @@ angular.module('RoomController') }); }; }]) +.directive('commandHistory', [ function() { + return function (scope, element, attrs) { + element.bind("keydown keypress", function (event) { + var keycodePressed = event.which; + var UP_ARROW = 38; + var DOWN_ARROW = 40; + if (keycodePressed === UP_ARROW) { + scope.history.goUp(event); + } + else if (keycodePressed === DOWN_ARROW) { + scope.history.goDown(event); + } + }); + } +}]) // A directive to anchor the scroller position at the bottom when the browser is resizing. // When the screen resizes, the bottom of the element remains the same, not the top. diff --git a/webclient/room/room.html b/webclient/room/room.html index c807e2afe1..2786246232 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -163,8 +163,7 @@