More consistency for invite records table
- Autojoined child spaces are recorded as invited - Update entry when reinvited - Delete entry when uninvited or removed from room - Allow linking with spaces you moderate, even if you didn't invite - Store power levels immediately for new invited rooms - Mark members as missing profile in this case - Only delete from invite table if it left the space
This commit is contained in:
@@ -148,7 +148,13 @@ as.router.get("/guild", defineEventHandler(async event => {
|
||||
|
||||
// Self-service guild that hasn't been linked yet - needs a special page encouraging the link flow
|
||||
if (!row.space_id && row.autocreate === 0) {
|
||||
const spaces = db.prepare("SELECT room_id, type, name, topic, avatar FROM invite LEFT JOIN guild_space ON invite.room_id = guild_space.space_id WHERE mxid = ? AND space_id IS NULL AND type = 'm.space'").all(session.data.mxid)
|
||||
let spaces =
|
||||
// invited spaces
|
||||
db.prepare("SELECT room_id, type, name, topic, avatar FROM invite LEFT JOIN guild_space ON invite.room_id = guild_space.space_id WHERE mxid = ? AND space_id IS NULL AND type = 'm.space'").all(session.data.mxid)
|
||||
// moderated spaces
|
||||
.concat(db.prepare("SELECT room_id, type, name, topic, avatar FROM invite LEFT JOIN guild_space ON invite.room_id = guild_space.space_id INNER JOIN member_cache USING (room_id) WHERE member_cache.mxid = ? AND power_level >= 50 AND space_id IS NULL AND type = 'm.space'").all(session.data.mxid))
|
||||
const seen = new Set(spaces.map(s => s.room_id))
|
||||
spaces = spaces.filter(s => seen.delete(s.room_id))
|
||||
return pugSync.render(event, "guild_not_linked.pug", {guild, guild_id, spaces})
|
||||
}
|
||||
|
||||
|
||||
@@ -282,11 +282,11 @@ as.router.post("/api/unlink-space", defineEventHandler(async event => {
|
||||
await utils.setUserPower(spaceID, utils.bot, 0, api)
|
||||
await api.leaveRoom(spaceID)
|
||||
db.prepare("DELETE FROM guild_space WHERE guild_id = ? AND space_id = ?").run(guild_id, spaceID)
|
||||
db.prepare("DELETE FROM invite WHERE room_id = ?").run(spaceID)
|
||||
}
|
||||
|
||||
// Mark as not considered for bridging
|
||||
db.prepare("DELETE FROM guild_active WHERE guild_id = ?").run(guild_id)
|
||||
db.prepare("DELETE FROM invite WHERE room_id = ?").run(spaceID)
|
||||
await snow.user.leaveGuild(guild_id)
|
||||
|
||||
setResponseHeader(event, "HX-Redirect", "/")
|
||||
|
||||
Reference in New Issue
Block a user