Fix bug whereby refreshing Vector would not allow querying of membership state
This was caused by Vector only sending a room alias with the `view_room` action. We now resolve this to a room ID if we don't have a room ID.
This commit is contained in:
parent
4de0e19ef3
commit
a306a5e694
1 changed files with 50 additions and 35 deletions
|
@ -256,6 +256,7 @@ function returnStateEvent(event, roomId, eventType, stateKey) {
|
|||
}
|
||||
|
||||
var currentRoomId = null;
|
||||
var currentRoomAlias = null;
|
||||
|
||||
// Listen for when a room is viewed
|
||||
dis.register(onAction);
|
||||
|
@ -264,6 +265,7 @@ function onAction(payload) {
|
|||
return;
|
||||
}
|
||||
currentRoomId = payload.room_id;
|
||||
currentRoomAlias = payload.room_alias;
|
||||
}
|
||||
|
||||
const onMessage = function(event) {
|
||||
|
@ -287,11 +289,20 @@ const onMessage = function(event) {
|
|||
sendError(event, "Missing room_id in request");
|
||||
return;
|
||||
}
|
||||
let promise = Promise.resolve(currentRoomId);
|
||||
if (!currentRoomId) {
|
||||
if (!currentRoomAlias) {
|
||||
sendError(event, "Must be viewing a room");
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
@ -326,6 +337,10 @@ const onMessage = function(event) {
|
|||
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
||||
break;
|
||||
}
|
||||
}, (err) => {
|
||||
console.error(err);
|
||||
sendError(event, "Failed to lookup current room.");
|
||||
})
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Reference in a new issue