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 @@ + + +