[Draft] feat(nostr-feed): Reddit-style link aggregator #9

Open
padreug wants to merge 19 commits from feature/link-aggregator into main
Showing only changes of commit 8def8484b5 - Show all commits

View file

@ -148,6 +148,8 @@ export class SubmissionService extends BaseService {
onEvent: (event: NostrEvent) => this.handleEvent(event),
onEose: () => {
this.debug('End of stored events')
// Refresh all submission votes from loaded reactions
this.refreshAllSubmissionVotes()
this._isLoading.value = false
},
onClose: () => {
@ -229,6 +231,8 @@ export class SubmissionService extends BaseService {
onEvent: (event: NostrEvent) => this.handleEvent(event),
onEose: () => {
this.debug('End of stored events for submission')
// Refresh submission votes from loaded reactions
this.refreshSubmissionVotes(submissionId)
// After loading comments, fetch their reactions
this.fetchCommentReactions(submissionId)
this._isLoading.value = false
@ -907,12 +911,23 @@ export class SubmissionService extends BaseService {
* Downvote a submission
*/
async downvote(submissionId: string): Promise<void> {
// TODO: Implement downvote using '-' reaction content
// For now, this is a placeholder that mirrors the upvote logic
const submission = this._submissions.get(submissionId)
if (!submission) throw new Error('Submission not found')
this.debug('Downvote not yet implemented')
if (submission.votes.userVote === 'downvote') {
// Remove downvote
await this.reactionService?.undislikeEvent(submissionId)
} else {
// Add downvote (ReactionService keeps only latest reaction per user)
await this.reactionService?.dislikeEvent(
submissionId,
submission.pubkey,
SUBMISSION_KINDS.SUBMISSION
)
}
// Refresh votes
this.refreshSubmissionVotes(submissionId)
}
/**
@ -926,6 +941,15 @@ export class SubmissionService extends BaseService {
submission.ranking = this.calculateRanking(submission, submission.votes)
}
/**
* Refresh votes for all submissions
*/
private refreshAllSubmissionVotes(): void {
for (const submissionId of this._submissions.keys()) {
this.refreshSubmissionVotes(submissionId)
}
}
/**
* Upvote a comment
*/