summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorMarie <github@yuugi.dev>2024-12-09 18:58:57 +0100
committerMarie <github@yuugi.dev>2024-12-09 18:58:57 +0100
commitbf01dcd8fb770d88f8509bbcb63bdaef1aa97fa5 (patch)
treeedd3bc5c20fd0e71e8b85fa58a31cea1784a8219 /packages
parentRevert import order update caused by saving (diff)
downloadsharkey-bf01dcd8fb770d88f8509bbcb63bdaef1aa97fa5.tar.gz
sharkey-bf01dcd8fb770d88f8509bbcb63bdaef1aa97fa5.tar.bz2
sharkey-bf01dcd8fb770d88f8509bbcb63bdaef1aa97fa5.zip
Apply suggestions
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts65
-rw-r--r--packages/frontend/src/components/MkNoteSimple.vue2
2 files changed, 37 insertions, 30 deletions
diff --git a/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts b/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts
index ea43448ed0..62e3d1072f 100644
--- a/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts
+++ b/packages/backend/src/queue/processors/ScheduleNotePostProcessorService.ts
@@ -11,6 +11,7 @@ import type { ChannelsRepository, DriveFilesRepository, MiDriveFile, NoteSchedul
import { DI } from '@/di-symbols.js';
import { NotificationService } from '@/core/NotificationService.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
+import type { MiScheduleNoteType } from '@/models/NoteSchedule.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type * as Bull from 'bullmq';
import type { ScheduleNotePostJobData } from '../types.js';
@@ -39,7 +40,36 @@ export class ScheduleNotePostProcessorService {
this.logger = this.queueLoggerService.logger.createSubLogger('schedule-note-post');
}
- @bindThis
+ @bindThis
+ private async isValidNoteSchedule(note: MiScheduleNoteType, id: string): Promise<boolean> {
+ const reply = note.reply ? await this.notesRepository.findOneBy({ id: note.reply }) : undefined;
+ const renote = note.reply ? await this.notesRepository.findOneBy({ id: note.renote }) : undefined;
+ const channel = note.channel ? await this.channelsRepository.findOneBy({ id: note.channel, isArchived: false }) : undefined;
+ if (note.reply && !reply) {
+ this.logger.warn('Schedule Note Failed Reason: parent note to reply does not exist');
+ this.notificationService.createNotification(id, 'scheduledNoteFailed', {
+ reason: 'Replied to note on your scheduled note no longer exists',
+ });
+ return false;
+ }
+ if (note.renote && !renote) {
+ this.logger.warn('Schedule Note Failed Reason: attached quote note no longer exists');
+ this.notificationService.createNotification(id, 'scheduledNoteFailed', {
+ reason: 'A quoted note from one of your scheduled notes no longer exists',
+ });
+ return false;
+ }
+ if (note.channel && !channel) {
+ this.logger.warn('Schedule Note Failed Reason: Channel does not exist');
+ this.notificationService.createNotification(id, 'scheduledNoteFailed', {
+ reason: 'An attached channel on your scheduled note no longer exists',
+ });
+ return false;
+ }
+ return true;
+ }
+
+ @bindThis
public async process(job: Bull.Job<ScheduleNotePostJobData>): Promise<void> {
this.noteScheduleRepository.findOneBy({ id: job.data.scheduleNoteId }).then(async (data) => {
if (!data) {
@@ -47,11 +77,10 @@ export class ScheduleNotePostProcessorService {
} else {
const me = await this.usersRepository.findOneBy({ id: data.userId });
const note = data.note;
-
- //idの形式でキューに積んであったのをDBから取り寄せる
const reply = note.reply ? await this.notesRepository.findOneBy({ id: note.reply }) : undefined;
const renote = note.reply ? await this.notesRepository.findOneBy({ id: note.renote }) : undefined;
const channel = note.channel ? await this.channelsRepository.findOneBy({ id: note.channel, isArchived: false }) : undefined;
+
let files: MiDriveFile[] = [];
const fileIds = note.files;
@@ -72,37 +101,15 @@ export class ScheduleNotePostProcessorService {
return;
}
- if (note.files.length !== files.length) {
- this.logger.warn('Schedule Note Failed Reason: files are missing in the user\'s drive');
- this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
- reason: 'Some attached files on your scheduled note no longer exist',
- });
- await this.noteScheduleRepository.remove(data);
- return;
- }
-
- if (note.reply && !reply) {
- this.logger.warn('Schedule Note Failed Reason: parent note to reply does not exist');
- this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
- reason: 'Replied to note on your scheduled note no longer exists',
- });
- await this.noteScheduleRepository.remove(data);
- return;
- }
-
- if (note.renote && !renote) {
- this.logger.warn('Schedule Note Failed Reason: attached quote note no longer exists');
- this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
- reason: 'A quoted note from one of your scheduled notes no longer exists',
- });
+ if (!await this.isValidNoteSchedule(note, me.id)) {
await this.noteScheduleRepository.remove(data);
return;
}
- if (note.channel && !channel) {
- this.logger.warn('Schedule Note Failed Reason: Channel does not exist');
+ if (note.files.length !== files.length) {
+ this.logger.warn('Schedule Note Failed Reason: files are missing in the user\'s drive');
this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
- reason: 'An attached channel on your scheduled note no longer exists',
+ reason: 'Some attached files on your scheduled note no longer exist',
});
await this.noteScheduleRepository.remove(data);
return;
diff --git a/packages/frontend/src/components/MkNoteSimple.vue b/packages/frontend/src/components/MkNoteSimple.vue
index e7a357d1b6..924262d62e 100644
--- a/packages/frontend/src/components/MkNoteSimple.vue
+++ b/packages/frontend/src/components/MkNoteSimple.vue
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
-<div v-show="!isDeleted" :class="$style.root" :tabindex="!isDeleted ? '-1' : undefined">
+<div v-if="!isDeleted" :class="$style.root">
<MkAvatar :class="$style.avatar" :user="note.user" link preview/>
<div :class="$style.main">
<MkNoteHeader :class="$style.header" :note="note" :mini="true"/>