Menu
Public repository / 4f0b1d374fab4075f2b552b5f250bca5f28afee9
AkurAI-Mail / src/lib/webmail/filters.js
Latest change 10d19fe0941c186ec244d1f0e2af6b19200dcb0c - OLI-248: pure webmail logic as plain ES modules with JSDoc types; inline icon module by Ólafur Búi Ólafsson
/** Quick-filter chips and smart mailboxes, mapped to /api/webmail query flags. */
export const FILTER_CHIPS = [
{ id: "unread", label: "Unread" },
{ id: "flagged", label: "Flagged" },
{ id: "attachment", label: "Has attachment" },
{ id: "contacts", label: "From contacts" },
] ;
/**
* @param {string} smartMailbox
* @param {Set<string>} chips
* @returns {Record<string, string>}
*/
export function filterParams(smartMailbox, chips) {
return {
unread: String(smartMailbox === "unread" || chips.has("unread")),
flagged: String(smartMailbox === "flagged" || chips.has("flagged")),
attachment: String(smartMailbox === "attachment" || chips.has("attachment")),
today: String(smartMailbox === "today"),
vip: String(smartMailbox === "vip"),
contacts: String(chips.has("contacts")),
priority: String(smartMailbox === "priority"),
};
}
/**
* True when the view is an unfiltered first page, i.e. safe to cache for offline use.
* @param {string} query
* @param {string} cursor
* @param {string} smartMailbox
* @param {Set<string>} chips
*/
export function isPlainView(query, cursor, smartMailbox, chips) {
return !query && !cursor && !smartMailbox && chips.size === 0;
}
/**
* @param {string} mailbox
* @param {string} folder
*/
export function mailboxCacheKey(mailbox, folder) {
return `akurai-webmail-cache:${mailbox || "default"}:${folder}`;
}