mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-20 19:34:19 -05:00
Handle "m.room.create" in order to inform controllers about new rooms
This commit is contained in:
parent
aa337f588c
commit
d5da6b0cef
@ -28,6 +28,7 @@ if typically all the $on method would do is update its own $scope.
|
||||
*/
|
||||
angular.module('eventHandlerService', [])
|
||||
.factory('eventHandlerService', ['matrixService', '$rootScope', '$q', function(matrixService, $rootScope, $q) {
|
||||
var ROOM_CREATE_EVENT = "ROOM_CREATE_EVENT";
|
||||
var MSG_EVENT = "MSG_EVENT";
|
||||
var MEMBER_EVENT = "MEMBER_EVENT";
|
||||
var PRESENCE_EVENT = "PRESENCE_EVENT";
|
||||
@ -48,7 +49,7 @@ angular.module('eventHandlerService', [])
|
||||
$rootScope.events.rooms[room_id].messages = [];
|
||||
$rootScope.events.rooms[room_id].members = {};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var resetRoomMessages = function(room_id) {
|
||||
if ($rootScope.events.rooms[room_id]) {
|
||||
@ -56,6 +57,13 @@ angular.module('eventHandlerService', [])
|
||||
}
|
||||
};
|
||||
|
||||
var handleRoomCreate = function(event, isLiveEvent) {
|
||||
initRoom(event.room_id);
|
||||
|
||||
// For now, we do not use the event data. Simply signal it to the app controllers
|
||||
$rootScope.$broadcast(ROOM_CREATE_EVENT, event, isLiveEvent);
|
||||
};
|
||||
|
||||
var handleMessage = function(event, isLiveEvent) {
|
||||
initRoom(event.room_id);
|
||||
|
||||
@ -110,6 +118,7 @@ angular.module('eventHandlerService', [])
|
||||
};
|
||||
|
||||
return {
|
||||
ROOM_CREATE_EVENT: ROOM_CREATE_EVENT,
|
||||
MSG_EVENT: MSG_EVENT,
|
||||
MEMBER_EVENT: MEMBER_EVENT,
|
||||
PRESENCE_EVENT: PRESENCE_EVENT,
|
||||
@ -118,6 +127,9 @@ angular.module('eventHandlerService', [])
|
||||
|
||||
handleEvent: function(event, isLiveEvent) {
|
||||
switch(event.type) {
|
||||
case "m.room.create":
|
||||
handleRoomCreate(event, isLiveEvent);
|
||||
break;
|
||||
case "m.room.message":
|
||||
handleMessage(event, isLiveEvent);
|
||||
break;
|
||||
@ -140,7 +152,7 @@ angular.module('eventHandlerService', [])
|
||||
console.log(JSON.stringify(event, undefined, 4));
|
||||
break;
|
||||
}
|
||||
if (event.type.indexOf('m.call.') == 0) {
|
||||
if (event.type.indexOf('m.call.') === 0) {
|
||||
handleCallEvent(event, isLiveEvent);
|
||||
}
|
||||
},
|
||||
|
@ -17,8 +17,8 @@ limitations under the License.
|
||||
'use strict';
|
||||
|
||||
angular.module('HomeController', ['matrixService', 'eventHandlerService', 'RecentsController'])
|
||||
.controller('HomeController', ['$scope', '$location', 'matrixService',
|
||||
function($scope, $location, matrixService) {
|
||||
.controller('HomeController', ['$scope', '$location', 'matrixService', 'eventHandlerService',
|
||||
function($scope, $location, matrixService, eventHandlerService) {
|
||||
|
||||
$scope.config = matrixService.config();
|
||||
$scope.public_rooms = [];
|
||||
@ -72,7 +72,6 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||
response.data.room_id);
|
||||
matrixService.createRoomIdToAliasMapping(
|
||||
response.data.room_id, response.data.room_alias);
|
||||
refresh();
|
||||
},
|
||||
function(error) {
|
||||
$scope.feedback = "Failure: " + error.data;
|
||||
@ -133,6 +132,14 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||
}
|
||||
);
|
||||
|
||||
// Listen to room creation event in order to update the public rooms list
|
||||
$scope.$on(eventHandlerService.ROOM_CREATE_EVENT, function(ngEvent, event, isLive) {
|
||||
if (isLive) {
|
||||
// As we do not know if this room is public, do a full list refresh
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
|
||||
refresh();
|
||||
};
|
||||
}]);
|
||||
|
@ -47,6 +47,11 @@ angular.module('RecentsController', ['matrixService', 'eventHandlerService'])
|
||||
$scope.rooms[event.room_id].lastMsg = event;
|
||||
}
|
||||
});
|
||||
$scope.$on(eventHandlerService.ROOM_CREATE_EVENT, function(ngEvent, event, isLive) {
|
||||
if (isLive) {
|
||||
$scope.rooms[event.room_id] = event;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user