refactor (backend): port renderReject to backend-rs
This commit is contained in:
parent
7e9db5fcff
commit
331384b0ff
10 changed files with 89 additions and 45 deletions
60
packages/backend-rs/index.d.ts
vendored
60
packages/backend-rs/index.d.ts
vendored
|
@ -48,6 +48,20 @@ export interface Acct {
|
||||||
|
|
||||||
export declare function acctToString(acct: Acct): string
|
export declare function acctToString(acct: Acct): string
|
||||||
|
|
||||||
|
export type Activity = 'Accept'|
|
||||||
|
'Add'|
|
||||||
|
'Emoji'|
|
||||||
|
'Flag'|
|
||||||
|
'Follow'|
|
||||||
|
'Hashtag'|
|
||||||
|
'Like'|
|
||||||
|
'Mention'|
|
||||||
|
'Image'|
|
||||||
|
'Read'|
|
||||||
|
'Reject'|
|
||||||
|
'Remove'|
|
||||||
|
'Tombstone';
|
||||||
|
|
||||||
export interface Ad {
|
export interface Ad {
|
||||||
id: string
|
id: string
|
||||||
createdAt: DateTimeWithTimeZone
|
createdAt: DateTimeWithTimeZone
|
||||||
|
@ -106,13 +120,13 @@ export type AntennaSrc = 'all'|
|
||||||
|
|
||||||
export interface ApAccept {
|
export interface ApAccept {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
object: ApFollow
|
object: ApFollow
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApAdd {
|
export interface ApAdd {
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
target: string
|
target: string
|
||||||
object: string
|
object: string
|
||||||
|
@ -120,14 +134,14 @@ export interface ApAdd {
|
||||||
|
|
||||||
export interface ApEmoji {
|
export interface ApEmoji {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
name: string
|
name: string
|
||||||
updated: string
|
updated: string
|
||||||
icon: Icon
|
icon: Icon
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApFlag {
|
export interface ApFlag {
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
content: string
|
content: string
|
||||||
object: string
|
object: string
|
||||||
|
@ -135,20 +149,20 @@ export interface ApFlag {
|
||||||
|
|
||||||
export interface ApFollow {
|
export interface ApFollow {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
object: string
|
object: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApHashtag {
|
export interface ApHashtag {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApLike {
|
export interface ApLike {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
object: string
|
object: string
|
||||||
content: string
|
content: string
|
||||||
|
@ -156,24 +170,11 @@ export interface ApLike {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApMention {
|
export interface ApMention {
|
||||||
type: ApObject
|
type: Activity
|
||||||
href: string
|
href: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApObject = 'Accept'|
|
|
||||||
'Add'|
|
|
||||||
'Emoji'|
|
|
||||||
'Flag'|
|
|
||||||
'Follow'|
|
|
||||||
'Hashtag'|
|
|
||||||
'Like'|
|
|
||||||
'Mention'|
|
|
||||||
'Image'|
|
|
||||||
'Read'|
|
|
||||||
'Remove'|
|
|
||||||
'Tombstone';
|
|
||||||
|
|
||||||
export interface App {
|
export interface App {
|
||||||
id: string
|
id: string
|
||||||
createdAt: DateTimeWithTimeZone
|
createdAt: DateTimeWithTimeZone
|
||||||
|
@ -186,13 +187,20 @@ export interface App {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApRead {
|
export interface ApRead {
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
object: string
|
object: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ApReject {
|
||||||
|
id: string
|
||||||
|
type: Activity
|
||||||
|
actor: string
|
||||||
|
object: ApFollow
|
||||||
|
}
|
||||||
|
|
||||||
export interface ApRemove {
|
export interface ApRemove {
|
||||||
type: ApObject
|
type: Activity
|
||||||
actor: string
|
actor: string
|
||||||
target: string
|
target: string
|
||||||
object: string
|
object: string
|
||||||
|
@ -200,7 +208,7 @@ export interface ApRemove {
|
||||||
|
|
||||||
export interface ApTombstone {
|
export interface ApTombstone {
|
||||||
id: string
|
id: string
|
||||||
type: ApObject
|
type: Activity
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AttestationChallenge {
|
export interface AttestationChallenge {
|
||||||
|
@ -604,7 +612,7 @@ export interface Hashtag {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Icon {
|
export interface Icon {
|
||||||
type: ApObject
|
type: Activity
|
||||||
mediaType: string
|
mediaType: string
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
@ -1372,6 +1380,8 @@ export declare function renderMention(user: UserLike): ApMention
|
||||||
|
|
||||||
export declare function renderRead(userId: string, messageUri: string): ApRead
|
export declare function renderRead(userId: string, messageUri: string): ApRead
|
||||||
|
|
||||||
|
export declare function renderReject(userId: string, followObject: ApFollow): ApReject
|
||||||
|
|
||||||
export declare function renderRemove(userId: string, noteId: string): ApRemove
|
export declare function renderRemove(userId: string, noteId: string): ApRemove
|
||||||
|
|
||||||
export declare function renderTombstone(noteId: string): ApTombstone
|
export declare function renderTombstone(noteId: string): ApTombstone
|
||||||
|
|
|
@ -362,8 +362,8 @@ if (!nativeBinding) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.acctToString = nativeBinding.acctToString
|
module.exports.acctToString = nativeBinding.acctToString
|
||||||
|
module.exports.Activity = nativeBinding.Activity
|
||||||
module.exports.AntennaSrc = nativeBinding.AntennaSrc
|
module.exports.AntennaSrc = nativeBinding.AntennaSrc
|
||||||
module.exports.ApObject = nativeBinding.ApObject
|
|
||||||
module.exports.ChatEvent = nativeBinding.ChatEvent
|
module.exports.ChatEvent = nativeBinding.ChatEvent
|
||||||
module.exports.ChatIndexEvent = nativeBinding.ChatIndexEvent
|
module.exports.ChatIndexEvent = nativeBinding.ChatIndexEvent
|
||||||
module.exports.checkWordMute = nativeBinding.checkWordMute
|
module.exports.checkWordMute = nativeBinding.checkWordMute
|
||||||
|
@ -448,6 +448,7 @@ module.exports.renderHashtag = nativeBinding.renderHashtag
|
||||||
module.exports.renderLike = nativeBinding.renderLike
|
module.exports.renderLike = nativeBinding.renderLike
|
||||||
module.exports.renderMention = nativeBinding.renderMention
|
module.exports.renderMention = nativeBinding.renderMention
|
||||||
module.exports.renderRead = nativeBinding.renderRead
|
module.exports.renderRead = nativeBinding.renderRead
|
||||||
|
module.exports.renderReject = nativeBinding.renderReject
|
||||||
module.exports.renderRemove = nativeBinding.renderRemove
|
module.exports.renderRemove = nativeBinding.renderRemove
|
||||||
module.exports.renderTombstone = nativeBinding.renderTombstone
|
module.exports.renderTombstone = nativeBinding.renderTombstone
|
||||||
module.exports.safeForSql = nativeBinding.safeForSql
|
module.exports.safeForSql = nativeBinding.safeForSql
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{config::CONFIG, misc::user};
|
use crate::misc::user;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[macros::export(object)]
|
#[macros::export(object)]
|
||||||
pub struct ApAccept {
|
pub struct ApAccept {
|
||||||
|
@ -16,7 +15,7 @@ impl ApAccept {
|
||||||
#[allow(dead_code)] // TODO: remove this line by actually using it
|
#[allow(dead_code)] // TODO: remove this line by actually using it
|
||||||
fn new(user_id: String, follow_object: follow::ApFollow) -> Self {
|
fn new(user_id: String, follow_object: follow::ApFollow) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: format!("{}/{}", CONFIG.url, Uuid::new_v4()),
|
id: random_local_uri(),
|
||||||
r#type: Activity::Accept,
|
r#type: Activity::Accept,
|
||||||
actor: user::local_uri(user_id),
|
actor: user::local_uri(user_id),
|
||||||
object: follow_object,
|
object: follow_object,
|
||||||
|
|
|
@ -7,6 +7,7 @@ pub mod hashtag;
|
||||||
pub mod like;
|
pub mod like;
|
||||||
pub mod mention;
|
pub mod mention;
|
||||||
pub mod read;
|
pub mod read;
|
||||||
|
pub mod reject;
|
||||||
pub mod remove;
|
pub mod remove;
|
||||||
pub mod tombstone;
|
pub mod tombstone;
|
||||||
|
|
||||||
|
@ -24,12 +25,20 @@ pub enum Activity {
|
||||||
Mention,
|
Mention,
|
||||||
Image,
|
Image,
|
||||||
Read,
|
Read,
|
||||||
|
Reject,
|
||||||
Remove,
|
Remove,
|
||||||
Tombstone,
|
Tombstone,
|
||||||
}
|
}
|
||||||
|
|
||||||
const AS_PUBLIC_URL: &str = "https://www.w3.org/ns/activitystreams#Public";
|
const AS_PUBLIC_URL: &str = "https://www.w3.org/ns/activitystreams#Public";
|
||||||
|
|
||||||
|
use crate::config::CONFIG;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
fn random_local_uri() -> String {
|
||||||
|
format!("{}/{}", CONFIG.url, Uuid::new_v4())
|
||||||
|
}
|
||||||
|
|
||||||
#[macros::export(object)]
|
#[macros::export(object)]
|
||||||
pub struct UserLike {
|
pub struct UserLike {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
use super::*;
|
||||||
|
use crate::misc::user;
|
||||||
|
|
||||||
|
#[macros::export(object)]
|
||||||
|
pub struct ApReject {
|
||||||
|
pub id: String,
|
||||||
|
pub r#type: Activity,
|
||||||
|
pub actor: String,
|
||||||
|
pub object: follow::ApFollow,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApObject for ApReject {}
|
||||||
|
|
||||||
|
impl ApReject {
|
||||||
|
#[allow(dead_code)] // TODO: remove this line by actually using it
|
||||||
|
fn new(user_id: String, follow_object: follow::ApFollow) -> Self {
|
||||||
|
Self {
|
||||||
|
id: random_local_uri(),
|
||||||
|
r#type: Activity::Accept,
|
||||||
|
actor: user::local_uri(user_id),
|
||||||
|
object: follow_object,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macros::ts_export]
|
||||||
|
pub fn render_reject(user_id: String, follow_object: follow::ApFollow) -> ApReject {
|
||||||
|
ApReject::new(user_id, follow_object)
|
||||||
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
import { config } from "@/config.js";
|
|
||||||
import type { User } from "@/models/entities/user.js";
|
|
||||||
|
|
||||||
export default (object: any, user: { id: User["id"] }) => ({
|
|
||||||
type: "Reject",
|
|
||||||
actor: `${config.url}/users/${user.id}`,
|
|
||||||
object,
|
|
||||||
});
|
|
|
@ -2,7 +2,6 @@ import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import { renderUndo } from "@/remote/activitypub/renderer/undo.js";
|
import { renderUndo } from "@/remote/activitypub/renderer/undo.js";
|
||||||
import { renderBlock } from "@/remote/activitypub/renderer/block.js";
|
import { renderBlock } from "@/remote/activitypub/renderer/block.js";
|
||||||
import { deliver } from "@/queue/index.js";
|
import { deliver } from "@/queue/index.js";
|
||||||
import renderReject from "@/remote/activitypub/renderer/reject.js";
|
|
||||||
import type { Blocking } from "@/models/entities/blocking.js";
|
import type { Blocking } from "@/models/entities/blocking.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import {
|
import {
|
||||||
|
@ -20,6 +19,7 @@ import {
|
||||||
publishToUserStream,
|
publishToUserStream,
|
||||||
UserEvent,
|
UserEvent,
|
||||||
renderFollow,
|
renderFollow,
|
||||||
|
renderReject,
|
||||||
} from "backend-rs";
|
} from "backend-rs";
|
||||||
import { getActiveWebhooks } from "@/misc/webhook-cache.js";
|
import { getActiveWebhooks } from "@/misc/webhook-cache.js";
|
||||||
import { webhookDeliver } from "@/queue/index.js";
|
import { webhookDeliver } from "@/queue/index.js";
|
||||||
|
@ -103,8 +103,8 @@ async function cancelRequest(follower: User, followee: User) {
|
||||||
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
|
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
|
||||||
const content = renderActivity(
|
const content = renderActivity(
|
||||||
renderReject(
|
renderReject(
|
||||||
|
followee.id,
|
||||||
renderFollow(follower, followee, request.requestId!),
|
renderFollow(follower, followee, request.requestId!),
|
||||||
followee,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
deliver(followee.id, content, follower.inbox);
|
deliver(followee.id, content, follower.inbox);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import renderReject from "@/remote/activitypub/renderer/reject.js";
|
|
||||||
import { deliver } from "@/queue/index.js";
|
import { deliver } from "@/queue/index.js";
|
||||||
import createFollowRequest from "./requests/create.js";
|
import createFollowRequest from "./requests/create.js";
|
||||||
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
||||||
|
@ -23,6 +22,7 @@ import {
|
||||||
UserEvent,
|
UserEvent,
|
||||||
renderAccept,
|
renderAccept,
|
||||||
renderFollow,
|
renderFollow,
|
||||||
|
renderReject,
|
||||||
} from "backend-rs";
|
} from "backend-rs";
|
||||||
import { createNotification } from "@/services/create-notification.js";
|
import { createNotification } from "@/services/create-notification.js";
|
||||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||||
|
@ -196,7 +196,7 @@ export default async function (
|
||||||
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee) && blocked) {
|
if (Users.isRemoteUser(follower) && Users.isLocalUser(followee) && blocked) {
|
||||||
// リモートフォローを受けてブロックしていた場合は、エラーにするのではなくRejectを送り返しておしまい。
|
// リモートフォローを受けてブロックしていた場合は、エラーにするのではなくRejectを送り返しておしまい。
|
||||||
const content = renderActivity(
|
const content = renderActivity(
|
||||||
renderReject(renderFollow(follower, followee, requestId), followee),
|
renderReject(followee.id, renderFollow(follower, followee, requestId)),
|
||||||
);
|
);
|
||||||
deliver(followee.id, content, follower.inbox);
|
deliver(followee.id, content, follower.inbox);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,10 +4,10 @@ import {
|
||||||
publishToUserStream,
|
publishToUserStream,
|
||||||
UserEvent,
|
UserEvent,
|
||||||
renderFollow,
|
renderFollow,
|
||||||
|
renderReject,
|
||||||
} from "backend-rs";
|
} from "backend-rs";
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import { renderUndo } from "@/remote/activitypub/renderer/undo.js";
|
import { renderUndo } from "@/remote/activitypub/renderer/undo.js";
|
||||||
import renderReject from "@/remote/activitypub/renderer/reject.js";
|
|
||||||
import { deliver, webhookDeliver } from "@/queue/index.js";
|
import { deliver, webhookDeliver } from "@/queue/index.js";
|
||||||
import Logger from "../logger.js";
|
import Logger from "../logger.js";
|
||||||
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
import { registerOrFetchInstanceDoc } from "@/services/register-or-fetch-instance-doc.js";
|
||||||
|
@ -22,6 +22,7 @@ export default async function (
|
||||||
id: User["id"];
|
id: User["id"];
|
||||||
host: User["host"];
|
host: User["host"];
|
||||||
uri: User["host"];
|
uri: User["host"];
|
||||||
|
username: User["username"];
|
||||||
inbox: User["inbox"];
|
inbox: User["inbox"];
|
||||||
sharedInbox: User["sharedInbox"];
|
sharedInbox: User["sharedInbox"];
|
||||||
},
|
},
|
||||||
|
@ -29,6 +30,7 @@ export default async function (
|
||||||
id: User["id"];
|
id: User["id"];
|
||||||
host: User["host"];
|
host: User["host"];
|
||||||
uri: User["host"];
|
uri: User["host"];
|
||||||
|
username: User["username"];
|
||||||
inbox: User["inbox"];
|
inbox: User["inbox"];
|
||||||
sharedInbox: User["sharedInbox"];
|
sharedInbox: User["sharedInbox"];
|
||||||
},
|
},
|
||||||
|
@ -79,7 +81,7 @@ export default async function (
|
||||||
if (Users.isLocalUser(followee) && Users.isRemoteUser(follower)) {
|
if (Users.isLocalUser(followee) && Users.isRemoteUser(follower)) {
|
||||||
// local user has null host
|
// local user has null host
|
||||||
const content = renderActivity(
|
const content = renderActivity(
|
||||||
renderReject(renderFollow(follower, followee), followee),
|
renderReject(followee.id, renderFollow(follower, followee)),
|
||||||
);
|
);
|
||||||
deliver(followee.id, content, follower.inbox);
|
deliver(followee.id, content, follower.inbox);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import renderReject from "@/remote/activitypub/renderer/reject.js";
|
|
||||||
import { deliver, webhookDeliver } from "@/queue/index.js";
|
import { deliver, webhookDeliver } from "@/queue/index.js";
|
||||||
import {
|
import {
|
||||||
Event,
|
Event,
|
||||||
|
@ -7,6 +6,7 @@ import {
|
||||||
publishToUserStream,
|
publishToUserStream,
|
||||||
UserEvent,
|
UserEvent,
|
||||||
renderFollow,
|
renderFollow,
|
||||||
|
renderReject,
|
||||||
} from "backend-rs";
|
} from "backend-rs";
|
||||||
import type { ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
import type { ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
||||||
import { Users, FollowRequests, Followings } from "@/models/index.js";
|
import { Users, FollowRequests, Followings } from "@/models/index.js";
|
||||||
|
@ -19,6 +19,7 @@ type Local =
|
||||||
id: ILocalUser["id"];
|
id: ILocalUser["id"];
|
||||||
host: ILocalUser["host"];
|
host: ILocalUser["host"];
|
||||||
uri: ILocalUser["uri"];
|
uri: ILocalUser["uri"];
|
||||||
|
username: ILocalUser["username"];
|
||||||
};
|
};
|
||||||
type Remote =
|
type Remote =
|
||||||
| IRemoteUser
|
| IRemoteUser
|
||||||
|
@ -26,6 +27,7 @@ type Remote =
|
||||||
id: IRemoteUser["id"];
|
id: IRemoteUser["id"];
|
||||||
host: IRemoteUser["host"];
|
host: IRemoteUser["host"];
|
||||||
uri: IRemoteUser["uri"];
|
uri: IRemoteUser["uri"];
|
||||||
|
username: IRemoteUser["username"];
|
||||||
inbox: IRemoteUser["inbox"];
|
inbox: IRemoteUser["inbox"];
|
||||||
};
|
};
|
||||||
type Both = Local | Remote;
|
type Both = Local | Remote;
|
||||||
|
@ -109,8 +111,8 @@ async function deliverReject(followee: Local, follower: Remote) {
|
||||||
|
|
||||||
const content = renderActivity(
|
const content = renderActivity(
|
||||||
renderReject(
|
renderReject(
|
||||||
|
followee.id,
|
||||||
renderFollow(follower, followee, request?.requestId || undefined),
|
renderFollow(follower, followee, request?.requestId || undefined),
|
||||||
followee,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
deliver(followee.id, content, follower.inbox);
|
deliver(followee.id, content, follower.inbox);
|
||||||
|
|
Loading…
Reference in a new issue