From dd4e3aa8e0386d89fe799cb6de13d9b07a2fcc66 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 3 Sep 2023 10:47:01 +1200 Subject: [PATCH] continue if user is already invited --- d2m/actions/register-user.js | 12 ++++++++++-- matrix/api.js | 7 +++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/d2m/actions/register-user.js b/d2m/actions/register-user.js index 00a985c3..bccc7ac6 100644 --- a/d2m/actions/register-user.js +++ b/d2m/actions/register-user.js @@ -72,8 +72,16 @@ async function ensureSimJoined(user, roomID) { // Ensure joined const existing = db.prepare("SELECT * FROM sim_member WHERE room_id = ? and mxid = ?").get(roomID, mxid) if (!existing) { - await api.inviteToRoom(roomID, mxid) - await api.joinRoom(roomID, mxid) + try { + await api.inviteToRoom(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) } return mxid diff --git a/matrix/api.js b/matrix/api.js index 7253a1af..5bbafffb 100644 --- a/matrix/api.js +++ b/matrix/api.js @@ -171,13 +171,12 @@ async function setUserPower(roomID, mxid, power) { assert(mxid[0] === "@") // 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 users = powerLevels.users || {} + powerLevels.users = powerLevels.users || {} if (power != null) { - users[mxid] = power + powerLevels.users[mxid] = power } else { - delete users[mxid] + delete powerLevels.users[mxid] } - powerLevels.users = users await sendState(roomID, "m.room.power_levels", "", powerLevels) return powerLevels }