mirror of https://github.com/vector-im/riot-web
Merge pull request #454 from matrix-org/kegan/get-room-on-first-load
Fix bug whereby refreshing Vector would not allow querying of membership statepull/21833/head
commit
2078f81f33
|
@ -256,6 +256,7 @@ function returnStateEvent(event, roomId, eventType, stateKey) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentRoomId = null;
|
var currentRoomId = null;
|
||||||
|
var currentRoomAlias = null;
|
||||||
|
|
||||||
// Listen for when a room is viewed
|
// Listen for when a room is viewed
|
||||||
dis.register(onAction);
|
dis.register(onAction);
|
||||||
|
@ -264,6 +265,7 @@ function onAction(payload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentRoomId = payload.room_id;
|
currentRoomId = payload.room_id;
|
||||||
|
currentRoomAlias = payload.room_alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
const onMessage = function(event) {
|
const onMessage = function(event) {
|
||||||
|
@ -287,11 +289,21 @@ const onMessage = function(event) {
|
||||||
sendError(event, "Missing room_id in request");
|
sendError(event, "Missing room_id in request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let promise = Promise.resolve(currentRoomId);
|
||||||
if (!currentRoomId) {
|
if (!currentRoomId) {
|
||||||
|
if (!currentRoomAlias) {
|
||||||
sendError(event, "Must be viewing a room");
|
sendError(event, "Must be viewing a room");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (roomId !== currentRoomId) {
|
// no room ID but there is an alias, look it up.
|
||||||
|
console.log("Looking up alias " + currentRoomAlias);
|
||||||
|
promise = MatrixClientPeg.get().getRoomIdForAlias(currentRoomAlias).then((res) => {
|
||||||
|
return res.room_id;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
promise.then((viewingRoomId) => {
|
||||||
|
if (roomId !== viewingRoomId) {
|
||||||
sendError(event, "Room " + roomId + " not visible");
|
sendError(event, "Room " + roomId + " not visible");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -326,6 +338,10 @@ const onMessage = function(event) {
|
||||||
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}, (err) => {
|
||||||
|
console.error(err);
|
||||||
|
sendError(event, "Failed to lookup current room.");
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue