mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
update presence times in realtime through the magic of two-way binding
This commit is contained in:
parent
d4145abd33
commit
b86d2a2d4f
@ -176,6 +176,8 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
|
|||||||
// set target_user_id to keep things clear
|
// set target_user_id to keep things clear
|
||||||
var target_user_id = chunk.state_key;
|
var target_user_id = chunk.state_key;
|
||||||
|
|
||||||
|
var now = new Date().getTime();
|
||||||
|
|
||||||
var isNewMember = !(target_user_id in $scope.members);
|
var isNewMember = !(target_user_id in $scope.members);
|
||||||
if (isNewMember) {
|
if (isNewMember) {
|
||||||
// FIXME: why are we copying these fields around inside chunk?
|
// FIXME: why are we copying these fields around inside chunk?
|
||||||
@ -185,45 +187,15 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
|
|||||||
if ("mtime_age" in chunk.content) {
|
if ("mtime_age" in chunk.content) {
|
||||||
chunk.mtime_age = chunk.content.mtime_age;
|
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) {
|
if ("displayname" in chunk.content) {
|
||||||
chunk.displayname = chunk.content.displayname;
|
chunk.displayname = chunk.content.displayname;
|
||||||
}
|
}
|
||||||
if ("avatar_url" in chunk.content) {
|
if ("avatar_url" in chunk.content) {
|
||||||
chunk.avatar_url = chunk.content.avatar_url;
|
chunk.avatar_url = chunk.content.avatar_url;
|
||||||
}
|
}
|
||||||
|
chunk.last_updated = now;
|
||||||
$scope.members[target_user_id] = chunk;
|
$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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (target_user_id in $rootScope.presence) {
|
if (target_user_id in $rootScope.presence) {
|
||||||
updatePresence($rootScope.presence[target_user_id]);
|
updatePresence($rootScope.presence[target_user_id]);
|
||||||
}
|
}
|
||||||
@ -235,6 +207,12 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateMemberListPresenceAge = function() {
|
||||||
|
$scope.now = new Date().getTime();
|
||||||
|
//console.log("updateMemberListPresenceAge() - now = " + $scope.now);
|
||||||
|
$timeout(updateMemberListPresenceAge, 5 * 1000);
|
||||||
|
};
|
||||||
|
|
||||||
var updatePresence = function(chunk) {
|
var updatePresence = function(chunk) {
|
||||||
if (!(chunk.content.user_id in $scope.members)) {
|
if (!(chunk.content.user_id in $scope.members)) {
|
||||||
console.log("updatePresence: Unknown member for chunk " + JSON.stringify(chunk));
|
console.log("updatePresence: Unknown member for chunk " + JSON.stringify(chunk));
|
||||||
@ -397,6 +375,8 @@ angular.module('RoomController', ['ngSanitize', 'mFileInput'])
|
|||||||
$scope.recentsSelectedRoomID = $scope.room_id;
|
$scope.recentsSelectedRoomID = $scope.room_id;
|
||||||
|
|
||||||
paginate(MESSAGES_PER_PAGINATION);
|
paginate(MESSAGES_PER_PAGINATION);
|
||||||
|
|
||||||
|
updateMemberListPresenceAge();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.inviteUser = function(user_id) {
|
$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>
|
<div class="userName">{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}<br/>{{ member.displayname ? "" : member.id.substr(member.id.indexOf(':')) }}</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="userPresence" ng-class="member.presenceState === 'online' ? 'online' : (member.presenceState === 'unavailable' ? 'unavailable' : '')">
|
<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>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user