channel name decoration for threads and voice-text
This commit is contained in:
parent
beeb27bbd8
commit
30bf87b106
2 changed files with 33 additions and 7 deletions
|
@ -36,12 +36,17 @@ function applyKStateDiffToRoom(roomID, kstate) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {{id: string, name: string, topic?: string?}} channel
|
||||
* @param {{id: string, name: string, topic?: string?, type: number}} channel
|
||||
* @param {{id: string}} guild
|
||||
* @param {string?} customName
|
||||
*/
|
||||
function convertNameAndTopic(channel, guild, customName) {
|
||||
const convertedName = customName || channel.name;
|
||||
let channelPrefix =
|
||||
( channel.type === DiscordTypes.ChannelType.PublicThread ? "[⛓️] "
|
||||
: channel.type === DiscordTypes.ChannelType.PrivateThread ? "[🔒⛓️] "
|
||||
: channel.type === DiscordTypes.ChannelType.GuildVoice ? "[🔊] "
|
||||
: "")
|
||||
const chosenName = customName || (channelPrefix + channel.name);
|
||||
const maybeTopicWithPipe = channel.topic ? ` | ${channel.topic}` : '';
|
||||
const maybeTopicWithNewlines = channel.topic ? `${channel.topic}\n\n` : '';
|
||||
const channelIDPart = `Channel ID: ${channel.id}`;
|
||||
|
@ -51,7 +56,7 @@ function convertNameAndTopic(channel, guild, customName) {
|
|||
? `#${channel.name}${maybeTopicWithPipe}\n\n${channelIDPart}\n${guildIDPart}`
|
||||
: `${maybeTopicWithNewlines}${channelIDPart}\n${guildIDPart}`;
|
||||
|
||||
return [convertedName, convertedTopic];
|
||||
return [chosenName, convertedTopic];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,28 +14,49 @@ test("channel2room: general", async t => {
|
|||
|
||||
test("convertNameAndTopic: custom name and topic", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:"}, {id: "456"}, "hauntings"),
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 0}, {id: "456"}, "hauntings"),
|
||||
["hauntings", "#the-twilight-zone | Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: custom name, no topic", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone"}, {id: "456"}, "hauntings"),
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", type: 0}, {id: "456"}, "hauntings"),
|
||||
["hauntings", "#the-twilight-zone\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: original name and topic", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:"}, {id: "456"}, null),
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 0}, {id: "456"}, null),
|
||||
["the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: original name, no topic", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone"}, {id: "456"}, null),
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", type: 0}, {id: "456"}, null),
|
||||
["the-twilight-zone", "Channel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: public thread icon", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 11}, {id: "456"}, null),
|
||||
["[⛓️] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: private thread icon", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 12}, {id: "456"}, null),
|
||||
["[🔒⛓️] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
||||
test("convertNameAndTopic: voice channel icon", t => {
|
||||
t.deepEqual(
|
||||
_convertNameAndTopic({id: "123", name: "the-twilight-zone", topic: "Spooky stuff here. :ghost:", type: 2}, {id: "456"}, null),
|
||||
["[🔊] the-twilight-zone", "Spooky stuff here. :ghost:\n\nChannel ID: 123\nGuild ID: 456"]
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue