From dec2f54a1b81af80c9df1755aebfb69237b49306 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 9 Dec 2017 10:56:22 +0000 Subject: [PATCH] When visiting a mesh site choose from a list of users --- src/freedombone-mesh-visit-site | 83 +++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/src/freedombone-mesh-visit-site b/src/freedombone-mesh-visit-site index c667ff08..2136892e 100755 --- a/src/freedombone-mesh-visit-site +++ b/src/freedombone-mesh-visit-site @@ -49,38 +49,61 @@ if [ ! -f $USERS_FILE ]; then exit 0 fi -data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit") -sel=$? -case $sel in +USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}') + +if [ $USERS_FILE_LINES -gt 200 ]; then + # If there are more than a Dunbar number of peers then ask for the peer name or ID + data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit") + sel=$? + case $sel in 0) - TOX_USERNAME_OR_ID="$data" - if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then - if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then - TOX_ID="$TOX_USERNAME_OR_ID" - else - TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//') - fi - - if [ ${#TOX_ID} -gt 5 ]; then - if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then - dialog --title $"Visit IPFS site" \ - --backtitle $"Freedombone mesh" \ - --msgbox $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" 8 60 - exit 3 - fi - IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}') - clear - echo $'Opening browser. Please wait...' - pkill $BROWSER - setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null & - - # Need to wait a while for the browser to begin opening - sleep 3 - fi + TOX_USERNAME_OR_ID="$data" + if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then + if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then + TOX_ID="$TOX_USERNAME_OR_ID" else - exit 1 + TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//') fi - ;; -esac + + if [ ${#TOX_ID} -gt 5 ]; then + if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then + zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500 + exit 3 + fi + IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}') + pkill $BROWSER + setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null & + + # Need to wait a while for the browser to begin opening + sleep 3 + fi + else + exit 1 + fi + ;; + esac +else + # If there are a relatively small number of users then choose from a list + TOX_ID=$( + cat $USERS_FILE | \ + awk -F ' ' '{ + for(i=1;i<=NF;i++){ + print $i; + } +}' | \ + zenity --list \ + --title='Visit the site of another user' \ + --column='Username' --column='Tox ID' \ + --print-column=2 --hide-column=2 --width=300 --height=400) + if [ ! $TOX_ID ]; then + exit 0 + fi + IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}') + pkill $BROWSER + setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null & + + # Need to wait a while for the browser to begin opening + sleep 3 +fi exit 0