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
|
sortForumPosts
|
||||||
} = require('pearcord-threads')
|
} = require('pearcord-threads')
|
||||||
const { forumPostHaystack } = require('pearcord-forum-search')
|
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 {
|
const {
|
||||||
classifyMessageLayout,
|
classifyMessageLayout,
|
||||||
LAYOUT
|
LAYOUT
|
||||||
@@ -1527,6 +1537,50 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
return this.userSettings.setPrefs(patch)
|
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 () {
|
async markAllNotificationsRead () {
|
||||||
if (!this.notifications) return 0
|
if (!this.notifications) return 0
|
||||||
return this.notifications.markAllRead()
|
return this.notifications.markAllRead()
|
||||||
@@ -4695,6 +4749,11 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
? await this.userSettings.getPrefs()
|
? await this.userSettings.getPrefs()
|
||||||
: null
|
: null
|
||||||
const userPrefsStats = this.userSettings?.getStats?.() || null
|
const userPrefsStats = this.userSettings?.getStats?.() || null
|
||||||
|
const serverRail = buildServerRailLayout(
|
||||||
|
this.guilds,
|
||||||
|
userPrefs?.serverFolders,
|
||||||
|
guildUnread
|
||||||
|
)
|
||||||
const profileCosmetics = this.profileCosmetics
|
const profileCosmetics = this.profileCosmetics
|
||||||
? await this.profileCosmetics.get()
|
? await this.profileCosmetics.get()
|
||||||
: null
|
: null
|
||||||
@@ -4919,6 +4978,8 @@ class PearcordPlatform extends EventEmitter {
|
|||||||
notificationUnread,
|
notificationUnread,
|
||||||
userPrefs,
|
userPrefs,
|
||||||
userPrefsStats,
|
userPrefsStats,
|
||||||
|
serverRail,
|
||||||
|
folderColors: FOLDER_COLORS,
|
||||||
profileCosmetics,
|
profileCosmetics,
|
||||||
profileCosmeticsStats,
|
profileCosmeticsStats,
|
||||||
cosmeticsByUserId,
|
cosmeticsByUserId,
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
"pearcord-contacts": "file:../pearcord-contacts",
|
"pearcord-contacts": "file:../pearcord-contacts",
|
||||||
"pearcord-notifications": "file:../pearcord-notifications",
|
"pearcord-notifications": "file:../pearcord-notifications",
|
||||||
"pearcord-settings": "file:../pearcord-settings",
|
"pearcord-settings": "file:../pearcord-settings",
|
||||||
|
"pearcord-server-folders": "file:../pearcord-server-folders",
|
||||||
"pearcord-profile-cosmetics": "file:../pearcord-profile-cosmetics",
|
"pearcord-profile-cosmetics": "file:../pearcord-profile-cosmetics",
|
||||||
"pearcord-device-sync": "file:../pearcord-device-sync",
|
"pearcord-device-sync": "file:../pearcord-device-sync",
|
||||||
"pearcord-step-up": "file:../pearcord-step-up",
|
"pearcord-step-up": "file:../pearcord-step-up",
|
||||||
|
|||||||
Reference in New Issue
Block a user