Merge branch 'feat/add_import_renote_mastodon' into 'develop'
feat: add import renote from Mastodon to firefish Co-authored-by: Buluo Laozhou <laozhoubuluo@gmail.com> Closes #10833 See merge request firefish/firefish!10652
This commit is contained in:
commit
f2faba970f
1 changed files with 14 additions and 8 deletions
|
@ -23,11 +23,17 @@ export async function importMastoPost(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const post = job.data.post;
|
const post = job.data.post;
|
||||||
|
const isRenote = post.type === "Announce";
|
||||||
let reply: Note | null = null;
|
let reply: Note | null = null;
|
||||||
|
let renote: Note | null = null;
|
||||||
job.progress(20);
|
job.progress(20);
|
||||||
if (post.object.inReplyTo != null) {
|
if (!isRenote && post.object.inReplyTo != null) {
|
||||||
reply = await resolveNote(post.object.inReplyTo);
|
reply = await resolveNote(post.object.inReplyTo);
|
||||||
}
|
}
|
||||||
|
// renote also need resolve original note
|
||||||
|
if (isRenote) {
|
||||||
|
renote = await resolveNote(post.object);
|
||||||
|
}
|
||||||
job.progress(40);
|
job.progress(40);
|
||||||
if (post.directMessage) {
|
if (post.directMessage) {
|
||||||
done();
|
done();
|
||||||
|
@ -42,17 +48,17 @@ export async function importMastoPost(
|
||||||
job.progress(60);
|
job.progress(60);
|
||||||
let text;
|
let text;
|
||||||
try {
|
try {
|
||||||
text = htmlToMfm(post.object.content, post.object.tag);
|
text = isRenote ? undefined : htmlToMfm(post.object.content, post.object.tag);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
job.progress(80);
|
job.progress(80);
|
||||||
|
|
||||||
let files: DriveFile[] = (post.object.attachment || [])
|
let files: DriveFile[] = (post.object?.attachment || [])
|
||||||
.map((x: any) => x?.driveFile)
|
.map((x: any) => x?.driveFile)
|
||||||
.filter((x: any) => x);
|
.filter((x: any) => x);
|
||||||
|
|
||||||
if (files.length == 0) {
|
if (!isRenote && files.length == 0) {
|
||||||
const urls = post.object.attachment
|
const urls = post.object.attachment
|
||||||
.map((x: any) => x.url)
|
.map((x: any) => x.url)
|
||||||
.filter((x: String) => x.startsWith("http"));
|
.filter((x: String) => x.startsWith("http"));
|
||||||
|
@ -70,7 +76,7 @@ export async function importMastoPost(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let note = await Notes.findOneBy({
|
let note = await Notes.findOneBy({
|
||||||
createdAt: new Date(post.object.published),
|
createdAt: isRenote ? new Date(post.published) : new Date(post.object.published),
|
||||||
text: text,
|
text: text,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
@ -91,13 +97,13 @@ export async function importMastoPost(
|
||||||
}
|
}
|
||||||
if (!note) {
|
if (!note) {
|
||||||
note = await create(user, {
|
note = await create(user, {
|
||||||
createdAt: new Date(post.object.published),
|
createdAt: isRenote ? new Date(post.published) : new Date(post.object.published),
|
||||||
files: files.length == 0 ? undefined : files,
|
files: files.length == 0 ? undefined : files,
|
||||||
poll: undefined,
|
poll: undefined,
|
||||||
text: text || undefined,
|
text: text || undefined,
|
||||||
reply,
|
reply,
|
||||||
renote: null,
|
renote,
|
||||||
cw: post.object.sensitive ? post.object.summary : undefined,
|
cw: (!isRenote && post.object.sensitive) ? post.object.summary : undefined,
|
||||||
localOnly: false,
|
localOnly: false,
|
||||||
visibility: "hiddenpublic",
|
visibility: "hiddenpublic",
|
||||||
visibleUsers: [],
|
visibleUsers: [],
|
||||||
|
|
Loading…
Reference in a new issue