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.pull/21833/head
parent
4de0e19ef3
commit
a306a5e694
|
@ -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,45 +289,58 @@ 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) {
|
||||||
sendError(event, "Must be viewing a room");
|
if (!currentRoomAlias) {
|
||||||
return;
|
sendError(event, "Must be viewing a room");
|
||||||
}
|
}
|
||||||
if (roomId !== currentRoomId) {
|
// no room ID but there is an alias, look it up.
|
||||||
sendError(event, "Room " + roomId + " not visible");
|
console.log("Looking up alias " + currentRoomAlias);
|
||||||
return;
|
promise = MatrixClientPeg.get().getRoomIdForAlias(currentRoomAlias).then((res) => {
|
||||||
|
return res.room_id;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting join rules does not require userId
|
promise.then((viewingRoomId) => {
|
||||||
if (event.data.action === "join_rules_state") {
|
if (roomId !== viewingRoomId) {
|
||||||
getJoinRules(event, roomId);
|
sendError(event, "Room " + roomId + " not visible");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userId) {
|
// Getting join rules does not require userId
|
||||||
sendError(event, "Missing user_id in request");
|
if (event.data.action === "join_rules_state") {
|
||||||
return;
|
getJoinRules(event, roomId);
|
||||||
}
|
return;
|
||||||
switch (event.data.action) {
|
}
|
||||||
case "membership_state":
|
|
||||||
getMembershipState(event, roomId, userId);
|
if (!userId) {
|
||||||
break;
|
sendError(event, "Missing user_id in request");
|
||||||
case "invite":
|
return;
|
||||||
inviteUser(event, roomId, userId);
|
}
|
||||||
break;
|
switch (event.data.action) {
|
||||||
case "bot_options":
|
case "membership_state":
|
||||||
botOptions(event, roomId, userId);
|
getMembershipState(event, roomId, userId);
|
||||||
break;
|
break;
|
||||||
case "set_bot_options":
|
case "invite":
|
||||||
setBotOptions(event, roomId, userId);
|
inviteUser(event, roomId, userId);
|
||||||
break;
|
break;
|
||||||
case "set_bot_power":
|
case "bot_options":
|
||||||
setBotPower(event, roomId, userId, event.data.level);
|
botOptions(event, roomId, userId);
|
||||||
break;
|
break;
|
||||||
default:
|
case "set_bot_options":
|
||||||
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
setBotOptions(event, roomId, userId);
|
||||||
break;
|
break;
|
||||||
}
|
case "set_bot_power":
|
||||||
|
setBotPower(event, roomId, userId, event.data.level);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn("Unhandled postMessage event with action '" + event.data.action +"'");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, (err) => {
|
||||||
|
console.error(err);
|
||||||
|
sendError(event, "Failed to lookup current room.");
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue