mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
update presence times in realtime through the magic of two-way binding
This commit is contained in:
parent
d4145abd33
commit
b86d2a2d4f
@ -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) {
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user