diff --git a/package-lock.json b/package-lock.json index aa24fb0..b1a2cf4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5850,14 +5850,6 @@ "node": ">= 0.4" } }, - "node_modules/async-validator": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz", - "integrity": "sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==", - "license": "MIT", - "optional": true, - "peer": true - }, "node_modules/at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", @@ -9763,13 +9755,13 @@ } }, "node_modules/jws": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz", - "integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", "dev": true, "license": "MIT", "dependencies": { - "jwa": "^2.0.0", + "jwa": "^2.0.1", "safe-buffer": "^5.0.1" } }, @@ -13979,9 +13971,9 @@ } }, "node_modules/vite": { - "version": "6.3.5", - "resolved": "https://registry.npmjs.org/vite/-/vite-6.3.5.tgz", - "integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==", + "version": "6.4.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz", + "integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==", "dev": true, "license": "MIT", "dependencies": { diff --git a/src/core/di-container.ts b/src/core/di-container.ts index 32221f5..f9d65f9 100644 --- a/src/core/di-container.ts +++ b/src/core/di-container.ts @@ -137,6 +137,11 @@ export const SERVICE_TOKENS = { PROFILE_SERVICE: Symbol('profileService'), REACTION_SERVICE: Symbol('reactionService'), + // Link aggregator services + SUBMISSION_SERVICE: Symbol('submissionService'), + LINK_PREVIEW_SERVICE: Symbol('linkPreviewService'), + COMMUNITY_SERVICE: Symbol('communityService'), + // Nostr metadata services NOSTR_METADATA_SERVICE: Symbol('nostrMetadataService'), diff --git a/src/modules/nostr-feed/LINK_AGGREGATOR_PLAN.md b/src/modules/nostr-feed/LINK_AGGREGATOR_PLAN.md new file mode 100644 index 0000000..9f91aff --- /dev/null +++ b/src/modules/nostr-feed/LINK_AGGREGATOR_PLAN.md @@ -0,0 +1,176 @@ +# Link Aggregator Implementation Plan + +## Overview + +Transform the nostr-feed module into a Reddit-style link aggregator with support for: +- **Link posts** - External URLs with Open Graph previews +- **Media posts** - Images/videos with inline display +- **Self posts** - Text/markdown content + +## NIP Compliance + +| NIP | Purpose | Usage | +|-----|---------|-------| +| NIP-72 | Moderated Communities | Community definitions (kind 34550), approvals (kind 4550) | +| NIP-22 | Comments | Community posts (kind 1111) with scoped threading | +| NIP-92 | Media Attachments | `imeta` tags for media metadata | +| NIP-94 | File Metadata | Reference for media fields | +| NIP-25 | Reactions | Upvote (`+`) / Downvote (`-`) | +| NIP-10 | Reply Threading | Fallback for kind 1 compatibility | + +## Event Structure + +### Submission (kind 1111) + +```jsonc +{ + "kind": 1111, + "content": "", + "tags": [ + // Community scope (NIP-72 + NIP-22) + ["A", "34550::", ""], + ["a", "34550::", ""], + ["K", "34550"], + ["k", "34550"], + ["P", ""], + ["p", ""], + + // Submission metadata + ["title", ""], + ["post-type", "link|media|self"], + + // Link post fields + ["r", ""], + ["preview-title", ""], + ["preview-description", ""], + ["preview-image", ""], + ["preview-site-name", ""], + + // Media post fields (NIP-92) + ["imeta", "url ", "m ", "dim ", "blurhash ", "alt "], + + // Common + ["t", ""], + ["nsfw", "true|false"] + ] +} +``` + +### Comment on Submission (kind 1111) + +```jsonc +{ + "kind": 1111, + "content": "", + "tags": [ + // Root scope (the community) + ["A", "34550::", ""], + ["K", "34550"], + ["P", ""], + + // Parent (the submission or parent comment) + ["e", "", "", ""], + ["k", "1111"], + ["p", ""] + ] +} +``` + +## Implementation Phases + +### Phase 1: Core Data Model +- [x] Create feature branch +- [x] Document plan +- [x] Create `types/submission.ts` - Type definitions +- [x] Create `SubmissionService.ts` - Submission CRUD +- [x] Create `LinkPreviewService.ts` - OG tag fetching +- [x] Extend `FeedService.ts` - Handle kind 1111 + +### Phase 2: Post Creation +- [x] Create `SubmitComposer.vue` - Multi-type composer +- [x] Add link preview on URL paste +- [x] Add NSFW toggle +- [x] Add route `/submit` for composer +- [ ] Integrate with pictrs for media upload (Future) + +### Phase 3: Feed Display +- [x] Create `SubmissionRow.vue` - Link aggregator row (Reddit/Lemmy style) +- [x] Create `VoteControls.vue` - Up/down voting +- [x] Create `SortTabs.vue` - Sort tabs (hot, new, top, controversial) +- [x] Create `SubmissionList.vue` - Main feed container +- [x] Create `SubmissionThumbnail.vue` - Thumbnail display +- [x] Add feed sorting (hot, new, top, controversial) +- [x] Add score calculation +- [x] Create `LinkAggregatorTest.vue` - Test page with mock data & live mode + +### Phase 4: Detail View +- [x] Create `SubmissionDetail.vue` - Full post view with content display +- [x] Create `SubmissionComment.vue` - Recursive threaded comments +- [x] Create `SubmissionDetailPage.vue` - Route page wrapper +- [x] Add route `/submission/:id` for detail view +- [x] Add comment sorting (best, new, old, controversial) +- [x] Integrate comment submission via SubmissionService.createComment() + +### Phase 5: Communities (Future) +- [ ] Create `CommunityService.ts` +- [ ] Create community browser +- [ ] Add moderation queue + +## Ranking Algorithms + +### Hot Rank (Lemmy-style) +```typescript +function hotRank(score: number, createdAt: Date): number { + const order = Math.log10(Math.max(Math.abs(score), 1)) + const sign = score > 0 ? 1 : score < 0 ? -1 : 0 + const seconds = (createdAt.getTime() - EPOCH.getTime()) / 1000 + return sign * order + seconds / 45000 +} +``` + +### Controversy Rank +```typescript +function controversyRank(upvotes: number, downvotes: number): number { + const total = upvotes + downvotes + if (total === 0) return 0 + const magnitude = Math.pow(total, 0.8) + const balance = total > 0 ? Math.min(upvotes, downvotes) / Math.max(upvotes, downvotes) : 0 + return magnitude * balance +} +``` + +## File Structure + +``` +src/modules/nostr-feed/ +├── types/ +│ └── submission.ts # NEW +├── services/ +│ ├── FeedService.ts # MODIFY +│ ├── SubmissionService.ts # NEW +│ ├── LinkPreviewService.ts # NEW +│ ├── CommunityService.ts # NEW (Phase 5) +│ ├── ProfileService.ts # EXISTING +│ └── ReactionService.ts # EXISTING (enhance for up/down) +├── components/ +│ ├── SubmissionCard.vue # NEW (Phase 3) +│ ├── SubmitComposer.vue # NEW (Phase 2) +│ ├── SubmissionDetail.vue # NEW (Phase 4) +│ ├── VoteButtons.vue # NEW (Phase 3) +│ ├── ThreadedPost.vue # EXISTING (reuse) +│ ├── NostrFeed.vue # EXISTING (modify) +│ └── NoteComposer.vue # EXISTING +├── composables/ +│ ├── useSubmissions.ts # NEW +│ ├── useCommunities.ts # NEW (Phase 5) +│ ├── useFeed.ts # EXISTING +│ └── useReactions.ts # EXISTING +└── config/ + └── content-filters.ts # MODIFY +``` + +## Migration Strategy + +1. **Backwards compatible** - Continue supporting kind 1 notes +2. **Gradual adoption** - Add kind 1111 alongside existing +3. **Feature flag** - Toggle between classic feed and link aggregator view diff --git a/src/modules/nostr-feed/components/SortTabs.vue b/src/modules/nostr-feed/components/SortTabs.vue new file mode 100644 index 0000000..84a174f --- /dev/null +++ b/src/modules/nostr-feed/components/SortTabs.vue @@ -0,0 +1,107 @@ + + + diff --git a/src/modules/nostr-feed/components/SubmissionComment.vue b/src/modules/nostr-feed/components/SubmissionComment.vue new file mode 100644 index 0000000..ab52a9e --- /dev/null +++ b/src/modules/nostr-feed/components/SubmissionComment.vue @@ -0,0 +1,275 @@ + + +