diff options
author | Matthew Hodgson <matthew@matrix.org> | 2014-08-29 17:21:57 +0100 |
---|---|---|
committer | Matthew Hodgson <matthew@matrix.org> | 2014-08-29 17:22:48 +0100 |
commit | b86d2a2d4fa6e9093bf08df88dce68e5f274c697 (patch) | |
tree | f6ac8fd7492cba165f3bc89f759f1010abb8ccfb | |
parent | Use str.join() properly (diff) | |
download | synapse-b86d2a2d4fa6e9093bf08df88dce68e5f274c697.tar.xz |
update presence times in realtime through the magic of two-way binding
-rw-r--r-- | webclient/room/room-controller.js | 48 | ||||
-rw-r--r-- | webclient/room/room.html | 2 |
2 files changed, 15 insertions, 35 deletions
diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 09dac85d26..ed7de62c08 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -88,7 +88,7 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) call.onHangup = $scope.onCallHangup; $scope.currentCall = call; }); - + $scope.memberCount = function() { return Object.keys($scope.members).length; }; @@ -175,6 +175,8 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) // set target_user_id to keep things clear var target_user_id = chunk.state_key; + + var now = new Date().getTime(); var isNewMember = !(target_user_id in $scope.members); if (isNewMember) { @@ -185,44 +187,14 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) if ("mtime_age" in chunk.content) { chunk.mtime_age = chunk.content.mtime_age; } - // Once the HS reliably returns the displaynames & avatar_urls for both - // local and remote users, we should use this rather than the evalAsync block - // below if ("displayname" in chunk.content) { chunk.displayname = chunk.content.displayname; } if ("avatar_url" in chunk.content) { chunk.avatar_url = chunk.content.avatar_url; } - $scope.members[target_user_id] = chunk; - -/* - // Stale code for explicitly hammering the homeserver for every displayname & avatar_url - - // get their display name and profile picture and set it to their - // member entry in $scope.members. We HAVE to use $timeout with 0 delay - // to make this function run AFTER the current digest cycle, else the - // response may update a STALE VERSION of the member list (manifesting - // as no member names appearing, or appearing sporadically). - $scope.$evalAsync(function() { - matrixService.getDisplayName(chunk.target_user_id).then( - function(response) { - var member = $scope.members[chunk.target_user_id]; - if (member !== undefined) { - member.displayname = response.data.displayname; - } - } - ); - matrixService.getProfilePictureUrl(chunk.target_user_id).then( - function(response) { - var member = $scope.members[chunk.target_user_id]; - if (member !== undefined) { - member.avatar_url = response.data.avatar_url; - } - } - ); - }); -*/ + chunk.last_updated = now; + $scope.members[target_user_id] = chunk; if (target_user_id in $rootScope.presence) { updatePresence($rootScope.presence[target_user_id]); @@ -234,6 +206,12 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) member.content.membership = chunk.content.membership; } }; + + var updateMemberListPresenceAge = function() { + $scope.now = new Date().getTime(); + //console.log("updateMemberListPresenceAge() - now = " + $scope.now); + $timeout(updateMemberListPresenceAge, 5 * 1000); + }; var updatePresence = function(chunk) { if (!(chunk.content.user_id in $scope.members)) { @@ -395,8 +373,10 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput']) // Make recents highlight the current room $scope.recentsSelectedRoomID = $scope.room_id; - + paginate(MESSAGES_PER_PAGINATION); + + updateMemberListPresenceAge(); }; $scope.inviteUser = function(user_id) { diff --git a/webclient/room/room.html b/webclient/room/room.html index a3514c3a91..cb9239ed56 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -25,7 +25,7 @@ <div class="userName">{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}<br/>{{ member.displayname ? "" : member.id.substr(member.id.indexOf(':')) }}</div> </td> <td class="userPresence" ng-class="member.presenceState === 'online' ? 'online' : (member.presenceState === 'unavailable' ? 'unavailable' : '')"> - {{ member.mtime_age | duration }}<br/>{{ member.mtime_age ? "ago" : "" }} + {{ member.mtime_age + (now - member.last_updated) | duration }}<br/>{{ member.mtime_age ? "ago" : "" }} </td> </table> </div> |