forked from cadence/out-of-your-element
Compare commits
3 commits
41c2131061
...
ea94dfe6b9
| Author | SHA1 | Date | |
|---|---|---|---|
| ea94dfe6b9 | |||
| 32ba4d8385 | |||
| c8bf730ec4 |
4 changed files with 23 additions and 13 deletions
|
|
@ -55,7 +55,7 @@ function convertNameAndTopic(channel, guild, customName) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const parentChannel = discord.channels.get(channel.parent_id)
|
const parentChannel = discord.channels.get(channel.parent_id)
|
||||||
let channelPrefix =
|
let channelPrefix =
|
||||||
( parentChannel?.type === DiscordTypes.ChannelType.GuildForum ? "[❓] "
|
( parentChannel?.type === DiscordTypes.ChannelType.GuildForum ? ""
|
||||||
: channel.type === DiscordTypes.ChannelType.PublicThread ? "[⛓️] "
|
: channel.type === DiscordTypes.ChannelType.PublicThread ? "[⛓️] "
|
||||||
: channel.type === DiscordTypes.ChannelType.AnnouncementThread ? "[⛓️] "
|
: channel.type === DiscordTypes.ChannelType.AnnouncementThread ? "[⛓️] "
|
||||||
: channel.type === DiscordTypes.ChannelType.PrivateThread ? "[🔒⛓️] "
|
: channel.type === DiscordTypes.ChannelType.PrivateThread ? "[🔒⛓️] "
|
||||||
|
|
@ -64,13 +64,13 @@ function convertNameAndTopic(channel, guild, customName) {
|
||||||
const chosenName = customName || (channelPrefix + channel.name);
|
const chosenName = customName || (channelPrefix + channel.name);
|
||||||
const maybeTopicWithPipe = channel.topic ? ` | ${channel.topic}` : '';
|
const maybeTopicWithPipe = channel.topic ? ` | ${channel.topic}` : '';
|
||||||
const maybeTopicWithNewlines = channel.topic ? `${channel.topic}\n\n` : '';
|
const maybeTopicWithNewlines = channel.topic ? `${channel.topic}\n\n` : '';
|
||||||
|
const maybeWithin = parentChannel ? `Within: ${parentChannel.name} (ID: ${parentChannel.id})\n` : '';
|
||||||
const channelIDPart = `Channel ID: ${channel.id}`;
|
const channelIDPart = `Channel ID: ${channel.id}`;
|
||||||
const guildIDPart = `Guild ID: ${guild.id}`;
|
const guildIDPart = `Guild ID: ${guild.id}`;
|
||||||
const maybeThreadWithinPart = parentChannel ? `Thread within: ${parentChannel.name} (ID: ${parentChannel.id})\n` : '';
|
|
||||||
|
|
||||||
const convertedTopic = customName
|
const convertedTopic = customName
|
||||||
? `#${channel.name}${maybeTopicWithPipe}\n\n${channelIDPart}\n${maybeThreadWithinPart}${guildIDPart}`
|
? `#${channel.name}${maybeTopicWithPipe}\n\n${maybeWithin}${channelIDPart}\n${guildIDPart}`
|
||||||
: `${maybeTopicWithNewlines}${channelIDPart}\n${maybeThreadWithinPart}${guildIDPart}`;
|
: `${maybeTopicWithNewlines}${maybeWithin}${channelIDPart}\n${guildIDPart}`;
|
||||||
|
|
||||||
return [chosenName, convertedTopic];
|
return [chosenName, convertedTopic];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,13 +158,17 @@ async function sendError(roomID, source, type, e, payload) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} type
|
* Wraps the function with an automated error catching and reporting mechanism
|
||||||
* @param {(event: Ty.Event.Outer<any> & {type: any, redacts:any, state_key:any}, ...args: any)=>any} fn
|
* @template {Ty.Event.Outer<any>} EVENT The event that the wrapped function processes, its first argument.
|
||||||
|
* @template {[]} ARGS Other arguments of the wrapped function
|
||||||
|
* @template RETURNS The output of the wrapped function
|
||||||
|
* @param {string} type Type of the event, during the processing of which the error may occur.
|
||||||
|
* @param {(event: EVENT, ...args: ARGS)=>RETURNS|Promise<RETURNS>} fn Function to wrap
|
||||||
|
* @returns {(event: EVENT, ...args: ARGS)=>Promise<RETURNS|undefined>} Wrapped function
|
||||||
*/
|
*/
|
||||||
function guard(type, fn) {
|
function guard(type, fn) {
|
||||||
return async function(/** @type {Ty.Event.Outer<any>} */ event, /** @type {any} */ ...args) {
|
return async function(event, ...args) {
|
||||||
try {
|
try {
|
||||||
// @ts-ignore
|
|
||||||
return await fn(event, ...args)
|
return await fn(event, ...args)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await sendError(event.room_id, "Matrix", type, e, event)
|
await sendError(event.room_id, "Matrix", type, e, event)
|
||||||
|
|
|
||||||
|
|
@ -257,6 +257,11 @@ block body
|
||||||
ul.my8.ml24
|
ul.my8.ml24
|
||||||
each row in removedEncryptedRooms
|
each row in removedEncryptedRooms
|
||||||
li: a(href=`https://matrix.to/#/${row.room_id}`)= row.name
|
li: a(href=`https://matrix.to/#/${row.room_id}`)= row.name
|
||||||
|
h3.mt24 Unavailable rooms: Root space
|
||||||
|
.s-card.p0
|
||||||
|
ul.my8.ml24
|
||||||
|
each row in removedRootSpaceRooms
|
||||||
|
li: a(href=`https://matrix.to/#/${row.room_id}`) (#{row.room_type}) #{row.name}
|
||||||
h3.mt24 Unavailable rooms: Archived thread
|
h3.mt24 Unavailable rooms: Archived thread
|
||||||
p If you still want to link with any of these rooms (eg. you accidentally unlinked it and want to bring it back, or you're migrating from a different bridge that happens to use OOYE's prefixes), please remove the [⛓️] or [🔒⛓️] prefix in Matrix's room settings and refresh the page.
|
p If you still want to link with any of these rooms (eg. you accidentally unlinked it and want to bring it back, or you're migrating from a different bridge that happens to use OOYE's prefixes), please remove the [⛓️] or [🔒⛓️] prefix in Matrix's room settings and refresh the page.
|
||||||
.s-card.p0
|
.s-card.p0
|
||||||
|
|
|
||||||
|
|
@ -118,8 +118,9 @@ function getPosition(channel, channels) {
|
||||||
* @param {DiscordTypes.APIGuild} guild
|
* @param {DiscordTypes.APIGuild} guild
|
||||||
* @param {Ty.R.Hierarchy[]} rooms
|
* @param {Ty.R.Hierarchy[]} rooms
|
||||||
* @param {string[]} roles
|
* @param {string[]} roles
|
||||||
|
* @param {string?} space
|
||||||
*/
|
*/
|
||||||
function getChannelRoomsLinks(guild, rooms, roles) {
|
function getChannelRoomsLinks(guild, rooms, roles, space) {
|
||||||
let channelIDs = discord.guildChannelMap.get(guild.id)
|
let channelIDs = discord.guildChannelMap.get(guild.id)
|
||||||
assert(channelIDs)
|
assert(channelIDs)
|
||||||
|
|
||||||
|
|
@ -149,7 +150,7 @@ function getChannelRoomsLinks(guild, rooms, roles) {
|
||||||
let linkedRoomIDs = linkedChannels.map(c => c.room_id)
|
let linkedRoomIDs = linkedChannels.map(c => c.room_id)
|
||||||
let unlinkedRooms = [...rooms]
|
let unlinkedRooms = [...rooms]
|
||||||
let removedLinkedRooms = dUtils.filterTo(unlinkedRooms, r => !linkedRoomIDs.includes(r.room_id))
|
let removedLinkedRooms = dUtils.filterTo(unlinkedRooms, r => !linkedRoomIDs.includes(r.room_id))
|
||||||
let removedWrongTypeRooms = []
|
let removedRootSpaceRooms = dUtils.filterTo(unlinkedRooms, r => r.room_id !== space)
|
||||||
let removedEncryptedRooms = dUtils.filterTo(unlinkedRooms, r => !r.encryption && !r["im.nheko.summary.encryption"])
|
let removedEncryptedRooms = dUtils.filterTo(unlinkedRooms, r => !r.encryption && !r["im.nheko.summary.encryption"])
|
||||||
// https://discord.com/developers/docs/topics/threads#active-archived-threads
|
// https://discord.com/developers/docs/topics/threads#active-archived-threads
|
||||||
// need to filter out linked archived threads from unlinkedRooms, will just do that by comparing against the name
|
// need to filter out linked archived threads from unlinkedRooms, will just do that by comparing against the name
|
||||||
|
|
@ -157,7 +158,7 @@ function getChannelRoomsLinks(guild, rooms, roles) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
linkedChannelsWithDetails, unlinkedChannels, unlinkedRooms,
|
linkedChannelsWithDetails, unlinkedChannels, unlinkedRooms,
|
||||||
removedUncachedChannels, removedWrongTypeChannels, removedPrivateChannels, removedLinkedRooms, removedWrongTypeRooms, removedArchivedThreadRooms, removedEncryptedRooms
|
removedUncachedChannels, removedWrongTypeChannels, removedPrivateChannels, removedLinkedRooms, removedRootSpaceRooms, removedArchivedThreadRooms, removedEncryptedRooms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,14 +199,14 @@ as.router.get("/guild", defineEventHandler(async event => {
|
||||||
|
|
||||||
// Easy mode guild that hasn't been linked yet - need to remove elements that would require an existing space
|
// Easy mode guild that hasn't been linked yet - need to remove elements that would require an existing space
|
||||||
if (!row.space_id) {
|
if (!row.space_id) {
|
||||||
const links = getChannelRoomsLinks(guild, [], roles)
|
const links = getChannelRoomsLinks(guild, [], roles, row.space_id)
|
||||||
return pugSync.render(event, "guild.pug", {guild, guild_id, ...links, ...row})
|
return pugSync.render(event, "guild.pug", {guild, guild_id, ...links, ...row})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linked guild
|
// Linked guild
|
||||||
const api = getAPI(event)
|
const api = getAPI(event)
|
||||||
const rooms = await api.getFullHierarchy(row.space_id)
|
const rooms = await api.getFullHierarchy(row.space_id)
|
||||||
const links = getChannelRoomsLinks(guild, rooms, roles)
|
const links = getChannelRoomsLinks(guild, rooms, roles, row.space_id)
|
||||||
return pugSync.render(event, "guild.pug", {guild, guild_id, ...links, ...row})
|
return pugSync.render(event, "guild.pug", {guild, guild_id, ...links, ...row})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue