Per-guild presence sync settings
On by default for existing and small guilds. Off for new large guilds. Can be toggled either way.
This commit is contained in:
@@ -102,6 +102,17 @@ block body
|
||||
#autocreate-loading
|
||||
|
||||
if space_id
|
||||
h3.mt32.fs-category Presence
|
||||
.s-card
|
||||
form.d-flex.ai-center.g8
|
||||
label.s-label.fl-grow1(for="presence")
|
||||
| Show online statuses on Matrix
|
||||
p.s-description This might cause lag on really big Discord servers.
|
||||
- let value = !!select("guild_space", "presence", {guild_id}).pluck().get()
|
||||
input(type="hidden" name="guild_id" value=guild_id)
|
||||
input.s-toggle-switch.order-last#autocreate(name="presence" type="checkbox" hx-post="/api/presence" hx-indicator="#presence-loading" hx-disabled-elt="this" checked=value autocomplete="off")
|
||||
#presence-loading
|
||||
|
||||
h3.mt32.fs-category Privacy level
|
||||
.s-card
|
||||
form(hx-post="/api/privacy-level" hx-trigger="change" hx-indicator="#privacy-level-loading" hx-disabled-elt="input")
|
||||
|
||||
@@ -8,6 +8,8 @@ const {as, db, sync, select} = require("../../passthrough")
|
||||
|
||||
/** @type {import("../auth")} */
|
||||
const auth = sync.require("../auth")
|
||||
/** @type {import("../../d2m/actions/set-presence")} */
|
||||
const setPresence = sync.require("../../d2m/actions/set-presence")
|
||||
|
||||
/**
|
||||
* @param {H3Event} event
|
||||
@@ -25,6 +27,10 @@ const schema = {
|
||||
guild_id: z.string(),
|
||||
autocreate: z.string().optional()
|
||||
}),
|
||||
presence: z.object({
|
||||
guild_id: z.string(),
|
||||
presence: z.string().optional()
|
||||
}),
|
||||
privacyLevel: z.object({
|
||||
guild_id: z.string(),
|
||||
level: z.enum(levels)
|
||||
@@ -51,6 +57,17 @@ as.router.post("/api/autocreate", defineEventHandler(async event => {
|
||||
return null // 204
|
||||
}))
|
||||
|
||||
as.router.post("/api/presence", defineEventHandler(async event => {
|
||||
const parsedBody = await readValidatedBody(event, schema.presence.parse)
|
||||
const managed = await auth.getManagedGuilds(event)
|
||||
if (!managed.has(parsedBody.guild_id)) throw createError({status: 403, message: "Forbidden", data: "Can't change settings for a guild you don't have Manage Server permissions in"})
|
||||
|
||||
db.prepare("UPDATE guild_space SET presence = ? WHERE guild_id = ?").run(+!!parsedBody.presence, parsedBody.guild_id)
|
||||
setPresence.checkPresenceEnabledGuilds()
|
||||
|
||||
return null // 204
|
||||
}))
|
||||
|
||||
as.router.post("/api/privacy-level", defineEventHandler(async event => {
|
||||
const parsedBody = await readValidatedBody(event, schema.privacyLevel.parse)
|
||||
const managed = await auth.getManagedGuilds(event)
|
||||
|
||||
Reference in New Issue
Block a user