Skip to content

feat(bookmarks): add message bookmarks (MSC4438)#601

Open
Just-Insane wants to merge 6 commits intoSableClient:devfrom
Just-Insane:feat/message-bookmarks
Open

feat(bookmarks): add message bookmarks (MSC4438)#601
Just-Insane wants to merge 6 commits intoSableClient:devfrom
Just-Insane:feat/message-bookmarks

Conversation

@Just-Insane
Copy link
Copy Markdown
Contributor

@Just-Insane Just-Insane commented Mar 30, 2026

Description

Implements MSC4438 message bookmarks as an experimental feature, allowing users to save individual messages to a personal bookmark list stored in Matrix account data.

Fixes #600

What's included:

  • Data layer: bookmarkDomain.ts, bookmarkRepository.ts — bookmark ID algorithm (djb2-style, compatible with Cinny reference impl), account data CRUD helpers following MSC4438 ordering guarantees (item written before index)
  • State: state/bookmarks.ts — Jotai atoms (bookmarkListAtom, bookmarkLoadingAtom, bookmarkIdSetAtom) reactive to Matrix account data
  • Hook: useBookmarks.tsuseBookmarkList, useIsBookmarked, useBookmarkActions (refresh, add, remove with optimistic updates)
  • UI — Bookmarks page: BookmarksList.tsx — sidebar page with room filter, Jump button, remove button
  • UI — Message menu item: MessageBookmarkItem in Message.tsx — context menu entry to bookmark/unbookmark a message
  • Routing: new bookmarks path under home, useHomeBookmarksSelected hook, wired into Router.tsx
  • Experimental settings toggle: MSC4438MessageBookmarks.tsx in Experimental settings — per-user opt-in
  • Tests: unit tests for domain logic, repository layer, and Jotai atoms (74 tests)

The feature is gated by two independent mechanisms (either enables it): the config.json experiments.messageBookmarks flag (operator level) and the per-user experimental settings toggle.

Note: This PR includes the experiment infrastructure (ExperimentConfig, ExperimentSelection, selectExperimentVariant, useExperimentVariant) also introduced in #572. If #572 merges first, the infrastructure parts of this PR can be dropped.

References:

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

AI disclosure:

  • Partially AI assisted (clarify which code was AI assisted and briefly explain what it does).
  • Fully AI generated (explain what all the generated code does in moderate detail).

This PR was fully generated with GitHub Copilot. The implementation adds MSC4438 message bookmarks: a djb2-style hash function generates a stable bookmark ID from roomId|eventId, which is used as the account data event-type suffix. The repository layer writes item events before updating the index (as required by MSC4438 for cross-device consistency) and soft-deletes items on removal since account data cannot be deleted from the server. Jotai atoms hold the cached bookmark list and a derived Set for O(1) per-message lookup. The UI consists of a sidebar list page (with room filter and jump/remove actions) and a context menu entry on message bubbles that toggles bookmark state with optimistic local updates.

- bookmarkDomain: types, djb2 ID algorithm, helpers
- bookmarkRepository: add/remove/list over account data
- state/bookmarks: Jotai atoms (list, loading, id set for O(1) lookup)
- useBookmarks: hooks (list, loading, isBookmarked, add/remove/refresh)
- BookmarksList: full page (filter, room-grouped, jump, remove dialog)
- paths/pathUtils/useHomeSelected/Router: HOME_BOOKMARKS_PATH + route
- Home: Bookmarks NavItem (gated behind enableMessageBookmarks flag)
- Message: MessageBookmarkItem (gated behind enableMessageBookmarks flag)
- settings: enableMessageBookmarks: false (experimental, opt-in)
- Experimental: MSC4438MessageBookmarks toggle with issue SableClient#600 link

Closes SableClient#600
Add experiment infrastructure (ExperimentConfig, selectExperimentVariant,
useExperimentVariant) to useClientConfig following PR SableClient#572 pattern.

Add 'messageBookmarks' experiment entry to config.json (disabled by default).
Operators can enable via config.json or CLIENT_CONFIG_OVERRIDES_JSON env var.

Gate bookmarks in Home.tsx and MessageBookmarkItem with experiment flag OR
user's experimental settings toggle — either path enables the feature.
);
}

// ---------------------------------------------------------------------------
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for these separators?

// Unstable event type identifiers (MSC4438 §Unstable prefix)
// ---------------------------------------------------------------------------

export const BOOKMARKS_INDEX_EVENT = 'org.matrix.msc4438.bookmarks.index';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn’t we store account prefixes in a completely different file?

import { useCallback } from 'react';
import { BookmarkItemContent, computeBookmarkId } from './bookmarkDomain';
import {
addBookmark as repoAdd,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may i ask what’s the reason for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Message Bookmarks (MSC4438)

2 participants