Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import accept from "../../../../services/following/requests/accept.js";
|
||||
import DbResolver from "../../db-resolver.js";
|
||||
import { relayAccepted } from "../../../../services/relay.js";
|
||||
export default (async (actor, activity)=>{
|
||||
// ※ activityはこっちから投げたフォローリクエストなので、activity.actorは存在するローカルユーザーである必要がある
|
||||
const dbResolver = new DbResolver();
|
||||
const follower = await dbResolver.getUserFromApId(activity.actor);
|
||||
if (follower == null) {
|
||||
return "skip: follower not found";
|
||||
}
|
||||
if (follower.host != null) {
|
||||
return "skip: follower is not a local user";
|
||||
}
|
||||
// relay
|
||||
const match = activity.id?.match(/follow-relay\/(\w+)/);
|
||||
if (match) {
|
||||
return await relayAccepted(match[1]);
|
||||
}
|
||||
await accept(actor, follower);
|
||||
return "ok";
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import Resolver from "../../resolver.js";
|
||||
import acceptFollow from "./follow.js";
|
||||
import { isFollow, getApType, isQuoteRequest } from "../../type.js";
|
||||
import { apLogger } from "../../logger.js";
|
||||
import { acceptQuoteRequest } from "./quote-request.js";
|
||||
const logger = apLogger;
|
||||
export default (async (actor, activity)=>{
|
||||
const uri = activity.id || activity;
|
||||
logger.info(`Accept: ${uri}`);
|
||||
const resolver = new Resolver();
|
||||
const object = await resolver.resolve(activity.object).catch((e)=>{
|
||||
logger.error(`Resolution failed: ${e}`);
|
||||
throw e;
|
||||
});
|
||||
if (isFollow(object)) return await acceptFollow(actor, object);
|
||||
else if (isQuoteRequest(object)) return await acceptQuoteRequest(actor, object, activity.result);
|
||||
return `skip: Unknown Accept type: ${getApType(object)}`;
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { resolveNote } from "../../models/note.js";
|
||||
import { Notes } from "../../../../models/index.js";
|
||||
import { parseUri } from "../../db-resolver.js";
|
||||
import edit from "../../../../services/note/edit.js";
|
||||
import { toPuny } from "../../../../misc/convert-host.js";
|
||||
export async function acceptQuoteRequest(actor, activity, result) {
|
||||
if (!result) return "skip: missing result";
|
||||
const localParsed = parseUri(activity.instrument);
|
||||
if (!localParsed.local) return "skip: note not local";
|
||||
const resultUrl = new URL(result);
|
||||
if (toPuny(resultUrl.host) !== actor.host) {
|
||||
return "skip: result not on same host as actor";
|
||||
}
|
||||
const [note, targetNote] = await Promise.all([
|
||||
Notes.findOne({
|
||||
where: {
|
||||
id: localParsed.id
|
||||
},
|
||||
relations: [
|
||||
"user"
|
||||
]
|
||||
}),
|
||||
resolveNote(activity.object)
|
||||
]);
|
||||
if (note === null) return "skip: note not found";
|
||||
if (targetNote === null) return "skip: target note not found";
|
||||
if (targetNote.userId !== actor.id) return "skip: tried to authorize note without ownership";
|
||||
if (note.renoteId === null) return "skip: note not renote";
|
||||
if (note.renoteId !== targetNote.id) return "skip: note not renoting target";
|
||||
if (note.quoteAuthorization !== null) return "skip: quote already authorizated";
|
||||
if (note.text == null && note.cw == null && !note.hasPoll && note.fileIds.length === 0) return "skip: note is plain renote";
|
||||
note.quoteAuthorization = result;
|
||||
await Notes.update({
|
||||
id: note.id
|
||||
}, {
|
||||
quoteAuthorization: note.quoteAuthorization
|
||||
});
|
||||
await edit(note.user, note, {
|
||||
text: note.text,
|
||||
cw: note.cw,
|
||||
quoteAuthorization: result
|
||||
}, true);
|
||||
return "ok";
|
||||
}
|
||||
Reference in New Issue
Block a user