0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 13:53:50 +01:00

Added waitForInitialSyncCompletion so that clients can know when they can access to the data retrieved by the initialSync Request

This commit is contained in:
Emmanuel ROHEE 2014-08-28 16:22:35 +02:00
parent 06c79a23d4
commit 7c99ebdbd1
2 changed files with 24 additions and 9 deletions

View file

@ -27,13 +27,15 @@ Typically, this service will store events or broadcast them to any listeners
if typically all the $on method would do is update its own $scope. if typically all the $on method would do is update its own $scope.
*/ */
angular.module('eventHandlerService', []) angular.module('eventHandlerService', [])
.factory('eventHandlerService', ['matrixService', '$rootScope', function(matrixService, $rootScope) { .factory('eventHandlerService', ['matrixService', '$rootScope', '$q', function(matrixService, $rootScope, $q) {
var MSG_EVENT = "MSG_EVENT"; var MSG_EVENT = "MSG_EVENT";
var MEMBER_EVENT = "MEMBER_EVENT"; var MEMBER_EVENT = "MEMBER_EVENT";
var PRESENCE_EVENT = "PRESENCE_EVENT"; var PRESENCE_EVENT = "PRESENCE_EVENT";
var InitialSyncDeferred = $q.defer();
$rootScope.events = { $rootScope.events = {
rooms: {}, // will contain roomId: { messages:[], members:{userid1: event} } rooms: {} // will contain roomId: { messages:[], members:{userid1: event} }
}; };
$rootScope.presence = {}; $rootScope.presence = {};
@ -47,11 +49,11 @@ angular.module('eventHandlerService', [])
} }
} }
var reInitRoom = function(room_id) { var resetRoomMessages = function(room_id) {
$rootScope.events.rooms[room_id] = {}; if ($rootScope.events.rooms[room_id]) {
$rootScope.events.rooms[room_id].messages = []; $rootScope.events.rooms[room_id].messages = [];
$rootScope.events.rooms[room_id].members = {}; }
} };
var handleMessage = function(event, isLiveEvent) { var handleMessage = function(event, isLiveEvent) {
initRoom(event.room_id); initRoom(event.room_id);
@ -125,8 +127,18 @@ angular.module('eventHandlerService', [])
} }
}, },
reInitRoom: function(room_id) { handleInitialSyncDone: function() {
reInitRoom(room_id); console.log("# handleInitialSyncDone");
InitialSyncDeferred.resolve($rootScope.events, $rootScope.presence);
}, },
// Returns a promise that resolves when the initialSync request has been processed
waitForInitialSyncCompletion: function() {
return InitialSyncDeferred.promise;
},
resetRoomMessages: function(room_id) {
resetRoomMessages(room_id);
}
}; };
}]); }]);

View file

@ -117,6 +117,9 @@ angular.module('eventStreamService', [])
var presence = response.data.presence; var presence = response.data.presence;
eventHandlerService.handleEvents(presence, false); eventHandlerService.handleEvents(presence, false);
// Initial sync is done
eventHandlerService.handleInitialSyncDone();
settings.from = response.data.end; settings.from = response.data.end;
doEventStream(deferred); doEventStream(deferred);
}, },