Added timeline methods: retrieve_feed, compose, delete
This commit is contained in:
parent
351fe65450
commit
0aa932972a
|
@ -3,6 +3,7 @@ pub mod error;
|
|||
pub mod help;
|
||||
pub mod network;
|
||||
pub mod session;
|
||||
pub mod timeline;
|
||||
|
||||
pub use error::ClientError;
|
||||
pub use error::SocialvoidError;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
use serde_json::json;
|
||||
use socialvoid_rawclient::Error;
|
||||
use socialvoid_types::Post;
|
||||
use socialvoid_types::SessionIdentification;
|
||||
|
||||
/// TODO: write tests for this
|
||||
|
||||
/// Retrieve the posts from the users timeline
|
||||
pub async fn retrieve_feed(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
session_identification: SessionIdentification,
|
||||
page: Option<usize>,
|
||||
) -> Result<Vec<Post>, Error> {
|
||||
client
|
||||
.send_request(
|
||||
"timeline.retrieve_feed",
|
||||
json!({
|
||||
"session_identification": serde_json::to_value(session_identification)?,
|
||||
"page": page,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Compose a new post to push to the timeline
|
||||
pub async fn compose(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
session_identification: SessionIdentification,
|
||||
text: String,
|
||||
attachments: Vec<String>,
|
||||
) -> Result<Post, Error> {
|
||||
client
|
||||
.send_request(
|
||||
"timeline.compose",
|
||||
json!({
|
||||
"session_identification": serde_json::to_value(session_identification)?,
|
||||
"text":text,
|
||||
"attachments":attachments,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Delete a post from the timeline using it's ID
|
||||
pub async fn delete(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
session_identification: SessionIdentification,
|
||||
post: String,
|
||||
) -> Result<bool, Error> {
|
||||
client
|
||||
.send_request(
|
||||
"timeline.delete",
|
||||
json!({
|
||||
"session_identification": serde_json::to_value(session_identification)?,
|
||||
"post":post,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
}
|
|
@ -139,6 +139,42 @@ pub enum RelationshipType {
|
|||
BlockedYou,
|
||||
}
|
||||
|
||||
/// Post
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Post {
|
||||
id: String,
|
||||
#[serde(rename = "type")]
|
||||
post_type: PostType,
|
||||
peer: Option<Peer>,
|
||||
source: Option<String>,
|
||||
text: Option<String>,
|
||||
attachments: Vec<Document>,
|
||||
entities: Vec<TextEntity>,
|
||||
mentioned_peers: Vec<Peer>,
|
||||
reply_to_post: Option<Box<Post>>,
|
||||
quoted_post: Option<Box<Post>>,
|
||||
reposted_post: Option<Box<Post>>,
|
||||
original_thread_post: Option<Box<Post>>,
|
||||
like_count: Option<usize>,
|
||||
repost_count: Option<usize>,
|
||||
quote_count: Option<usize>,
|
||||
reply_count: Option<usize>,
|
||||
posted_timestamp: u32,
|
||||
flags: Vec<String>,
|
||||
}
|
||||
|
||||
/// Post Type
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||
pub enum PostType {
|
||||
Unknown,
|
||||
Deleted,
|
||||
Post,
|
||||
Reply,
|
||||
Quote,
|
||||
Repost,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Profile {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(
|
||||
|
|
Loading…
Reference in New Issue