@@ -420,6 +420,9 @@ function createMockCustomEmojiSetEvents(): RelayEvent[] {
420420 [
421421 [ "d" , CUSTOM_EMOJI_SET_D_TAG ] ,
422422 [ "emoji" , "sprout" , "https://example.com/e2e/sprout.png" ] ,
423+ // A relay-hosted emoji whose URL matches rewriteRelayUrl()'s pattern,
424+ // used by the reaction guard to assert the proxy rewrite fires.
425+ [ "emoji" , REACTION_EMOJI_SHORTCODE , REACTION_EMOJI_URL ] ,
423426 ] ,
424427 // The current mock identity owns this set, so the settings card's
425428 // "My emoji" section is non-empty and removable.
@@ -516,6 +519,32 @@ declare global {
516519
517520const DEFAULT_RELAY_HTTP_URL = "http://localhost:3000" ;
518521const DEFAULT_RELAY_WS_URL = "ws://localhost:3000" ;
522+
523+ // NIP event kinds the mock reaction handlers emit.
524+ const KIND_REACTION = 7 ; // NIP-25 reaction
525+ const KIND_DELETION = 5 ; // NIP-09 deletion
526+
527+ // Fake media-proxy port the mock answers for `get_media_proxy_port`, so
528+ // `rewriteRelayUrl()` produces a real `http://localhost:<port>/media/...` src
529+ // in e2e (instead of the `sprout-media://` fallback). The reaction guard
530+ // asserts against this exact port.
531+ const MOCK_MEDIA_PROXY_PORT = 54321 ;
532+
533+ // A relay-hosted custom emoji used by the reaction guard. Its URL matches
534+ // `rewriteRelayUrl()`'s `/media/{64-hex}.{ext}` pattern on the relay origin, so
535+ // reacting with it exercises the proxy rewrite (unlike the `:sprout:` fixture,
536+ // whose external example.com URL passes through unchanged).
537+ const REACTION_EMOJI_SHORTCODE = "react" ;
538+ const REACTION_EMOJI_SHA = "c" . repeat ( 64 ) ;
539+ const REACTION_EMOJI_URL = `${ DEFAULT_RELAY_HTTP_URL } /media/${ REACTION_EMOJI_SHA } .png` ;
540+
541+ // A reaction-target message seeded into `general` with a real 64-hex event id.
542+ // The reaction guard reacts to THIS message: getReactionTargetId() only accepts
543+ // a 64-hex `e` tag, and the other mock seeds (and user-sent messages) use short
544+ // non-hex ids, so they can't be reaction targets. Content is distinctive so the
545+ // test locates its row without relying on seed ordering.
546+ const REACTION_TARGET_EVENT_ID = "d" . repeat ( 64 ) ;
547+ const REACTION_TARGET_CONTENT = "React to me with a custom emoji" ;
519548const E2E_IDENTITY_OVERRIDE_STORAGE_KEY = "sprout:e2e-identity-override.v1" ;
520549const DEFAULT_MOCK_IDENTITY = {
521550 pubkey : "deadbeef" . repeat ( 8 ) ,
@@ -1782,6 +1811,20 @@ function getMockMessageStore(channelId: string): RelayEvent[] {
17821811 content : "Hey team — checking in." ,
17831812 sig : "mocksig" . repeat ( 20 ) . slice ( 0 , 128 ) ,
17841813 } ,
1814+ // Reaction-target seed for the custom-emoji reaction guard. Real
1815+ // 64-hex id so getReactionTargetId() accepts it as a reaction target
1816+ // (the short-id seeds above can't be reacted to). Backdated after the
1817+ // other seeds, so it stays at row index >= 2 and never displaces
1818+ // first()=welcome / nth(1)=alice that other specs rely on.
1819+ {
1820+ id : REACTION_TARGET_EVENT_ID ,
1821+ pubkey : ALICE_PUBKEY ,
1822+ created_at : Math . floor ( Date . now ( ) / 1000 ) - 45 ,
1823+ kind : 9 ,
1824+ tags : [ [ "h" , channelId ] ] ,
1825+ content : REACTION_TARGET_CONTENT ,
1826+ sig : "mocksig" . repeat ( 20 ) . slice ( 0 , 128 ) ,
1827+ } ,
17851828 ]
17861829 : channelId === "a27e1ee9-76a6-5bdf-a5d5-1d85610dad11"
17871830 ? [
@@ -2190,15 +2233,28 @@ function handleGetLikedNotes(): RawUserNotesResponse {
21902233 return { notes : [ ] , next_cursor : null } ;
21912234}
21922235
2236+ // A random 64-hex event id, matching the shape of real Nostr event ids
2237+ // (sha256 → 64 hex). Most mock events use the 32-hex `createMockEvent` default,
2238+ // but kind:7 reactions need a real 64-hex id: the timeline's deletion path only
2239+ // accepts 64-hex `e` tags (getDeletionTargets in formatTimelineMessages.ts), so
2240+ // a kind:5 targeting a 32-hex reaction id would be silently ignored and the
2241+ // reaction pill would never clear on toggle-off.
2242+ function mockEventId ( ) : string {
2243+ const bytes = new Uint8Array ( 32 ) ;
2244+ crypto . getRandomValues ( bytes ) ;
2245+ return Array . from ( bytes , ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) ) . join ( "" ) ;
2246+ }
2247+
21932248function createMockEvent (
21942249 kind : number ,
21952250 content : string ,
21962251 tags : string [ ] [ ] ,
21972252 pubkey = DEFAULT_MOCK_IDENTITY . pubkey ,
21982253 createdAt = Math . floor ( Date . now ( ) / 1000 ) ,
2254+ id = crypto . randomUUID ( ) . replace ( / - / g, "" ) ,
21992255) : RelayEvent {
22002256 return {
2201- id : crypto . randomUUID ( ) . replace ( / - / g , "" ) ,
2257+ id,
22022258 pubkey,
22032259 created_at : createdAt ,
22042260 kind,
@@ -4557,6 +4613,102 @@ async function handleSendChannelMessage(
45574613 } ;
45584614}
45594615
4616+ /** Locate the channel a stored mock event lives in (reactions carry no channel arg). */
4617+ function findMockEventChannel ( eventId : string ) : string | undefined {
4618+ for ( const [ channelId , events ] of mockMessages ) {
4619+ if ( events . some ( ( event ) => event . id === eventId ) ) {
4620+ return channelId ;
4621+ }
4622+ }
4623+ return undefined ;
4624+ }
4625+
4626+ /**
4627+ * Mock the `add_reaction` Tauri command. Mirrors the real Rust command: a
4628+ * kind:7 whose content is the emoji, plus — for a custom emoji — the NIP-30
4629+ * `["emoji", shortcode, url]` tag (shortcode normalized to match the relay).
4630+ * Recorded into the target's channel store and emitted live so the timeline's
4631+ * reaction aggregation renders the pill (the channel subscription includes
4632+ * kind:7). Unicode reactions carry no emoji tag, like the real command.
4633+ */
4634+ async function handleAddReaction (
4635+ args : { eventId : string ; emoji : string ; emojiUrl ?: string | null } ,
4636+ config : E2eConfig | undefined ,
4637+ ) : Promise < void > {
4638+ const channelId = findMockEventChannel ( args . eventId ) ;
4639+ if ( ! channelId ) {
4640+ throw new Error ( `mock add_reaction: unknown target event ${ args . eventId } ` ) ;
4641+ }
4642+
4643+ const emoji = args . emoji . trim ( ) ;
4644+ // `h` routes the live event to the channel store (getChannelIdFromTags);
4645+ // `e` names the reaction target. For a custom emoji, the NIP-30
4646+ // `["emoji", shortcode, url]` tag carries the image URL.
4647+ const tags : string [ ] [ ] = [
4648+ [ "h" , channelId ] ,
4649+ [ "e" , args . eventId ] ,
4650+ ] ;
4651+ if ( args . emojiUrl ) {
4652+ const shortcode = emoji . replace ( / ^ : + / , "" ) . replace ( / : + $ / , "" ) . toLowerCase ( ) ;
4653+ tags . push ( [ "emoji" , shortcode , args . emojiUrl ] ) ;
4654+ }
4655+
4656+ const event = createMockEvent (
4657+ KIND_REACTION ,
4658+ emoji ,
4659+ tags ,
4660+ getMockMemberPubkey ( config ) ,
4661+ Math . floor ( Date . now ( ) / 1000 ) ,
4662+ // 64-hex id so the kind:5 deletion emitted by remove_reaction is accepted
4663+ // by the timeline (getDeletionTargets requires a 64-hex `e` tag).
4664+ mockEventId ( ) ,
4665+ ) ;
4666+ recordMockMessage ( channelId , event ) ;
4667+ emitMockLiveEvent ( channelId , event ) ;
4668+ }
4669+
4670+ /**
4671+ * Mock the `remove_reaction` Tauri command. Finds the active member's own
4672+ * kind:7 for this target+emoji, removes it from the store, and emits a kind:5
4673+ * deletion so the timeline drops the reaction (the real command deletes via a
4674+ * kind:5 too).
4675+ */
4676+ async function handleRemoveReaction (
4677+ args : { eventId : string ; emoji : string } ,
4678+ config : E2eConfig | undefined ,
4679+ ) : Promise < void > {
4680+ const channelId = findMockEventChannel ( args . eventId ) ;
4681+ if ( ! channelId ) {
4682+ return ;
4683+ }
4684+
4685+ const myPubkey = getMockMemberPubkey ( config ) . toLowerCase ( ) ;
4686+ const emoji = args . emoji . trim ( ) ;
4687+ const store = getMockMessageStore ( channelId ) ;
4688+ const reaction = store . find (
4689+ ( event ) =>
4690+ event . kind === KIND_REACTION &&
4691+ event . pubkey . toLowerCase ( ) === myPubkey &&
4692+ event . content . trim ( ) === emoji &&
4693+ event . tags . some ( ( t ) => t [ 0 ] === "e" && t [ 1 ] === args . eventId ) ,
4694+ ) ;
4695+ if ( ! reaction ) {
4696+ return ;
4697+ }
4698+
4699+ const index = store . indexOf ( reaction ) ;
4700+ store . splice ( index , 1 ) ;
4701+
4702+ const deletion = createMockEvent (
4703+ KIND_DELETION ,
4704+ "" ,
4705+ [ [ "e" , reaction . id ] ] ,
4706+ getMockMemberPubkey ( config ) ,
4707+ ) ;
4708+ recordMockMessage ( channelId , deletion ) ;
4709+ emitMockLiveEvent ( channelId , deletion ) ;
4710+ }
4711+
45604712async function handleGetEvent (
45614713 args : {
45624714 eventId : string ;
@@ -5323,6 +5475,18 @@ export function maybeInstallE2eTauriMocks() {
53235475 payload as Parameters < typeof handleSendChannelMessage > [ 0 ] ,
53245476 activeConfig ,
53255477 ) ;
5478+ case "add_reaction" :
5479+ return handleAddReaction (
5480+ payload as Parameters < typeof handleAddReaction > [ 0 ] ,
5481+ activeConfig ,
5482+ ) ;
5483+ case "remove_reaction" :
5484+ return handleRemoveReaction (
5485+ payload as Parameters < typeof handleRemoveReaction > [ 0 ] ,
5486+ activeConfig ,
5487+ ) ;
5488+ case "get_media_proxy_port" :
5489+ return MOCK_MEDIA_PROXY_PORT ;
53265490 case "pick_and_upload_media" :
53275491 return resolveMockUploadDescriptors ( activeConfig ) ;
53285492 case "upload_media_bytes" :
0 commit comments