Skip to content
Snippets Groups Projects
Commit 7c99ebdb authored by Emmanuel ROHEE's avatar Emmanuel ROHEE
Browse files

Added waitForInitialSyncCompletion so that clients can know when they can...

Added waitForInitialSyncCompletion so that clients can know when they can access to the data retrieved by the initialSync Request
parent 06c79a23
No related branches found
No related tags found
No related merge requests found
...@@ -27,13 +27,15 @@ Typically, this service will store events or broadcast them to any listeners ...@@ -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', []) ...@@ -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', []) ...@@ -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);
}
}; };
}]); }]);
...@@ -117,6 +117,9 @@ angular.module('eventStreamService', []) ...@@ -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);
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment