6.0 KiB
6.0 KiB
Event Management: Edit & Repost Feature
Overview
Add the ability to edit and repost events from the Event Detail panel in event-management.html. The raw JSON in #preEventJson becomes an editable <textarea>, and for encrypted events, the decrypted content in #preDecryptedContent also becomes an editable <textarea>. On repost, the page re-encrypts (if needed), re-signs, and publishes the updated event.
Current Architecture
flowchart TD
A[Select event in middle column] --> B[renderDetail populates preEventJson]
B --> C{isLikelyEncryptedEvent?}
C -- yes --> D[autoDecryptDetailEvent]
D --> E[Display decrypted text in preDecryptedContent]
C -- no --> F[Show 'Content does not appear encrypted']
Proposed Architecture
flowchart TD
A[Select event in middle column] --> B[renderDetail populates txtEventJson textarea]
B --> C{isLikelyEncryptedEvent?}
C -- yes --> D[autoDecryptDetailEvent]
D --> E[Display decrypted text in txtDecryptedContent textarea - editable]
C -- no --> F[Show 'Content does not appear encrypted' - textarea hidden/readonly]
G[User clicks 'Edit & Repost'] --> H{Was content encrypted?}
H -- yes --> I[Read txtDecryptedContent plaintext]
I --> J[Detect original encryption method - NIP-04 or NIP-44]
J --> K[Re-encrypt plaintext using same method + peer pubkey]
K --> L[Inject encrypted content into event JSON]
H -- no --> L
L --> M[Parse txtEventJson to get kind, tags, content]
M --> N[Build unsigned event with fresh created_at]
N --> O[publishEvent via NDK worker - auto-signs]
O --> P[Update UI: status message, refresh kind list]
Detailed Changes
1. HTML: Convert <pre> elements to <textarea> elements
File: event-management.html
- Replace
<pre id="preEventJson">(line 294) with<textarea id="txtEventJson">styled identically (monospace, same border/background) - Replace
<pre id="preDecryptedContent">(line 296) with<textarea id="txtDecryptedContent">styled identically - Add an "Edit & Repost" button to the existing
.btnRowin the detail panel (line 287-293), next to the existing buttons
2. CSS: Style the new textareas
- Add styles for
#txtEventJsonand#txtDecryptedContentthat match the existing#preEventJson/#preDecryptedContentstyles - Both textareas should be resizable vertically, use monospace font, and have the same border/background treatment
- The decrypted textarea should be visually distinct when editable vs when showing non-encrypted placeholder text
3. JavaScript: Track encryption metadata
When autoDecryptDetailEvent succeeds, store the encryption context so we can re-encrypt on repost:
lastDecryptResult— object storing{ method: 'NIP-04'|'NIP-44', peerPubkey: string, plaintext: string }from the last successful decrypt- Reset this to
nullwhenever a new event is selected or when no encryption is detected
4. JavaScript: Wire up the Edit & Repost button
The btnEditRepost click handler:
- Parse the JSON from
txtEventJson.value— extractkind,tags,content - Check if decrypted content was edited:
- If
lastDecryptResultis set (event was encrypted) ANDtxtDecryptedContent.valuediffers fromlastDecryptResult.plaintext:- Re-encrypt using the detected method:
- NIP-04:
await window.nostr.nip04.encrypt(peerPubkey, newPlaintext) - NIP-44:
await window.nostr.nip44.encrypt(peerPubkey, newPlaintext)
- NIP-04:
- Replace the
contentfield in the parsed JSON with the new ciphertext
- Re-encrypt using the detected method:
- If the user edited the raw JSON content field directly (and it differs from the original), use that as-is (user is responsible for providing valid ciphertext or plaintext)
- If
- Build the unsigned event:
const draft = { kind: parsedEvent.kind, created_at: Math.floor(Date.now() / 1000), tags: parsedEvent.tags, content: finalContent }; - Publish via
publishEvent(draft)— the NDK worker handles signing automatically - Update UI:
- Show status in
divKindsStatus - Optionally refresh the kind from relays to see the new event appear
- Update
currentDetailEventand re-render
- Show status in
5. JavaScript: Update element references
- Update all references from
preEventJson→txtEventJsonandpreDecryptedContent→txtDecryptedContent - Update
renderDetail()to set.valueinstead of.textContent - Update
setDecryptedOutput()to set.valueinstead of.textContent - Update
btnCopyEventJsonhandler to read from.value
6. JavaScript: Confirmation dialog
Before publishing, show a window.confirm() dialog:
- For encrypted events: "Re-encrypt and publish updated event (kind X)?"
- For non-encrypted events: "Publish updated event (kind X) with fresh timestamp?"
7. Edge Cases
- Non-replaceable kinds (kind 1, etc.): Publishing creates a brand new event. The confirm dialog should warn that this creates a new event, not a replacement.
- Replaceable kinds (0, 3, 10000-19999): Publishing with same pubkey supersedes the old one automatically.
- Parameterized replaceable kinds (30000-39999): Must preserve the
dtag to replace the correct event. - Missing signer: If
window.nostr.signEventis unavailable, show an error. - Encryption unavailable: If the event was NIP-44 encrypted but
window.nostr.nip44.encryptis missing, show an error before attempting. - Parse errors: If the user enters invalid JSON in the textarea, catch and display the error.
Files Modified
| File | Changes |
|---|---|
event-management.html |
HTML: swap <pre> → <textarea>, add Edit & Repost button. CSS: textarea styles. JS: new button handler, updated element refs, encryption tracking |
No New Files
All changes are contained within the single event-management.html file since the page is self-contained with inline <script> and <style>.