Skip to content

Commit

Permalink
Add homeserver schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
SHAcollision committed Aug 27, 2024
1 parent f4b3750 commit 4df9e38
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 19 deletions.
13 changes: 13 additions & 0 deletions src/models/homeserver/bookmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};

/// Represents raw homeserver bookmark with id
/// URI: /pub/pubky.app/bookmarks/:URI_BOOKMARKED_OBJECT
///
/// Example URI:
///
/// `/pub/pubky.app/bookmarks/pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy/pub/pubky.app/posts/2ZKGWXZ44J300/cool`
///
#[derive(Serialize, Deserialize, Default)]
pub struct HomeserverBookmark {
pub created_at: i64,
}
13 changes: 13 additions & 0 deletions src/models/homeserver/follow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};

/// Represents raw homeserver follow object with timestamp
/// URI: /pub/pubky.app/follows/:user_id
///
/// Example URI:
///
/// `/pub/pubky.app/follows/pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy``
///
#[derive(Serialize, Deserialize, Default)]
pub struct HomeserverFollow {
pub created_at: i64,
}
12 changes: 10 additions & 2 deletions src/models/homeserver/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/// Raw schemas stored on homeserver.
pub mod user;
/// Raw schemas as stored on homeserver.
mod bookmark;
mod follow;
mod post;
mod tag;
mod user;

pub use bookmark::HomeserverBookmark;
pub use follow::HomeserverFollow;
pub use post::{HomeserverPost, PostKind};
pub use tag::HomeserverTag;
pub use user::{HomeserverUser, UserLink};
32 changes: 32 additions & 0 deletions src/models/homeserver/post.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Represents the type of pubky-app posted data
/// Used primarily to best display the content in UI
#[derive(Serialize, Deserialize, ToSchema, Default)]
pub enum PostKind {
#[default]
Short,
Long,
Image,
Video,
Link,
File,
}

/// Used primarily to best display the content in UI
#[derive(Serialize, Deserialize, Default)]
pub struct PostEmbed {
pub r#type: String, //e.g., "post", we have to define a type for this.
pub uri: String,
}

/// Represents raw post in homeserver with content and kind
/// URI: /pub/pubky.app/posts/:post_id
/// Where post_id is CrockfordBase32 encoding of timestamp
#[derive(Serialize, Deserialize, Default)]
pub struct HomeserverPost {
pub content: String,
pub kind: PostKind,
pub embed: PostEmbed,
}
13 changes: 13 additions & 0 deletions src/models/homeserver/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use serde::{Deserialize, Serialize};

/// Represents raw homeserver tag with id
/// URI: /pub/pubky.app/tags/:URI_TAGGED_OBJECT/:label
///
/// Example URI:
///
/// `/pub/pubky.app/tags/pxnu33x7jtpx9ar1ytsi4yxbp6a5o36gwhffs8zoxmbuptici1jy/pub/pubky.app/posts/2ZKGWXZ44J300/cool`
///
#[derive(Serialize, Deserialize, Default)]
pub struct HomeserverTag {
pub created_at: i64,
}
1 change: 1 addition & 0 deletions src/models/homeserver/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Profile schema
/// URI: /pub/pubky.app/profile.json
#[derive(Deserialize, Serialize, Debug)]
pub struct HomeserverUser {
pub name: String,
Expand Down
17 changes: 2 additions & 15 deletions src/models/post/details.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
use super::PostStream;
use crate::db::connectors::neo4j::get_neo4j_graph;
use crate::models::homeserver::PostKind;
use crate::{queries, RedisOps};
use neo4rs::Node;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use super::PostStream;

/// Represents the type of pubky-app posted data
/// Used primarily to best display the content in UI
#[derive(Serialize, Deserialize, ToSchema, Default)]
pub enum PostKind {
#[default]
Short,
Long,
Image,
Video,
Link,
File,
}

/// Represents post data with content, bio, image, links, and status.
#[derive(Serialize, Deserialize, ToSchema, Default)]
pub struct PostDetails {
Expand Down
2 changes: 1 addition & 1 deletion src/models/post/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod view;

pub use bookmark::Bookmark;
pub use counts::PostCounts;
pub use details::{PostDetails, PostKind};
pub use details::PostDetails;
pub use relationships::PostRelationships;
pub use stream::{PostStream, PostStreamReach, PostStreamSorting};
pub use thread::PostThread;
Expand Down
3 changes: 2 additions & 1 deletion src/routes/v0/post/details.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::models::post::{PostDetails, PostKind};
use crate::models::homeserver::PostKind;
use crate::models::post::PostDetails;
use crate::routes::v0::endpoints::POST_DETAILS_ROUTE;
use crate::{Error, Result};
use axum::extract::Path;
Expand Down

0 comments on commit 4df9e38

Please sign in to comment.