feat(platform): threadsPanel view + setThreadsPanelIncludeArchived (Phase 75)
Compute threadLastActivity, root message snippets, and threadsPanel payload for UI sidebar. Exposes threadsPanelIncludeArchived toggle via channel emit. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -82,6 +82,7 @@ const {
|
||||
defaultThreadName,
|
||||
groupThreadsByParent,
|
||||
listForumPostsForParent,
|
||||
buildThreadsPanel,
|
||||
isThreadChannel,
|
||||
isForumChannel,
|
||||
isAnnouncementChannel,
|
||||
@@ -350,6 +351,7 @@ class PearcordPlatform extends EventEmitter {
|
||||
await this.boosts.ready()
|
||||
this._forumTagFilter = null
|
||||
this._forumIncludeArchived = false
|
||||
this._threadsPanelIncludeArchived = false
|
||||
this.guilds = await this.listGuilds()
|
||||
void this._finishSessionStartup()
|
||||
this.emit('user', user)
|
||||
@@ -4204,6 +4206,12 @@ class PearcordPlatform extends EventEmitter {
|
||||
return thread
|
||||
}
|
||||
|
||||
setThreadsPanelIncludeArchived (includeArchived) {
|
||||
this._threadsPanelIncludeArchived = !!includeArchived
|
||||
this.emit('channel')
|
||||
return { includeArchived: this._threadsPanelIncludeArchived }
|
||||
}
|
||||
|
||||
async archiveThread (threadId, archived = true) {
|
||||
if (!this.guild?.guild) throw new Error('no guild')
|
||||
const channels = await this.guild.listChannels()
|
||||
@@ -4581,13 +4589,42 @@ class PearcordPlatform extends EventEmitter {
|
||||
const discoveryStats = this.discovery
|
||||
? await this.discovery.refreshStats()
|
||||
: null
|
||||
const threadsByParent = groupThreadsByParent(channels)
|
||||
const threadsByParent = groupThreadsByParent(channels, {
|
||||
includeArchived: this._threadsPanelIncludeArchived
|
||||
})
|
||||
const threadMessageCounts = {}
|
||||
const threadLastActivity = {}
|
||||
const threadRootMessages = {}
|
||||
for (const ch of channels) {
|
||||
if (!isThreadChannel(ch)) continue
|
||||
const rows = await this.db.find(COLLECTIONS.MESSAGES, { channelId: ch.id })
|
||||
threadMessageCounts[ch.id] = rows.length
|
||||
threadLastActivity[ch.id] = rows.length
|
||||
? Math.max(...rows.map((m) => m.createdAt || 0))
|
||||
: (ch.createdAt || 0)
|
||||
if (ch.rootMessageId) {
|
||||
let root = await this.db.get(COLLECTIONS.MESSAGES, {
|
||||
channelId: ch.parentId,
|
||||
id: ch.rootMessageId
|
||||
})
|
||||
if (!root) {
|
||||
root = rows.find((m) => m.id === ch.rootMessageId) || null
|
||||
}
|
||||
if (root) threadRootMessages[ch.rootMessageId] = root
|
||||
}
|
||||
}
|
||||
const threadsPanel = this.mode === 'guild' && guild
|
||||
? buildThreadsPanel({
|
||||
channels,
|
||||
threadsByParent,
|
||||
unread,
|
||||
threadMessageCounts,
|
||||
threadLastActivity,
|
||||
rootMessages: threadRootMessages,
|
||||
activeChannelId: this.activeChannelId,
|
||||
includeArchived: this._threadsPanelIncludeArchived
|
||||
})
|
||||
: null
|
||||
const activeChannel = channels.find((c) => c.id === this.activeChannelId) || null
|
||||
let forumPosts =
|
||||
activeChannel && isForumChannel(activeChannel)
|
||||
@@ -4864,6 +4901,9 @@ class PearcordPlatform extends EventEmitter {
|
||||
dmEncryptionEnabled: this.mode === 'dm' && dmEncryptionAvailable(),
|
||||
threadsByParent,
|
||||
threadMessageCounts,
|
||||
threadLastActivity,
|
||||
threadsPanel,
|
||||
threadsPanelIncludeArchived: this._threadsPanelIncludeArchived,
|
||||
threadTypingByParent,
|
||||
forumPosts,
|
||||
forumPaletteTags,
|
||||
|
||||
Reference in New Issue
Block a user