diff --git a/ttyverse.pl b/ttyverse.pl index f995fe3..c1e72ca 100755 --- a/ttyverse.pl +++ b/ttyverse.pl @@ -256,7 +256,7 @@ EOF dmupdate credurl blockurl blockdelurl muteurl mutedelurl friendsurl modifyliurl adduliurl delliurl getliurl getlisurl getfliurl creliurl delliurl deluliurl crefliurl delfliurl - getuliurl getufliurl dmsenturl reblogurl boostsbyurl dmidurl + getuliurl getufliurl dmsenturl reblogurl boostsbyurl bookmarkurl unbookmarkurl dmidurl statusliurl followliurl leaveliurl followersurl oauthurl oauthauthurl oauthaccurl oauthbase wtrendurl atrendurl lookupidurl @@ -282,7 +282,7 @@ EOF nocounter linelength friendsurl followersurl lists modifyliurl adduliurl delliurl getliurl getlisurl getfliurl creliurl delliurl deluliurl crefliurl delfliurl atrendurl - getuliurl getufliurl dmsenturl reblogurl boostsbyurl wtrendurl + getuliurl getufliurl dmsenturl reblogurl boostsbyurl bookmarkurl unbookmarkurl wtrendurl statusliurl followliurl leaveliurl dmidurl nostreamreplies frupdurl filterusers filterats filterrts filterflags filteratonly nofilter @@ -388,6 +388,8 @@ EOF $idurl = "${apibase}/statuses/%I"; $delurl = "${apibase}/statuses/%I"; $reblogurl = "${apibase}/statuses/%I/reblog"; + $bookmarkurl = "${apibase}/statuses/%I/bookmark"; + $unbookmarkurl = "${apibase}/statuses/%I/unbookmark"; $wurl = "${apibase}/accounts/%I"; $followurl = "${apibase}/accounts/%I/follow"; $leaveurl = "${apibase}/accounts/%I/unfollow"; @@ -691,7 +693,7 @@ if ($termrl && $termrl->ReadLine eq 'Term::ReadLine::Gnu') { /listfriends /followers /following /dump /du /eval /ev /version /update /versioncheck /updatecheck /thread /th /entities /ent /delete - /deletelast /boostsof /rtsof /vote /whois /w /me + /deletelast /boostsof /rtsof /bookmark /unbookmark /vote /whois /w /me ); } else { # Dynamic extraction from source code @@ -1329,6 +1331,8 @@ $delurl ||= "${apibase}/statuses/%I"; $reblogurl ||= "${apibase}/statuses/%I/reblog"; $boostsbyurl ||= "${apibase}/statuses/%I/reblogged_by"; +$bookmarkurl ||= "${apibase}/statuses/%I/bookmark"; +$unbookmarkurl ||= "${apibase}/statuses/%I/unbookmark"; # Twitter endpoints removed - not available in fediverse # $boostsofmeurl: No direct equivalent in fediverse (privacy feature) @@ -3191,6 +3195,8 @@ Example: /url a5 - opens all URLs in post a5 /delete a5 - deletes post a5, if it's your post /boost a5 - boosts post a5 + /bookmark a5 - bookmarks post a5 + /unbookmark a5 - removes bookmark from post a5 /vote a5 2 - vote for option 2 on poll in post a5 /vote a5 1,3 - vote for options 1 and 3 (if multiple choice) /replyall a5 message - reply to all users mentioned in post a5 @@ -3996,6 +4002,22 @@ m#^/(un)?f(boost|a|av|ave|avorite|avourite)? ([zZ]?[a-zA-Z]?[0-9]+)$#) { return 0; } + # Bookmark/Unbookmark commands + if (m#^/(un)?bookmark ([zZ]?[a-zA-Z]?[0-9]+)$#) { + my $mode = $1; + my $code = lc($2); + my $post = &get_post($code); + if (!defined($post)) { + print $stdout "-- no such post (yet?): $code\n"; + return 0; + } + &cordbookmark($post->{'id_str'}, 1, + (($mode eq 'un') ? $unbookmarkurl : $bookmarkurl), + &descape($post->{'text'}), + (($mode eq 'un') ? 'removed' : 'created')); + return 0; + } + # enable and disable NewRTs from users # we allow this even if newRTs are off from -noreblogs if (s#^/rts(on|off)\s+## && length) { @@ -7389,6 +7411,31 @@ sub cordfav { return $en; } +# create or destroy a bookmark +sub cordbookmark { + my $id = shift; + my $interactive = shift; + my $basebookmark = shift; + my $text = shift; + my $verb = shift; + + # Substitute the post ID into the URL template + my $bookmark_url = $basebookmark; + $bookmark_url =~ s/%I/$id/; + + print $stdout "-- DEBUG: cordbookmark called with id=$id, url=$bookmark_url\n" if ($verbose); + my ($en, $em) = ¢ral_cd_dispatch("id=$id", $interactive, $bookmark_url); + print $stdout "-- DEBUG: central_cd_dispatch returned en=$en, em=$em\n" if ($verbose); + if ($interactive) { + if (!$en) { + print $stdout "-- bookmark $verb for post id #${id}: \"$text\"\n"; + } else { + print $stdout "*** (was the bookmark already ${verb}?)\n"; + } + } + return $en; +} + # follow or unfollow a user sub foruuser { my $uname = shift; @@ -8629,7 +8676,7 @@ sub defaultautocompletion { '/reply', '/url', '/thread', '/repost', '/replyall', '/replies', '/timelines', '/timeline', '/visibility', '/ruler', '/exit', '/me', '/vcheck', '/orepost', '/erepost', '/frepost', '/liston', - '/listoff', '/dmsent', '/boostsof', '/rtsof', '/rtson', '/rtsoff', + '/listoff', '/dmsent', '/boostsof', '/rtsof', '/bookmark', '/unbookmark', '/rtson', '/rtsoff', '/lists', '/withlist', '/add', '/padd', '/push', '/pop', '/followers', '/following', '/friends', '/lfollow', '/lleave', '/listfollowers', '/listfriends',