mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 03:15:12 +00:00
federate Flag.object
as an array to fix Pleroma compatibility
This commit is contained in:
parent
b15f25758a
commit
4e592fb1c9
5 changed files with 42 additions and 26 deletions
|
@ -98,7 +98,10 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
||||||
* AP Person => Misskey User in DB
|
* AP Person => Misskey User in DB
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async getUserFromApId(value: string | IObject): Promise<MiLocalUser | MiRemoteUser | null> {
|
public async getUserFromApId(value: string | IObject | [string | IObject]): Promise<MiLocalUser | MiRemoteUser | null> {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (Array.isArray(value)) value = value[0];
|
||||||
|
|
||||||
const parsed = this.parseUri(value);
|
const parsed = this.parseUri(value);
|
||||||
|
|
||||||
if (parsed.local) {
|
if (parsed.local) {
|
||||||
|
|
|
@ -253,7 +253,8 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await this.apNoteService.resolveNote(activity.object);
|
const object = Array.isArray(activity.object) ? activity.object[0] : activity.object;
|
||||||
|
const note = await this.apNoteService.resolveNote(object);
|
||||||
if (note == null) return 'note not found';
|
if (note == null) return 'note not found';
|
||||||
await this.notePiningService.addPinned(actor, note.id);
|
await this.notePiningService.addPinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
@ -270,11 +271,12 @@ export class ApInboxService {
|
||||||
|
|
||||||
const resolver = this.apResolverService.createResolver();
|
const resolver = this.apResolverService.createResolver();
|
||||||
|
|
||||||
if (!activity.object) return 'skip: activity has no object property';
|
const activityObject = Array.isArray(activity.object) ? activity.object[0] : activity.object;
|
||||||
const targetUri = getApId(activity.object);
|
if (!activityObject) return 'skip: activity has no object property';
|
||||||
|
const targetUri = getApId(activityObject);
|
||||||
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
||||||
|
|
||||||
const target = await resolver.resolve(activity.object).catch(e => {
|
const target = await resolver.resolve(activityObject).catch(e => {
|
||||||
this.logger.error(`Resolution failed: ${e}`);
|
this.logger.error(`Resolution failed: ${e}`);
|
||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
|
@ -370,29 +372,30 @@ export class ApInboxService {
|
||||||
|
|
||||||
this.logger.info(`Create: ${uri}`);
|
this.logger.info(`Create: ${uri}`);
|
||||||
|
|
||||||
if (!activity.object) return 'skip: activity has no object property';
|
const activityObject = Array.isArray(activity.object) ? activity.object[0] : activity.object;
|
||||||
const targetUri = getApId(activity.object);
|
if (!activityObject) return 'skip: activity has no object property';
|
||||||
|
const targetUri = getApId(activityObject);
|
||||||
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
if (targetUri.startsWith('bear:')) return 'skip: bearcaps url not supported.';
|
||||||
|
|
||||||
// copy audiences between activity <=> object.
|
// copy audiences between activity <=> object.
|
||||||
if (typeof activity.object === 'object') {
|
if (typeof activityObject === 'object') {
|
||||||
const to = unique(concat([toArray(activity.to), toArray(activity.object.to)]));
|
const to = unique(concat([toArray(activity.to), toArray(activityObject.to)]));
|
||||||
const cc = unique(concat([toArray(activity.cc), toArray(activity.object.cc)]));
|
const cc = unique(concat([toArray(activity.cc), toArray(activityObject.cc)]));
|
||||||
|
|
||||||
activity.to = to;
|
activity.to = to;
|
||||||
activity.cc = cc;
|
activity.cc = cc;
|
||||||
activity.object.to = to;
|
activityObject.to = to;
|
||||||
activity.object.cc = cc;
|
activityObject.cc = cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no attributedTo, use Activity actor.
|
// If there is no attributedTo, use Activity actor.
|
||||||
if (typeof activity.object === 'object' && !activity.object.attributedTo) {
|
if (typeof activityObject === 'object' && !activityObject.attributedTo) {
|
||||||
activity.object.attributedTo = activity.actor;
|
activityObject.attributedTo = activity.actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolver = this.apResolverService.createResolver();
|
const resolver = this.apResolverService.createResolver();
|
||||||
|
|
||||||
const object = await resolver.resolve(activity.object).catch(e => {
|
const object = await resolver.resolve(activityObject).catch(e => {
|
||||||
this.logger.error(`Resolution failed: ${e}`);
|
this.logger.error(`Resolution failed: ${e}`);
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
|
@ -448,15 +451,15 @@ export class ApInboxService {
|
||||||
// 削除対象objectのtype
|
// 削除対象objectのtype
|
||||||
let formerType: string | undefined;
|
let formerType: string | undefined;
|
||||||
|
|
||||||
if (typeof activity.object === 'string') {
|
const activityObject = Array.isArray(activity.object) ? activity.object[0] : activity.object;
|
||||||
|
if (typeof activityObject === 'string') {
|
||||||
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
// typeが不明だけど、どうせ消えてるのでremote resolveしない
|
||||||
formerType = undefined;
|
formerType = undefined;
|
||||||
} else {
|
} else {
|
||||||
const object = activity.object;
|
if (isTombstone(activityObject)) {
|
||||||
if (isTombstone(object)) {
|
formerType = toSingle(activityObject.formerType);
|
||||||
formerType = toSingle(object.formerType);
|
|
||||||
} else {
|
} else {
|
||||||
formerType = toSingle(object.type);
|
formerType = toSingle(activityObject.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,7 +619,8 @@ export class ApInboxService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await this.apNoteService.resolveNote(activity.object);
|
const activityObject = Array.isArray(activity.object) ? activity.object[0] : activity.object;
|
||||||
|
const note = await this.apNoteService.resolveNote(activityObject);
|
||||||
if (note == null) return 'note not found';
|
if (note == null) return 'note not found';
|
||||||
await this.notePiningService.removePinned(actor, note.id);
|
await this.notePiningService.removePinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -199,7 +199,8 @@ export class ApRendererService {
|
||||||
type: 'Flag',
|
type: 'Flag',
|
||||||
actor: this.userEntityService.genLocalUserUri(user.id),
|
actor: this.userEntityService.genLocalUserUri(user.id),
|
||||||
content,
|
content,
|
||||||
object,
|
// This MUST be an array for Pleroma compatibility: https://activitypub.software/TransFem-org/Sharkey/-/issues/641#note_7301
|
||||||
|
object: [object],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,10 @@ export class Resolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async resolve(value: string | IObject): Promise<IObject> {
|
public async resolve(value: string | IObject | [string | IObject]): Promise<IObject> {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (Array.isArray(value)) value = value[0];
|
||||||
|
|
||||||
if (typeof value !== 'string') {
|
if (typeof value !== 'string') {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,13 @@ export function getOneApId(value: ApObject): string {
|
||||||
/**
|
/**
|
||||||
* Get ActivityStreams Object id
|
* Get ActivityStreams Object id
|
||||||
*/
|
*/
|
||||||
export function getApId(value: string | IObject): string {
|
export function getApId(value: string | IObject | [string | IObject]): string {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (Array.isArray(value)) value = value[0];
|
||||||
|
|
||||||
if (typeof value === 'string') return value;
|
if (typeof value === 'string') return value;
|
||||||
if (typeof value.id === 'string') return value.id;
|
if (typeof value.id === 'string') return value.id;
|
||||||
throw new Error('cannot detemine id');
|
throw new Error('cannot determine id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,7 +87,9 @@ export function getApHrefNullable(value: string | IObject | undefined): string |
|
||||||
export interface IActivity extends IObject {
|
export interface IActivity extends IObject {
|
||||||
//type: 'Activity';
|
//type: 'Activity';
|
||||||
actor: IObject | string;
|
actor: IObject | string;
|
||||||
object: IObject | string;
|
// ActivityPub spec allows for arrays: https://www.w3.org/TR/activitystreams-vocabulary/#properties
|
||||||
|
// Misskey can only handle one value, so we use a tuple for that case.
|
||||||
|
object: IObject | string | [IObject | string] ;
|
||||||
target?: IObject | string;
|
target?: IObject | string;
|
||||||
/** LD-Signature */
|
/** LD-Signature */
|
||||||
signature?: {
|
signature?: {
|
||||||
|
|
Loading…
Reference in a new issue