From 9e4cfe6eee5ca814e5ee330765c6836821553540 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 24 Jun 2023 12:53:54 +0200 Subject: [PATCH] Navigate based on person and community ids instead of names --- src/api/community.rs | 4 ++-- src/api/user.rs | 6 +++--- src/components/comment_row.rs | 2 +- src/components/community_row.rs | 2 +- src/components/mention_row.rs | 4 ++-- src/components/post_page.rs | 8 ++++---- src/components/post_row.rs | 4 ++-- src/main.rs | 19 ++++++++++--------- 8 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/api/community.rs b/src/api/community.rs index 9a1074a..f1ff1e7 100644 --- a/src/api/community.rs +++ b/src/api/community.rs @@ -2,9 +2,9 @@ use lemmy_api_common::{community::{GetCommunity, GetCommunityResponse, Community use crate::settings; -pub fn get_community(name: String) -> std::result::Result { +pub fn get_community(id: CommunityId) -> std::result::Result { let params = GetCommunity { - name: Some(name), + id: Some(id), auth: settings::get_current_account().jwt, ..Default::default() }; diff --git a/src/api/user.rs b/src/api/user.rs index b8ab6dc..7057207 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -1,11 +1,11 @@ -use lemmy_api_common::{person::{GetPersonDetailsResponse, GetPersonDetails, GetPersonMentionsResponse, GetRepliesResponse, MarkAllAsRead, GetReplies, GetPersonMentions}, lemmy_db_schema::CommentSortType}; +use lemmy_api_common::{person::{GetPersonDetailsResponse, GetPersonDetails, GetPersonMentionsResponse, GetRepliesResponse, MarkAllAsRead, GetReplies, GetPersonMentions}, lemmy_db_schema::{CommentSortType, newtypes::PersonId}}; use crate::settings; -pub fn get_user(username: String, page: i64) -> std::result::Result { +pub fn get_user(id: PersonId, page: i64) -> std::result::Result { let params = GetPersonDetails { page: Some(page), - username: Some(username), + person_id: Some(id), auth: settings::get_current_account().jwt, ..Default::default() }; diff --git a/src/components/comment_row.rs b/src/components/comment_row.rs index d767477..58cd299 100644 --- a/src/components/comment_row.rs +++ b/src/components/comment_row.rs @@ -131,7 +131,7 @@ impl FactoryComponent for CommentRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { CommentRowMsg::OpenPerson => { - sender.output(PostInput::PassAppMessage(crate::AppMsg::OpenPerson(self.comment.creator.name.clone()))); + sender.output(PostInput::PassAppMessage(crate::AppMsg::OpenPerson(self.comment.creator.id.clone()))); } CommentRowMsg::DeleteComment => { let comment_id = self.comment.comment.id; diff --git a/src/components/community_row.rs b/src/components/community_row.rs index 5d6171d..79be961 100644 --- a/src/components/community_row.rs +++ b/src/components/community_row.rs @@ -95,7 +95,7 @@ impl FactoryComponent for CommunityRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { CommunityRowMsg::OpenCommunity => { - sender.output(crate::AppMsg::OpenCommunity(self.community.community.name.clone())) + sender.output(crate::AppMsg::OpenCommunity(self.community.community.id.clone())) } } } diff --git a/src/components/mention_row.rs b/src/components/mention_row.rs index 22e33f9..4b67e49 100644 --- a/src/components/mention_row.rs +++ b/src/components/mention_row.rs @@ -138,13 +138,13 @@ impl FactoryComponent for MentionRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { MentionRowMsg::OpenPerson => { - sender.output(crate::AppMsg::OpenPerson(self.comment.creator.name.clone())); + sender.output(crate::AppMsg::OpenPerson(self.comment.creator.id.clone())); } MentionRowMsg::OpenPost => { sender.output(crate::AppMsg::OpenPost(self.comment.post.id.clone())); } MentionRowMsg::OpenCommunity => { - sender.output(crate::AppMsg::OpenCommunity(self.comment.community.name.clone())); + sender.output(crate::AppMsg::OpenCommunity(self.comment.community.id.clone())); } } } diff --git a/src/components/post_page.rs b/src/components/post_page.rs index d388119..bf9fb2e 100644 --- a/src/components/post_page.rs +++ b/src/components/post_page.rs @@ -240,12 +240,12 @@ impl SimpleComponent for PostPage { } } PostInput::OpenPerson => { - let name = self.info.post_view.creator.name.clone(); - let _ = sender.output(crate::AppMsg::OpenPerson(name)); + let person_id = self.info.post_view.creator.id.clone(); + let _ = sender.output(crate::AppMsg::OpenPerson(person_id)); } PostInput::OpenCommunity => { - let community_name = self.info.community_view.community.name.clone(); - let _ = sender.output(crate::AppMsg::OpenCommunity(community_name)); + let community_id = self.info.community_view.community.id.clone(); + let _ = sender.output(crate::AppMsg::OpenCommunity(community_id)); } PostInput::OpenLink => { let post = self.info.post_view.post.clone(); diff --git a/src/components/post_row.rs b/src/components/post_row.rs index 7986606..3a4a155 100644 --- a/src/components/post_row.rs +++ b/src/components/post_row.rs @@ -150,10 +150,10 @@ impl FactoryComponent for PostRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { PostViewMsg::OpenCommunity => { - sender.output(crate::AppMsg::OpenCommunity(self.post.community.name.clone())) + sender.output(crate::AppMsg::OpenCommunity(self.post.community.id.clone())) } PostViewMsg::OpenPerson => { - sender.output(crate::AppMsg::OpenPerson(self.post.creator.name.clone())) + sender.output(crate::AppMsg::OpenPerson(self.post.creator.id.clone())) } PostViewMsg::OpenPost => { sender.output(crate::AppMsg::OpenPost(self.post.post.id.clone())) diff --git a/src/main.rs b/src/main.rs index 3525df6..650da4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ pub mod dialogs; use api::{user::default_person, community::default_community, post::default_post}; use components::{post_row::PostRow, community_row::CommunityRow, profile_page::{ProfilePage, self}, community_page::{CommunityPage, self}, post_page::{PostPage, self}, inbox_page::{InboxPage, InboxInput}}; use gtk::prelude::*; -use lemmy_api_common::{lemmy_db_views_actor::structs::CommunityView, lemmy_db_views::structs::PostView, person::GetPersonDetailsResponse, lemmy_db_schema::{newtypes::PostId, ListingType}, post::GetPostResponse, community::GetCommunityResponse}; +use lemmy_api_common::{lemmy_db_views_actor::structs::CommunityView, lemmy_db_views::structs::PostView, person::GetPersonDetailsResponse, lemmy_db_schema::{newtypes::{PostId, CommunityId, PersonId}, ListingType}, post::GetPostResponse, community::GetCommunityResponse}; use relm4::{prelude::*, factory::FactoryVecDeque, set_global_css, actions::{RelmAction, RelmActionGroup}}; use settings::get_current_account; @@ -58,9 +58,9 @@ pub enum AppMsg { DoneFetchPosts(Vec), DoneFetchCommunities(Vec), FetchCommunities(Option, bool), - OpenCommunity(String), + OpenCommunity(CommunityId), DoneFetchCommunity(GetCommunityResponse), - OpenPerson(String), + OpenPerson(PersonId), DoneFetchPerson(GetPersonDetailsResponse), OpenPost(PostId), DoneFetchPost(GetPostResponse), @@ -241,6 +241,7 @@ impl SimpleComponent for App { set_hexpand: true, set_tooltip_text: Some("Search"), set_margin_end: 10, + set_buffer: &model.community_search_buffer, }, gtk::Button { set_label: "Search", @@ -355,8 +356,8 @@ impl SimpleComponent for App { }); let profile_sender = sender.clone(); let profile_action: RelmAction = RelmAction::new_stateless(move |_| { - let person = settings::get_current_account().name; - if !person.is_empty() { profile_sender.input(AppMsg::OpenPerson(person)); } + let person = settings::get_current_account(); + if !person.name.is_empty() { profile_sender.input(AppMsg::OpenPerson(PersonId(person.id))); } }); let login_sender = sender.clone(); let login_action: RelmAction = RelmAction::new_stateless(move |_| { @@ -438,10 +439,10 @@ impl SimpleComponent for App { self.communities.guard().push_back(community); } } - AppMsg::OpenPerson(person_name) => { + AppMsg::OpenPerson(person_id) => { self.state = AppState::Loading; std::thread::spawn(move || { - let message = match api::user::get_user(person_name, 1) { + let message = match api::user::get_user(person_id, 1) { Ok(person) => AppMsg::DoneFetchPerson(person), Err(err) => AppMsg::ShowMessage(err.to_string()) }; @@ -452,10 +453,10 @@ impl SimpleComponent for App { self.profile_page.sender().emit(profile_page::ProfileInput::UpdatePerson(person)); self.state = AppState::Person; } - AppMsg::OpenCommunity(community_name) => { + AppMsg::OpenCommunity(community_id) => { self.state = AppState::Loading; std::thread::spawn(move || { - let message = match api::community::get_community(community_name) { + let message = match api::community::get_community(community_id) { Ok(community) => AppMsg::DoneFetchCommunity(community), Err(err) => AppMsg::ShowMessage(err.to_string()) };