mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 02:13:09 +02:00
upd: import own replies to own tweets
This commit is contained in:
parent
13600e0abc
commit
4929467016
3 changed files with 34 additions and 7 deletions
|
@ -272,8 +272,8 @@ export class QueueService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public createImportTweetsToDbJob(user: ThinUser, targets: string[]) {
|
||||
const jobs = targets.map(rel => this.generateToDbJobData('importTweetsToDb', { user, target: rel }));
|
||||
public createImportTweetsToDbJob(user: ThinUser, targets: string[], note: MiNote['id'] | null) {
|
||||
const jobs = targets.map(rel => this.generateToDbJobData('importTweetsToDb', { user, target: rel, note }));
|
||||
return this.dbQueue.addBulk(jobs);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,29 @@ export class ImportNotesProcessorService {
|
|||
return notesTree;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private async recreateTwitChain(arr: any[]) {
|
||||
type TweetsMap = {
|
||||
[id: string]: any;
|
||||
};
|
||||
const tweetsTree: any[] = [];
|
||||
const lookup: TweetsMap = {};
|
||||
for await (const tweet of arr) {
|
||||
lookup[`${tweet.id_str}`] = tweet;
|
||||
tweet.replies = [];
|
||||
let parent = null;
|
||||
|
||||
if (!tweet.in_reply_to_status_id_str) {
|
||||
tweetsTree.push(tweet);
|
||||
} else {
|
||||
parent = lookup[`${tweet.in_reply_to_status_id_str}`];
|
||||
}
|
||||
|
||||
if (parent) parent.replies.push(tweet);
|
||||
}
|
||||
return tweetsTree;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
private isIterable(obj: any) {
|
||||
if (obj == null) {
|
||||
|
@ -155,7 +178,10 @@ export class ImportNotesProcessorService {
|
|||
const tweets = Object.keys(fakeWindow.window.YTD.tweets.part0).reduce((m, key, i, obj) => {
|
||||
return m.concat(fakeWindow.window.YTD.tweets.part0[key].tweet);
|
||||
}, []);
|
||||
this.queueService.createImportTweetsToDbJob(job.data.user, tweets);
|
||||
// Due to the way twitter outputs the tweets the entire array needs to be reversed for the recreate function.
|
||||
const reversedTweets = tweets.reverse();
|
||||
const processedTweets = await this.recreateTwitChain(reversedTweets);
|
||||
this.queueService.createImportTweetsToDbJob(job.data.user, processedTweets, null);
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
|
@ -430,14 +456,14 @@ export class ImportNotesProcessorService {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async processTwitterDb(job: Bull.Job<DbNoteImportToDbJobData>): Promise<void> {
|
||||
public async processTwitterDb(job: Bull.Job<DbKeyNoteImportToDbJobData>): Promise<void> {
|
||||
const tweet = job.data.target;
|
||||
const user = await this.usersRepository.findOneBy({ id: job.data.user.id });
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tweet.in_reply_to_status_id_str) return;
|
||||
const parentNote = job.data.note ? await this.notesRepository.findOneBy({ id: job.data.note }) : null;
|
||||
|
||||
async function replaceTwitterUrls(full_text: string, urls: any) {
|
||||
let full_textedit = full_text;
|
||||
|
@ -516,7 +542,8 @@ export class ImportNotesProcessorService {
|
|||
}
|
||||
}
|
||||
}
|
||||
await this.noteCreateService.import(user, { createdAt: date, text: text, files: files });
|
||||
const createdNote = await this.noteCreateService.import(user, { createdAt: date, reply: parentNote, text: text, files: files });
|
||||
if (tweet.replies) this.queueService.createImportTweetsToDbJob(user, tweet.replies, createdNote.id);
|
||||
} catch (e) {
|
||||
this.logger.warn(`Error: ${e}`);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ export type DbJobMap = {
|
|||
exportUserLists: DbJobDataWithUser;
|
||||
importAntennas: DBAntennaImportJobData;
|
||||
importNotes: DbNoteImportJobData;
|
||||
importTweetsToDb: DbNoteImportToDbJobData;
|
||||
importTweetsToDb: DbKeyNoteImportToDbJobData;
|
||||
importIGToDb: DbNoteImportToDbJobData;
|
||||
importMastoToDb: DbNoteImportToDbJobData;
|
||||
importPleroToDb: DbNoteImportToDbJobData;
|
||||
|
|
Loading…
Reference in a new issue