feat(platform): server folders in view and user-prefs CRUD
Wire pearcord-server-folders into PearcordPlatform: createServerFolder, assignGuildToFolder, collapse/rename/delete, and buildServerRailLayout on view() as serverRail with folderColors. Persist via updateUserPrefs serverFolders and emit user-prefs after saves. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -89,6 +89,16 @@ const {
|
||||
sortForumPosts
|
||||
} = require('pearcord-threads')
|
||||
const { forumPostHaystack } = require('pearcord-forum-search')
|
||||
const {
|
||||
normalizeServerFolders,
|
||||
buildServerRailLayout,
|
||||
createFolder: createServerFolderState,
|
||||
deleteFolder: deleteServerFolderState,
|
||||
assignGuildToFolder: assignGuildToFolderState,
|
||||
setFolderCollapsed: setFolderCollapsedState,
|
||||
renameFolder: renameServerFolderState,
|
||||
FOLDER_COLORS
|
||||
} = require('pearcord-server-folders')
|
||||
const {
|
||||
classifyMessageLayout,
|
||||
LAYOUT
|
||||
@@ -1527,6 +1537,50 @@ class PearcordPlatform extends EventEmitter {
|
||||
return this.userSettings.setPrefs(patch)
|
||||
}
|
||||
|
||||
async getServerFolders () {
|
||||
if (!this.userSettings) return normalizeServerFolders(null)
|
||||
const prefs = await this.userSettings.getPrefs()
|
||||
return normalizeServerFolders(prefs.serverFolders)
|
||||
}
|
||||
|
||||
async _saveServerFolders (state) {
|
||||
const normalized = normalizeServerFolders(state)
|
||||
await this.updateUserPrefs({ serverFolders: normalized })
|
||||
this.emit('user-prefs')
|
||||
return normalized
|
||||
}
|
||||
|
||||
async createServerFolder ({ name, color } = {}) {
|
||||
const state = await this.getServerFolders()
|
||||
const { state: next, folder } = createServerFolderState(state, { name, color })
|
||||
await this._saveServerFolders(next)
|
||||
return folder
|
||||
}
|
||||
|
||||
async deleteServerFolder (folderId) {
|
||||
const state = await this.getServerFolders()
|
||||
await this._saveServerFolders(deleteServerFolderState(state, folderId))
|
||||
return true
|
||||
}
|
||||
|
||||
async assignGuildToFolder (guildId, folderId = null) {
|
||||
const state = await this.getServerFolders()
|
||||
await this._saveServerFolders(assignGuildToFolderState(state, guildId, folderId))
|
||||
return true
|
||||
}
|
||||
|
||||
async setServerFolderCollapsed (folderId, collapsed) {
|
||||
const state = await this.getServerFolders()
|
||||
await this._saveServerFolders(setFolderCollapsedState(state, folderId, collapsed))
|
||||
return true
|
||||
}
|
||||
|
||||
async renameServerFolder (folderId, name) {
|
||||
const state = await this.getServerFolders()
|
||||
await this._saveServerFolders(renameServerFolderState(state, folderId, name))
|
||||
return true
|
||||
}
|
||||
|
||||
async markAllNotificationsRead () {
|
||||
if (!this.notifications) return 0
|
||||
return this.notifications.markAllRead()
|
||||
@@ -4695,6 +4749,11 @@ class PearcordPlatform extends EventEmitter {
|
||||
? await this.userSettings.getPrefs()
|
||||
: null
|
||||
const userPrefsStats = this.userSettings?.getStats?.() || null
|
||||
const serverRail = buildServerRailLayout(
|
||||
this.guilds,
|
||||
userPrefs?.serverFolders,
|
||||
guildUnread
|
||||
)
|
||||
const profileCosmetics = this.profileCosmetics
|
||||
? await this.profileCosmetics.get()
|
||||
: null
|
||||
@@ -4919,6 +4978,8 @@ class PearcordPlatform extends EventEmitter {
|
||||
notificationUnread,
|
||||
userPrefs,
|
||||
userPrefsStats,
|
||||
serverRail,
|
||||
folderColors: FOLDER_COLORS,
|
||||
profileCosmetics,
|
||||
profileCosmeticsStats,
|
||||
cosmeticsByUserId,
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"pearcord-contacts": "file:../pearcord-contacts",
|
||||
"pearcord-notifications": "file:../pearcord-notifications",
|
||||
"pearcord-settings": "file:../pearcord-settings",
|
||||
"pearcord-server-folders": "file:../pearcord-server-folders",
|
||||
"pearcord-profile-cosmetics": "file:../pearcord-profile-cosmetics",
|
||||
"pearcord-device-sync": "file:../pearcord-device-sync",
|
||||
"pearcord-step-up": "file:../pearcord-step-up",
|
||||
|
||||
Reference in New Issue
Block a user