Skip to content

Commit

Permalink
feat: implement fep-4adb (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 19, 2024
1 parent 63a7a5a commit c036a26
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions FEDERATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md)
- [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md)
- [FEP-fffd: Proxy Objects](https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md)
- [FEP-4adb: Dereferencing identifiers with webfinger](https://codeberg.org/fediverse/fep/src/branch/main/fep/4adb/fep-4adb.md)

## ActivityPub

Expand Down
22 changes: 20 additions & 2 deletions crates/api_apub/src/users/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use hatsu_db_schema::prelude::User;
use hatsu_utils::{AppData, AppError};
use sea_orm::EntityTrait;
// use serde::Deserialize;
use serde_json::Value;
use serde_json::{json, Value};

// #[derive(TypedPath, Deserialize)]
// #[typed_path("/u/:name")]
Expand Down Expand Up @@ -52,11 +52,29 @@ pub async fn user(
let url = hatsu_utils::url::generate_user_url(data.domain(), &name)?;
// "@context": [
// "https://www.w3.org/ns/activitystreams",
// "https://w3id.org/security/v1"
// "https://w3id.org/security/v1",
// {
// "xrd": "http://docs.oasis-open.org/ns/xri/xrd-1.0#",
// "aliases": {
// "@id": "xrd:Alias",
// "@type": "@id",
// "@container": "@list"
// }
// }
// ]
let context = vec![
Value::String(context().to_string()),
Value::String(security().to_string()),
// FEP-4adb
// https://github.com/importantimport/hatsu/issues/15
json!({
"xrd": "http://docs.oasis-open.org/ns/xri/xrd-1.0#",
"aliases": {
"@id": "xrd:Alias",
"@type": "@id",
"@container": "@list"
},
})
];

match User::find_by_id(&url.to_string()).one(&data.conn).await? {
Expand Down
6 changes: 5 additions & 1 deletion crates/apub/src/actors/db_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Object for ApubUser {
Ok(user.into())
}

async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
Ok(Service {
kind: ServiceType::Service.to_string(),
name: self.name.clone(),
Expand All @@ -133,6 +133,10 @@ impl Object for ApubUser {
outbox: Url::parse(&self.outbox)?,
followers: Url::parse(&self.followers)?,
following: Url::parse(&self.following)?,
// FEP-4adb
// https://github.com/importantimport/hatsu/issues/15
// TODO: customize via _hatsu.aliases
aliases: Some(vec![format!("acct:{}@{}", &self.preferred_username, &self.preferred_username), format!("acct:{}@{}", &self.preferred_username, data.domain())]),
public_key: self.public_key(),
})
}
Expand Down
4 changes: 4 additions & 0 deletions crates/apub/src/actors/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub struct Service {
pub followers: Url,
// 正在关注
pub following: Url,
/// FEP-4adb
/// https://github.com/importantimport/hatsu/issues/15
#[serde(skip_serializing_if = "Option::is_none")]
pub aliases: Option<Vec<String>>,
// 公钥
#[schema(value_type = PublicKeySchema)]
pub public_key: PublicKey,
Expand Down
1 change: 1 addition & 0 deletions docs/src/others/federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [FEP-67ff: FEDERATION.md](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md)
- [FEP-f1d5: NodeInfo in Fediverse Software](https://codeberg.org/fediverse/fep/src/branch/main/fep/f1d5/fep-f1d5.md)
- [FEP-fffd: Proxy Objects](https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md)
- [FEP-4adb: Dereferencing identifiers with webfinger](https://codeberg.org/fediverse/fep/src/branch/main/fep/4adb/fep-4adb.md)

## ActivityPub

Expand Down

0 comments on commit c036a26

Please sign in to comment.