forked from FoundKeyGang/FoundKey
slight refactoring & translating japanese
This commit is contained in:
parent
e49b8d0ef3
commit
b4080d788d
4 changed files with 31 additions and 27 deletions
|
@ -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}`);
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: リクエストもフォローもされていない';
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue