Files
indiekit-endpoint-microsub/lib/storage/deck.js
Ricardo 26225f1f80 feat: add multi-view reader with Channels, Deck, and Timeline views
Three reader views accessible via icon toolbar:
- Channels: existing view (renamed), per-channel timelines
- Deck: TweetDeck-style configurable columns with compact cards
- Timeline: all channels merged chronologically with colored borders

Includes channel color palette, cross-channel query, deck config
storage, session-based view preference, and view switcher partial.
2026-02-26 14:42:00 +01:00

57 lines
1.4 KiB
JavaScript

/**
* Deck configuration storage
* @module storage/deck
*/
import { ObjectId } from "mongodb";
/**
* Get deck config collection
* @param {object} application - Indiekit application
* @returns {object} MongoDB collection
*/
function getCollection(application) {
return application.collections.get("microsub_deck_config");
}
/**
* Get deck configuration for a user
* @param {object} application - Indiekit application
* @param {string} userId - User ID
* @returns {Promise<object|null>} Deck config or null
*/
export async function getDeckConfig(application, userId) {
const collection = getCollection(application);
return collection.findOne({ userId });
}
/**
* Save deck configuration
* @param {object} application - Indiekit application
* @param {string} userId - User ID
* @param {Array<string>} channelIds - Ordered array of channel ObjectId strings
* @returns {Promise<void>}
*/
export async function saveDeckConfig(application, userId, channelIds) {
const collection = getCollection(application);
const columns = channelIds.map((id, order) => ({
channelId: new ObjectId(id),
order,
}));
await collection.updateOne(
{ userId },
{
$set: {
columns,
updatedAt: new Date().toISOString(),
},
$setOnInsert: {
userId,
createdAt: new Date().toISOString(),
},
},
{ upsert: true },
);
}