Some patches

This commit is contained in:
localhost_frssoft 2022-04-18 09:43:25 +03:00
parent 3ced170a0a
commit 251cc25b30
1 changed files with 107 additions and 107 deletions

View File

@ -20,7 +20,7 @@ copy_mentions=$(jj -i config.json copy_mentions)
mkdir -m 711 -p .app_sessions mkdir -m 711 -p .app_sessions
touch .auth.json touch .auth.json
chmod 600 .auth.json chmod 600 .auth.json
auth="$(jj -i .auth.json "$(echo $instance | sed 's/\./\\\./g')")" auth="$(jj -i .auth.json "$(echo "$instance" | sed 's/\./\\\./g')")"
echo "Instance: $instance" echo "Instance: $instance"
if [ -n "$auth" ]; then if [ -n "$auth" ]; then
default_curl_opt() default_curl_opt()
@ -35,7 +35,7 @@ if [ -n "$auth" ]; then
else else
default_curl_opt() default_curl_opt()
{ {
curl -s --compressed $1 curl -s --compressed "$1"
} }
echo 'Please make auth and restart' echo 'Please make auth and restart'
fi fi
@ -43,20 +43,20 @@ fi
auth_api_create_client() auth_api_create_client()
{ {
if [ ! -e ".app_sessions/$instance" ]; then if [ ! -e ".app_sessions/$instance" ]; then
curl -s --compressed --url $instance_point/apps \ curl -s --compressed --url "$instance_point/apps" \
--data-urlencode 'client_name=pleroma-cli' \ --data-urlencode 'client_name=pleroma-cli' \
--data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \ --data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
--data-urlencode 'scopes=read write follow' \ --data-urlencode 'scopes=read write follow' \
--data-urlencode 'website=https://gitea.phreedom.club/localhost_frssoft/pleroma-cli' \ --data-urlencode 'website=https://gitea.phreedom.club/localhost_frssoft/pleroma-cli' \
--output .app_sessions/$instance --output ".app_sessions/$instance" \
chmod 600 .app_sessions/$instance --create-file-mode 0600
fi fi
} }
auth_api_get_code() auth_api_get_code()
{ {
auth_api_create_client auth_api_create_client
client_id=$(jj -i .app_sessions/$instance client_id) client_id=$(jj -i ".app_sessions/$instance" client_id)
default_auth_browser "https://$instance/oauth/authorize?client_id=$client_id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read+write+follow" default_auth_browser "https://$instance/oauth/authorize?client_id=$client_id&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=read+write+follow"
echo 'Input token-code:' echo 'Input token-code:'
read pass read pass
@ -66,16 +66,16 @@ auth_api_get_token()
{ {
auth_api_get_code auth_api_get_code
clear clear
client_id=$(jj -i .app_sessions/$instance client_id) client_id=$(jj -i ".app_sessions/$instance" client_id)
client_secret=$(jj -i .app_sessions/$instance client_secret) client_secret=$(jj -i ".app_sessions/$instance" client_secret)
token=$(curl -s --compressed --url https://$instance/oauth/token \ token=$(curl -s --compressed --url "https://$instance/oauth/token" \
--data-urlencode 'grant_type=authorization_code' \ --data-urlencode 'grant_type=authorization_code' \
--data-urlencode "client_id=$client_id" \ --data-urlencode "client_id=$client_id" \
--data-urlencode "client_secret=$client_secret" \ --data-urlencode "client_secret=$client_secret" \
--data-urlencode "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \ --data-urlencode "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
--data-urlencode 'scope=read write follow' \ --data-urlencode 'scope=read write follow' \
--data-urlencode "code=$pass" | jj access_token) --data-urlencode "code=$pass" | jj access_token)
jj -p -i .auth.json -v "$token" "$(echo $instance | sed 's/\./\\\./g')" -o .auth.json jj -p -i .auth.json -v "$token" "$(echo "$instance" | sed 's/\./\\\./g')" -o .auth.json
} }
#[AUTH SECTION END] #[AUTH SECTION END]
@ -145,26 +145,26 @@ legacy_addr_preprocess()
follow_api_export() follow_api_export()
{ {
count=40 count=40
mkdir -m 711 -p backups_$instance mkdir -m 711 -p backups_"$instance"
account_info=$(account_api_me) account_info=$(account_api_me)
acc_id=$(echo $account_info | jj id) acc_id=$(echo "$account_info" | jj id)
acc_following_count=$(echo $account_info | jj following_count) acc_following_count=$(echo "$account_info" | jj following_count)
while [ $count -gt 0 ]; do while [ $count -gt 0 ]; do
followings=$(followings_api_get $acc_id) followings=$(followings_api_get "$acc_id")
count=$(echo $followings | jj \#) count=$(echo "$followings" | jj \#)
if [ $count -eq 0 ]; then if [ "$count" -eq 0 ]; then
echo "$acc_following_count followings exported" echo "$acc_following_count followings exported"
elif [ $count -lt 40 ]; then elif [ "$count" -lt 40 ]; then
countindex=$(expr $count - 1) countindex=$(expr "$count" - 1)
echo $followings | jj -l \#.acct | delq | legacy_addr_preprocess >> backups_$instance/friends.csv echo "$followings" | jj -l \#.acct | delq | legacy_addr_preprocess >> "backups_$instance"/friends.csv
offset=$(echo $followings | jj $countindex.id) offset=$(echo "$followings" | jj "$countindex".id)
echo "+$count follows" echo "+$count follows"
count=0 count=0
echo "$acc_following_count followings exported" echo "$acc_following_count followings exported"
elif [ $count -gt 0 ]; then elif [ $count -gt 0 ]; then
countindex=$(expr $count - 1) countindex=$(expr $count - 1)
echo $followings | jj -l \#.acct | delq | legacy_addr_preprocess >> backups_$instance/friends.csv echo "$followings" | jj -l \#.acct | delq | legacy_addr_preprocess >> "backups_$instance"/friends.csv
offset=$(echo $followings | jj $countindex.id) offset=$(echo "$followings" | jj "$countindex".id)
echo "+$count follows" echo "+$count follows"
fi fi
sleep 1 sleep 1
@ -174,22 +174,22 @@ follow_api_export()
blocks_api_export() blocks_api_export()
{ {
count=40 count=40
mkdir -m 711 -p backups_$instance mkdir -m 711 -p "backups_$instance"
while [ $count -gt 0 ]; do while [ $count -gt 0 ]; do
blocks=$(blocks_api_get) blocks=$(blocks_api_get)
count=$(echo $blocks | jj \#) count=$(echo "$blocks" | jj \#)
if [ $count -eq 0 ]; then if [ "$count" -eq 0 ]; then
echo "Blocks exported" echo "Blocks exported"
elif [ $count -lt 40 ]; then elif [ "$count" -lt 40 ]; then
countindex=$(expr $count - 1) countindex=$(expr "$count" - 1)
echo $blocks | jj -l \#.acct | delq | legacy_addr_preprocess >> backups_$instance/blocks.csv echo "$blocks" | jj -l \#.acct | delq | legacy_addr_preprocess >> "backups_$instance"/blocks.csv
offset=$(echo $blocks | jj $countindex.id) offset=$(echo "$blocks" | jj "$countindex".id)
echo "+$count blocks" echo "+$count blocks"
count=0 count=0
echo "Blocks exported" echo "Blocks exported"
elif [ $count -gt 0 ]; then elif [ $count -gt 0 ]; then
echo $blocks | jj -l \#.acct | delq | legacy_addr_preprocess >> backups_$instance/blocks.csv echo "$blocks" | jj -l \#.acct | delq | legacy_addr_preprocess >> "backups_$instance"/blocks.csv
offset=$(echo $blocks | jj $countindex.id) offset=$(echo "$blocks" | jj "$countindex".id)
echo "+$count blocks" echo "+$count blocks"
fi fi
sleep 1 sleep 1
@ -199,22 +199,22 @@ blocks_api_export()
mutes_api_export() mutes_api_export()
{ {
count=40 count=40
mkdir -m 711 -p backups_$instance mkdir -m 711 -p "backups_$instance"
while [ $count -gt 0 ]; do while [ $count -gt 0 ]; do
mutes=$(mutes_api_get) mutes=$(mutes_api_get)
count=$(echo $mutes | jj \#) count=$(echo "$mutes" | jj \#)
if [ $count -eq 0 ]; then if [ "$count" -eq 0 ]; then
echo "Mutes exported" echo "Mutes exported"
elif [ $count -lt 40 ]; then elif [ "$count" -lt 40 ]; then
countindex=$(expr $count - 1) countindex=$(expr "$count" - 1)
echo $mutes | jj -l \#.acct | delq | legacy_addr_preprocess >> backups_$instance/mutes.csv echo "$mutes" | jj -l \#.acct | delq | legacy_addr_preprocess >> "backups_$instance"/mutes.csv
offset=$(echo $mutes | jj $countindex.id) offset=$(echo "$mutes" | jj "$countindex".id)
echo "+$count mutes" echo "+$count mutes"
count=0 count=0
echo "Mutes exported" echo "Mutes exported"
elif [ $count -gt 0 ]; then elif [ $count -gt 0 ]; then
echo $mutes | jj -l \#.acct | delq| legacy_addr_preprocess >> backups_$instance/mutes.csv echo "$mutes" | jj -l \#.acct | delq| legacy_addr_preprocess >> "backups_$instance"/mutes.csv
offset=$(echo $mutes | jj $countindex.id) offset=$(echo "$mutes" | jj "$countindex".id)
echo "+$count mutes" echo "+$count mutes"
fi fi
sleep 1 sleep 1
@ -242,7 +242,7 @@ mutes_api_import()
account_api_me() account_api_me()
{ {
default_curl_opt $instance_point/accounts/verify_credentials default_curl_opt "$instance_point/accounts/verify_credentials"
} }
followings_api_get() followings_api_get()
@ -253,21 +253,21 @@ followings_api_get()
followings_menu() followings_menu()
{ {
account_info=$(account_api_me) account_info=$(account_api_me)
acc_id=$(echo $account_info | jj id) acc_id=$(echo "$account_info" | jj id)
acc_following_count=$(echo $account_info | jj following_count) acc_following_count=$(echo "$account_info" | jj following_count)
echo "Followers: $acc_following_count" echo "Followers: $acc_following_count"
sub_menu_lvl=1 sub_menu_lvl=1
while [ $sub_menu_lvl -eq 1 ]; do while [ $sub_menu_lvl -eq 1 ]; do
followings=$(followings_api_get $acc_id) followings=$(followings_api_get "$acc_id")
accts=$(echo $followings | jj -l \#.acct | nl -s: -v0 -w1) accts=$(echo "$followings" | jj -l \#.acct | nl -s: -v0 -w1)
choice=$(echo "Main menu\n$accts\nNext" | fzy) choice=$(echo "Main menu\n$accts\nNext" | fzy)
case $choice in case $choice in
"Main menu") sub_menu_lvl=0 ;; "Main menu") sub_menu_lvl=0 ;;
"Next") offset=$(echo $followings | jj $(expr $(echo $followings | jj \#) - 1).id) ;; "Next") offset=$(echo "$followings" | jj $(expr $(echo "$followings" | jj \#) - 1).id) ;;
*) *)
index=$(echo $choice | cut -f 1 -d:) index=$(echo "$choice" | cut -f 1 -d:)
statuses_view_menu "$(echo $followings | jj $index.acct)" statuses_view_menu "$(echo "$followings" | jj "$index".acct)"
;; ;;
esac esac
done done
@ -320,20 +320,20 @@ statuses_render()
jsonmassive=$(echo "$jsonmassive" | jj '#[sensitive=false]#') jsonmassive=$(echo "$jsonmassive" | jj '#[sensitive=false]#')
fi fi
if [ "$reversed_statuses" = 'true' ]; then if [ "$reversed_statuses" = 'true' ]; then
ids_massive=$(echo $ids_massive | tr ' ' '\n' | tac | tr '\n' ' ') ids_massive=$(echo "$ids_massive" | tr ' ' '\n' | tac | tr '\n' ' ')
fi fi
for i in $ids_massive; do for i in $ids_massive; do
status=$(echo "$jsonmassive" | jj "#[id=$i]") status=$(echo "$jsonmassive" | jj "#[id=$i]")
whoacct=$(echo $status | jj account.acct) whoacct=$(echo "$status" | jj account.acct)
reblog=$(echo $status | jj reblog.id) reblog=$(echo "$status" | jj reblog.id)
reblogacct=$(echo $status | jj reblog.account.acct) reblogacct=$(echo "$status" | jj reblog.account.acct)
uri=$(echo $status | jj uri) uri=$(echo "$status" | jj uri)
id_status=$(echo $status | jj id) id_status=$(echo "$status" | jj id)
dateutc=$(echo $status | jj created_at) dateutc=$(echo "$status" | jj created_at)
reply_to_id=$(echo $status | jj in_reply_to_id) reply_to_id=$(echo "$status" | jj in_reply_to_id)
visibility_status=$(echo $status | jj visibility) visibility_status=$(echo "$status" | jj visibility)
echo "| $(date -d $dateutc "$format_time") $visibility_status $whoacct" echo "| $(date -d "$dateutc" "$format_time") $visibility_status $whoacct"
echo "| <$id_status> $uri" echo "| <$id_status> $uri"
if [ -n "$reply_to_id" ]; then if [ -n "$reply_to_id" ]; then
echo "| Reply to: $reply_to_id" echo "| Reply to: $reply_to_id"
@ -346,7 +346,7 @@ statuses_render()
echo "#[$spoiler_text]" echo "#[$spoiler_text]"
fi fi
echo "$status" | jj -r content | delqse | html_to_txt_render echo "$status" | jj -r content | delqse | html_to_txt_render
attachments=$(echo $status | jj -l media_attachments.#.remote_url | delq) attachments=$(echo "$status" | jj -l media_attachments.#.remote_url | delq)
if [ -n "$attachments" ]; then if [ -n "$attachments" ]; then
echo "#EXTINF:-1, $uri" >> attachments.m3u8 echo "#EXTINF:-1, $uri" >> attachments.m3u8
echo '[Attachments:]' echo '[Attachments:]'
@ -359,28 +359,28 @@ statuses_render()
statuses_view_menu() statuses_view_menu()
{ {
sub_menu_lvl=2 sub_menu_lvl=2
json=$(statuses_api_account $1) json=$(statuses_api_account "$1")
while [ $sub_menu_lvl -eq 2 ]; do while [ $sub_menu_lvl -eq 2 ]; do
clear clear
echo "[Statuses $1]" echo "[Statuses $1]"
ids_massive=$(echo $json | jj -l \#.id | delq) ids_massive=$(echo "$json" | jj -l \#.id | delq)
jsonmassive=$json jsonmassive=$json
statuses_render statuses_render
menustatuses=$(echo 'Prev\nNext\nReply\nShare\nFavorite\nShare and favorite\nThread\nBack' | fzy) menustatuses=$(echo 'Prev\nNext\nReply\nShare\nFavorite\nShare and favorite\nThread\nBack' | fzy)
case "$menustatuses" in case "$menustatuses" in
"Back") sub_menu_lvl=1 ;; "Back") sub_menu_lvl=1 ;;
"Prev") "Prev")
indexator=$(expr $(echo $json | jj \#) - 1) indexator=$(expr $(echo "$json" | jj \#) - 1)
echo '#EXTM3U' > attachments.m3u8 echo '#EXTM3U' > attachments.m3u8
clear clear
offset=$(echo $json | jj $indexator.id) offset=$(echo "$json" | jj "$indexator".id)
json=$(statuses_api_account $1 $offset) json=$(statuses_api_account "$1" "$offset")
;; ;;
"Next") "Next")
echo '#EXTM3U' > attachments.m3u8 echo '#EXTM3U' > attachments.m3u8
clear clear
offset=$(echo $json | jj 0.id) offset=$(echo "$json" | jj 0.id)
json=$(statuses_api_account $1 '' $offset) json=$(statuses_api_account "$1" '' "$offset")
;; ;;
"Reply") reply_mode ;; "Reply") reply_mode ;;
"Share") share_mode ;; "Share") share_mode ;;
@ -395,15 +395,15 @@ thread_open()
{ {
echo 'Input id' echo 'Input id'
read status_id read status_id
thread_menu $status_id thread_menu "$status_id"
} }
thread_menu() thread_menu()
{ {
sub_menu_lvl=2 sub_menu_lvl=2
jsonthread=$(thread_api_statuses $1) jsonthread=$(thread_api_statuses "$1")
ancestors=$(echo $jsonthread | jj ancestors) ancestors=$(echo "$jsonthread" | jj ancestors)
descendants=$(echo $jsonthread | jj descendants) descendants=$(echo "$jsonthread" | jj descendants)
if [ '[]' != "$ancestors" ] && [ '[]' != "$descendants" ]; then if [ '[]' != "$ancestors" ] && [ '[]' != "$descendants" ]; then
jsonthread=$(echo "$ancestors""$descendants") jsonthread=$(echo "$ancestors""$descendants")
elif [ '[]' != "$ancestors" ]; then elif [ '[]' != "$ancestors" ]; then
@ -414,7 +414,7 @@ thread_menu()
while [ $sub_menu_lvl -eq 2 ]; do while [ $sub_menu_lvl -eq 2 ]; do
clear clear
echo '[Thread]' echo '[Thread]'
ids_massive=$(echo $jsonthread | jj -l \#.id | delq) ids_massive=$(echo "$jsonthread" | jj -l \#.id | delq)
jsonmassive=$jsonthread jsonmassive=$jsonthread
statuses_render statuses_render
menuthread=$(echo 'Back\nReply\nShare\nFavorite\nShare and favorite' | fzy) menuthread=$(echo 'Back\nReply\nShare\nFavorite\nShare and favorite' | fzy)
@ -446,23 +446,23 @@ timeline_menu()
sub_menu_lvl=1 sub_menu_lvl=1
echo '#EXTM3U' > attachments.m3u8 echo '#EXTM3U' > attachments.m3u8
while [ $sub_menu_lvl -eq 1 ]; do while [ $sub_menu_lvl -eq 1 ]; do
ids_massive=$(echo $json | jj -l \#.id | delq) ids_massive=$(echo "$json" | jj -l \#.id | delq)
jsonmassive=$json jsonmassive=$json
statuses_render statuses_render
menu=$(echo 'Prev\nNext\nReply\nShare\nFavorite\nShare and favorite\nThread\nMain menu' | fzy) menu=$(echo 'Prev\nNext\nReply\nShare\nFavorite\nShare and favorite\nThread\nMain menu' | fzy)
case $menu in case $menu in
"Prev") "Prev")
indexator=$(expr $(echo $json | jj \#) - 1) indexator=$(expr $(echo "$json" | jj \#) - 1)
echo '#EXTM3U' > attachments.m3u8 echo '#EXTM3U' > attachments.m3u8
clear clear
offset=$(echo $json | jj $indexator.id) offset=$(echo "$json" | jj "$indexator".id)
json=$(timeline_api $offset) json=$(timeline_api "$offset")
;; ;;
"Next") "Next")
echo '#EXTM3U' > attachments.m3u8 echo '#EXTM3U' > attachments.m3u8
clear clear
offset=$(echo $json | jj 0.id) offset=$(echo "$json" | jj 0.id)
json=$(timeline_api '' $offset) json=$(timeline_api '' "$offset")
;; ;;
"Reply") reply_mode ;; "Reply") reply_mode ;;
"Share") share_mode ;; "Share") share_mode ;;
@ -478,14 +478,14 @@ reply_mode()
{ {
echo 'Input id' echo 'Input id'
read status_id read status_id
reply_status=$(status_api_one $status_id) reply_status=$(status_api_one "$status_id")
if [ "$quoting_reply" = 'true' ]; then if [ "$quoting_reply" = 'true' ]; then
echo "$reply_status" | jj content | html_to_txt_render | sed 's/^/> /' > tmp_status.md echo "$reply_status" | jj content | html_to_txt_render | sed 's/^/> /' > tmp_status.md
fi fi
if [ "$copy_mentions" = 'true' ]; then if [ "$copy_mentions" = 'true' ]; then
mentions_reply=$(echo "$reply_status" | jj -l 'mentions.#.acct' | delq | legacy_addr_preprocess | tr '\n' ',' | sed 's/,$//g') mentions_reply=$(echo "$reply_status" | jj -l 'mentions.#.acct' | delq | legacy_addr_preprocess | tr '\n' ',' | sed 's/,$//g')
fi fi
write_status_menu $status_id write_status_menu "$status_id"
} }
share_and_favorite_mode() share_and_favorite_mode()
@ -497,17 +497,17 @@ share_and_favorite_mode()
if [ "$status_id" = 's' ]; then if [ "$status_id" = 's' ]; then
shareandfavmode=0 shareandfavmode=0
else else
share_api_status $status_id share_api_status "$status_id"
echo $http_code echo "$http_code"
favorite_api_status $status_id favorite_api_status "$status_id"
echo $http_code echo "$http_code"
fi fi
done done
} }
share_api_status() share_api_status()
{ {
post_request -w "%{http_code}" --url $instance_point/statuses/$1/reblog --output /dev/null post_request -w "%{http_code}" --url "$instance_point/statuses/$1/reblog" --output /dev/null
} }
share_mode() share_mode()
@ -519,15 +519,15 @@ share_mode()
if [ "$status_id" = 's' ]; then if [ "$status_id" = 's' ]; then
sharemode=0 sharemode=0
else else
share_api_status $status_id share_api_status "$status_id"
echo $http_code echo "$http_code"
fi fi
done done
} }
favorite_api_status() favorite_api_status()
{ {
post_request -w "%{http_code}" --url $instance_point/statuses/$1/favourite --output /dev/null post_request -w "%{http_code}" --url "$instance_point/statuses/$1/favourite" --output /dev/null
} }
favourite_mode() favourite_mode()
@ -539,8 +539,8 @@ favourite_mode()
if [ "$status_id" = 's' ]; then if [ "$status_id" = 's' ]; then
favoritemode=0 favoritemode=0
else else
favorite_api_status $status_id favorite_api_status "$status_id"
echo $http_code echo "$http_code"
fi fi
done done
} }
@ -549,7 +549,7 @@ write_api_status()
{ {
if [ -n "$mediaattach" ]; then if [ -n "$mediaattach" ]; then
media=$(upload_api_media | jj id) media=$(upload_api_media | jj id)
post_request -w "%{http_code}" --url $instance_point/statuses \ post_request -w "%{http_code}" --url "$instance_point"/statuses \
--data-urlencode "status=$1" \ --data-urlencode "status=$1" \
--data-urlencode "content_type=$content_type" \ --data-urlencode "content_type=$content_type" \
--data-urlencode "visibility=$status_visibility" \ --data-urlencode "visibility=$status_visibility" \
@ -557,22 +557,22 @@ write_api_status()
--data-urlencode "media_ids[]=$media" \ --data-urlencode "media_ids[]=$media" \
--data-urlencode "to[]=$mentions_reply" \ --data-urlencode "to[]=$mentions_reply" \
--output /dev/null --output /dev/null
echo $http_code echo "$http_code"
else else
post_request -w "%{http_code}" --url $instance_point/statuses \ post_request -w "%{http_code}" --url "$instance_point"/statuses \
--data-urlencode "status=$1" \ --data-urlencode "status=$1" \
--data-urlencode "content_type=$content_type" \ --data-urlencode "content_type=$content_type" \
--data-urlencode "visibility=$status_visibility" \ --data-urlencode "visibility=$status_visibility" \
--data-urlencode "in_reply_to_id=$replyto" \ --data-urlencode "in_reply_to_id=$replyto" \
--data-urlencode "to[]=$mentions_reply" \ --data-urlencode "to[]=$mentions_reply" \
--output /dev/null --output /dev/null
echo $http_code echo "$http_code"
fi fi
} }
upload_api_media() upload_api_media()
{ {
post_request --url $instance_point/media \ post_request --url "$instance_point"/media \
--form "file=$mediaattach" --form "file=$mediaattach"
} }
@ -640,23 +640,23 @@ notif_menu()
json=$(notif_api_get_all) json=$(notif_api_get_all)
while [ $sub_menu_lvl -eq 1 ]; do while [ $sub_menu_lvl -eq 1 ]; do
clear clear
count_new_notif=$(echo $json | jj -l '#[pleroma.is_seen=false]#.pleroma.is_seen' | wc -w) count_new_notif=$(echo "$json" | jj -l '#[pleroma.is_seen=false]#.pleroma.is_seen' | wc -w)
echo "New notifications: $count_new_notif" echo "New notifications: $count_new_notif"
for i in $(echo $json | jj -l \#.id); do for i in $(echo "$json" | jj -l \#.id); do
date_utc=$(echo $json | jj \#[id=$i].created_at) date_utc=$(echo "$json" | jj \#[id="$i"].created_at)
date -d "$date_utc" "$format_time" date -d "$date_utc" "$format_time"
acct=$(echo $json | jj \#[id=$i].account.acct) acct=$(echo "$json" | jj \#[id="$i"].account.acct)
status_id=$(echo $json | jj \#[id=$i].status.id) status_id=$(echo "$json" | jj \#[id="$i"].status.id)
typenotif=$(echo $json | jj \#[id=$i].type) typenotif=$(echo "$json" | jj \#[id="$i"].type)
echo "<$status_id> $typenotif <- $acct" echo "<$status_id> $typenotif <- $acct"
echo $json | jj -r \#[id=$i].status.content | delqse | html_to_txt_render echo "$json" | jj -r \#[id="$i"].status.content | delqse | html_to_txt_render
echo '___' echo '___'
done done
menu_choice=$(echo "Main menu\nRead\nRefresh\n$clrnotif" | fzy) menu_choice=$(echo "Main menu\nRead\nRefresh\n$clrnotif" | fzy)
case "$menu_choice" in case "$menu_choice" in
"Main menu") sub_menu_lvl=0 ;; "Main menu") sub_menu_lvl=0 ;;
"Read") "Read")
notif_api_read "$(echo $json | jj 0.id)" notif_api_read "$(echo "$json" | jj 0.id)"
json=$(notif_api_get_all) json=$(notif_api_get_all)
;; ;;
"Refresh") json=$(notif_api_get_all) ;; "Refresh") json=$(notif_api_get_all) ;;
@ -679,7 +679,7 @@ notif_api_read()
notif_api_remove_all() notif_api_remove_all()
{ {
post_request --url $instance_point/notifications/clear post_request --url "$instance_point"/notifications/clear
} }
menu_write_status='Write status' menu_write_status='Write status'
@ -722,18 +722,18 @@ case $main_menu in
"Manual input") echo "Type instance (ex. $instance):" && read instance ;; "Manual input") echo "Type instance (ex. $instance):" && read instance ;;
esac esac
if [ $empty -eq 0 ]; then if [ $empty -eq 0 ]; then
echo $instance >> $instance_hist echo "$instance" >> $instance_hist
cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null
export instance export instance
export instance_point="https://$instance/api/v1" export instance_point="https://$instance/api/v1"
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy) conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
if [ "$conf_instance_state" = 'Permanent' ]; then if [ "$conf_instance_state" = 'Permanent' ]; then
jj -i config.json instance -v $instance -o config.json jj -i config.json instance -v "$instance" -o config.json
else else
echo '' echo ''
fi fi
clear clear
auth="$(jj -i .auth.json "$(echo $instance | sed 's/\./\\\./g')")" auth="$(jj -i .auth.json "$(echo "$instance" | sed 's/\./\\\./g')")"
echo "Instance: $instance" echo "Instance: $instance"
if [ -n "$auth" ]; then if [ -n "$auth" ]; then
default_curl_opt() default_curl_opt()
@ -748,7 +748,7 @@ case $main_menu in
else else
default_curl_opt() default_curl_opt()
{ {
curl -s --compressed $1 curl -s --compressed "$1"
} }
echo 'Please make auth and restart' echo 'Please make auth and restart'
fi fi