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;
}
// アナウンス先をブロックしてたら中断
// Cancel if the announced from host is blocked.
const meta = await fetchMeta();
if (meta.blockedHosts.includes(extractDbHost(uri))) return;
const unlock = await getApLock(uri);
try {
// 既に同じURIを持つものが登録されていないかチェック
// Check if this has already been announced.
const exist = await fetchNote(uri);
if (exist) {
return;
}
// Announce対象をresolve
// resolve the announce target
let renote;
try {
renote = await resolveNote(targetUri);
} catch (e) {
// 対象が4xxならスキップ
// skip if the target returns a HTTP client error
if (e instanceof StatusError) {
if (e.isClientError) {
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) {
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) {
return '投稿を削除しようとしているユーザーは投稿の作成者ではありません';
return 'skip: cant delete other actors message';
}
await deleteMessage(message);
return 'ok: message deleted';
}
} else {
if (note.userId !== actor.id) {
return 'skip: cant delete other actors note';
}
if (note.userId !== actor.id) {
return '投稿を削除しようとしているユーザーは投稿の作成者ではありません';
await deleteNode(actor, note);
return 'ok: note deleted';
}
await deleteNode(actor, note);
return 'ok: note deleted';
} finally {
unlock();
}

View file

@ -14,28 +14,27 @@ export default async (actor: CacheableRemoteUser, activity: IFollow): Promise<st
}
if (followee.host != null) {
return 'skip: フォロー解除しようとしているユーザーはローカルユーザーではありません';
return 'skip: the unfollowed user is not local';
}
const req = await FollowRequests.findOneBy({
followerId: actor.id,
followeeId: followee.id,
});
const following = await Followings.findOneBy({
followerId: actor.id,
followeeId: followee.id,
});
const [req, following] = await Promise.all([
FollowRequests.findOneBy({
followerId: actor.id,
followeeId: followee.id,
}),
Followings.findOneBy({
followerId: actor.id,
followeeId: followee.id,
}),
]);
if (req) {
await cancelRequest(followee, actor);
return 'ok: follow request canceled';
}
if (following) {
} else if (following) {
await unfollow(actor, followee);
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 { 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 {
private history: Set<string>;
private user?: ILocalUser;