diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-10-15 21:50:26 +0000 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-10-15 21:50:26 +0000 |
| commit | de9b99c937ff76e44bc3988fc58fcc2151d85e74 (patch) | |
| tree | fb92a7724bb10da11fc44ae5dd59de9a8ce95c3e /packages/backend/src/core/NoteDeleteService.ts | |
| parent | merge: Restore report forwarding to Pleroma (resolves #641) (!690) (diff) | |
| parent | move upgrade notes to separate file (diff) | |
| download | sharkey-de9b99c937ff76e44bc3988fc58fcc2151d85e74.tar.gz sharkey-de9b99c937ff76e44bc3988fc58fcc2151d85e74.tar.bz2 sharkey-de9b99c937ff76e44bc3988fc58fcc2151d85e74.zip | |
merge: Add filter options to following feed (resolves #726) (!671)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/671
Closes #726
Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/NoteDeleteService.ts')
| -rw-r--r-- | packages/backend/src/core/NoteDeleteService.ts | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index 3f86f41942..fa77caabd1 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -6,8 +6,8 @@ import { Brackets, In, Not } from 'typeorm'; import { Injectable, Inject } from '@nestjs/common'; import type { MiUser, MiLocalUser, MiRemoteUser } from '@/models/User.js'; -import type { MiNote, IMentionedRemoteUsers } from '@/models/Note.js'; -import { LatestNote } from '@/models/LatestNote.js'; +import { MiNote, IMentionedRemoteUsers } from '@/models/Note.js'; +import { SkLatestNote } from '@/models/LatestNote.js'; import type { InstancesRepository, LatestNotesRepository, NotesRepository, UsersRepository } from '@/models/_.js'; import { RelayService } from '@/core/RelayService.js'; import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; @@ -25,7 +25,7 @@ import { bindThis } from '@/decorators.js'; import { MetaService } from '@/core/MetaService.js'; import { SearchService } from '@/core/SearchService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; -import { isQuote, isRenote } from '@/misc/is-renote.js'; +import { isPureRenote, isQuote, isRenote } from '@/misc/is-renote.js'; @Injectable() export class NoteDeleteService { @@ -240,8 +240,14 @@ export class NoteDeleteService { // If it's a DM, then it can't possibly be the latest note so we can safely skip this. if (note.visibility === 'specified') return; + // If it's a pure renote, then it can't possibly be the latest note so we can safely skip this. + if (isPureRenote(note)) return; + + // Compute the compound key of the entry to check + const key = SkLatestNote.keyFor(note); + // Check if the deleted note was possibly the latest for the user - const hasLatestNote = await this.latestNotesRepository.existsBy({ userId: note.userId }); + const hasLatestNote = await this.latestNotesRepository.existsBy(key); if (hasLatestNote) return; // Find the newest remaining note for the user. @@ -250,8 +256,16 @@ export class NoteDeleteService { .createQueryBuilder('note') .select() .where({ - userId: note.userId, - visibility: Not('specified'), + userId: key.userId, + visibility: key.isPublic + ? 'public' + : Not('specified'), + replyId: key.isReply + ? Not(null) + : null, + renoteId: key.isQuote + ? Not(null) + : null, }) .andWhere(` ( @@ -268,8 +282,8 @@ export class NoteDeleteService { if (!nextLatest) return; // Record it as the latest - const latestNote = new LatestNote({ - userId: note.userId, + const latestNote = new SkLatestNote({ + ...key, noteId: nextLatest.id, }); @@ -278,7 +292,7 @@ export class NoteDeleteService { await this.latestNotesRepository .createQueryBuilder('latest') .insert() - .into(LatestNote) + .into(SkLatestNote) .values(latestNote) .orIgnore() .execute(); |