From 4234cbc0e14f412be7448e5bb16565a3aa8a9a72 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Fri, 16 Jun 2023 17:46:23 -0700 Subject: [PATCH] Add support for highlights --- ROADMAP.md | 5 +- src/app/shared/NoteContent.svelte | 107 ++-------------------- src/app/shared/NoteContentKind1.svelte | 67 ++++++++++++++ src/app/shared/NoteContentKind1985.svelte | 16 ++++ src/app/shared/NoteContentKind9802.svelte | 20 ++++ src/app/shared/NoteContentLink.svelte | 2 - src/app/shared/NoteContentRating.svelte | 39 ++++++++ src/util/nostr.ts | 1 - src/util/notes.ts | 18 +++- 9 files changed, 171 insertions(+), 104 deletions(-) create mode 100644 src/app/shared/NoteContentKind1.svelte create mode 100644 src/app/shared/NoteContentKind1985.svelte create mode 100644 src/app/shared/NoteContentKind9802.svelte create mode 100644 src/app/shared/NoteContentRating.svelte diff --git a/ROADMAP.md b/ROADMAP.md index 42b90cde..dc4ca416 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,7 +1,10 @@ # Current +- [ ] Spam + - Add configurable POW req for replies + - Add event queue and undo, use the delay to calculate POW - [ ] Support other kinds - - Fix note truncation + - Fix note truncation, sometimes an ellipsis ends up after the last one - [ ] Feeds load forever if a modal is open - [ ] Support other list types than 30001 - [ ] Fix connection management stuff. Have GPT help diff --git a/src/app/shared/NoteContent.svelte b/src/app/shared/NoteContent.svelte index 272f8281..733e36b2 100644 --- a/src/app/shared/NoteContent.svelte +++ b/src/app/shared/NoteContent.svelte @@ -1,107 +1,20 @@ -
-

- {#if rating} - {@const [type, value] = Tags.from(note) - .reject(t => ["l", "L"].includes(t[0])) - .first()} - {@const action = switcher(type, { - r: () => modal.push({type: "relay/detail", url: value}), - p: () => modal.push({type: "person/feed", pubkey: value}), - e: () => modal.push({type: "note/detail", note: {id: value}}), - })} - {@const display = switcherFn(type, { - r: () => displayRelay({url: value}), - p: () => displayPerson(getPersonWithFallback(value)), - e: () => "a note", - default: "something", - })} -

- Rated - {#if action} - {display} - {:else} - {display} - {/if} -
- -
-
- {/if} - {#each shortContent as { type, value }, i} - {#if type === NEWLINE} - - {:else if type === TOPIC} - - {:else if type === INVOICE} -
- -
- {:else if type === LINK} - - {:else if type.match(/^nostr:np(rofile|ub)$/)} - - {:else if type.startsWith("nostr:") && showMedia && isStandalone(i) && value.id !== anchorId} - -
- -
-
- {:else if type.startsWith("nostr:")} - - {:else} - {value} - {/if} - {" "} - {/each} -

- {#if showMedia && extraLinks.length > 0} - - {/if} -
+{#if note.kind === 1985} + +{:else if note.kind === 9802} + +{:else} + +{/if} diff --git a/src/app/shared/NoteContentKind1.svelte b/src/app/shared/NoteContentKind1.svelte new file mode 100644 index 00000000..cfe0f614 --- /dev/null +++ b/src/app/shared/NoteContentKind1.svelte @@ -0,0 +1,67 @@ + + +
+

+ {#each shortContent as { type, value }, i} + {#if type === NEWLINE} + + {:else if type === TOPIC} + + {:else if type === INVOICE} +

+ +
+ {:else if type === LINK} + + {:else if type.match(/^nostr:np(rofile|ub)$/)} + + {:else if type.startsWith("nostr:") && showMedia && isStartOrEnd(i) && value.id !== anchorId} + +
+ +
+
+ {:else if type.startsWith("nostr:")} + + {:else} + {value} + {/if} + {" "} + {/each} +

+ {#if showMedia && extraLinks.length > 0} + + {/if} +
diff --git a/src/app/shared/NoteContentKind1985.svelte b/src/app/shared/NoteContentKind1985.svelte new file mode 100644 index 00000000..24fe84c5 --- /dev/null +++ b/src/app/shared/NoteContentKind1985.svelte @@ -0,0 +1,16 @@ + + +
+ {#if rating} + + {/if} + +
diff --git a/src/app/shared/NoteContentKind9802.svelte b/src/app/shared/NoteContentKind9802.svelte new file mode 100644 index 00000000..dd067021 --- /dev/null +++ b/src/app/shared/NoteContentKind9802.svelte @@ -0,0 +1,20 @@ + + +
+
+ +
+
+ +{#if ref} + +{/if} diff --git a/src/app/shared/NoteContentLink.svelte b/src/app/shared/NoteContentLink.svelte index 4854d880..2d075438 100644 --- a/src/app/shared/NoteContentLink.svelte +++ b/src/app/shared/NoteContentLink.svelte @@ -10,8 +10,6 @@ hidden = true } - console.log(value) - let hidden = false diff --git a/src/app/shared/NoteContentRating.svelte b/src/app/shared/NoteContentRating.svelte new file mode 100644 index 00000000..1dcf0a3c --- /dev/null +++ b/src/app/shared/NoteContentRating.svelte @@ -0,0 +1,39 @@ + + +
+ Rated + {#if action} + {display} + {:else} + {display} + {/if} +
+ +
+
diff --git a/src/util/nostr.ts b/src/util/nostr.ts index f0ed54a6..020ac573 100644 --- a/src/util/nostr.ts +++ b/src/util/nostr.ts @@ -6,7 +6,6 @@ import {tryJson, avg} from "src/util/misc" import {invoiceAmount} from "src/util/lightning" export const noteKinds = [1, 1985, 30023, 30018, 10001, 1063, 9802] -// export const noteKinds = [9802] export const personKinds = [0, 2, 3, 10001, 10002] export const userKinds = personKinds.concat([10000, 30001, 30078]) export const appDataKeys = [ diff --git a/src/util/notes.ts b/src/util/notes.ts index 21672cd2..e2f4bb66 100644 --- a/src/util/notes.ts +++ b/src/util/notes.ts @@ -1,4 +1,4 @@ -import {last, identity} from "ramda" +import {last, pluck, identity} from "ramda" import {nip19} from "nostr-tools" import {first} from "hurdak/lib/hurdak" import {fromNostrURI} from "src/util/nostr" @@ -14,7 +14,7 @@ export const NOSTR_NPUB = "nostr:npub" export const NOSTR_NPROFILE = "nostr:nprofile" export const NOSTR_NADDR = "nostr:naddr" -const canDisplayUrl = url => !url.match(/\.(apk|docx|xlsx|csv|dmg)/) +export const canDisplayUrl = url => !url.match(/\.(apk|docx|xlsx|csv|dmg)/) export const parseContent = ({content, tags = []}) => { const result = [] @@ -160,7 +160,7 @@ export const parseContent = ({content, tags = []}) => { return result } -export const truncateContent = (content, {showEntire, maxLength, showMedia}) => { +export const truncateContent = (content, {showEntire, maxLength, showMedia = false}) => { if (showEntire) { return content } @@ -194,3 +194,15 @@ export const truncateContent = (content, {showEntire, maxLength, showMedia}) => return result } + +export const getLinks = parts => + pluck( + "value", + parts.filter(x => x.type === LINK && x.canDisplay) + ) + +export const isStandalone = (content, i) => + !content[i - 1] || + content[i - 1].type === NEWLINE || + !content[i + 1] || + content[i + 1].type === NEWLINE