forked from MirrorHub/synapse
use all new /rooms/<room id>/state to actually gather the state for rooms whenever join them. a bit ugly, as we don't currently have a nice place to gather housekeeping after joining a room, so horrible code duplication...
This commit is contained in:
parent
284fac379c
commit
437969eac9
3 changed files with 49 additions and 8 deletions
|
@ -265,6 +265,12 @@ angular.module('matrixService', [])
|
||||||
return doRequest("GET", path, params);
|
return doRequest("GET", path, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// get room state for a specific room
|
||||||
|
roomState: function(room_id) {
|
||||||
|
var path = "/rooms/" + room_id + "/state";
|
||||||
|
return doRequest("GET", path);
|
||||||
|
},
|
||||||
|
|
||||||
// Joins a room
|
// Joins a room
|
||||||
join: function(room_id) {
|
join: function(room_id) {
|
||||||
return this.membershipChange(room_id, undefined, "join");
|
return this.membershipChange(room_id, undefined, "join");
|
||||||
|
|
|
@ -86,18 +86,24 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||||
|
|
||||||
// Go to a room
|
// Go to a room
|
||||||
$scope.goToRoom = function(room_id) {
|
$scope.goToRoom = function(room_id) {
|
||||||
// Simply open the room page on this room id
|
|
||||||
//$location.url("room/" + room_id);
|
|
||||||
matrixService.join(room_id).then(
|
matrixService.join(room_id).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
|
var final_room_id = room_id;
|
||||||
if (response.data.hasOwnProperty("room_id")) {
|
if (response.data.hasOwnProperty("room_id")) {
|
||||||
if (response.data.room_id != room_id) {
|
final_room_id = response.data.room_id;
|
||||||
$location.url("room/" + response.data.room_id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$location.url("room/" + room_id);
|
// TODO: factor out the common housekeeping whenever we try to join a room or alias
|
||||||
|
matrixService.roomState(final_room_id).then(
|
||||||
|
function(response) {
|
||||||
|
eventHandlerService.handleEvents(response, false, true);
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
$scope.feedback = "Failed to get room state for: " + final_room_id;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$location.url("room/" + final_room_id);
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
$scope.feedback = "Can't join room: " + JSON.stringify(error.data);
|
$scope.feedback = "Can't join room: " + JSON.stringify(error.data);
|
||||||
|
@ -108,6 +114,15 @@ angular.module('HomeController', ['matrixService', 'eventHandlerService', 'Recen
|
||||||
$scope.joinAlias = function(room_alias) {
|
$scope.joinAlias = function(room_alias) {
|
||||||
matrixService.joinAlias(room_alias).then(
|
matrixService.joinAlias(room_alias).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
|
// TODO: factor out the common housekeeping whenever we try to join a room or alias
|
||||||
|
matrixService.roomState(response.room_id).then(
|
||||||
|
function(response) {
|
||||||
|
eventHandlerService.handleEvents(response, false, true);
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
$scope.feedback = "Failed to get room state for: " + response.room_id;
|
||||||
|
}
|
||||||
|
);
|
||||||
// Go to this room
|
// Go to this room
|
||||||
$location.url("room/" + room_alias);
|
$location.url("room/" + room_alias);
|
||||||
},
|
},
|
||||||
|
|
|
@ -479,6 +479,15 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
||||||
else {
|
else {
|
||||||
promise = matrixService.joinAlias(room_alias).then(
|
promise = matrixService.joinAlias(room_alias).then(
|
||||||
function(response) {
|
function(response) {
|
||||||
|
// TODO: factor out the common housekeeping whenever we try to join a room or alias
|
||||||
|
matrixService.roomState(response.room_id).then(
|
||||||
|
function(response) {
|
||||||
|
eventHandlerService.handleEvents(response, false, true);
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
$scope.feedback = "Failed to get room state for: " + response.room_id;
|
||||||
|
}
|
||||||
|
);
|
||||||
$location.url("room/" + room_alias);
|
$location.url("room/" + room_alias);
|
||||||
},
|
},
|
||||||
function(error) {
|
function(error) {
|
||||||
|
@ -732,6 +741,16 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
||||||
$scope.state.waiting_for_joined_event = true;
|
$scope.state.waiting_for_joined_event = true;
|
||||||
matrixService.join($scope.room_id).then(
|
matrixService.join($scope.room_id).then(
|
||||||
function() {
|
function() {
|
||||||
|
// TODO: factor out the common housekeeping whenever we try to join a room or alias
|
||||||
|
matrixService.roomState($scope.room_id).then(
|
||||||
|
function(response) {
|
||||||
|
eventHandlerService.handleEvents(response, false, true);
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
console.error("Failed to get room state for: " + $scope.room_id);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// onInit3 will be called once the joined m.room.member event is received from the events stream
|
// onInit3 will be called once the joined m.room.member event is received from the events stream
|
||||||
// This avoids to get the joined information twice in parallel:
|
// This avoids to get the joined information twice in parallel:
|
||||||
// - one from the events stream
|
// - one from the events stream
|
||||||
|
@ -740,6 +759,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
|
||||||
},
|
},
|
||||||
function(reason) {
|
function(reason) {
|
||||||
console.log("Can't join room: " + JSON.stringify(reason));
|
console.log("Can't join room: " + JSON.stringify(reason));
|
||||||
|
// FIXME: what if it wasn't a perms problem?
|
||||||
$scope.state.permission_denied = "You do not have permission to join this room";
|
$scope.state.permission_denied = "You do not have permission to join this room";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue