mirror of
https://github.com/nullishamy/ferri.git
synced 2025-04-29 20:29:23 +00:00
feat: add user types into rewrite
This commit is contained in:
parent
d59660da37
commit
76fb8838c2
2 changed files with 118 additions and 1 deletions
|
@ -26,3 +26,36 @@ impl From<ap::Actor> for db::Actor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<db::User> for api::Account {
|
||||||
|
fn from(val: db::User) -> api::Account {
|
||||||
|
api::Account {
|
||||||
|
id: val.id,
|
||||||
|
username: val.username,
|
||||||
|
acct: "FIXME_api::Account::acct".to_string(),
|
||||||
|
display_name: val.display_name,
|
||||||
|
|
||||||
|
locked: false,
|
||||||
|
bot: false,
|
||||||
|
|
||||||
|
created_at: "FIXME_api::Account::created_at".to_string(),
|
||||||
|
attribution_domains: vec![],
|
||||||
|
|
||||||
|
note: "".to_string(),
|
||||||
|
url: "FIXME_api::Account::url".to_string(),
|
||||||
|
|
||||||
|
avatar: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||||
|
avatar_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||||
|
header: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||||
|
header_static: "https://ferri.amy.mov/assets/pfp.png".to_string(),
|
||||||
|
|
||||||
|
followers_count: 0,
|
||||||
|
following_count: 0,
|
||||||
|
statuses_count: 0,
|
||||||
|
last_status_at: "FIXME_api::Account::last_status_at".to_string(),
|
||||||
|
|
||||||
|
emojis: vec![],
|
||||||
|
fields: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@ pub enum ObjectContext {
|
||||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
pub struct ObjectUri(String);
|
pub struct ObjectUri(String);
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct ObjectUuid(String);
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
#[serde(rename = "@context")]
|
#[serde(rename = "@context")]
|
||||||
|
@ -34,7 +37,15 @@ pub mod db {
|
||||||
pub id: ObjectUri,
|
pub id: ObjectUri,
|
||||||
pub inbox: String,
|
pub inbox: String,
|
||||||
pub outbox: String,
|
pub outbox: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct User {
|
||||||
|
pub id: ObjectUuid,
|
||||||
|
pub actor_id: ObjectUri,
|
||||||
|
pub username: String,
|
||||||
|
pub display_name: String
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod ap {
|
pub mod ap {
|
||||||
|
@ -49,6 +60,33 @@ pub mod ap {
|
||||||
pub inbox: String,
|
pub inbox: String,
|
||||||
pub outbox: String,
|
pub outbox: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct Person {
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub obj: Object,
|
||||||
|
|
||||||
|
pub following: String,
|
||||||
|
pub followers: String,
|
||||||
|
|
||||||
|
pub summary: String,
|
||||||
|
pub inbox: String,
|
||||||
|
pub outbox: String,
|
||||||
|
|
||||||
|
pub preferred_username: String,
|
||||||
|
pub name: String,
|
||||||
|
|
||||||
|
pub public_key: Option<UserKey>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct UserKey {
|
||||||
|
pub id: String,
|
||||||
|
pub owner: String,
|
||||||
|
|
||||||
|
#[serde(rename = "publicKeyPem")]
|
||||||
|
pub public_key: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod api {
|
pub mod api {
|
||||||
|
@ -58,6 +96,51 @@ pub mod api {
|
||||||
// API will not really use actors so treat them as DB actors
|
// API will not really use actors so treat them as DB actors
|
||||||
// until we require specificity
|
// until we require specificity
|
||||||
pub type Actor = db::Actor;
|
pub type Actor = db::Actor;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct Account {
|
||||||
|
pub id: ObjectUuid,
|
||||||
|
pub username: String,
|
||||||
|
pub acct: String,
|
||||||
|
pub display_name: String,
|
||||||
|
|
||||||
|
pub locked: bool,
|
||||||
|
pub bot: bool,
|
||||||
|
|
||||||
|
pub created_at: String,
|
||||||
|
pub attribution_domains: Vec<String>,
|
||||||
|
|
||||||
|
pub note: String,
|
||||||
|
pub url: String,
|
||||||
|
|
||||||
|
pub avatar: String,
|
||||||
|
pub avatar_static: String,
|
||||||
|
pub header: String,
|
||||||
|
pub header_static: String,
|
||||||
|
|
||||||
|
pub followers_count: i64,
|
||||||
|
pub following_count: i64,
|
||||||
|
pub statuses_count: i64,
|
||||||
|
pub last_status_at: String,
|
||||||
|
|
||||||
|
pub emojis: Vec<Emoji>,
|
||||||
|
pub fields: Vec<CustomField>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct Emoji {
|
||||||
|
pub shortcode: String,
|
||||||
|
pub url: String,
|
||||||
|
pub static_url: String,
|
||||||
|
pub visible_in_picker: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
|
pub struct CustomField {
|
||||||
|
pub name: String,
|
||||||
|
pub value: String,
|
||||||
|
pub verified_at: Option<String>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -67,6 +150,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn ap_actor_to_db() {
|
fn ap_actor_to_db() {
|
||||||
let domain = "https://example.com";
|
let domain = "https://example.com";
|
||||||
|
|
||||||
let ap = ap::Actor {
|
let ap = ap::Actor {
|
||||||
obj: Object {
|
obj: Object {
|
||||||
context: as_context(),
|
context: as_context(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue