Optimize sxmo_modemtext contact listing

When you number of conversation start to grow, it rapidly take some
seconds for the menu to open itself. The [ -d "folder" ] test really is
uneficient.

This simplify this part as we now ask sxmo_contacts to only list texted
contacts.
master
Stacy Harper 4 years ago
parent 823ad95477
commit e444553ae4
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65
  1. 29
      scripts/core/sxmo_contacts.sh
  2. 5
      scripts/modem/sxmo_modemtext.sh

@ -16,16 +16,13 @@
CONTACTSFILE="$XDG_CONFIG_HOME"/sxmo/contacts.tsv CONTACTSFILE="$XDG_CONFIG_HOME"/sxmo/contacts.tsv
LOGFILE="$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv LOGFILE="$XDG_DATA_HOME"/sxmo/modem/modemlog.tsv
contacts() { prepare_contacts_list() {
grep -q . "$CONTACTSFILE" || echo " " > "$CONTACTSFILE" cut -f3 |
RECENTCONTACTEDNUMBERSREVCHRON="$(
cut -f3 "$LOGFILE" |
sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/" |
tac | tac |
awk '!($0 in a){a[$0]; print}' | awk '!($0 in a){a[$0]; print}' |
sed '/^[[:space:]]*$/d' sed '/^[[:space:]]*$/d' |
)" awk -F'\t' '
printf %b "$RECENTCONTACTEDNUMBERSREVCHRON" | awk -F'\t' '
FNR==NR{a[$1]=$2; next} FNR==NR{a[$1]=$2; next}
{ {
if (!a[$1]) a[$1] = "Unknown Number"; if (!a[$1]) a[$1] = "Unknown Number";
@ -34,6 +31,18 @@ contacts() {
' "$CONTACTSFILE" - ' "$CONTACTSFILE" -
} }
contacts() {
prepare_contacts_list < "$LOGFILE"
}
texted_contacts() {
grep "\(recv\|sent\)_txt" "$LOGFILE" | prepare_contacts_list
}
called_contacts() {
grep "call_\(pickup\|start\)" "$LOGFILE" | prepare_contacts_list
}
all_contacts() { all_contacts() {
awk -F'\t' '{ awk -F'\t' '{
print $1 ": " $2 print $1 ": " $2
@ -47,10 +56,16 @@ unknown_contacts() {
| grep "^+[0-9]\{9,14\}$" | grep "^+[0-9]\{9,14\}$"
} }
[ -f "$CONTACTSFILE" ] || touch "$CONTACTSFILE"
if [ "$1" = "--all" ]; then if [ "$1" = "--all" ]; then
all_contacts all_contacts
elif [ "$1" = "--unknown" ]; then elif [ "$1" = "--unknown" ]; then
unknown_contacts unknown_contacts
elif [ "$1" = "--texted" ]; then
texted_contacts
elif [ "$1" = "--called" ]; then
called_contacts
else else
contacts contacts
fi fi

@ -89,10 +89,7 @@ readtextmenu() {
# 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\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 --texted | xargs -IL echo "L logfile"
[ -d "$LOGDIR"/"$(printf %b "$CONTACT" | cut -d: -f1)" ] || continue
printf %b "$CONTACT" | xargs -IL echo "L logfile"
done
)" )"
PICKED="$(printf %b "$ENTRIES" | dmenu -p Texts -c -l 10 -i)" || exit PICKED="$(printf %b "$ENTRIES" | dmenu -p Texts -c -l 10 -i)" || exit

Loading…
Cancel
Save