feat(platform): navigateDeepLink for invite join and guild routes (Phase 74)
navigateDeepLink handles invite (joinInvite), guild-channel (load + selectChannel), guild-only, and message kinds. Exposes formatInviteDeepLink and formatGuildDeepLink for UI copy/share flows. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -106,6 +106,8 @@ const {
|
||||
extractFirstUrl,
|
||||
parsePearcordDeepLink,
|
||||
formatPearcordDeepLink,
|
||||
formatGuildDeepLink: buildGuildDeepLink,
|
||||
formatInviteDeepLink: buildInviteDeepLink,
|
||||
id,
|
||||
now
|
||||
} = require('pearcord-shared')
|
||||
@@ -2162,10 +2164,39 @@ class PearcordPlatform extends EventEmitter {
|
||||
return formatPearcordDeepLink({ messageId: mid })
|
||||
}
|
||||
|
||||
/** Navigate from pearcord:// URL or hash; loads guild/DM context then jumps. */
|
||||
formatInviteDeepLink (inviteCode) {
|
||||
return buildInviteDeepLink(inviteCode)
|
||||
}
|
||||
|
||||
formatGuildDeepLink (opts = {}) {
|
||||
return buildGuildDeepLink({
|
||||
guildId: opts.guildId || this.guild?.guild?.id,
|
||||
channelId: opts.channelId
|
||||
})
|
||||
}
|
||||
|
||||
/** Navigate from pearcord:// URL — invite join, guild/channel, or message jump. */
|
||||
async navigateDeepLink (url) {
|
||||
const parsed = parsePearcordDeepLink(url)
|
||||
if (!parsed?.messageId) throw new Error('invalid pearcord deep link')
|
||||
if (!parsed) throw new Error('invalid pearcord deep link')
|
||||
|
||||
if (parsed.kind === 'invite' && parsed.inviteCode) {
|
||||
const guild = await this.joinInvite(parsed.inviteCode)
|
||||
return { kind: 'invite', joined: true, guildId: guild?.id || this.guild?.guild?.id }
|
||||
}
|
||||
|
||||
if (parsed.kind === 'guild-channel' && parsed.guildId && parsed.channelId) {
|
||||
await this.loadGuild(parsed.guildId)
|
||||
await this.selectChannel(parsed.channelId)
|
||||
return { kind: 'guild-channel', found: true, guildId: parsed.guildId, channelId: parsed.channelId }
|
||||
}
|
||||
|
||||
if (parsed.kind === 'guild' && parsed.guildId) {
|
||||
await this.loadGuild(parsed.guildId)
|
||||
return { kind: 'guild', found: true, guildId: parsed.guildId }
|
||||
}
|
||||
|
||||
if (parsed.kind === 'message' && parsed.messageId) {
|
||||
if (parsed.mode === 'dm' || (parsed.channelId && !parsed.guildId)) {
|
||||
if (parsed.channelId) {
|
||||
await this.openGroupDM({ channelId: parsed.channelId })
|
||||
@@ -2175,7 +2206,11 @@ class PearcordPlatform extends EventEmitter {
|
||||
} else if (parsed.guildId) {
|
||||
await this.loadGuild(parsed.guildId)
|
||||
}
|
||||
return this.jumpToMessage(parsed.messageId)
|
||||
const jump = await this.jumpToMessage(parsed.messageId)
|
||||
return { kind: 'message', ...jump }
|
||||
}
|
||||
|
||||
throw new Error('unsupported pearcord deep link')
|
||||
}
|
||||
|
||||
async joinVoiceChannel (channelId, opts = {}) {
|
||||
|
||||
Reference in New Issue
Block a user