merge: Add importCompleted notification. Send importCompleted when antenna/customEmoji/muting/userList is imported (!1165)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1165

Closes #891

Approved-by: dakkar <dakkar@thenautilus.net>
Approved-by: Hazelnoot <acomputerdog@gmail.com>
This commit is contained in:
Hazelnoot 2025-07-21 18:42:29 +00:00
commit ed68230811
19 changed files with 163 additions and 39 deletions

View file

@ -187,6 +187,10 @@ export class NotificationEntityService implements OnModuleInit {
exportedEntity: notification.exportedEntity,
fileId: notification.fileId,
} : {}),
...(notification.type === 'importCompleted' ? {
importedEntity: notification.importedEntity,
fileId: notification.fileId,
} : {}),
...(notification.type === 'scheduledNoteFailed' ? {
reason: notification.reason,
} : {}),

View file

@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { userExportableEntities } from '@/types.js';
import { userExportableEntities, userImportableEntities } from '@/types.js';
import { MiUser } from './User.js';
import { MiNote } from './Note.js';
import { MiAccessToken } from './AccessToken.js';
@ -92,6 +92,12 @@ export type MiNotification = {
createdAt: string;
exportedEntity: typeof userExportableEntities[number];
fileId: MiDriveFile['id'];
} | {
type: 'importCompleted';
id: string;
createdAt: string;
importedEntity: typeof userImportableEntities[number];
fileId?: MiDriveFile['id'];
} | {
type: 'login';
id: string;

View file

@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { notificationTypes, userExportableEntities } from '@/types.js';
import { notificationTypes, userExportableEntities, userImportableEntities } from '@/types.js';
const baseSchema = {
type: 'object',
@ -334,6 +334,26 @@ export const packedNotificationSchema = {
format: 'id',
},
},
}, {
type: 'object',
properties: {
...baseSchema.properties,
type: {
type: 'string',
optional: false, nullable: false,
enum: ['importCompleted'],
},
importedEntity: {
type: 'string',
optional: false, nullable: false,
enum: userImportableEntities,
},
fileId: {
type: 'string',
optional: false, nullable: false,
format: 'id',
},
},
}, {
type: 'object',
properties: {

View file

@ -12,6 +12,7 @@ import type { AntennasRepository, UsersRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import { NotificationService } from '@/core/NotificationService.js';
import { DBAntennaImportJobData } from '../types.js';
import type * as Bull from 'bullmq';
@ -65,6 +66,7 @@ export class ImportAntennasProcessorService {
private queueLoggerService: QueueLoggerService,
private idService: IdService,
private globalEventService: GlobalEventService,
private notificationService: NotificationService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('import-antennas');
}
@ -106,6 +108,10 @@ export class ImportAntennasProcessorService {
this.logger.debug('Antenna created: ' + result.id);
this.globalEventService.publishInternalEvent('antennaCreated', result);
}
this.notificationService.createNotification(job.data.user.id, 'importCompleted', {
importedEntity: 'antenna',
});
} catch (err: any) {
this.logger.error('Error importing antennas:', err);
}

View file

@ -18,6 +18,7 @@ import { bindThis } from '@/decorators.js';
import type { Config } from '@/config.js';
import { renderInlineError } from '@/misc/render-inline-error.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import { NotificationService } from '@/core/NotificationService.js';
import type * as Bull from 'bullmq';
import type { DbUserImportJobData } from '../types.js';
@ -40,6 +41,7 @@ export class ImportCustomEmojisProcessorService {
private driveService: DriveService,
private downloadService: DownloadService,
private queueLoggerService: QueueLoggerService,
private notificationService: NotificationService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('import-custom-emojis');
}
@ -127,7 +129,12 @@ export class ImportCustomEmojisProcessorService {
cleanup();
this.logger.debug('Imported');
this.notificationService.createNotification(job.data.user.id, 'importCompleted', {
importedEntity: 'customEmoji',
fileId: file.id,
});
this.logger.debug('Imported', file.name);
} catch (e) {
this.logger.error('Error importing custom emojis:', e as Error);
cleanup();

View file

@ -16,6 +16,7 @@ import { UtilityService } from '@/core/UtilityService.js';
import { bindThis } from '@/decorators.js';
import { renderInlineError } from '@/misc/render-inline-error.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import { NotificationService } from '@/core/NotificationService.js';
import type * as Bull from 'bullmq';
import type { DbUserImportJobData } from '../types.js';
@ -35,6 +36,7 @@ export class ImportMutingProcessorService {
private remoteUserResolveService: RemoteUserResolveService,
private downloadService: DownloadService,
private queueLoggerService: QueueLoggerService,
private notificationService: NotificationService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('import-muting');
}
@ -99,6 +101,11 @@ export class ImportMutingProcessorService {
}
}
this.notificationService.createNotification(job.data.user.id, 'importCompleted', {
importedEntity: 'muting',
fileId: file.id,
});
this.logger.debug('Imported');
}
}

View file

@ -17,6 +17,7 @@ import { UtilityService } from '@/core/UtilityService.js';
import { bindThis } from '@/decorators.js';
import { renderInlineError } from '@/misc/render-inline-error.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import { NotificationService } from '@/core/NotificationService.js';
import type * as Bull from 'bullmq';
import type { DbUserImportJobData } from '../types.js';
@ -43,6 +44,7 @@ export class ImportUserListsProcessorService {
private remoteUserResolveService: RemoteUserResolveService,
private downloadService: DownloadService,
private queueLoggerService: QueueLoggerService,
private notificationService: NotificationService,
) {
this.logger = this.queueLoggerService.logger.createSubLogger('import-user-lists');
}
@ -109,6 +111,11 @@ export class ImportUserListsProcessorService {
}
}
this.notificationService.createNotification(job.data.user.id, 'importCompleted', {
importedEntity: 'userList',
fileId: file.id,
});
this.logger.debug('Imported');
}
}

View file

@ -39,6 +39,7 @@ export const notificationTypes = [
'chatRoomInvitationReceived',
'achievementEarned',
'exportCompleted',
'importCompleted',
'login',
'createToken',
'scheduledNoteFailed',