refactor (backend): port renderFlag to backend-rs
This commit is contained in:
parent
7fc5c5a468
commit
a54576564b
6 changed files with 56 additions and 21 deletions
10
packages/backend-rs/index.d.ts
vendored
10
packages/backend-rs/index.d.ts
vendored
|
@ -119,6 +119,13 @@ export interface ApEmoji {
|
|||
icon: Icon
|
||||
}
|
||||
|
||||
export interface ApFlag {
|
||||
type: ApObject
|
||||
actor: string
|
||||
content: string
|
||||
object: string
|
||||
}
|
||||
|
||||
export interface ApFollow {
|
||||
id: string
|
||||
type: ApObject
|
||||
|
@ -128,6 +135,7 @@ export interface ApFollow {
|
|||
|
||||
export type ApObject = 'Accept'|
|
||||
'Emoji'|
|
||||
'Flag'|
|
||||
'Follow'|
|
||||
'Image'|
|
||||
'Tombstone';
|
||||
|
@ -1301,6 +1309,8 @@ export declare function renderAccept(userId: string, followObject: ApFollow): Ap
|
|||
|
||||
export declare function renderEmoji(emoji: Emoji): ApEmoji
|
||||
|
||||
export declare function renderFlag(targetUserUri: string, comment: string): Promise<ApFlag>
|
||||
|
||||
export declare function renderFollow(follower: UserLike, followee: UserLike, requestId?: string | undefined | null): ApFollow
|
||||
|
||||
export declare function renderFollowRelay(relayId: string): Promise<ApFollow>
|
||||
|
|
|
@ -440,6 +440,7 @@ module.exports.RelayStatus = nativeBinding.RelayStatus
|
|||
module.exports.removeOldAttestationChallenges = nativeBinding.removeOldAttestationChallenges
|
||||
module.exports.renderAccept = nativeBinding.renderAccept
|
||||
module.exports.renderEmoji = nativeBinding.renderEmoji
|
||||
module.exports.renderFlag = nativeBinding.renderFlag
|
||||
module.exports.renderFollow = nativeBinding.renderFollow
|
||||
module.exports.renderFollowRelay = nativeBinding.renderFollowRelay
|
||||
module.exports.renderTombstone = nativeBinding.renderTombstone
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
use super::*;
|
||||
use crate::{config::CONFIG, federation::internal_actor};
|
||||
|
||||
#[macros::export(object)]
|
||||
pub struct ApFlag {
|
||||
pub r#type: ApObject,
|
||||
pub actor: String,
|
||||
pub content: String,
|
||||
// TODO: object can be an array of uri's
|
||||
pub object: String,
|
||||
}
|
||||
|
||||
impl ActivityPubObject for ApFlag {}
|
||||
|
||||
impl ApFlag {
|
||||
#[allow(dead_code)] // TODO: remove this line
|
||||
async fn new(
|
||||
target_user_uri: String,
|
||||
comment: String,
|
||||
) -> Result<Self, internal_actor::instance::Error> {
|
||||
Ok(Self {
|
||||
r#type: ApObject::Flag,
|
||||
actor: format!(
|
||||
"{}/users/{}",
|
||||
CONFIG.url,
|
||||
internal_actor::instance::get().await?.id
|
||||
),
|
||||
content: comment,
|
||||
object: target_user_uri,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[macros::ts_export]
|
||||
pub async fn render_flag(
|
||||
target_user_uri: String,
|
||||
comment: String,
|
||||
) -> Result<ApFlag, internal_actor::instance::Error> {
|
||||
ApFlag::new(target_user_uri, comment).await
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
pub mod accept;
|
||||
pub mod emoji;
|
||||
pub mod flag;
|
||||
pub mod follow;
|
||||
pub mod tombstone;
|
||||
|
||||
|
@ -9,6 +10,7 @@ pub trait ActivityPubObject {}
|
|||
pub enum ApObject {
|
||||
Accept,
|
||||
Emoji,
|
||||
Flag,
|
||||
Follow,
|
||||
Image,
|
||||
Tombstone,
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import { config } from "@/config.js";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
|
||||
// to anonymise reporters, the reporting actor must be a system user
|
||||
// object has to be a uri or array of uris
|
||||
export const renderFlag = (
|
||||
user: ILocalUser,
|
||||
object: [string],
|
||||
content: string,
|
||||
) => {
|
||||
return {
|
||||
type: "Flag",
|
||||
actor: `${config.url}/users/${user.id}`,
|
||||
content,
|
||||
object,
|
||||
};
|
||||
};
|
|
@ -1,10 +1,9 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { AbuseUserReports, Users } from "@/models/index.js";
|
||||
import { getInstanceActor } from "backend-rs";
|
||||
import { getInstanceActor, renderFlag } from "backend-rs";
|
||||
import { deliver } from "@/queue/index.js";
|
||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||
import { renderFlag } from "@/remote/activitypub/renderer/flag.js";
|
||||
import { ILocalUser } from "@/models/entities/user";
|
||||
import type { ILocalUser } from "@/models/entities/user";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
@ -35,7 +34,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
|
||||
deliver(
|
||||
actor.id,
|
||||
renderActivity(renderFlag(actor, [targetUser.uri!], report.comment)),
|
||||
renderActivity(await renderFlag(targetUser.uri, report.comment)),
|
||||
targetUser.inbox,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue