thread Pleroma imports as well

I have _not_ tested this, but it should work fine, those exports are
the same shape as Mastodon's
This commit is contained in:
dakkar 2023-11-30 13:24:57 +00:00
parent c59e74dfd5
commit c958d935e4
3 changed files with 19 additions and 12 deletions

View file

@ -284,8 +284,8 @@ export class QueueService {
} }
@bindThis @bindThis
public createImportPleroToDbJob(user: ThinUser, targets: string[]) { public createImportPleroToDbJob(user: ThinUser, targets: string[], note: MiNote['id'] | null) {
const jobs = targets.map(rel => this.generateToDbJobData('importPleroToDb', { user, target: rel })); const jobs = targets.map(rel => this.generateToDbJobData('importPleroToDb', { user, target: rel, note }));
return this.dbQueue.addBulk(jobs); return this.dbQueue.addBulk(jobs);
} }

View file

@ -268,7 +268,8 @@ export class ImportNotesProcessorService {
if (isPleroma) { if (isPleroma) {
const outboxJson = fs.readFileSync(outputPath + '/outbox.json', 'utf-8'); const outboxJson = fs.readFileSync(outputPath + '/outbox.json', 'utf-8');
const outbox = JSON.parse(outboxJson); const outbox = JSON.parse(outboxJson);
this.queueService.createImportPleroToDbJob(job.data.user, outbox.orderedItems.filter((x: any) => x.type === 'Create' && x.object.type === 'Note')); const processedToots = await this.recreateChain(['object', 'id'], ['object', 'inReplyTo'], outbox.orderedItems.filter((x: any) => x.type === 'Create' && x.object.type === 'Note'), true);
this.queueService.createImportPleroToDbJob(job.data.user, processedToots, null);
} else { } else {
const outboxJson = fs.readFileSync(outputPath + '/outbox.json', 'utf-8'); const outboxJson = fs.readFileSync(outputPath + '/outbox.json', 'utf-8');
const outbox = JSON.parse(outboxJson); const outbox = JSON.parse(outboxJson);
@ -421,13 +422,15 @@ export class ImportNotesProcessorService {
} }
@bindThis @bindThis
public async processPleroToDb(job: Bull.Job<DbNoteImportToDbJobData>): Promise<void> { public async processPleroToDb(job: Bull.Job<DbNoteWithParentImportToDbJobData>): Promise<void> {
const post = job.data.target; const post = job.data.target;
const user = await this.usersRepository.findOneBy({ id: job.data.user.id }); const user = await this.usersRepository.findOneBy({ id: job.data.user.id });
if (user == null) { if (user == null) {
return; return;
} }
if (post.directMessage) return;
const date = new Date(post.object.published); const date = new Date(post.object.published);
let text = undefined; let text = undefined;
const files: MiDriveFile[] = []; const files: MiDriveFile[] = [];
@ -437,15 +440,18 @@ export class ImportNotesProcessorService {
if (folder == null) return; if (folder == null) return;
if (post.object.inReplyTo != null) { if (post.object.inReplyTo != null) {
try { const parentNote = job.data.note ? await this.notesRepository.findOneBy({ id: job.data.note }) : null;
reply = await this.apNoteService.resolveNote(post.object.inReplyTo); if (parentNote) {
} catch (error) { reply = parentNote;
reply = null; } else {
try {
reply = await this.apNoteService.resolveNote(post.object.inReplyTo);
} catch (error) {
reply = null;
}
} }
} }
if (post.directMessage) return;
const hashtags = extractApHashtagObjects(post.object.tag).map((x) => x.name).filter((x): x is string => x != null); const hashtags = extractApHashtagObjects(post.object.tag).map((x) => x.name).filter((x): x is string => x != null);
try { try {
@ -489,7 +495,8 @@ export class ImportNotesProcessorService {
} }
} }
await this.noteCreateService.import(user, { createdAt: date, text: text, files: files, apMentions: new Array(0), cw: post.object.sensitive ? post.object.summary : null, reply: reply }); const createdNote = await this.noteCreateService.import(user, { createdAt: date, text: text, files: files, apMentions: new Array(0), cw: post.object.sensitive ? post.object.summary : null, reply: reply });
if (post.childNotes) this.queueService.createImportPleroToDbJob(user, post.childNotes, createdNote.id);
} }
@bindThis @bindThis

View file

@ -54,7 +54,7 @@ export type DbJobMap = {
importIGToDb: DbNoteImportToDbJobData; importIGToDb: DbNoteImportToDbJobData;
importFBToDb: DbNoteImportToDbJobData; importFBToDb: DbNoteImportToDbJobData;
importMastoToDb: DbNoteWithParentImportToDbJobData; importMastoToDb: DbNoteWithParentImportToDbJobData;
importPleroToDb: DbNoteImportToDbJobData; importPleroToDb: DbNoteWithParentImportToDbJobData;
importKeyNotesToDb: DbNoteWithParentImportToDbJobData; importKeyNotesToDb: DbNoteWithParentImportToDbJobData;
importFollowing: DbUserImportJobData; importFollowing: DbUserImportJobData;
importFollowingToDb: DbUserImportToDbJobData; importFollowingToDb: DbUserImportToDbJobData;