slight refactoring & translating japanese

This commit is contained in:
Johann150 2022-12-02 19:00:58 +01:00
parent e49b8d0ef3
commit b4080d788d
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
4 changed files with 31 additions and 27 deletions

View file

@ -18,25 +18,25 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac
return; return;
} }
// アナウンス先をブロックしてたら中断 // Cancel if the announced from host is blocked.
const meta = await fetchMeta(); const meta = await fetchMeta();
if (meta.blockedHosts.includes(extractDbHost(uri))) return; if (meta.blockedHosts.includes(extractDbHost(uri))) return;
const unlock = await getApLock(uri); const unlock = await getApLock(uri);
try { try {
// 既に同じURIを持つものが登録されていないかチェック // Check if this has already been announced.
const exist = await fetchNote(uri); const exist = await fetchNote(uri);
if (exist) { if (exist) {
return; return;
} }
// Announce対象をresolve // resolve the announce target
let renote; let renote;
try { try {
renote = await resolveNote(targetUri); renote = await resolveNote(targetUri);
} catch (e) { } catch (e) {
// 対象が4xxならスキップ // skip if the target returns a HTTP client error
if (e instanceof StatusError) { if (e instanceof StatusError) {
if (e.isClientError) { if (e.isClientError) {
apLogger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`); apLogger.warn(`Ignored announce target ${targetUri} - ${e.statusCode}`);

View file

@ -16,22 +16,22 @@ export default async function(actor: CacheableRemoteUser, uri: string): Promise<
if (note == null) { if (note == null) {
const message = await dbResolver.getMessageFromApId(uri); const message = await dbResolver.getMessageFromApId(uri);
if (message == null) return 'message not found'; if (message == null) return 'skip: message not found';
if (message.userId !== actor.id) { if (message.userId !== actor.id) {
return '投稿を削除しようとしているユーザーは投稿の作成者ではありません'; return 'skip: cant delete other actors message';
} }
await deleteMessage(message); await deleteMessage(message);
return 'ok: message deleted'; return 'ok: message deleted';
} } else {
if (note.userId !== actor.id) {
return 'skip: cant delete other actors note';
}
if (note.userId !== actor.id) { await deleteNode(actor, note);
return '投稿を削除しようとしているユーザーは投稿の作成者ではありません'; return 'ok: note deleted';
} }
await deleteNode(actor, note);
return 'ok: note deleted';
} finally { } finally {
unlock(); unlock();
} }

View file

@ -14,28 +14,27 @@ export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<st
} }
if (followee.host != null) { if (followee.host != null) {
return 'skip: フォロー解除しようとしているユーザーはローカルユーザーではありません'; return 'skip: the unfollowed user is not local';
} }
const req = await FollowRequests.findOneBy({ const [req, following] = await Promise.all([
followerId: actor.id, FollowRequests.findOneBy({
followeeId: followee.id, followerId: actor.id,
}); followeeId: followee.id,
}),
const following = await Followings.findOneBy({ Followings.findOneBy({
followerId: actor.id, followerId: actor.id,
followeeId: followee.id, followeeId: followee.id,
}); }),
]);
if (req) { if (req) {
await cancelRequest(followee, actor); await cancelRequest(followee, actor);
return 'ok: follow request canceled'; return 'ok: follow request canceled';
} } else if (following) {
if (following) {
await unfollow(actor, followee); await unfollow(actor, followee);
return 'ok: unfollowed'; return 'ok: unfollowed';
} else {
return 'skip: no such following or follow request';
} }
return 'skip: リクエストもフォローもされていない';
}; };

View file

@ -16,6 +16,11 @@ import { signedGet } from './request.js';
import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type.js'; import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type.js';
import { parseUri } from './db-resolver.js'; import { parseUri } from './db-resolver.js';
/**
* Tries to resolve an ActivityPub URI into an AP object.
*
* As opposed to the DbResolver which will try to resolve an ActivityPub URI into a database object.
*/
export default class Resolver { export default class Resolver {
private history: Set<string>; private history: Set<string>;
private user?: ILocalUser; private user?: ILocalUser;