/* Copyright 2014 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ 'use strict'; /* This service serves as the entry point for all models in the app. If access to underlying data in a room is required, then this service should be used as the dependency. */ // NB: This is more explicit than linking top-level models to $rootScope // in that by adding this service as a dep you are clearly saying "this X // needs access to the underlying data store", rather than polluting the // $rootScope. angular.module('modelService', []) .factory('modelService', ['matrixService', function(matrixService) { /***** Room Object *****/ var Room = function Room(room_id) { this.room_id = room_id; this.old_room_state = new RoomState(); this.current_room_state = new RoomState(); this.messages = []; // events which can be displayed on the UI. TODO move? }; Room.prototype = { addMessages: function addMessages(events, toFront) { for (var i=0; i }; console.log("Models inited."); return { getRoom: function(roomId) { if(!rooms[roomId]) { rooms[roomId] = new Room(roomId); } return rooms[roomId]; } }; }]);