kernl API
    Preparing search index...

    Function createMemoryBackend

    • A complete MessagingBackend that lives in memory.

      Used by the shell's offline preview and by tests. Conversations are keyed direct:<pubkey> or group:<pubkey>,<pubkey> over the sorted correspondents. send() stores the message as sent, notifies subscribers and returns it; deliver() plays the other side. Unread counts are the number of received messages in a conversation. Cursors are numeric offsets.

      send() rejects with invalid:no-recipients when neither a conversation nor a recipient is named, with invalid:unknown-conversation for an id the backend has never seen, and with unavailable:offline while available is false. Reads keep working offline so a preview can still show history.

      Parameters

      Returns MemoryBackend

      A backend that also exposes deliver().

      const backend = createMemoryBackend({ owner: 'me', now: () => 1_700_000_000 });
      await backend.send({ recipients: ['alice'], content: 'hi' });
      backend.deliver({ senderPubkey: 'alice', content: 'hello' });
      (await backend.conversations()).conversations[0];
      // { id: 'direct:alice', kind: 'direct', participants: [{ pubkey: 'alice' }], unread: 1, updatedAt: 1700000000 }