refactor (backend): port renderFollowRelay to backend-rs
This commit is contained in:
parent
bca44bf50a
commit
55e46c03b9
8 changed files with 55 additions and 18 deletions
11
packages/backend-rs/index.d.ts
vendored
11
packages/backend-rs/index.d.ts
vendored
|
@ -48,6 +48,8 @@ export interface Acct {
|
|||
|
||||
export declare function acctToString(acct: Acct): string
|
||||
|
||||
export type Activity = 'Follow';
|
||||
|
||||
export interface Ad {
|
||||
id: string
|
||||
createdAt: DateTimeWithTimeZone
|
||||
|
@ -389,6 +391,13 @@ export interface Following {
|
|||
followeeSharedInbox: string | null
|
||||
}
|
||||
|
||||
export interface FollowRelay {
|
||||
id: string
|
||||
type: Activity
|
||||
actor: string
|
||||
object: string
|
||||
}
|
||||
|
||||
export interface FollowRequest {
|
||||
id: string
|
||||
createdAt: DateTimeWithTimeZone
|
||||
|
@ -1190,6 +1199,8 @@ export type RelayStatus = 'accepted'|
|
|||
/** Delete all entries in the [attestation_challenge] table created at more than 5 minutes ago */
|
||||
export declare function removeOldAttestationChallenges(): Promise<void>
|
||||
|
||||
export declare function renderFollowRelay(relayId: string): Promise<FollowRelay>
|
||||
|
||||
export interface RenoteMuting {
|
||||
id: string
|
||||
createdAt: DateTimeWithTimeZone
|
||||
|
|
|
@ -362,6 +362,7 @@ if (!nativeBinding) {
|
|||
}
|
||||
|
||||
module.exports.acctToString = nativeBinding.acctToString
|
||||
module.exports.Activity = nativeBinding.Activity
|
||||
module.exports.AntennaSrc = nativeBinding.AntennaSrc
|
||||
module.exports.ChatEvent = nativeBinding.ChatEvent
|
||||
module.exports.ChatIndexEvent = nativeBinding.ChatIndexEvent
|
||||
|
@ -429,6 +430,7 @@ module.exports.PushNotificationKind = nativeBinding.PushNotificationKind
|
|||
module.exports.PushSubscriptionType = nativeBinding.PushSubscriptionType
|
||||
module.exports.RelayStatus = nativeBinding.RelayStatus
|
||||
module.exports.removeOldAttestationChallenges = nativeBinding.removeOldAttestationChallenges
|
||||
module.exports.renderFollowRelay = nativeBinding.renderFollowRelay
|
||||
module.exports.safeForSql = nativeBinding.safeForSql
|
||||
module.exports.sendPushNotification = nativeBinding.sendPushNotification
|
||||
module.exports.shouldNyaify = nativeBinding.shouldNyaify
|
||||
|
|
1
packages/backend-rs/src/federation/activitypub/mod.rs
Normal file
1
packages/backend-rs/src/federation/activitypub/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod object;
|
|
@ -0,0 +1,9 @@
|
|||
pub mod relay;
|
||||
|
||||
pub trait ActivityPubObject {}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[macros::export(string_enum)]
|
||||
pub enum Activity {
|
||||
Follow,
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
use super::*;
|
||||
use crate::{config::CONFIG, federation::internal_actor};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[macros::export(object)]
|
||||
pub struct FollowRelay {
|
||||
pub id: String,
|
||||
pub r#type: Activity,
|
||||
pub actor: String,
|
||||
pub object: String,
|
||||
}
|
||||
|
||||
impl ActivityPubObject for FollowRelay {}
|
||||
|
||||
#[macros::export(js_name = "renderFollowRelay")]
|
||||
pub async fn follow(relay_id: &str) -> Result<FollowRelay, internal_actor::relay::Error> {
|
||||
Ok(FollowRelay {
|
||||
id: format!("{}/activities/follow-relay/{}", CONFIG.url, relay_id),
|
||||
r#type: Activity::Follow,
|
||||
actor: format!(
|
||||
"{}/users/{}",
|
||||
CONFIG.url,
|
||||
internal_actor::relay::get_id().await?
|
||||
),
|
||||
object: "https://www.w3.org/ns/activitystreams#Public".to_owned(),
|
||||
})
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
//! Services used to federate with other servers
|
||||
|
||||
pub mod acct;
|
||||
pub mod activitypub;
|
||||
pub mod internal_actor;
|
||||
pub mod nodeinfo;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import { config } from "@/config.js";
|
||||
import type { Relay } from "@/models/entities/relay.js";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
|
||||
export function renderFollowRelay(relay: Relay, relayActorId: string) {
|
||||
const follow = {
|
||||
id: `${config.url}/activities/follow-relay/${relay.id}`,
|
||||
type: "Follow",
|
||||
actor: `${config.url}/users/${relayActorId}`,
|
||||
object: "https://www.w3.org/ns/activitystreams#Public",
|
||||
};
|
||||
|
||||
return follow;
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import { renderFollowRelay } from "@/remote/activitypub/renderer/follow-relay.js";
|
||||
import {
|
||||
renderActivity,
|
||||
attachLdSignature,
|
||||
|
@ -7,7 +6,7 @@ import { renderUndo } from "@/remote/activitypub/renderer/undo.js";
|
|||
import { deliver } from "@/queue/index.js";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import { Relays } from "@/models/index.js";
|
||||
import { getRelayActorId, genId } from "backend-rs";
|
||||
import { getRelayActorId, genId, renderFollowRelay } from "backend-rs";
|
||||
import { Cache } from "@/misc/cache.js";
|
||||
import type { Relay } from "@/models/entities/relay.js";
|
||||
|
||||
|
@ -21,7 +20,7 @@ export async function addRelay(inbox: string) {
|
|||
}).then((x) => Relays.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
const relayActorId = await getRelayActorId();
|
||||
const follow = renderFollowRelay(relay, relayActorId);
|
||||
const follow = await renderFollowRelay(relay.id);
|
||||
const activity = renderActivity(follow);
|
||||
deliver(relayActorId, activity, relay.inbox);
|
||||
|
||||
|
@ -38,7 +37,7 @@ export async function removeRelay(inbox: string) {
|
|||
}
|
||||
|
||||
const relayActorId = await getRelayActorId();
|
||||
const follow = renderFollowRelay(relay, relayActorId);
|
||||
const follow = await renderFollowRelay(relay.id);
|
||||
const undo = renderUndo(follow, relayActorId);
|
||||
const activity = renderActivity(undo);
|
||||
deliver(relayActorId, activity, relay.inbox);
|
||||
|
|
Loading…
Reference in a new issue