feat: migrate to lemmy v0.19 (closes #33)

This commit is contained in:
Bnyro
2024-01-06 11:30:55 +01:00
parent 7f8d62cc98
commit c069b15cd8
23 changed files with 221 additions and 3409 deletions
Generated
+140 -896
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -9,7 +9,7 @@ relm4-components = { version = "0.6.2", features = ["web"] }
reqwest = { version = "0.11", features = ["json", "blocking", "multipart"] } reqwest = { version = "0.11", features = ["json", "blocking", "multipart"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
lemmy_api_common = "0.18" lemmy_api_common = "0.19"
markdown = "0.3" markdown = "0.3"
html2pango = "0.5" html2pango = "0.5"
rand = "0.8" rand = "0.8"
+3 -20
View File
@@ -6,8 +6,6 @@ use lemmy_api_common::{
lemmy_db_schema::newtypes::{CommentId, PostId}, lemmy_db_schema::newtypes::{CommentId, PostId},
}; };
use crate::settings;
pub fn create_comment( pub fn create_comment(
post_id: PostId, post_id: PostId,
content: String, content: String,
@@ -17,7 +15,6 @@ pub fn create_comment(
post_id, post_id,
content, content,
parent_id, parent_id,
auth: settings::get_current_account().jwt.unwrap(),
..Default::default() ..Default::default()
}; };
super::post("/comment", &params) super::post("/comment", &params)
@@ -25,11 +22,7 @@ pub fn create_comment(
// see posts.rs for possible score parameters // see posts.rs for possible score parameters
pub fn like_comment(comment_id: CommentId, score: i16) -> Result<CommentResponse, reqwest::Error> { pub fn like_comment(comment_id: CommentId, score: i16) -> Result<CommentResponse, reqwest::Error> {
let params = CreateCommentLike { let params = CreateCommentLike { comment_id, score };
comment_id,
score,
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/comment/like", &params) super::post("/comment/like", &params)
} }
@@ -40,7 +33,6 @@ pub fn edit_comment(
let params = EditComment { let params = EditComment {
content: Some(body), content: Some(body),
comment_id, comment_id,
auth: settings::get_current_account().jwt.unwrap(),
..Default::default() ..Default::default()
}; };
super::put("/post", &params) super::put("/post", &params)
@@ -50,17 +42,12 @@ pub fn delete_comment(comment_id: CommentId) -> Result<CommentResponse, reqwest:
let params = DeleteComment { let params = DeleteComment {
comment_id, comment_id,
deleted: true, deleted: true,
auth: settings::get_current_account().jwt.unwrap(),
}; };
super::post("/comment/delete", &params) super::post("/comment/delete", &params)
} }
pub fn save_comment(comment_id: CommentId, save: bool) -> Result<CommentResponse, reqwest::Error> { pub fn save_comment(comment_id: CommentId, save: bool) -> Result<CommentResponse, reqwest::Error> {
let params = SaveComment { let params = SaveComment { comment_id, save };
auth: settings::get_current_account().jwt.unwrap(),
comment_id,
save,
};
super::put("/comment/save", &params) super::put("/comment/save", &params)
} }
@@ -68,10 +55,6 @@ pub fn report_comment(
comment_id: CommentId, comment_id: CommentId,
reason: String, reason: String,
) -> Result<CommentReportResponse, reqwest::Error> { ) -> Result<CommentReportResponse, reqwest::Error> {
let params = CreateCommentReport { let params = CreateCommentReport { comment_id, reason };
comment_id,
reason,
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/comment/report", &params) super::post("/comment/report", &params)
} }
-2
View File
@@ -5,7 +5,6 @@ use lemmy_api_common::{
}; };
use super::search; use super::search;
use crate::settings;
pub fn fetch_communities( pub fn fetch_communities(
page: i64, page: i64,
@@ -17,7 +16,6 @@ pub fn fetch_communities(
type_: listing_type, type_: listing_type,
sort: Some(SortType::TopMonth), sort: Some(SortType::TopMonth),
page: Some(page), page: Some(page),
auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };
-5
View File
@@ -6,12 +6,9 @@ use lemmy_api_common::{
lemmy_db_schema::newtypes::CommunityId, lemmy_db_schema::newtypes::CommunityId,
}; };
use crate::settings;
pub fn get_community(id: CommunityId) -> std::result::Result<GetCommunityResponse, reqwest::Error> { pub fn get_community(id: CommunityId) -> std::result::Result<GetCommunityResponse, reqwest::Error> {
let params = GetCommunity { let params = GetCommunity {
id: Some(id), id: Some(id),
auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };
@@ -25,7 +22,6 @@ pub fn follow_community(
let params = FollowCommunity { let params = FollowCommunity {
community_id, community_id,
follow, follow,
auth: settings::get_current_account().jwt.unwrap(),
}; };
super::post("/community/follow", &params) super::post("/community/follow", &params)
} }
@@ -41,7 +37,6 @@ pub fn block_community(
let params = BlockCommunity { let params = BlockCommunity {
community_id, community_id,
block, block,
auth: settings::get_current_account().jwt.unwrap(),
}; };
super::post("/community/block", &params) super::post("/community/block", &params)
+11 -15
View File
@@ -1,19 +1,11 @@
use crate::settings; use lemmy_api_common::site::{GetFederatedInstancesResponse, InstanceWithFederationState};
use lemmy_api_common::{
lemmy_db_schema::source::instance::Instance,
site::{GetFederatedInstances, GetFederatedInstancesResponse},
};
pub fn fetch_instances(query_filter: &str) -> std::result::Result<Vec<Instance>, reqwest::Error> {
// TODO: Update code to use the Instance views from lemmy 0.18.0
let params = GetFederatedInstances {
auth: settings::get_current_account().jwt,
};
pub fn fetch_instances(
query_filter: &str,
) -> std::result::Result<Vec<InstanceWithFederationState>, reqwest::Error> {
// we fetch the instances from the official instance because the instance is likely unset on first startup // we fetch the instances from the official instance because the instance is likely unset on first startup
let instances = super::CLIENT let instances = super::CLIENT
.get("https://lemmy.ml/api/v3/federated_instances".to_owned()) .get("https://lemmy.ml/api/v3/federated_instances".to_owned())
.query(&params)
.send()? .send()?
.json::<GetFederatedInstancesResponse>()?; .json::<GetFederatedInstancesResponse>()?;
@@ -23,11 +15,15 @@ pub fn fetch_instances(query_filter: &str) -> std::result::Result<Vec<Instance>,
.linked .linked
.iter() .iter()
.filter(|instance| { .filter(|instance| {
instance.software == Some("lemmy".to_owned()) instance.instance.software == Some("lemmy".to_owned())
&& instance.domain.clone().contains(&lowercase_query_filter) && instance
.instance
.domain
.clone()
.contains(&lowercase_query_filter)
}) })
.cloned() .cloned()
.collect::<Vec<Instance>>()), .collect::<Vec<InstanceWithFederationState>>()),
None => Ok(vec![]), None => Ok(vec![]),
} }
} }
+37 -5
View File
@@ -1,6 +1,9 @@
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use crate::{config, settings::get_current_account}; use crate::{
config,
settings::{self, get_current_account},
};
pub mod auth; pub mod auth;
pub mod comment; pub mod comment;
@@ -19,7 +22,7 @@ pub mod user;
static API_VERSION: &str = "v3"; static API_VERSION: &str = "v3";
use relm4::once_cell::sync::Lazy; use relm4::once_cell::sync::Lazy;
use reqwest::blocking::Client; use reqwest::{blocking::Client, header::HeaderMap, header::HeaderValue};
pub static CLIENT: Lazy<Client> = Lazy::new(|| { pub static CLIENT: Lazy<Client> = Lazy::new(|| {
let user_agent = format!("{}/{}", config::NAME, config::VERSION); let user_agent = format!("{}/{}", config::NAME, config::VERSION);
@@ -37,12 +40,31 @@ fn get_url(path: &str) -> String {
format!("{}{}", get_api_url(), path) format!("{}{}", get_api_url(), path)
} }
fn get_auth_header() -> HeaderMap<HeaderValue> {
let mut headers = HeaderMap::new();
if let Some(jwt) = settings::get_current_account().jwt {
let auth_string = "Bearer ".to_string() + &jwt.into_inner();
headers.insert(
"Authorization",
HeaderValue::from_str(&auth_string).unwrap(),
);
}
headers
}
fn get<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error> fn get<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error>
where where
T: DeserializeOwned, T: DeserializeOwned,
Params: Serialize + std::fmt::Debug, Params: Serialize + std::fmt::Debug,
{ {
CLIENT.get(get_url(path)).query(&params).send()?.json() CLIENT
.get(get_url(path))
.headers(get_auth_header())
.query(&params)
.send()?
.json()
} }
fn post<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error> fn post<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error>
@@ -50,7 +72,12 @@ where
T: DeserializeOwned, T: DeserializeOwned,
Params: Serialize + std::fmt::Debug, Params: Serialize + std::fmt::Debug,
{ {
CLIENT.post(get_url(path)).json(&params).send()?.json() CLIENT
.post(get_url(path))
.headers(get_auth_header())
.json(&params)
.send()?
.json()
} }
fn put<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error> fn put<T, Params>(path: &str, params: &Params) -> Result<T, reqwest::Error>
@@ -58,5 +85,10 @@ where
T: DeserializeOwned, T: DeserializeOwned,
Params: Serialize + std::fmt::Debug, Params: Serialize + std::fmt::Debug,
{ {
CLIENT.put(get_url(path)).json(&params).send()?.json() CLIENT
.put(get_url(path))
.headers(get_auth_header())
.json(&params)
.send()?
.json()
} }
+2 -13
View File
@@ -2,33 +2,22 @@ use lemmy_api_common::{
comment::{CommentResponse, RemoveComment}, comment::{CommentResponse, RemoveComment},
lemmy_db_schema::newtypes::{CommentId, PostId}, lemmy_db_schema::newtypes::{CommentId, PostId},
post::{PostResponse, RemovePost}, post::{PostResponse, RemovePost},
sensitive::Sensitive,
}; };
pub fn remove_post( pub fn remove_post(post_id: i32, reason: String) -> Result<PostResponse, reqwest::Error> {
post_id: i32,
reason: String,
auth: Sensitive<String>,
) -> Result<PostResponse, reqwest::Error> {
let params = RemovePost { let params = RemovePost {
post_id: PostId(post_id), post_id: PostId(post_id),
removed: true, removed: true,
reason: Some(reason), reason: Some(reason),
auth,
}; };
super::post("/post/remove", &params) super::post("/post/remove", &params)
} }
pub fn remove_comment( pub fn remove_comment(comment_id: i32, reason: String) -> Result<CommentResponse, reqwest::Error> {
comment_id: i32,
reason: String,
auth: Sensitive<String>,
) -> Result<CommentResponse, reqwest::Error> {
let params = RemoveComment { let params = RemoveComment {
comment_id: CommentId(comment_id), comment_id: CommentId(comment_id),
removed: true, removed: true,
reason: Some(reason), reason: Some(reason),
auth,
}; };
super::post("/comment/remove", &params) super::post("/comment/remove", &params)
} }
+5 -23
View File
@@ -1,4 +1,3 @@
use crate::settings;
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::{ use lemmy_api_common::{
comment::{GetComments, GetCommentsResponse}, comment::{GetComments, GetCommentsResponse},
@@ -18,7 +17,6 @@ pub fn get_post(id: PostId) -> Result<GetPostResponse, reqwest::Error> {
let params = GetPost { let params = GetPost {
id: Some(id), id: Some(id),
comment_id: None, comment_id: None,
auth: settings::get_current_account().jwt,
}; };
super::get("/post", &params) super::get("/post", &params)
@@ -30,7 +28,6 @@ pub fn get_comments(post_id: PostId) -> Result<Vec<CommentView>, reqwest::Error>
sort: Some(CommentSortType::Hot), sort: Some(CommentSortType::Hot),
type_: Some(ListingType::All), type_: Some(ListingType::All),
max_depth: Some(8), max_depth: Some(8),
auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };
@@ -70,7 +67,6 @@ pub fn create_post(
body: Some(body), body: Some(body),
url, url,
community_id: CommunityId(community_id), community_id: CommunityId(community_id),
auth: settings::get_current_account().jwt.unwrap(),
..Default::default() ..Default::default()
}; };
super::post("/post", &params) super::post("/post", &params)
@@ -87,7 +83,6 @@ pub fn edit_post(
body: Some(body), body: Some(body),
url, url,
post_id: PostId(post_id), post_id: PostId(post_id),
auth: settings::get_current_account().jwt.unwrap(),
..Default::default() ..Default::default()
}; };
super::put("/post", &params) super::put("/post", &params)
@@ -95,11 +90,7 @@ pub fn edit_post(
// for score, use 1 to upvote, -1 to vote down and 0 to reset the user's voting // for score, use 1 to upvote, -1 to vote down and 0 to reset the user's voting
pub fn like_post(post_id: PostId, score: i16) -> Result<PostResponse, reqwest::Error> { pub fn like_post(post_id: PostId, score: i16) -> Result<PostResponse, reqwest::Error> {
let params = CreatePostLike { let params = CreatePostLike { post_id, score };
post_id,
score,
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/post/like", &params) super::post("/post/like", &params)
} }
@@ -107,34 +98,25 @@ pub fn delete_post(post_id: PostId) -> Result<PostResponse, reqwest::Error> {
let params = DeletePost { let params = DeletePost {
post_id, post_id,
deleted: true, deleted: true,
auth: settings::get_current_account().jwt.unwrap(),
}; };
super::post("/post/delete", &params) super::post("/post/delete", &params)
} }
pub fn save_post(post_id: PostId, save: bool) -> Result<PostResponse, reqwest::Error> { pub fn save_post(post_id: PostId, save: bool) -> Result<PostResponse, reqwest::Error> {
let params = SavePost { let params = SavePost { post_id, save };
auth: settings::get_current_account().jwt.unwrap(),
post_id,
save,
};
super::put("/post/save", &params) super::put("/post/save", &params)
} }
pub fn report_post(post_id: PostId, reason: String) -> Result<PostReportResponse, reqwest::Error> { pub fn report_post(post_id: PostId, reason: String) -> Result<PostReportResponse, reqwest::Error> {
let params = CreatePostReport { let params = CreatePostReport { post_id, reason };
post_id,
reason,
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/post/report", &params) super::post("/post/report", &params)
} }
pub fn mark_post_as_read(post_id: PostId, read: bool) -> Result<PostResponse, reqwest::Error> { pub fn mark_post_as_read(post_id: PostId, read: bool) -> Result<PostResponse, reqwest::Error> {
let params = MarkPostAsRead { let params = MarkPostAsRead {
post_id, post_id: Some(post_id),
read, read,
auth: settings::get_current_account().jwt.unwrap(), ..Default::default()
}; };
super::post("/post/mark_as_read", &params) super::post("/post/mark_as_read", &params)
} }
-3
View File
@@ -4,8 +4,6 @@ use lemmy_api_common::{
post::{GetPosts, GetPostsResponse}, post::{GetPosts, GetPostsResponse},
}; };
use crate::settings;
pub fn list_posts( pub fn list_posts(
page: i64, page: i64,
community_name: Option<String>, community_name: Option<String>,
@@ -17,7 +15,6 @@ pub fn list_posts(
type_: listing_type, type_: listing_type,
sort: sort_type, sort: sort_type,
community_name, community_name,
auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };
-3
View File
@@ -11,7 +11,6 @@ pub fn create_private_message(
recipient_id: PersonId, recipient_id: PersonId,
) -> std::result::Result<PrivateMessageResponse, reqwest::Error> { ) -> std::result::Result<PrivateMessageResponse, reqwest::Error> {
let params = CreatePrivateMessage { let params = CreatePrivateMessage {
auth: crate::settings::get_current_account().jwt.unwrap(),
recipient_id, recipient_id,
content, content,
}; };
@@ -23,7 +22,6 @@ pub fn edit_private_message(
private_message_id: PrivateMessageId, private_message_id: PrivateMessageId,
) -> std::result::Result<PrivateMessageResponse, reqwest::Error> { ) -> std::result::Result<PrivateMessageResponse, reqwest::Error> {
let params = EditPrivateMessage { let params = EditPrivateMessage {
auth: crate::settings::get_current_account().jwt.unwrap(),
private_message_id, private_message_id,
content, content,
}; };
@@ -37,7 +35,6 @@ pub fn list_private_messages(
let params = GetPrivateMessages { let params = GetPrivateMessages {
unread_only: Some(unread_only), unread_only: Some(unread_only),
page: Some(page), page: Some(page),
auth: crate::settings::get_current_account().jwt.unwrap(),
..Default::default() ..Default::default()
}; };
super::get("/private_message/list", &params) super::get("/private_message/list", &params)
-3
View File
@@ -3,8 +3,6 @@ use lemmy_api_common::{
site::{Search, SearchResponse}, site::{Search, SearchResponse},
}; };
use crate::settings;
pub fn fetch_search( pub fn fetch_search(
page: i64, page: i64,
query: String, query: String,
@@ -15,7 +13,6 @@ pub fn fetch_search(
sort: Some(SortType::TopMonth), sort: Some(SortType::TopMonth),
page: Some(page), page: Some(page),
type_: search_type, type_: search_type,
auth: settings::get_current_account().jwt,
..Default::default() ..Default::default()
}; };
+2 -7
View File
@@ -1,12 +1,7 @@
use lemmy_api_common::site::{GetSite, GetSiteResponse}; use lemmy_api_common::site::GetSiteResponse;
use crate::settings;
pub fn fetch_site() -> std::result::Result<GetSiteResponse, reqwest::Error> { pub fn fetch_site() -> std::result::Result<GetSiteResponse, reqwest::Error> {
let params = GetSite { super::get("/site", &())
auth: settings::get_current_account().jwt,
};
super::get("/site", &params)
} }
pub fn default_site_info() -> GetSiteResponse { pub fn default_site_info() -> GetSiteResponse {
+2 -15
View File
@@ -3,12 +3,9 @@ use lemmy_api_common::{
person::{ person::{
BlockPerson, BlockPersonResponse, GetPersonDetails, GetPersonDetailsResponse, BlockPerson, BlockPersonResponse, GetPersonDetails, GetPersonDetailsResponse,
GetPersonMentions, GetPersonMentionsResponse, GetReplies, GetRepliesResponse, GetPersonMentions, GetPersonMentionsResponse, GetReplies, GetRepliesResponse,
MarkAllAsRead,
}, },
}; };
use crate::settings;
pub fn get_user( pub fn get_user(
id: PersonId, id: PersonId,
page: i64, page: i64,
@@ -17,7 +14,6 @@ pub fn get_user(
let params = GetPersonDetails { let params = GetPersonDetails {
page: Some(page), page: Some(page),
person_id: Some(id), person_id: Some(id),
auth: settings::get_current_account().jwt,
saved_only: Some(saved_only), saved_only: Some(saved_only),
..Default::default() ..Default::default()
}; };
@@ -29,11 +25,7 @@ pub fn block_user(
person_id: PersonId, person_id: PersonId,
block: bool, block: bool,
) -> std::result::Result<BlockPersonResponse, reqwest::Error> { ) -> std::result::Result<BlockPersonResponse, reqwest::Error> {
let params = BlockPerson { let params = BlockPerson { person_id, block };
person_id,
block,
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/user/block", &params) super::post("/user/block", &params)
} }
@@ -47,7 +39,6 @@ pub fn get_mentions(
unread_only: bool, unread_only: bool,
) -> std::result::Result<GetPersonMentionsResponse, reqwest::Error> { ) -> std::result::Result<GetPersonMentionsResponse, reqwest::Error> {
let params = GetPersonMentions { let params = GetPersonMentions {
auth: settings::get_current_account().jwt.unwrap(),
unread_only: Some(unread_only), unread_only: Some(unread_only),
page: Some(page), page: Some(page),
sort: Some(CommentSortType::New), sort: Some(CommentSortType::New),
@@ -61,7 +52,6 @@ pub fn get_replies(
unread_only: bool, unread_only: bool,
) -> std::result::Result<GetRepliesResponse, reqwest::Error> { ) -> std::result::Result<GetRepliesResponse, reqwest::Error> {
let params = GetReplies { let params = GetReplies {
auth: settings::get_current_account().jwt.unwrap(),
page: Some(page), page: Some(page),
unread_only: Some(unread_only), unread_only: Some(unread_only),
sort: Some(CommentSortType::New), sort: Some(CommentSortType::New),
@@ -71,8 +61,5 @@ pub fn get_replies(
} }
pub fn mark_all_as_read() -> std::result::Result<GetRepliesResponse, reqwest::Error> { pub fn mark_all_as_read() -> std::result::Result<GetRepliesResponse, reqwest::Error> {
let params = MarkAllAsRead { super::post("/user/mark_all_as_read", &())
auth: settings::get_current_account().jwt.unwrap(),
};
super::post("/user/mark_all_as_read", &params)
} }
+3 -3
View File
@@ -1,5 +1,5 @@
use gtk::prelude::*; use gtk::prelude::*;
use lemmy_api_common::lemmy_db_schema::source::instance::Instance; use lemmy_api_common::site::InstanceWithFederationState;
use relm4::{factory::FactoryVecDeque, prelude::*}; use relm4::{factory::FactoryVecDeque, prelude::*};
use crate::{api, settings}; use crate::{api, settings};
@@ -14,7 +14,7 @@ pub struct InstancesPage {
#[derive(Debug)] #[derive(Debug)]
pub enum InstancesPageInput { pub enum InstancesPageInput {
FetchInstances, FetchInstances,
DoneFetchInstances(Vec<Instance>), DoneFetchInstances(Vec<InstanceWithFederationState>),
SetInstance(String), SetInstance(String),
} }
@@ -133,7 +133,7 @@ impl SimpleComponent for InstancesPage {
InstancesPageInput::DoneFetchInstances(instances) => { InstancesPageInput::DoneFetchInstances(instances) => {
self.instances.guard().clear(); self.instances.guard().clear();
for instance in instances { for instance in instances {
self.instances.guard().push_back(instance); self.instances.guard().push_back(instance.instance);
} }
} }
InstancesPageInput::SetInstance(instance_url) => { InstancesPageInput::SetInstance(instance_url) => {
+1
View File
@@ -102,6 +102,7 @@ impl SimpleComponent for LoginPage {
let mut account = settings::get_current_account(); let mut account = settings::get_current_account();
account.jwt = Some(token); account.jwt = Some(token);
settings::update_current_account(account.clone()); settings::update_current_account(account.clone());
if let Ok(site) = api::site::fetch_site() { if let Ok(site) = api::site::fetch_site() {
let user = site.my_user.unwrap().local_user_view.person; let user = site.my_user.unwrap().local_user_view.person;
account.name = user.name; account.name = user.name;
-4
View File
@@ -15,8 +15,6 @@ pub struct VotingStats {
downvotes: i64, downvotes: i64,
score: i64, score: i64,
own_vote: Option<i16>, own_vote: Option<i16>,
#[allow(dead_code)]
id: i32,
post_id: Option<i32>, post_id: Option<i32>,
comment_id: Option<i32>, comment_id: Option<i32>,
} }
@@ -28,7 +26,6 @@ impl VotingStats {
downvotes: counts.downvotes, downvotes: counts.downvotes,
own_vote: my_vote, own_vote: my_vote,
post_id: Some(counts.post_id.0), post_id: Some(counts.post_id.0),
id: counts.id,
score: counts.score, score: counts.score,
comment_id: None, comment_id: None,
} }
@@ -40,7 +37,6 @@ impl VotingStats {
downvotes: counts.downvotes, downvotes: counts.downvotes,
own_vote: my_vote, own_vote: my_vote,
post_id: None, post_id: None,
id: counts.id,
score: counts.score, score: counts.score,
comment_id: Some(counts.comment_id.0), comment_id: Some(counts.comment_id.0),
} }
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -854
View File
File diff suppressed because one or more lines are too long
+1 -379
View File
File diff suppressed because one or more lines are too long
+2 -3
View File
@@ -21,9 +21,8 @@ pub fn markdown_to_pango_markup(text: String) -> String {
html2pango::markup_html(&markdown::to_html(&text)).unwrap_or(text) html2pango::markup_html(&markdown::to_html(&text)).unwrap_or(text)
} }
pub fn format_elapsed_time(time: chrono::NaiveDateTime) -> String { pub fn format_elapsed_time(time: chrono::DateTime<chrono::Utc>) -> String {
let formatter = timeago::Formatter::new(); let formatter = timeago::Formatter::new();
let current_time = chrono::Utc::now(); let current_time = chrono::Utc::now();
let published = time.and_utc(); formatter.convert_chrono(time, current_time)
formatter.convert_chrono(published, current_time)
} }
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
BASE_URL="https://lemmy.ml/api/v3"
curl "$BASE_URL/user?username=kzhe@lemmy.zip" > src/examples/person.json
curl "$BASE_URL/community?name=asklemmy" > src/examples/community.json
curl "$BASE_URL/post?id=10133939" > src/examples/post.json
curl "$BASE_URL/site" > src/examples/site.json