Rework of the sxmo_modemtext with benefit

* Draft files are assigned to each number:

Stored here ".local/share/modem/+33666666666/draft.txt"
We automatically edit this single file, making crash or unexpected
edition issue to leave intact saved draft.

* Simplification of some logics

Having a known draft file instead of using a TEXT var simplify lots
of things

* EDITOR is not run in a subshell

Some editors as kakoune got issues with that. Futhermore, it will be
usefull for some other development as making all menu ssh mode
compatible

* Remove modem check

As we now got draft, why do we care if modem is up or down ?

* Display the contact name instead of it number in the conversation

Or use "Unknown Number (+337798676)"

* Unify display message notif adding possibilities to bypass the
main menu

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
master
Stacy Harper 4 years ago committed by Maarten van Gompel
parent 016363dd57
commit 262418637f
  1. 2
      scripts/core/sxmo_appmenu.sh
  2. 2
      scripts/modem/sxmo_modemmonitor.sh
  3. 137
      scripts/modem/sxmo_modemtext.sh

@ -307,7 +307,7 @@ programchoicesinit() {
number="$(echo "$WMNAME" | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ')" number="$(echo "$WMNAME" | sed -e 's|^\"||' -e 's|\"$||' | cut -f1 -d' ')"
#sms #sms
CHOICES=" CHOICES="
$icon_msg Reply ^ 0 ^ sxmo_modemtext.sh $number $icon_msg Reply ^ 0 ^ sxmo_modemtext.sh sendtextmenu $number
$icon_phn Call ^ 0 ^ sxmo_modemdial.sh $number $icon_phn Call ^ 0 ^ sxmo_modemdial.sh $number
" "
WINNAME=sms WINNAME=sms

@ -172,7 +172,7 @@ checkfornewtexts() {
sxmo_notificationwrite.sh \ sxmo_notificationwrite.sh \
random \ random \
"st -T '$NUM SMS' -e tail -n9999 -f '$LOGDIR/$NUM/sms.txt'" \ "sxmo_modemtext.sh tailtextlog $NUM" \
"$LOGDIR/$NUM/sms.txt" \ "$LOGDIR/$NUM/sms.txt" \
"Message - $CONTACTNAME: $TEXT" "Message - $CONTACTNAME: $TEXT"

@ -5,7 +5,6 @@
. "$(dirname "$0")/sxmo_common.sh" . "$(dirname "$0")/sxmo_common.sh"
TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true") TERMMODE=$([ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] && echo "true")
DRAFT_DIR="$XDG_DATA_HOME/sxmo/modem/draft"
menu() { menu() {
if [ "$TERMMODE" != "true" ]; then if [ "$TERMMODE" != "true" ]; then
@ -21,26 +20,7 @@ err() {
kill $$ kill $$
} }
modem_n() {
MODEMS="$(mmcli -L)"
echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || err "Couldn't find modem - is your modem enabled?"
echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}
editmsg() {
TMP="$(mktemp --suffix "$1_msg")"
echo "$2" > "$TMP"
if [ "$TERMMODE" != "true" ]; then
st -e "$EDITOR" "$TMP"
else
"$EDITOR" "$TMP"
fi
cat "$TMP"
}
choosenumbermenu() { choosenumbermenu() {
modem_n >/dev/null || err "Couldn't determine modem number - is modem online?"
# Prompt for number # Prompt for number
NUMBER="$( NUMBER="$(
printf %b "\n$icon_cls Cancel\n$icon_grp More contacts\n$(sxmo_contacts.sh | grep -E "^\+?[0-9]+:")" | printf %b "\n$icon_cls Cancel\n$icon_grp More contacts\n$(sxmo_contacts.sh | grep -E "^\+?[0-9]+:")" |
@ -49,94 +29,97 @@ choosenumbermenu() {
cut -d: -f1 | cut -d: -f1 |
tr -d -- '- ' tr -d -- '- '
)" )"
echo "$NUMBER" | grep -q "Morecontacts" && NUMBER="$( #joined words without space is not a bug if echo "$NUMBER" | grep -q "Morecontacts"; then
printf %b "\nCancel\n$(sxmo_contacts.sh --all)" | NUMBER="$( #joined words without space is not a bug
grep . | printf %b "\nCancel\n$(sxmo_contacts.sh --all)" |
menu sxmo_dmenu_with_kb.sh -l 10 -p "Number" -c -i | grep . |
cut -d: -f1 | menu sxmo_dmenu_with_kb.sh -l 10 -p "Number" -c -i |
tr -d -- '- ' cut -d: -f1 |
)" tr -d -- '- '
echo "$NUMBER" | grep -q "Cancel" && exit 1 )"
echo "$NUMBER" | grep -qE '^[+0-9]+$' || err "That doesn't seem like a valid number" fi
echo "$NUMBER"
if echo "$NUMBER" | grep -q "Cancel"; then
exit 1
elif ! echo "$NUMBER" | grep -qE '^[+0-9]+$'; then
notify-send "That doesn't seem like a valid number"
else
echo "$NUMBER"
fi
} }
sendnewtextmenu() { sendtextmenu() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
NUMBER="$1" NUMBER="$1"
else else
NUMBER="$(choosenumbermenu)" NUMBER="$(choosenumbermenu)"
fi fi
# Compose first version of msg
TEXT="$(editmsg "$NUMBER" 'Enter text message here')"
sendtextmenu "$NUMBER" "$TEXT"
}
sendtextmenu() { DRAFT="$LOGDIR/$NUMBER/draft.txt"
NUMBER="$1" if [ ! -f "$DRAFT" ]; then
TEXT="$2" mkdir -p "$(dirname "$DRAFT")"
echo 'Enter text message here' > "$DRAFT"
fi
if [ "$TERMMODE" != "true" ]; then
st -e "$EDITOR" "$DRAFT"
else
"$EDITOR" "$DRAFT"
fi
while true while true
do do
CONFIRM="$( CONFIRM="$(
printf %b "$icon_edt Edit Message ($(echo "$TEXT" | head -n1))\n$icon_snd Send to → $NUMBER\n$icon_sav Save as Draft\n$icon_cls Cancel" | printf %b "$icon_edt Edit\n$icon_snd Send\n$icon_cls Cancel" |
menu dmenu -c -idx 1 -p "Confirm" -l 10 menu dmenu -c -idx 1 -p "Confirm" -l 10
)" )"
echo "$CONFIRM" | grep -E "Send to" && (echo "$TEXT" | sxmo_modemsendsms.sh "$NUMBER" -) && echo "Sent text to $NUMBER">&2 && exit 0 if echo "$CONFIRM" | grep -q "Send"; then
echo "$CONFIRM" | grep -E "Cancel$" && exit 1 (cat "$DRAFT" | sxmo_modemsendsms.sh "$NUMBER" -) && \
echo "$CONFIRM" | grep -E "Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")" rm "$DRAFT" && \
echo "$CONFIRM" | grep -E "Save as Draft$" && err "Draft saved to $(draft "$NUMBER" "$TEXT")" echo "Sent text to $NUMBER">&2 && exit 0
elif echo "$CONFIRM" | grep -q "Edit"; then
sendtextmenu "$NUMBER"
elif echo "$CONFIRM" | grep -q "Cancel"; then
exit 1
fi
done done
} }
draft() { tailtextlog() {
NUMBER="$1" NUMBER="$1"
TEXT="$2" CONTACTNAME="$(sxmo_contacts.sh | grep "^$NUMBER" | cut -d' ' -f2-)"
DRAFT_FILE="$NUMBER-$(date +'%Y-%m-%d_%H-%m-%S')" [ "Unknown Number" = "$CONTACTNAME" ] && CONTACTNAME="$CONTACTNAME ($NUMBER)"
echo "$NUMBER" > "$DRAFT_DIR/$DRAFT_FILE"
echo "$TEXT" >> "$DRAFT_DIR/$DRAFT_FILE"
echo "$DRAFT_FILE"
}
senddrafttextmenu() { set -- sh -c "tail -n9999 -f \"$LOGDIR/$NUMBER/sms.txt\" | sed \"s|$NUMBER|$CONTACTNAME|g\""
CONFIRM="$(
printf %b "$icon_cls Cancel\n$(ls "$DRAFT_DIR")" |
menu sxmo_dmenu_with_kb.sh -p "Draft Message" -l 10 -c -i
)"
echo "$CONFIRM" | grep -E "Cancel$" && exit 1
FILE="$DRAFT_DIR/$CONFIRM"
NUMBER="$(head -n1 "$FILE")"
TEXT="$(tail -n +2 "$FILE")"
rm "$FILE"
sendtextmenu "$NUMBER" "$TEXT"
}
tailtextlog() {
if [ "$TERMMODE" != "true" ]; then if [ "$TERMMODE" != "true" ]; then
st -T "$1 SMS" -e tail -n9999 -f "$LOGDIR/$1/sms.txt" st -T "$NUMBER SMS" -e "$@"
else else
tail -n9999 -f "$LOGDIR/$1/sms.txt" "$@"
fi fi
} }
main() { readtextmenu() {
[ ! -d "$DRAFT_DIR" ] && mkdir -p "$DRAFT_DIR"
# E.g. only display logfiles for directories that exist and join w contact name # E.g. only display logfiles for directories that exist and join w contact name
ENTRIES="$( ENTRIES="$(
printf %b "$icon_cls Close Menu\n$icon_edt Send a Text$( [ "$(ls -A "$DRAFT_DIR")" ] && printf %b "\n$icon_edt Send a Draft Text")\n"; printf %b "$icon_cls Close Menu\n$icon_edt Send a Text\n";
sxmo_contacts.sh | while read -r CONTACT; do sxmo_contacts.sh | while read -r CONTACT; do
[ -d "$LOGDIR"/"$(printf %b "$CONTACT" | cut -d: -f1)" ] || continue [ -d "$LOGDIR"/"$(printf %b "$CONTACT" | cut -d: -f1)" ] || continue
printf %b "$CONTACT" | xargs -IL echo "L logfile" printf %b "$CONTACT" | xargs -IL echo "L logfile"
done done
)" )"
CONTACTIDANDNUM="$(printf %b "$ENTRIES" | menu dmenu -p Texts -c -l 10 -i)" PICKED="$(printf %b "$ENTRIES" | menu dmenu -p Texts -c -l 10 -i)"
echo "$CONTACTIDANDNUM" | grep "Close Menu" && exit 1
echo "$CONTACTIDANDNUM" | grep "Send a Text" && sendnewtextmenu && exit 1 if echo "$PICKED" | grep "Close Menu"; then
echo "$CONTACTIDANDNUM" | grep "Send a Draft Text" && senddrafttextmenu && exit 1 exit 1
tailtextlog "$(echo "$CONTACTIDANDNUM" | cut -d: -f1)" elif echo "$PICKED" | grep "Send a Text"; then
sendtextmenu
else
tailtextlog "$(echo "$PICKED" | cut -d: -f1)"
fi
} }
if [ -n "$1" ]; then if [ "2" != "$#" ]; then
sendnewtextmenu "$1" readtextmenu
else else
main "$@"
fi fi

Loading…
Cancel
Save