Skip to content

Commit

Permalink
Merge pull request #56 from lqvp/shahu
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-mai authored Dec 21, 2024
2 parents 649d4c5 + 3064b5f commit 0722af7
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 158 deletions.
23 changes: 12 additions & 11 deletions packages/backend/src/core/QueueModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {
UserWebhookDeliverJobData,
SystemWebhookDeliverJobData,
ScheduleNotePostJobData,
ScheduledNoteDeleteJobData,
} from '../queue/types.js';
import type { Provider } from '@nestjs/common';

export type SystemQueue = Bull.Queue<Record<string, unknown>>;
export type EndedPollNotificationQueue = Bull.Queue<EndedPollNotificationJobData>;
export type ScheduledNoteDeleteQueue = Bull.Queue<ScheduledNoteDeleteJobData>
export type DeliverQueue = Bull.Queue<DeliverJobData>;
export type InboxQueue = Bull.Queue<InboxJobData>;
export type DbQueue = Bull.Queue;
Expand All @@ -31,6 +31,7 @@ export type ObjectStorageQueue = Bull.Queue;
export type UserWebhookDeliverQueue = Bull.Queue<UserWebhookDeliverJobData>;
export type SystemWebhookDeliverQueue = Bull.Queue<SystemWebhookDeliverJobData>;
export type ScheduleNotePostQueue = Bull.Queue<ScheduleNotePostJobData>;
export type ScheduledNoteDeleteQueue = Bull.Queue<ScheduledNoteDeleteJobData>

const $system: Provider = {
provide: 'queue:system',
Expand All @@ -44,12 +45,6 @@ const $endedPollNotification: Provider = {
inject: [DI.config],
};

const $scheduledNoteDeleted: Provider = {
provide: 'queue:scheduledNoteDelete',
useFactory: (config: Config) => new Bull.Queue(QUEUE.SCHEDULED_NOTE_DELETE, baseQueueOptions(config, QUEUE.SCHEDULED_NOTE_DELETE)),
inject: [DI.config],
};

const $deliver: Provider = {
provide: 'queue:deliver',
useFactory: (config: Config) => new Bull.Queue(QUEUE.DELIVER, baseQueueOptions(config, QUEUE.DELIVER)),
Expand Down Expand Up @@ -98,13 +93,18 @@ const $scheduleNotePost: Provider = {
inject: [DI.config],
};

const $scheduledNoteDeleted: Provider = {
provide: 'queue:scheduledNoteDelete',
useFactory: (config: Config) => new Bull.Queue(QUEUE.SCHEDULED_NOTE_DELETE, baseQueueOptions(config, QUEUE.SCHEDULED_NOTE_DELETE)),
inject: [DI.config],
};

@Module({
imports: [
],
providers: [
$system,
$endedPollNotification,
$scheduledNoteDeleted,
$deliver,
$inbox,
$db,
Expand All @@ -113,11 +113,11 @@ const $scheduleNotePost: Provider = {
$userWebhookDeliver,
$systemWebhookDeliver,
$scheduleNotePost,
$scheduledNoteDeleted,
],
exports: [
$system,
$endedPollNotification,
$scheduledNoteDeleted,
$deliver,
$inbox,
$db,
Expand All @@ -126,13 +126,13 @@ const $scheduleNotePost: Provider = {
$userWebhookDeliver,
$systemWebhookDeliver,
$scheduleNotePost,
$scheduledNoteDeleted,
],
})
export class QueueModule implements OnApplicationShutdown {
constructor(
@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand All @@ -141,6 +141,7 @@ export class QueueModule implements OnApplicationShutdown {
@Inject('queue:userWebhookDeliver') public userWebhookDeliverQueue: UserWebhookDeliverQueue,
@Inject('queue:systemWebhookDeliver') public systemWebhookDeliverQueue: SystemWebhookDeliverQueue,
@Inject('queue:scheduleNotePost') public scheduleNotePostQueue: ScheduleNotePostQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
) {}

public async dispose(): Promise<void> {
Expand All @@ -150,7 +151,6 @@ export class QueueModule implements OnApplicationShutdown {
await Promise.all([
this.systemQueue.close(),
this.endedPollNotificationQueue.close(),
this.scheduledNoteDeleteQueue.close(),
this.deliverQueue.close(),
this.inboxQueue.close(),
this.dbQueue.close(),
Expand All @@ -159,6 +159,7 @@ export class QueueModule implements OnApplicationShutdown {
this.userWebhookDeliverQueue.close(),
this.systemWebhookDeliverQueue.close(),
this.scheduleNotePostQueue.close(),
this.scheduledNoteDeleteQueue.close(),
]);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/core/QueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
SystemWebhookDeliverQueue,
UserWebhookDeliverQueue,
ScheduleNotePostQueue,
ScheduledNoteDeleteQueue,
} from './QueueModule.js';
import type httpSignature from '@peertube/http-signature';
import type * as Bull from 'bullmq';
Expand All @@ -47,7 +48,6 @@ export class QueueService {

@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand All @@ -56,6 +56,7 @@ export class QueueService {
@Inject('queue:userWebhookDeliver') public userWebhookDeliverQueue: UserWebhookDeliverQueue,
@Inject('queue:systemWebhookDeliver') public systemWebhookDeliverQueue: SystemWebhookDeliverQueue,
@Inject('queue:scheduleNotePost') public ScheduleNotePostQueue: ScheduleNotePostQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
) {
this.systemQueue.add('tickCharts', {
}, {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/WebhookTestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function generateDummyNote(override?: Partial<MiNote>): MiNote {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
deleteAt: null,
...override,
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/entities/ChannelEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class ChannelEntityService {
notesCount: channel.notesCount,
isSensitive: channel.isSensitive,
allowRenoteToExternal: channel.allowRenoteToExternal,
announcement: channel.announcement as string | null,

...(me ? {
isFollowing,
Expand All @@ -95,7 +96,6 @@ export class ChannelEntityService {

...(detailed ? {
pinnedNotes: (await this.noteEntityService.packMany(pinnedNotes, me)).sort((a, b) => channel.pinnedNoteIds.indexOf(a.id) - channel.pinnedNoteIds.indexOf(b.id)),
announcement: channel.announcement,
} : {}),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
needConfirmationToRead: announcement.needConfirmationToRead,
userId: announcement.userId,
isRoleSpecified: announcement.isRoleSpecified,
roles: announcementRoles.filter(announcementRole => announcementRole.announcementId === announcement.id).map(announcementRole => announcementRole.role).filter((role): role is MiRole => role !== null),
roles: announcementRoles
.filter(announcementRole => announcementRole.announcementId === announcement.id)
.map(announcementRole => announcementRole.role)
.filter((role): role is NonNullable<typeof role> => role !== null),
reads: reads.get(announcement)!,
}));
});
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export const meta = {
},
},
emailWhitelist: {
type: 'string',
optional: false, nullable: true,
type: 'boolean',
optional: false, nullable: false,
},
preservedUsernames: {
type: 'array',
Expand Down Expand Up @@ -518,8 +518,8 @@ export const meta = {
type: 'string',
optional: false, nullable: false,
},
emailToReceiveAbuseReport: {
type: 'string',
federationHosts: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const paramDef = {
},
customSplashText: { type: 'array', nullable: true, items: {
type: 'string',
}},
} },
},
required: [],
} as const;
Expand Down
14 changes: 12 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/schedule/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { QueueService } from '@/core/QueueService.js';
import { IdService } from '@/core/IdService.js';
import { MiScheduleNoteType } from '@/models/NoteSchedule.js';
import { RoleService } from '@/core/RoleService.js';
import { isQuote, isRenote } from '@/misc/is-renote.js';
import { ApiError } from '../../../error.js';

export const meta = {
Expand Down Expand Up @@ -132,6 +133,15 @@ export const meta = {
},
} as const;

function checkPureRenote(note: MiNote): boolean {
return note.renoteId != null &&
note.replyId == null &&
note.text == null &&
note.cw == null &&
(!note.fileIds || note.fileIds.length === 0) &&
!note.hasPoll;
}

export const paramDef = {
type: 'object',
properties: {
Expand Down Expand Up @@ -275,7 +285,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

if (renote == null) {
throw new ApiError(meta.errors.noSuchRenoteTarget);
} else if (isPureRenote(renote)) {
} else if (isRenote(renote) && !isQuote(renote)) {
throw new ApiError(meta.errors.cannotReRenote);
}

Expand Down Expand Up @@ -308,7 +318,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

if (reply == null) {
throw new ApiError(meta.errors.noSuchReplyTarget);
} else if (isPureRenote(reply)) {
} else if (checkPureRenote(reply)) {
throw new ApiError(meta.errors.cannotReplyToPureRenote);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
UserWebhookDeliverQueue,
SystemWebhookDeliverQueue,
ScheduleNotePostQueue,
ScheduledNoteDeleteQueue,
} from '@/core/QueueModule.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
Expand Down Expand Up @@ -137,7 +138,6 @@ export class ClientServerService {

@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand All @@ -146,6 +146,7 @@ export class ClientServerService {
@Inject('queue:userWebhookDeliver') public userWebhookDeliverQueue: UserWebhookDeliverQueue,
@Inject('queue:systemWebhookDeliver') public systemWebhookDeliverQueue: SystemWebhookDeliverQueue,
@Inject('queue:scheduleNotePost') public scheduleNotePostQueue: ScheduleNotePostQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteQueue,
) {
//this.createServer = this.createServer.bind(this);
}
Expand Down Expand Up @@ -268,7 +269,6 @@ export class ClientServerService {
queues: [
this.systemQueue,
this.endedPollNotificationQueue,
this.scheduledNoteDeleteQueue,
this.deliverQueue,
this.inboxQueue,
this.dbQueue,
Expand All @@ -277,6 +277,7 @@ export class ClientServerService {
this.userWebhookDeliverQueue,
this.systemWebhookDeliverQueue,
this.scheduleNotePostQueue,
this.scheduledNoteDeleteQueue,
].map(q => new BullMQAdapter(q)),
serverAdapter: bullBoardServerAdapter,
});
Expand Down
1 change: 1 addition & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('NoteCreateService', () => {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
deleteAt: null,
};

const poll: IPoll = {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/test/unit/misc/is-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const base: MiNote = {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
deleteAt: null,
};

describe('misc:is-renote', () => {
Expand Down
Loading

0 comments on commit 0722af7

Please sign in to comment.