feat: support for (un)blocking communities
This commit is contained in:
parent
3ccbdfd903
commit
58c77072ed
|
@ -1,5 +1,5 @@
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, FollowCommunity, GetCommunity, GetCommunityResponse},
|
community::{CommunityResponse, FollowCommunity, GetCommunity, GetCommunityResponse, BlockCommunityResponse, BlockCommunity},
|
||||||
lemmy_db_schema::newtypes::CommunityId,
|
lemmy_db_schema::newtypes::CommunityId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ pub fn get_community(id: CommunityId) -> std::result::Result<GetCommunityRespons
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn follow_community(
|
pub fn follow_community(
|
||||||
community_id: i32,
|
community_id: CommunityId,
|
||||||
follow: bool,
|
follow: bool,
|
||||||
) -> Result<CommunityResponse, reqwest::Error> {
|
) -> Result<CommunityResponse, reqwest::Error> {
|
||||||
let params = FollowCommunity {
|
let params = FollowCommunity {
|
||||||
community_id: CommunityId(community_id),
|
community_id: community_id,
|
||||||
follow,
|
follow,
|
||||||
auth: settings::get_current_account().jwt.unwrap(),
|
auth: settings::get_current_account().jwt.unwrap(),
|
||||||
};
|
};
|
||||||
|
@ -30,3 +30,16 @@ pub fn follow_community(
|
||||||
pub fn default_community() -> GetCommunityResponse {
|
pub fn default_community() -> GetCommunityResponse {
|
||||||
serde_json::from_str(include_str!("../examples/community.json")).unwrap()
|
serde_json::from_str(include_str!("../examples/community.json")).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn block_community(
|
||||||
|
community_id: CommunityId,
|
||||||
|
block: bool,
|
||||||
|
) -> std::result::Result<BlockCommunityResponse, reqwest::Error> {
|
||||||
|
let params = BlockCommunity {
|
||||||
|
community_id,
|
||||||
|
block,
|
||||||
|
auth: settings::get_current_account().jwt.unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
super::post("/community/block", ¶ms)
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ use lemmy_api_common::{
|
||||||
lemmy_db_schema::{newtypes::PersonId, CommentSortType},
|
lemmy_db_schema::{newtypes::PersonId, CommentSortType},
|
||||||
person::{
|
person::{
|
||||||
GetPersonDetails, GetPersonDetailsResponse, GetPersonMentions, GetPersonMentionsResponse,
|
GetPersonDetails, GetPersonDetailsResponse, GetPersonMentions, GetPersonMentionsResponse,
|
||||||
GetReplies, GetRepliesResponse, MarkAllAsRead,
|
GetReplies, GetRepliesResponse, MarkAllAsRead
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@ pub enum CommunityInput {
|
||||||
ToggleSubscription,
|
ToggleSubscription,
|
||||||
UpdateSubscriptionState(SubscribedType),
|
UpdateSubscriptionState(SubscribedType),
|
||||||
UpdateOrder(SortType),
|
UpdateOrder(SortType),
|
||||||
|
ToggleBlocked,
|
||||||
|
UpdateBlocked(bool),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ impl SimpleComponent for CommunityPage {
|
||||||
set_orientation: gtk::Orientation::Horizontal,
|
set_orientation: gtk::Orientation::Horizontal,
|
||||||
set_halign: gtk::Align::Center,
|
set_halign: gtk::Align::Center,
|
||||||
set_margin_top: 10,
|
set_margin_top: 10,
|
||||||
|
set_spacing: 10,
|
||||||
#[watch]
|
#[watch]
|
||||||
set_visible: settings::get_current_account().jwt.is_some(),
|
set_visible: settings::get_current_account().jwt.is_some(),
|
||||||
|
|
||||||
|
@ -113,9 +116,20 @@ impl SimpleComponent for CommunityPage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
gtk::Button {
|
||||||
|
set_label: "Block",
|
||||||
|
#[watch]
|
||||||
|
set_visible: !model.info.blocked,
|
||||||
|
connect_clicked => CommunityInput::ToggleBlocked,
|
||||||
|
},
|
||||||
|
gtk::Button {
|
||||||
|
set_label: "Unblock",
|
||||||
|
#[watch]
|
||||||
|
set_visible: model.info.blocked,
|
||||||
|
connect_clicked => CommunityInput::ToggleBlocked,
|
||||||
|
},
|
||||||
gtk::Button {
|
gtk::Button {
|
||||||
set_label: "Create post",
|
set_label: "Create post",
|
||||||
set_margin_start: 10,
|
|
||||||
connect_clicked => CommunityInput::OpenCreatePostDialog,
|
connect_clicked => CommunityInput::OpenCreatePostDialog,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -236,21 +250,19 @@ impl SimpleComponent for CommunityPage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
CommunityInput::ToggleSubscription => {
|
CommunityInput::ToggleSubscription => {
|
||||||
let community_id = self.info.community.id.0;
|
let community_id = self.info.community.id;
|
||||||
let new_state = matches!(self.info.subscribed, SubscribedType::NotSubscribed);
|
let new_state = matches!(self.info.subscribed, SubscribedType::NotSubscribed);
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let message = match api::community::follow_community(community_id, new_state) {
|
match api::community::follow_community(community_id, new_state) {
|
||||||
Ok(community) => Some(CommunityInput::UpdateSubscriptionState(
|
Ok(community) => {
|
||||||
|
sender.input(CommunityInput::UpdateSubscriptionState(
|
||||||
community.community_view.subscribed,
|
community.community_view.subscribed,
|
||||||
)),
|
));
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
None
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Some(message) = message {
|
|
||||||
sender.input(message)
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
CommunityInput::UpdateSubscriptionState(state) => {
|
CommunityInput::UpdateSubscriptionState(state) => {
|
||||||
|
@ -262,6 +274,21 @@ impl SimpleComponent for CommunityPage {
|
||||||
self.posts.guard().clear();
|
self.posts.guard().clear();
|
||||||
sender.input_sender().emit(CommunityInput::FetchPosts);
|
sender.input_sender().emit(CommunityInput::FetchPosts);
|
||||||
}
|
}
|
||||||
|
CommunityInput::ToggleBlocked => {
|
||||||
|
let community_id = self.info.community.id;
|
||||||
|
let blocked = self.info.blocked;
|
||||||
|
std::thread::spawn(move || {
|
||||||
|
match api::community::block_community(community_id, !blocked) {
|
||||||
|
Ok(resp) => {
|
||||||
|
sender.input(CommunityInput::UpdateBlocked(resp.blocked));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("{}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
CommunityInput::UpdateBlocked(blocked) => self.info.blocked = blocked,
|
||||||
CommunityInput::None => {}
|
CommunityInput::None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue