continue if user is already invited
This commit is contained in:
parent
6803b156bc
commit
dd4e3aa8e0
2 changed files with 13 additions and 6 deletions
|
@ -72,8 +72,16 @@ async function ensureSimJoined(user, roomID) {
|
||||||
// Ensure joined
|
// Ensure joined
|
||||||
const existing = db.prepare("SELECT * FROM sim_member WHERE room_id = ? and mxid = ?").get(roomID, mxid)
|
const existing = db.prepare("SELECT * FROM sim_member WHERE room_id = ? and mxid = ?").get(roomID, mxid)
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
|
try {
|
||||||
await api.inviteToRoom(roomID, mxid)
|
await api.inviteToRoom(roomID, mxid)
|
||||||
await api.joinRoom(roomID, mxid)
|
await api.joinRoom(roomID, mxid)
|
||||||
|
} catch (e) {
|
||||||
|
if (e.message.includes("is already in the room.")) {
|
||||||
|
// Sweet!
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
db.prepare("INSERT INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
db.prepare("INSERT INTO sim_member (room_id, mxid) VALUES (?, ?)").run(roomID, mxid)
|
||||||
}
|
}
|
||||||
return mxid
|
return mxid
|
||||||
|
|
|
@ -171,13 +171,12 @@ async function setUserPower(roomID, mxid, power) {
|
||||||
assert(mxid[0] === "@")
|
assert(mxid[0] === "@")
|
||||||
// Yes there's no shortcut https://github.com/matrix-org/matrix-appservice-bridge/blob/2334b0bae28a285a767fe7244dad59f5a5963037/src/components/intent.ts#L352
|
// Yes there's no shortcut https://github.com/matrix-org/matrix-appservice-bridge/blob/2334b0bae28a285a767fe7244dad59f5a5963037/src/components/intent.ts#L352
|
||||||
const powerLevels = await getStateEvent(roomID, "m.room.power_levels", "")
|
const powerLevels = await getStateEvent(roomID, "m.room.power_levels", "")
|
||||||
const users = powerLevels.users || {}
|
powerLevels.users = powerLevels.users || {}
|
||||||
if (power != null) {
|
if (power != null) {
|
||||||
users[mxid] = power
|
powerLevels.users[mxid] = power
|
||||||
} else {
|
} else {
|
||||||
delete users[mxid]
|
delete powerLevels.users[mxid]
|
||||||
}
|
}
|
||||||
powerLevels.users = users
|
|
||||||
await sendState(roomID, "m.room.power_levels", "", powerLevels)
|
await sendState(roomID, "m.room.power_levels", "", powerLevels)
|
||||||
return powerLevels
|
return powerLevels
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue