From 1b577d3326593377f246df8a327c731ef163031d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 6 Jan 2026 19:48:55 +0000 Subject: [PATCH] Refactor: remove legacy compatibility systems - Removed `WATCH_HISTORY_LEGACY_KIND` (30078) support from watch history fetch and config. - Removed `WATCH_HISTORY_LEGACY_LIST_IDENTIFIERS` from config. - Removed `LEGACY_EVENTS_STORAGE_KEY` (bitvidEvents) migration logic from client. - Removed `loadLegacyAdminState` and `LEGACY_STORAGE_KEYS` from admin list store. - Updated tests to remove references to legacy kinds. --- config/instance-config.js | 9 ---- js/adminListStore.js | 90 ------------------------------------ js/config.js | 4 -- js/nostr/client.js | 21 --------- js/nostr/watchHistory.js | 9 ---- tests/watch-history.test.mjs | 3 +- 6 files changed, 1 insertion(+), 135 deletions(-) diff --git a/config/instance-config.js b/config/instance-config.js index abeb30fd..8c81c133 100644 --- a/config/instance-config.js +++ b/config/instance-config.js @@ -302,7 +302,6 @@ export const THEME_ACCENT_OVERRIDES = Object.freeze({ * accept the chosen kind. */ export const WATCH_HISTORY_KIND = 30003; -export const WATCH_HISTORY_LEGACY_KIND = 30078; /** * Identifier applied to the watch-history list when storing it on relays. @@ -314,14 +313,6 @@ export const WATCH_HISTORY_LEGACY_KIND = 30078; */ export const WATCH_HISTORY_LIST_IDENTIFIER = "watch-history"; -/** - * Legacy identifiers that bitvid clients should continue honoring when - * fetching historical watch-history snapshots. - */ -export const WATCH_HISTORY_LEGACY_LIST_IDENTIFIERS = Object.freeze([ - "watch-history:v2:index", -]); - /** * Whether to enable the V2 encrypted watch-history service. * diff --git a/js/adminListStore.js b/js/adminListStore.js index ef9c83fa..5d070bf1 100644 --- a/js/adminListStore.js +++ b/js/adminListStore.js @@ -18,14 +18,6 @@ import { } from "./nostrEventSchemas.js"; import { publishEventToRelay } from "./nostrPublish.js"; -const LEGACY_STORAGE_KEYS = { - editors: "bitvid_admin_editors", - whitelist: "bitvid_admin_whitelist", - whitelistLegacy: "bitvid_whitelist", - blacklist: "bitvid_admin_blacklist", - blacklistLegacy: "bitvid_blacklist", -}; - const ADMIN_STATE_CACHE_VERSION = 1; const ADMIN_STATE_CACHE_KEY = `bitvid_admin_state_v${ADMIN_STATE_CACHE_VERSION}`; @@ -240,42 +232,6 @@ function hasAnyEntries(state = {}) { ); } -function readJsonListFromStorage(key) { - if (typeof localStorage === "undefined") { - return null; - } - - try { - const raw = localStorage.getItem(key); - if (raw === null) { - return null; - } - const parsed = JSON.parse(raw); - return Array.isArray(parsed) ? parsed : null; - } catch (error) { - devLogger.warn( - `[adminListStore] Failed to parse legacy list for ${key}:`, - error, - ); - return null; - } -} - -function loadLegacyAdminState() { - const editors = readJsonListFromStorage(LEGACY_STORAGE_KEYS.editors) || []; - const whitelist = - readJsonListFromStorage(LEGACY_STORAGE_KEYS.whitelist) || - readJsonListFromStorage(LEGACY_STORAGE_KEYS.whitelistLegacy) || - []; - const blacklist = - readJsonListFromStorage(LEGACY_STORAGE_KEYS.blacklist) || - readJsonListFromStorage(LEGACY_STORAGE_KEYS.blacklistLegacy) || - []; - - const sanitized = sanitizeAdminState({ editors, whitelist, blacklist }); - return hasAnyEntries(sanitized) ? sanitized : null; -} - export const readCachedAdminState = () => { if (typeof localStorage === "undefined") { return null; @@ -324,40 +280,6 @@ export const writeCachedAdminState = (state) => { } }; -function clearLegacyStorageFor(listKey) { - if (typeof localStorage === "undefined") { - return; - } - - const keyGroups = { - editors: [LEGACY_STORAGE_KEYS.editors], - whitelist: [ - LEGACY_STORAGE_KEYS.whitelist, - LEGACY_STORAGE_KEYS.whitelistLegacy, - ], - blacklist: [ - LEGACY_STORAGE_KEYS.blacklist, - LEGACY_STORAGE_KEYS.blacklistLegacy, - ], - }; - - const keys = keyGroups[listKey]; - if (!Array.isArray(keys)) { - return; - } - - for (const key of keys) { - try { - localStorage.removeItem(key); - } catch (error) { - devLogger.warn( - `[adminListStore] Failed to clear legacy storage for ${key}:`, - error, - ); - } - } -} - function ensureNostrReady() { const nostrClient = requireNostrClient(); @@ -1010,8 +932,6 @@ async function persistNostrState(actorNpub, updates = {}) { loggingError, ); }); - - clearLegacyStorageFor(listKey); } } @@ -1082,16 +1002,6 @@ export async function loadAdminState() { } } - if (!hasAnyEntries(mergedState)) { - const legacy = loadLegacyAdminState(); - if (legacy && isDevMode) { - userLogger.warn( - "[adminListStore] Ignoring legacy admin lists because remote mode is enforced. Publish them to Nostr to retain access.", - legacy - ); - } - } - return mergedState || sanitizeAdminState(); } diff --git a/js/config.js b/js/config.js index 214bdeb1..3a270c83 100644 --- a/js/config.js +++ b/js/config.js @@ -28,9 +28,7 @@ import { DEFAULT_TRUSTED_MUTE_HIDE_THRESHOLD, DEFAULT_TRUSTED_SPAM_HIDE_THRESHOLD, WATCH_HISTORY_KIND, - WATCH_HISTORY_LEGACY_KIND, WATCH_HISTORY_LIST_IDENTIFIER, - WATCH_HISTORY_LEGACY_LIST_IDENTIFIERS, WATCH_HISTORY_MAX_ITEMS, WATCH_HISTORY_BATCH_RESOLVE, WATCH_HISTORY_BATCH_PAGE_SIZE, @@ -119,9 +117,7 @@ export { ADMIN_WHITELIST_MODE_STORAGE_KEY }; // ----------------------------------------------------------------------------- export { WATCH_HISTORY_KIND }; -export { WATCH_HISTORY_LEGACY_KIND }; export { WATCH_HISTORY_LIST_IDENTIFIER }; -export { WATCH_HISTORY_LEGACY_LIST_IDENTIFIERS }; export { WATCH_HISTORY_MAX_ITEMS }; export { WATCH_HISTORY_BATCH_RESOLVE }; export { WATCH_HISTORY_BATCH_PAGE_SIZE }; diff --git a/js/nostr/client.js b/js/nostr/client.js index 156aea7c..73f02b36 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -298,7 +298,6 @@ function shouldRequestExtensionPermissions(signer) { } const EVENTS_CACHE_STORAGE_KEY = "bitvid:eventsCache:v1"; -const LEGACY_EVENTS_STORAGE_KEY = "bitvidEvents"; const EVENTS_CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes const EVENTS_CACHE_DB_NAME = "bitvid-events-cache"; const EVENTS_CACHE_DB_VERSION = 1; @@ -3333,25 +3332,6 @@ export class NostrClient { let payload = parsePayload(localStorage.getItem(EVENTS_CACHE_STORAGE_KEY)); - if (!payload) { - const legacyRaw = localStorage.getItem(LEGACY_EVENTS_STORAGE_KEY); - const legacyParsed = parsePayload(legacyRaw); - if (legacyParsed) { - payload = { - version: 1, - savedAt: now, - events: legacyParsed, - }; - } - if (legacyRaw) { - try { - localStorage.removeItem(LEGACY_EVENTS_STORAGE_KEY); - } catch (err) { - devLogger.warn("[nostr] Failed to remove legacy cache:", err); - } - } - } - const applied = this.applyCachedPayload(payload, "localStorage"); if (!applied && payload) { @@ -5570,7 +5550,6 @@ export class NostrClient { EVENTS_CACHE_STORAGE_KEY, JSON.stringify(serializedPayload), ); - localStorage.removeItem(LEGACY_EVENTS_STORAGE_KEY); } catch (err) { devLogger.warn("[nostr] Failed to persist events cache:", err); } diff --git a/js/nostr/watchHistory.js b/js/nostr/watchHistory.js index debdb485..b1ac8a68 100644 --- a/js/nostr/watchHistory.js +++ b/js/nostr/watchHistory.js @@ -1,8 +1,6 @@ import { WATCH_HISTORY_KIND, - WATCH_HISTORY_LEGACY_KIND, WATCH_HISTORY_LIST_IDENTIFIER, - WATCH_HISTORY_LEGACY_LIST_IDENTIFIERS, WATCH_HISTORY_MAX_ITEMS, WATCH_HISTORY_BATCH_RESOLVE, WATCH_HISTORY_BATCH_PAGE_SIZE, @@ -1885,13 +1883,6 @@ class WatchHistoryManager { let pointerEvents = []; try { const kinds = [WATCH_HISTORY_KIND]; - if ( - Number.isFinite(WATCH_HISTORY_LEGACY_KIND) && - WATCH_HISTORY_LEGACY_KIND > 0 && - WATCH_HISTORY_LEGACY_KIND !== WATCH_HISTORY_KIND - ) { - kinds.push(WATCH_HISTORY_LEGACY_KIND); - } const filters = [ { kinds, diff --git a/tests/watch-history.test.mjs b/tests/watch-history.test.mjs index b2eec13b..c2ed27ab 100644 --- a/tests/watch-history.test.mjs +++ b/tests/watch-history.test.mjs @@ -11,7 +11,6 @@ const { WATCH_HISTORY_BATCH_PAGE_SIZE, WATCH_HISTORY_LIST_IDENTIFIER, WATCH_HISTORY_KIND, - WATCH_HISTORY_LEGACY_KIND, } = await import("../js/config.js"); const { @@ -2564,7 +2563,7 @@ async function testWatchHistoryFeedHydration() { results.push(videoEvent); } - if (filter.kinds && (filter.kinds.includes(WATCH_HISTORY_KIND) || filter.kinds.includes(WATCH_HISTORY_LEGACY_KIND))) { + if (filter.kinds && (filter.kinds.includes(WATCH_HISTORY_KIND))) { results.push({ id: "history-event-id", kind: WATCH_HISTORY_KIND,