AkurAI Build
Menu

Public repository / 7a6a24a4e46f9f1d964c5593c076f9bdf638fea0

AkurAI-Mail / src/lib/webmail/filters.ts

Latest change 22202d1bde69be4ace8a299dffd91f8ff24378df - Recover deployed webmail frontend (frontend parity with EC2 a6afffc) 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" },
] as const;

export function filterParams(smartMailbox: string, chips: Set<string>): Record<string, string> {
  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. */
export function isPlainView(query: string, cursor: string, smartMailbox: string, chips: Set<string>) {
  return !query && !cursor && !smartMailbox && chips.size === 0;
}

export function mailboxCacheKey(mailbox: string, folder: string) {
  return `akurai-webmail-cache:${mailbox || "default"}:${folder}`;
}