diff --git a/src/modules/nostr-feed/services/SubmissionService.ts b/src/modules/nostr-feed/services/SubmissionService.ts index 787f3e9..33e8900 100644 --- a/src/modules/nostr-feed/services/SubmissionService.ts +++ b/src/modules/nostr-feed/services/SubmissionService.ts @@ -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 { - // 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 */