AP audience (visibility) パースの修正 (#5783)
* Refactor audience * audienceのないAP Object 対応 * fix * Update src/remote/activitypub/audience.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> * Update src/remote/activitypub/audience.ts Co-Authored-By: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
parent
f6987c72ac
commit
711aa564c1
5 changed files with 123 additions and 68 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import Resolver from '../../resolver';
|
||||
import post from '../../../../services/note/create';
|
||||
import { IRemoteUser, User } from '../../../../models/entities/user';
|
||||
import { IAnnounce, getApId, getApIds } from '../../type';
|
||||
import { IRemoteUser } from '../../../../models/entities/user';
|
||||
import { IAnnounce, getApId } from '../../type';
|
||||
import { fetchNote, resolveNote } from '../../models/note';
|
||||
import { resolvePerson } from '../../models/person';
|
||||
import { apLogger } from '../../logger';
|
||||
import { extractDbHost } from '../../../../misc/convert-host';
|
||||
import { fetchMeta } from '../../../../misc/fetch-meta';
|
||||
import { getApLock } from '../../../../misc/app-lock';
|
||||
import { parseAudience } from '../../audience';
|
||||
|
||||
const logger = apLogger;
|
||||
|
||||
|
|
@ -51,42 +51,16 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity:
|
|||
|
||||
logger.info(`Creating the (Re)Note: ${uri}`);
|
||||
|
||||
//#region Visibility
|
||||
const to = getApIds(activity.to);
|
||||
const cc = getApIds(activity.cc);
|
||||
|
||||
const visibility = getVisibility(to, cc, actor);
|
||||
|
||||
let visibleUsers: User[] = [];
|
||||
if (visibility == 'specified') {
|
||||
visibleUsers = await Promise.all(to.map(uri => resolvePerson(uri)));
|
||||
}
|
||||
//#endergion
|
||||
const activityAudience = await parseAudience(actor, activity.to, activity.cc);
|
||||
|
||||
await post(actor, {
|
||||
createdAt: activity.published ? new Date(activity.published) : null,
|
||||
renote,
|
||||
visibility,
|
||||
visibleUsers,
|
||||
visibility: activityAudience.visibility,
|
||||
visibleUsers: activityAudience.visibleUsers,
|
||||
uri
|
||||
});
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
type visibility = 'public' | 'home' | 'followers' | 'specified';
|
||||
|
||||
function getVisibility(to: string[], cc: string[], actor: IRemoteUser): visibility {
|
||||
const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
|
||||
|
||||
if (to.includes(PUBLIC)) {
|
||||
return 'public';
|
||||
} else if (cc.includes(PUBLIC)) {
|
||||
return 'home';
|
||||
} else if (to.includes(`${actor.uri}/followers`)) {
|
||||
return 'followers';
|
||||
} else {
|
||||
return 'specified';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export default async (actor: IRemoteUser, activity: ICreate): Promise<void> => {
|
|||
});
|
||||
|
||||
if (validPost.includes(object.type)) {
|
||||
createNote(resolver, actor, object);
|
||||
createNote(resolver, actor, object, false, activity);
|
||||
} else {
|
||||
logger.warn(`Unknown type: ${object.type}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import Resolver from '../../resolver';
|
||||
import { IRemoteUser } from '../../../../models/entities/user';
|
||||
import { createNote, fetchNote } from '../../models/note';
|
||||
import { getApId, IObject } from '../../type';
|
||||
import { getApId, IObject, ICreate } from '../../type';
|
||||
import { getApLock } from '../../../../misc/app-lock';
|
||||
|
||||
/**
|
||||
* 投稿作成アクティビティを捌きます
|
||||
*/
|
||||
export default async function(resolver: Resolver, actor: IRemoteUser, note: IObject, silent = false): Promise<void> {
|
||||
export default async function(resolver: Resolver, actor: IRemoteUser, note: IObject, silent = false, activity?: ICreate): Promise<void> {
|
||||
const uri = getApId(note);
|
||||
|
||||
const unlock = await getApLock(uri);
|
||||
|
|
@ -15,7 +15,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, note: IObj
|
|||
try {
|
||||
const exist = await fetchNote(note);
|
||||
if (exist == null) {
|
||||
await createNote(note);
|
||||
await createNote(note, resolver, silent, activity);
|
||||
}
|
||||
} finally {
|
||||
unlock();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue