mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-20 15:30:09 +00:00
Apply suggestions
This commit is contained in:
parent
234d14a892
commit
bf01dcd8fb
2 changed files with 38 additions and 31 deletions
|
@ -11,6 +11,7 @@ import type { ChannelsRepository, DriveFilesRepository, MiDriveFile, NoteSchedul
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { NotificationService } from '@/core/NotificationService.js';
|
import { NotificationService } from '@/core/NotificationService.js';
|
||||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
|
import type { MiScheduleNoteType } from '@/models/NoteSchedule.js';
|
||||||
import { QueueLoggerService } from '../QueueLoggerService.js';
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
||||||
import type * as Bull from 'bullmq';
|
import type * as Bull from 'bullmq';
|
||||||
import type { ScheduleNotePostJobData } from '../types.js';
|
import type { ScheduleNotePostJobData } from '../types.js';
|
||||||
|
@ -39,7 +40,36 @@ export class ScheduleNotePostProcessorService {
|
||||||
this.logger = this.queueLoggerService.logger.createSubLogger('schedule-note-post');
|
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> {
|
public async process(job: Bull.Job<ScheduleNotePostJobData>): Promise<void> {
|
||||||
this.noteScheduleRepository.findOneBy({ id: job.data.scheduleNoteId }).then(async (data) => {
|
this.noteScheduleRepository.findOneBy({ id: job.data.scheduleNoteId }).then(async (data) => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
@ -47,11 +77,10 @@ export class ScheduleNotePostProcessorService {
|
||||||
} else {
|
} else {
|
||||||
const me = await this.usersRepository.findOneBy({ id: data.userId });
|
const me = await this.usersRepository.findOneBy({ id: data.userId });
|
||||||
const note = data.note;
|
const note = data.note;
|
||||||
|
|
||||||
//idの形式でキューに積んであったのをDBから取り寄せる
|
|
||||||
const reply = note.reply ? await this.notesRepository.findOneBy({ id: note.reply }) : undefined;
|
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 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;
|
const channel = note.channel ? await this.channelsRepository.findOneBy({ id: note.channel, isArchived: false }) : undefined;
|
||||||
|
|
||||||
let files: MiDriveFile[] = [];
|
let files: MiDriveFile[] = [];
|
||||||
const fileIds = note.files;
|
const fileIds = note.files;
|
||||||
|
|
||||||
|
@ -72,6 +101,11 @@ export class ScheduleNotePostProcessorService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!await this.isValidNoteSchedule(note, me.id)) {
|
||||||
|
await this.noteScheduleRepository.remove(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (note.files.length !== files.length) {
|
if (note.files.length !== files.length) {
|
||||||
this.logger.warn('Schedule Note Failed Reason: files are missing in the user\'s drive');
|
this.logger.warn('Schedule Note Failed Reason: files are missing in the user\'s drive');
|
||||||
this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
|
this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
|
||||||
|
@ -81,33 +115,6 @@ export class ScheduleNotePostProcessorService {
|
||||||
return;
|
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',
|
|
||||||
});
|
|
||||||
await this.noteScheduleRepository.remove(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (note.channel && !channel) {
|
|
||||||
this.logger.warn('Schedule Note Failed Reason: Channel does not exist');
|
|
||||||
this.notificationService.createNotification(me.id, 'scheduledNoteFailed', {
|
|
||||||
reason: 'An attached channel on your scheduled note no longer exists',
|
|
||||||
});
|
|
||||||
await this.noteScheduleRepository.remove(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createdNote = await this.noteCreateService.create(me, {
|
const createdNote = await this.noteCreateService.create(me, {
|
||||||
...note,
|
...note,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
|
|
@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<template>
|
<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/>
|
<MkAvatar :class="$style.avatar" :user="note.user" link preview/>
|
||||||
<div :class="$style.main">
|
<div :class="$style.main">
|
||||||
<MkNoteHeader :class="$style.header" :note="note" :mini="true"/>
|
<MkNoteHeader :class="$style.header" :note="note" :mini="true"/>
|
||||||
|
|
Loading…
Reference in a new issue