From: Simon Tatham Date: Sat, 3 Feb 2024 10:54:50 +0000 (+0000) Subject: Support listing your follow requesters. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7ce6a8f55fe678c644dcdebb826e910793f27fe0;p=mastodonochrome.git Support listing your follow requesters. We don't yet have a method of approving or denying the request. --- diff --git a/src/activity_stack.rs b/src/activity_stack.rs index 01e5d4c..e040fd2 100644 --- a/src/activity_stack.rs +++ b/src/activity_stack.rs @@ -28,6 +28,7 @@ pub enum UtilityActivity { LogsMenu1, LogsMenu2, EgoLog, + ListFollowRequesters, ExitMenu, ExamineUser(String), // the account _id_, not its name ListUserFollowers(String), diff --git a/src/client.rs b/src/client.rs index a064416..29a1816 100644 --- a/src/client.rs +++ b/src/client.rs @@ -30,6 +30,7 @@ pub enum FeedId { User(String, Boosts, Replies), Mentions, Ego, + YourFollowRequesters, Favouriters(String), Boosters(String), Followers(String), @@ -989,6 +990,9 @@ impl Client { FeedId::Followees(id) => { Req::get(&format!("api/v1/accounts/{id}/following")) } + FeedId::YourFollowRequesters => { + Req::get(&format!("api/v1/follow_requests")) + } FeedId::Errors => return Ok(false), }; @@ -1100,7 +1104,8 @@ impl Client { FeedId::Favouriters(..) | FeedId::Boosters(..) | FeedId::Followers(..) - | FeedId::Followees(..) => { + | FeedId::Followees(..) + | FeedId::YourFollowRequesters => { let acs: Vec = match serde_json::from_str(&body) { Ok(acs) => Ok(acs), Err(e) => { diff --git a/src/file.rs b/src/file.rs index 3141285..feb66a9 100644 --- a/src/file.rs +++ b/src/file.rs @@ -164,7 +164,10 @@ impl FileDataSource for StaticSource { enum CanList { Nothing, ForPost, - ForUser, + + // true if the account is your own, and also locked, so that we + // also need a third option to list follow _requesters_ + ForUser(bool), } trait FileType { @@ -1312,17 +1315,25 @@ impl ActivityState ) } UIMode::ListSubmenu => { - let fs = match self.file_desc.can_list() { - CanList::ForUser => fs - .add(Pr('I'), "List Followers", 99) - .add(Pr('O'), "List Followed", 99), - CanList::ForPost => fs - .add(Pr('F'), "List Favouriters", 99) - .add(Pr('B'), "List Boosters", 99), - CanList::Nothing => { - panic!("Then we shouldn't be in this submenu") - } - }; + let fs = + match self.file_desc.can_list() { + CanList::ForUser(locked) => { + let fs = fs + .add(Pr('I'), "List Followers", 98) + .add(Pr('O'), "List Followed", 98); + if locked { + fs.add(Pr('R'), "List Requesters", 99) + } else { + fs + } + } + CanList::ForPost => fs + .add(Pr('F'), "List Favouriters", 99) + .add(Pr('B'), "List Boosters", 99), + CanList::Nothing => { + panic!("Then we shouldn't be in this submenu") + } + }; fs.add(Pr('Q'), "Quit", 100) } UIMode::PostsSubmenu => { @@ -1660,7 +1671,7 @@ impl ActivityState } Pr('i') | Pr('I') => { - if self.file_desc.can_list() == CanList::ForUser { + if let CanList::ForUser(_) = self.file_desc.can_list() { LogicalAction::Goto( UtilityActivity::ListUserFollowers( self.contents.source.single_id(), @@ -1673,7 +1684,7 @@ impl ActivityState } Pr('o') | Pr('O') => { - if self.file_desc.can_list() == CanList::ForUser { + if let CanList::ForUser(_) = self.file_desc.can_list() { LogicalAction::Goto( UtilityActivity::ListUserFollowees( self.contents.source.single_id(), @@ -1685,6 +1696,16 @@ impl ActivityState } } + Pr('r') | Pr('R') => { + if self.file_desc.can_list() == CanList::ForUser(true) { + LogicalAction::Goto( + UtilityActivity::ListFollowRequesters.into(), + ) + } else { + LogicalAction::Nothing + } + } + Pr('q') | Pr('Q') => { self.ui_mode = UIMode::Normal; LogicalAction::Nothing @@ -2039,6 +2060,26 @@ pub fn list_user_followees( Ok(Box::new(file)) } +pub fn list_follow_requesters( + client: &mut Client, +) -> Result, ClientError> { + let name = client.our_account_fq(); + + let file = File::new( + client, + FeedSource::new(FeedId::YourFollowRequesters), + ColouredString::uniform( + &format!("Users who have requested to follow {name}"), + 'H', + ), + UserListFeedType {}, + None, + None, + false, + )?; + Ok(Box::new(file)) +} + pub fn hashtag_timeline( unfolded: Rc>>, client: &mut Client, @@ -2062,7 +2103,9 @@ pub fn hashtag_timeline( Ok(Box::new(file)) } -struct ExamineUserFileType {} +struct ExamineUserFileType { + locked: bool, +} impl FileType for ExamineUserFileType { type Item = ExamineUserDisplay; const CAN_GET_POSTS: bool = true; @@ -2078,7 +2121,7 @@ impl FileType for ExamineUserFileType { } fn can_list(&self) -> CanList { - CanList::ForUser + CanList::ForUser(self.locked) } } @@ -2087,6 +2130,7 @@ pub fn examine_user( account_id: &str, ) -> Result, ClientError> { let ac = client.account_by_id(account_id)?; + let locked = ac.id == client.our_account_id() && ac.locked; let username = client.fq(&ac.acct); let title = ColouredString::uniform( &format!("Information about user {username}"), @@ -2097,7 +2141,7 @@ pub fn examine_user( client, StaticSource::singleton(ac.id), title, - ExamineUserFileType {}, + ExamineUserFileType { locked }, Some(&FilePosition::item_top(isize::MIN).into()), None, false, diff --git a/src/tui.rs b/src/tui.rs index fe1d615..2ad2545 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1092,6 +1092,9 @@ impl TuiLogicalState { Activity::Util(UtilityActivity::ListUserFollowees(ref id)) => { list_user_followees(client, id) } + Activity::Util(UtilityActivity::ListFollowRequesters) => { + list_follow_requesters(client) + } Activity::NonUtil(NonUtilityActivity::UserPosts( ref user, boosts,