Merge branch 'refactor/dont_federate_initially_flag' into 'develop'
refactor: use dont federate initially flag instead of visibility hack Co-authored-by: laozhoubuluo <laozhoubuluo@gmail.com> See merge request firefish/firefish!10738
This commit is contained in:
commit
f56107859f
5 changed files with 89 additions and 41 deletions
|
@ -1,3 +1,5 @@
|
|||
import { noteVisibilities } from "@/types.js";
|
||||
|
||||
export type Post = {
|
||||
text: string | undefined;
|
||||
cw: string | null;
|
||||
|
@ -12,7 +14,9 @@ export function parse(acct: any): Post {
|
|||
cw: acct.cw,
|
||||
localOnly: acct.localOnly,
|
||||
createdAt: new Date(acct.createdAt),
|
||||
visibility: `hidden${acct.visibility || ""}`,
|
||||
visibility: noteVisibilities.includes(acct.visibility)
|
||||
? acct.visibility
|
||||
: "specified",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -92,22 +92,29 @@ export async function importCkPost(
|
|||
logger.info("Post updated");
|
||||
}
|
||||
if (note == null) {
|
||||
note = await create(user, {
|
||||
createdAt: createdAt,
|
||||
files: files.length === 0 ? undefined : files,
|
||||
poll: undefined,
|
||||
text: text || undefined,
|
||||
reply: post.replyId ? job.data.parent : null,
|
||||
renote: post.renoteId ? job.data.parent : null,
|
||||
cw: cw,
|
||||
localOnly,
|
||||
visibility: visibility,
|
||||
visibleUsers: [],
|
||||
channel: null,
|
||||
apMentions: new Array(0),
|
||||
apHashtags: undefined,
|
||||
apEmojis: undefined,
|
||||
});
|
||||
note = await create(
|
||||
user,
|
||||
{
|
||||
createdAt: createdAt,
|
||||
scheduledAt: undefined,
|
||||
files: files.length === 0 ? undefined : files,
|
||||
poll: undefined,
|
||||
text: text || undefined,
|
||||
reply: post.replyId ? job.data.parent : null,
|
||||
renote: post.renoteId ? job.data.parent : null,
|
||||
cw: cw,
|
||||
localOnly,
|
||||
visibility: visibility,
|
||||
visibleUsers: [],
|
||||
channel: null,
|
||||
apMentions: new Array(0),
|
||||
apHashtags: undefined,
|
||||
apEmojis: undefined,
|
||||
},
|
||||
false,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
logger.debug("New post has been created");
|
||||
} else {
|
||||
logger.info("This post already exists");
|
||||
|
|
|
@ -10,6 +10,11 @@ import type { DriveFile } from "@/models/entities/drive-file.js";
|
|||
import { Notes, NoteEdits } from "@/models/index.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { genId } from "backend-rs";
|
||||
import promiseLimit from "promise-limit";
|
||||
import { unique, concat } from "@/prelude/array.js";
|
||||
import type { CacheableUser } from "@/models/entities/user.js";
|
||||
import { resolvePerson } from "@/remote/activitypub/models/person.js";
|
||||
import { isPublic } from "@/remote/activitypub/audience.js";
|
||||
|
||||
const logger = queueLogger.createSubLogger("import-masto-post");
|
||||
|
||||
|
@ -118,24 +123,57 @@ export async function importMastoPost(
|
|||
logger.info("Post updated");
|
||||
}
|
||||
if (note == null) {
|
||||
note = await create(user, {
|
||||
createdAt: isRenote
|
||||
? new Date(post.published)
|
||||
: new Date(post.object.published),
|
||||
files: files.length === 0 ? undefined : files,
|
||||
poll: undefined,
|
||||
text: text || undefined,
|
||||
reply,
|
||||
renote,
|
||||
cw: !isRenote && post.object.sensitive ? post.object.summary : undefined,
|
||||
localOnly: false,
|
||||
visibility: "hiddenpublic",
|
||||
visibleUsers: [],
|
||||
channel: null,
|
||||
apMentions: new Array(0),
|
||||
apHashtags: undefined,
|
||||
apEmojis: undefined,
|
||||
});
|
||||
let visibility = "specified";
|
||||
let visibleUsers: CacheableUser[] = [];
|
||||
if ((post.to as string[]).some(isPublic)) {
|
||||
visibility = "public";
|
||||
} else if ((post.cc as string[]).some(isPublic)) {
|
||||
visibility = "home";
|
||||
} else if ((post.cc as string[]).some((cc) => cc.endsWith("/followers"))) {
|
||||
visibility = "followers";
|
||||
} else {
|
||||
try {
|
||||
const visibleUsersList = unique(concat([post.to, post.cc]));
|
||||
|
||||
const limit = promiseLimit<CacheableUser | null>(2);
|
||||
visibleUsers = (
|
||||
await Promise.all(
|
||||
visibleUsersList.map((id) =>
|
||||
limit(() => resolvePerson(id).catch(() => null)),
|
||||
),
|
||||
)
|
||||
).filter((x): x is CacheableUser => x != null);
|
||||
} catch {
|
||||
// nothing need to do.
|
||||
}
|
||||
}
|
||||
|
||||
note = await create(
|
||||
user,
|
||||
{
|
||||
createdAt: isRenote
|
||||
? new Date(post.published)
|
||||
: new Date(post.object.published),
|
||||
scheduledAt: undefined,
|
||||
files: files.length === 0 ? undefined : files,
|
||||
poll: undefined,
|
||||
text: text || undefined,
|
||||
reply,
|
||||
renote,
|
||||
cw:
|
||||
!isRenote && post.object.sensitive ? post.object.summary : undefined,
|
||||
localOnly: false,
|
||||
visibility,
|
||||
visibleUsers,
|
||||
channel: null,
|
||||
apMentions: new Array(0),
|
||||
apHashtags: undefined,
|
||||
apEmojis: undefined,
|
||||
},
|
||||
false,
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
logger.debug("New post has been created");
|
||||
} else {
|
||||
logger.info("This post already exists");
|
||||
|
|
|
@ -90,7 +90,7 @@ function groupingAudience(ids: string[], actor: CacheableRemoteUser) {
|
|||
return groups;
|
||||
}
|
||||
|
||||
function isPublic(id: string) {
|
||||
export function isPublic(id: string) {
|
||||
return [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"as:Public",
|
||||
|
@ -98,6 +98,6 @@ function isPublic(id: string) {
|
|||
].includes(id);
|
||||
}
|
||||
|
||||
function isFollowers(id: string, actor: CacheableRemoteUser) {
|
||||
export function isFollowers(id: string, actor: CacheableRemoteUser) {
|
||||
return id === (actor.followersUri || `${actor.uri}/followers`);
|
||||
}
|
||||
|
|
|
@ -162,11 +162,12 @@ export default async (
|
|||
data: NoteLike,
|
||||
silent = false,
|
||||
waitToPublish?: (note: Note) => Promise<void>,
|
||||
dontFederateInitially = false,
|
||||
) =>
|
||||
// biome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME
|
||||
new Promise<Note>(async (res, rej) => {
|
||||
const dontFederateInitially =
|
||||
data.visibility?.startsWith("hidden") === true;
|
||||
dontFederateInitially =
|
||||
dontFederateInitially || data.visibility?.startsWith("hidden");
|
||||
|
||||
// Whether this is a scheduled "draft" post (yet to be published)
|
||||
const isDraft = data.scheduledAt != null;
|
||||
|
@ -204,8 +205,6 @@ export default async (
|
|||
if (data.channel != null) data.visibility = "public";
|
||||
if (data.channel != null) data.visibleUsers = [];
|
||||
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
|
||||
if (
|
||||
|
|
Loading…
Reference in a new issue