activitypub: also forward resolver to resolveNote

This commit is contained in:
Johann150 2022-12-10 11:20:56 +01:00
parent cf7449509f
commit 507b328fdf
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
5 changed files with 10 additions and 8 deletions

View file

@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js';
import { addPinned } from '@/services/i/pin.js';
import { resolveNote } from '@/remote/activitypub/models/note.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) {
throw new Error('invalid actor');
}
@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IAdd): Promise<void>
}
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');
await addPinned(actor, note.id);
return;

View file

@ -33,7 +33,7 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac
// resolve the announce target
let renote;
try {
renote = await resolveNote(targetUri);
renote = await resolveNote(targetUri, resolver);
} catch (e) {
// skip if the target returns a HTTP client error
if (e instanceof StatusError) {

View file

@ -53,7 +53,7 @@ async function performOneActivity(actor: CacheableRemoteUser, activity: IObject,
} else if (isReject(activity)) {
await reject(actor, activity, resolver);
} 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)) {
await remove(actor, activity).catch(err => apLogger.error(err));
} else if (isAnnounce(activity)) {

View file

@ -2,8 +2,9 @@ import { CacheableRemoteUser } from '@/models/entities/user.js';
import { removePinned } from '@/services/i/pin.js';
import { IRemove } from '../../type.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) {
throw new Error('invalid actor');
}
@ -13,7 +14,7 @@ export default async (actor: CacheableRemoteUser, activity: IRemove): Promise<vo
}
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');
await removePinned(actor, note.id);
return;

View file

@ -161,7 +161,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
}> => {
if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
try {
const res = await resolveNote(uri);
const res = await resolveNote(uri, resolver);
if (res) {
return {
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.
* 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;
if (uri == null) throw new Error('missing uri');