activitypub: also forward resolver to resolveNote
This commit is contained in:
parent
cf7449509f
commit
507b328fdf
5 changed files with 10 additions and 8 deletions
|
@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js';
|
||||||
import { addPinned } from '@/services/i/pin.js';
|
import { addPinned } from '@/services/i/pin.js';
|
||||||
import { resolveNote } from '@/remote/activitypub/models/note.js';
|
import { resolveNote } from '@/remote/activitypub/models/note.js';
|
||||||
import { IAdd } from '@/remote/activitypub/type.js';
|
import { IAdd } from '@/remote/activitypub/type.js';
|
||||||
|
import Resolver from '@/remote/activitypub/resolver.js';
|
||||||
|
|
||||||
export default async (actor: CacheableRemoteUser, activity: IAdd): Promise<void> => {
|
export default async (actor: CacheableRemoteUser, activity: IAdd, resolver: Resolver): Promise<void> => {
|
||||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||||
throw new Error('invalid actor');
|
throw new Error('invalid actor');
|
||||||
}
|
}
|
||||||
|
@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IAdd): Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await resolveNote(activity.object);
|
const note = await resolveNote(activity.object, resolver);
|
||||||
if (note == null) throw new Error('note not found');
|
if (note == null) throw new Error('note not found');
|
||||||
await addPinned(actor, note.id);
|
await addPinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -33,7 +33,7 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac
|
||||||
// resolve the announce target
|
// resolve the announce target
|
||||||
let renote;
|
let renote;
|
||||||
try {
|
try {
|
||||||
renote = await resolveNote(targetUri);
|
renote = await resolveNote(targetUri, resolver);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// skip if the target returns a HTTP client error
|
// skip if the target returns a HTTP client error
|
||||||
if (e instanceof StatusError) {
|
if (e instanceof StatusError) {
|
||||||
|
|
|
@ -53,7 +53,7 @@ async function performOneActivity(actor: CacheableRemoteUser, activity: IObject,
|
||||||
} else if (isReject(activity)) {
|
} else if (isReject(activity)) {
|
||||||
await reject(actor, activity, resolver);
|
await reject(actor, activity, resolver);
|
||||||
} else if (isAdd(activity)) {
|
} else if (isAdd(activity)) {
|
||||||
await add(actor, activity).catch(err => apLogger.error(err));
|
await add(actor, activity, resolver).catch(err => apLogger.error(err));
|
||||||
} else if (isRemove(activity)) {
|
} else if (isRemove(activity)) {
|
||||||
await remove(actor, activity).catch(err => apLogger.error(err));
|
await remove(actor, activity).catch(err => apLogger.error(err));
|
||||||
} else if (isAnnounce(activity)) {
|
} else if (isAnnounce(activity)) {
|
||||||
|
|
|
@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js';
|
||||||
import { removePinned } from '@/services/i/pin.js';
|
import { removePinned } from '@/services/i/pin.js';
|
||||||
import { IRemove } from '../../type.js';
|
import { IRemove } from '../../type.js';
|
||||||
import { resolveNote } from '../../models/note.js';
|
import { resolveNote } from '../../models/note.js';
|
||||||
|
import Resolver from '@/remote/activitypub/resolver.js';
|
||||||
|
|
||||||
export default async (actor: CacheableRemoteUser, activity: IRemove): Promise<void> => {
|
export default async (actor: CacheableRemoteUser, activity: IRemove, resolver: Resolver): Promise<void> => {
|
||||||
if ('actor' in activity && actor.uri !== activity.actor) {
|
if ('actor' in activity && actor.uri !== activity.actor) {
|
||||||
throw new Error('invalid actor');
|
throw new Error('invalid actor');
|
||||||
}
|
}
|
||||||
|
@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IRemove): Promise<vo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.target === actor.featured) {
|
if (activity.target === actor.featured) {
|
||||||
const note = await resolveNote(activity.object);
|
const note = await resolveNote(activity.object, resolver);
|
||||||
if (note == null) throw new Error('note not found');
|
if (note == null) throw new Error('note not found');
|
||||||
await removePinned(actor, note.id);
|
await removePinned(actor, note.id);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -161,7 +161,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
|
||||||
}> => {
|
}> => {
|
||||||
if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
|
if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
|
||||||
try {
|
try {
|
||||||
const res = await resolveNote(uri);
|
const res = await resolveNote(uri, resolver);
|
||||||
if (res) {
|
if (res) {
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
|
@ -266,7 +266,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
|
||||||
* If the target Note is registered in FoundKey, return it; otherwise, fetch it from a remote server and return it.
|
* If the target Note is registered in FoundKey, return it; otherwise, fetch it from a remote server and return it.
|
||||||
* Fetch the Note from the remote server, register it in FoundKey, and return it.
|
* Fetch the Note from the remote server, register it in FoundKey, and return it.
|
||||||
*/
|
*/
|
||||||
export async function resolveNote(value: string | IObject, resolver?: Resolver): Promise<Note | null> {
|
export async function resolveNote(value: string | IObject, resolver: Resolver): Promise<Note | null> {
|
||||||
const uri = typeof value === 'string' ? value : value.id;
|
const uri = typeof value === 'string' ? value : value.id;
|
||||||
if (uri == null) throw new Error('missing uri');
|
if (uri == null) throw new Error('missing uri');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue