Change webclient to always hit the im sync api before streaming so we get current presence state

This commit is contained in:
Erik Johnston 2014-08-21 17:17:41 +01:00
parent e7ee0b9fc1
commit 7dac1bfc91
2 changed files with 41 additions and 7 deletions

View File

@ -49,10 +49,11 @@ angular.module('eventStreamService', [])
localStorage.setItem("streamSettings", JSON.stringify(settings)); localStorage.setItem("streamSettings", JSON.stringify(settings));
}; };
var startEventStream = function() { var doEventStream = function(deferred) {
settings.shouldPoll = true; settings.shouldPoll = true;
settings.isActive = true; settings.isActive = true;
var deferred = $q.defer(); deferred = deferred || $q.defer();
// run the stream from the latest token // run the stream from the latest token
matrixService.getEventStream(settings.from, TIMEOUT_MS).then( matrixService.getEventStream(settings.from, TIMEOUT_MS).then(
function(response) { function(response) {
@ -63,13 +64,16 @@ angular.module('eventStreamService', [])
settings.from = response.data.end; settings.from = response.data.end;
console.log("[EventStream] Got response from "+settings.from+" to "+response.data.end); console.log(
"[EventStream] Got response from "+settings.from+
" to "+response.data.end
);
eventHandlerService.handleEvents(response.data.chunk, true); eventHandlerService.handleEvents(response.data.chunk, true);
deferred.resolve(response); deferred.resolve(response);
if (settings.shouldPoll) { if (settings.shouldPoll) {
$timeout(startEventStream, 0); $timeout(doEventStream, 0);
} }
else { else {
console.log("[EventStream] Stopping poll."); console.log("[EventStream] Stopping poll.");
@ -83,13 +87,38 @@ angular.module('eventStreamService', [])
deferred.reject(error); deferred.reject(error);
if (settings.shouldPoll) { if (settings.shouldPoll) {
$timeout(startEventStream, ERR_TIMEOUT_MS); $timeout(doEventStream, ERR_TIMEOUT_MS);
} }
else { else {
console.log("[EventStream] Stopping polling."); console.log("[EventStream] Stopping polling.");
} }
} }
); );
return deferred.promise;
}
var startEventStream = function() {
settings.shouldPoll = true;
settings.isActive = true;
var deferred = $q.defer();
// FIXME: We are discarding all the messages.
matrixService.rooms().then(
function(response) {
var presence = response.data.presence;
for (var i = 0; i < presence.length; ++i) {
eventHandlerService.handleEvent(presence[i], false);
}
settings.from = response.data.end
doEventStream(deferred);
},
function(error) {
$scope.feedback = "Failure: " + error.data;
}
);
return deferred.promise; return deferred.promise;
}; };

View File

@ -93,11 +93,16 @@ angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload',
// List all rooms joined or been invited to // List all rooms joined or been invited to
matrixService.rooms().then( matrixService.rooms().then(
function(response) { function(response) {
var data = assignRoomAliases(response.data); var data = assignRoomAliases(response.data.rooms);
$scope.feedback = "Success"; $scope.feedback = "Success";
for (var i=0; i<data.length; i++) { for (var i=0; i<data.length; i++) {
$scope.rooms[data[i].room_id] = data[i]; $scope.rooms[data[i].room_id] = data[i];
} }
var presence = response.data.presence;
for (var i = 0; i < presence.length; ++i) {
eventHandlerService.handleEvent(presence[i], false);
}
}, },
function(error) { function(error) {
$scope.feedback = "Failure: " + error.data; $scope.feedback = "Failure: " + error.data;