From 8293caf6d3f53aea3da4ef1768792ef02547ad28 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 5 Jan 2026 14:44:45 +0000 Subject: [PATCH] Refactor watch history to use simplified monthly record schema --- js/nostr/client.js | 1 - js/nostr/watchHistory.js | 1 - js/nostrEventSchemas.js | 109 +++------------------------------------ 3 files changed, 6 insertions(+), 105 deletions(-) diff --git a/js/nostr/client.js b/js/nostr/client.js index 1b340655..fe0477aa 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -40,7 +40,6 @@ import { import { buildVideoPostEvent, buildRepostEvent, - buildWatchHistoryIndexEvent, buildWatchHistoryEvent, getNostrEventSchema, NOTE_TYPES, diff --git a/js/nostr/watchHistory.js b/js/nostr/watchHistory.js index efcbdfe0..58308f9e 100644 --- a/js/nostr/watchHistory.js +++ b/js/nostr/watchHistory.js @@ -11,7 +11,6 @@ import { } from "../config.js"; import { buildWatchHistoryEvent, - buildWatchHistoryIndexEvent, } from "../nostrEventSchemas.js"; import { publishEventToRelays } from "../nostrPublish.js"; import { diff --git a/js/nostrEventSchemas.js b/js/nostrEventSchemas.js index 17c9896a..c6ff502b 100644 --- a/js/nostrEventSchemas.js +++ b/js/nostrEventSchemas.js @@ -19,8 +19,7 @@ export const NOTE_TYPES = Object.freeze({ VIEW_EVENT: "viewEvent", VIDEO_REACTION: "videoReaction", VIDEO_COMMENT: "videoComment", - WATCH_HISTORY_INDEX: "watchHistoryIndex", - WATCH_HISTORY_CHUNK: "watchHistoryChunk", + WATCH_HISTORY: "watchHistory", SUBSCRIPTION_LIST: "subscriptionList", USER_BLOCK_LIST: "userBlockList", HASHTAG_PREFERENCES: "hashtagPreferences", @@ -351,26 +350,9 @@ const BASE_SCHEMAS = { description: "Plain text comment body sanitized for UTF-8 compatibility.", }, }, - [NOTE_TYPES.WATCH_HISTORY_INDEX]: { - type: NOTE_TYPES.WATCH_HISTORY_INDEX, - label: "Watch history month index", - kind: WATCH_HISTORY_KIND, - identifierTag: { - name: "d", - }, - monthTagName: "month", - headTag: { name: "head", value: "month" }, - monthPointerTagName: "a", - appendTags: DEFAULT_APPEND_TAGS, - content: { - format: "json", - description: - "JSON payload listing watched event identifiers for a given YYYY-MM month; entries may include optional watchedAt metadata.", - }, - }, - [NOTE_TYPES.WATCH_HISTORY_CHUNK]: { - type: NOTE_TYPES.WATCH_HISTORY_CHUNK, - label: "Watch history monthly payload", + [NOTE_TYPES.WATCH_HISTORY]: { + type: NOTE_TYPES.WATCH_HISTORY, + label: "Watch history month", kind: WATCH_HISTORY_KIND, identifierTag: { name: "d", @@ -1344,85 +1326,6 @@ export function buildCommentEvent({ }; } -export function buildWatchHistoryIndexEvent({ - pubkey, - created_at, - monthIdentifier, - snapshotId, - isHead = false, - monthAddresses = [], - chunkAddresses = [], - additionalTags = [], - content, -}) { - const schema = getNostrEventSchema(NOTE_TYPES.WATCH_HISTORY_INDEX); - const tags = []; - const identifierName = schema?.identifierTag?.name || "d"; - - // Prioritize monthIdentifier, fallback to snapshotId (legacy) - const identifierValue = - (typeof monthIdentifier === "string" && monthIdentifier.trim()) || - (typeof snapshotId === "string" && snapshotId.trim()) || - schema?.identifierTag?.value || - WATCH_HISTORY_LIST_IDENTIFIER; - - if (identifierName && identifierValue) { - tags.push([identifierName, identifierValue]); - } - - // Ensure "month" tag is present if we have an identifier (assuming it's a month) - const monthTagName = schema?.monthTagName || "month"; - if (monthTagName && identifierValue) { - tags.push([monthTagName, identifierValue]); - } - - const pointerTagName = schema?.monthPointerTagName || schema?.chunkPointerTagName || "a"; - const resolvedMonthAddresses = Array.isArray(monthAddresses) && monthAddresses.length - ? monthAddresses - : chunkAddresses; - - resolvedMonthAddresses?.forEach((address) => { - if (typeof address === "string" && address) { - tags.push([pointerTagName, address]); - } - }); - - if (isHead && schema?.headTag?.name && schema?.headTag?.value) { - tags.unshift([schema.headTag.name, schema.headTag.value]); - } - - appendSchemaTags(tags, schema); - const sanitizedAdditionalTags = sanitizeAdditionalTags(additionalTags); - if (sanitizedAdditionalTags.length) { - tags.push(...sanitizedAdditionalTags.map((tag) => tag.slice())); - } - - let resolvedContent = content; - if (resolvedContent === undefined) { - const payload = { - month: identifierValue || "", - items: [], - }; - if (isHead) { - payload.head = true; - } - resolvedContent = JSON.stringify(payload); - } else if (typeof resolvedContent !== "string") { - resolvedContent = JSON.stringify(resolvedContent ?? {}); - } - - return { - kind: schema?.kind ?? WATCH_HISTORY_KIND, - pubkey, - created_at, - tags, - content: - typeof resolvedContent === "string" - ? resolvedContent - : String(resolvedContent ?? ""), - }; -} - export function buildWatchHistoryEvent({ pubkey, created_at, @@ -1432,11 +1335,11 @@ export function buildWatchHistoryEvent({ content, encryption, }) { - const schema = getNostrEventSchema(NOTE_TYPES.WATCH_HISTORY_CHUNK); + const schema = getNostrEventSchema(NOTE_TYPES.WATCH_HISTORY); const tags = []; const identifierName = schema?.identifierTag?.name || "d"; - // Prioritize monthIdentifier, fallback to snapshotId + // Prioritize monthIdentifier, fallback to snapshotId (for legacy compat in signature) const identifierValue = (typeof monthIdentifier === "string" && monthIdentifier.trim()) || (typeof snapshotId === "string" && snapshotId.trim()) ||