Merge branch 'refactor/dont_federate_initially_flag' into 'develop'

refactor: use dont federate initially flag instead of visibility hack


See merge request firefish/firefish!10738
This commit is contained in:
laozhoubuluo 2024-04-22 02:19:28 +00:00
commit c4c175964f
5 changed files with 55 additions and 45 deletions

4
.gitignore vendored
View File

@ -56,10 +56,6 @@ packages/backend/assets/instance.css
packages/backend/assets/sounds/None.mp3 packages/backend/assets/sounds/None.mp3
packages/backend/assets/LICENSE packages/backend/assets/LICENSE
!/packages/backend/queue/processors/db
!/packages/backend/src/db
!/packages/backend/src/server/api/endpoints/drive/files
packages/megalodon/lib packages/megalodon/lib
packages/megalodon/.idea packages/megalodon/.idea

View File

@ -1,3 +1,5 @@
import { noteVisibilities } from "@/types.js";
export type Post = { export type Post = {
text: string | undefined; text: string | undefined;
cw: string | null; cw: string | null;
@ -12,7 +14,9 @@ export function parse(acct: any): Post {
cw: acct.cw, cw: acct.cw,
localOnly: acct.localOnly, localOnly: acct.localOnly,
createdAt: new Date(acct.createdAt), createdAt: new Date(acct.createdAt),
visibility: `hidden${acct.visibility || ""}`, visibility: noteVisibilities.includes(acct.visibility)
? acct.visibility
: "public",
}; };
} }

View File

@ -74,22 +74,27 @@ export async function importCkPost(
logger.info(`Note file updated`); logger.info(`Note file updated`);
} }
if (!note) { if (!note) {
note = await create(user, { note = await create(
createdAt: createdAt, user,
files: files.length == 0 ? undefined : files, {
poll: undefined, createdAt: createdAt,
text: text || undefined, files: files.length == 0 ? undefined : files,
reply: post.replyId ? job.data.parent : null, poll: undefined,
renote: post.renoteId ? job.data.parent : null, text: text || undefined,
cw: cw, reply: post.replyId ? job.data.parent : null,
localOnly, renote: post.renoteId ? job.data.parent : null,
visibility: visibility, cw: cw,
visibleUsers: [], localOnly,
channel: null, visibility: visibility,
apMentions: new Array(0), visibleUsers: [],
apHashtags: undefined, channel: null,
apEmojis: undefined, apMentions: new Array(0),
}); apHashtags: undefined,
apEmojis: undefined,
},
false,
true,
);
logger.info(`Create new note`); logger.info(`Create new note`);
} else { } else {
logger.info(`Note exist`); logger.info(`Note exist`);

View File

@ -100,24 +100,30 @@ export async function importMastoPost(
logger.info(`Note file updated`); logger.info(`Note file updated`);
} }
if (!note) { if (!note) {
note = await create(user, { note = await create(
createdAt: isRenote user,
? new Date(post.published) {
: new Date(post.object.published), createdAt: isRenote
files: files.length == 0 ? undefined : files, ? new Date(post.published)
poll: undefined, : new Date(post.object.published),
text: text || undefined, files: files.length == 0 ? undefined : files,
reply, poll: undefined,
renote, text: text || undefined,
cw: !isRenote && post.object.sensitive ? post.object.summary : undefined, reply,
localOnly: false, renote,
visibility: "hiddenpublic", cw:
visibleUsers: [], !isRenote && post.object.sensitive ? post.object.summary : undefined,
channel: null, localOnly: false,
apMentions: new Array(0), visibility: "public",
apHashtags: undefined, visibleUsers: [],
apEmojis: undefined, channel: null,
}); apMentions: new Array(0),
apHashtags: undefined,
apEmojis: undefined,
},
false,
true,
);
logger.info(`Create new note`); logger.info(`Create new note`);
} else { } else {
logger.info(`Note exist`); logger.info(`Note exist`);

View File

@ -174,11 +174,12 @@ export default async (
}, },
data: Option, data: Option,
silent = false, silent = false,
dontFederateInitially = false,
) => ) =>
// biome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME // biome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME
new Promise<Note>(async (res, rej) => { new Promise<Note>(async (res, rej) => {
const dontFederateInitially = const dontFederateInitiallyFlag =
data.visibility?.startsWith("hidden") === true; data.visibility === "hidden" ? true : dontFederateInitially;
// If you reply outside the channel, match the scope of the target. // If you reply outside the channel, match the scope of the target.
// TODO (I think it's a process that could be done on the client side, but it's server side for now.) // TODO (I think it's a process that could be done on the client side, but it's server side for now.)
@ -212,8 +213,6 @@ export default async (
if (data.channel != null) data.visibility = "public"; if (data.channel != null) data.visibility = "public";
if (data.channel != null) data.visibleUsers = []; if (data.channel != null) data.visibleUsers = [];
if (data.channel != null) data.localOnly = true; if (data.channel != null) data.localOnly = true;
if (data.visibility.startsWith("hidden") && data.visibility !== "hidden")
data.visibility = data.visibility.slice(6);
// enforce silent clients on server // enforce silent clients on server
if ( if (
@ -476,7 +475,7 @@ export default async (
} }
} }
if (!dontFederateInitially) { if (!dontFederateInitiallyFlag) {
let publishKey: string; let publishKey: string;
let noteToPublish: Note; let noteToPublish: Note;
const relays = await getCachedRelays(); const relays = await getCachedRelays();
@ -614,7 +613,7 @@ export default async (
}); });
//#region AP deliver //#region AP deliver
if (Users.isLocalUser(user) && !dontFederateInitially) { if (Users.isLocalUser(user) && !dontFederateInitiallyFlag) {
(async () => { (async () => {
const noteActivity = await renderNoteOrRenoteActivity(data, note); const noteActivity = await renderNoteOrRenoteActivity(data, note);
const dm = new DeliverManager(user, noteActivity); const dm = new DeliverManager(user, noteActivity);