Fix the unreliable modem numbers prefix issues

Sometime, the modem will give 0611924312 as incoming text or
call number instead of +33611924312 (example in france).

This cause two issues cause of format missmatch:

* Notifications sometime come from "Unknown" when we actually know
the contact
* Text/Dial menu entries are duplicated with "Unknown" persons

We try here to fix boths issues with a simple idea. We will fallback
to a default prefix when it is missing (on phone like numbers,
composed of 10 numbers).

This prefix is an environment variable that cause 0 impact if missing.

* sxmo_contacts.sh will fix the recent numbers prefixes with the default
* sxmo_modemmonitor.sh will also fix the prefix with the default one

This should solve missmatch issues as both will use country code format

I only recommend to always store contacts in the prefixed format in the
contacts.tsv file.

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 df73a9af1c
commit 91fe7fbeab
  1. 5
      configs/appcfg/xinit_template
  2. 28
      scripts/core/sxmo_contactmenu.sh
  3. 1
      scripts/core/sxmo_contacts.sh
  4. 6
      scripts/modem/sxmo_modemmonitor.sh

@ -24,6 +24,11 @@ amixer set "Line Out" 50%
# Play a funky startup tune # Play a funky startup tune
#mpv --quiet --no-video ~/welcome.ogg & #mpv --quiet --no-video ~/welcome.ogg &
# You will sometime get SMS or calls from not
# country code prefixed phone numbers. To ensure
# we match your contacts, we will use this one.
#export DEFAULT_NUMBER_PREFIX=+33
# turn on modemmonitor on login # turn on modemmonitor on login
# Note: if the modemmonitor is not on you can # Note: if the modemmonitor is not on you can
# not receive texts/calls! # not receive texts/calls!

@ -3,9 +3,23 @@
# shellcheck source=scripts/core/sxmo_common.sh # shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh" . "$(dirname "$0")/sxmo_common.sh"
valid_number() {
number="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")"
if echo "$number" | grep -q "^+[0-9]\{11\}$"; then
echo "$number"
else
notify-send "\"$number\" is not a valid phone number"
notify-send "Valid format is \"+[0-9]{11}\""
fi
}
newcontact() { newcontact() {
name="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_usr Name")" name="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_usr Name")"
while [ -z "$number" ]; do
number="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_phl Number")" number="$(echo | sxmo_dmenu_with_kb.sh -c -l 2 -p "$icon_phl Number")"
number="$(valid_number "$number")"
done
PICKED="$number $name" # now act like if we picked this new contact PICKED="$number $name" # now act like if we picked this new contact
echo "$PICKED" >> "$CONTACTFILE" echo "$PICKED" >> "$CONTACTFILE"
@ -35,18 +49,22 @@ editcontactnumber() {
oldname="$(echo "$1" | cut -d" " -f2)" oldname="$(echo "$1" | cut -d" " -f2)"
ENTRIES="$(printf %b "Old number: $oldnumber")" ENTRIES="$(printf %b "Old number: $oldnumber")"
PICKED= # already used var name
while [ -z "$PICKED" ]; do
PICKED="$( PICKED="$(
echo "$ENTRIES" | echo "$ENTRIES" |
sxmo_dmenu_with_kb.sh -c -l 3 -p "$icon_edt Edit Contact" sxmo_dmenu_with_kb.sh -c -l 3 -p "$icon_edt Edit Contact"
)" )"
if echo "$PICKED" | grep -q "^Old number: "; then
editcontact "$1"
return
fi
PICKED="$(valid_number "$PICKED")"
done
if ! echo "$PICKED" | grep -q "^Old number: "; then
newcontact="$PICKED $oldname" newcontact="$PICKED $oldname"
sed -i "s/^$1$/$newcontact/" "$CONTACTFILE" sed -i "s/^$1$/$newcontact/" "$CONTACTFILE"
set -- "$newcontact" editcontact "$newcontact"
fi
editcontact "$1"
} }
deletecontact() { deletecontact() {

@ -20,6 +20,7 @@ contacts() {
grep -q . "$CONTACTSFILE" || echo " " > "$CONTACTSFILE" grep -q . "$CONTACTSFILE" || echo " " > "$CONTACTSFILE"
RECENTCONTACTEDNUMBERSREVCHRON="$( RECENTCONTACTEDNUMBERSREVCHRON="$(
cut -f3 "$LOGFILE" | cut -f3 "$LOGFILE" |
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'

@ -47,11 +47,9 @@ lookupcontactname() {
if [ "$1" = "--" ]; then if [ "$1" = "--" ]; then
echo "Unknown number" echo "Unknown number"
else else
NUMBER="$1" NUMBER="$(echo "$1" | sed "s/^0\([0-9]\{9\}\)$/${DEFAULT_NUMBER_PREFIX:-0}\1/")"
CONTACT=$(sxmo_contacts.sh --all | CONTACT=$(sxmo_contacts.sh --all |
grep "$NUMBER:" | #this is not an exact match but a suffix match grep "^$NUMBER:" |
#which also works if the + and country code are missing
#but may lead to false positives in rare cases (short numbers)
cut -d':' -f 2 | cut -d':' -f 2 |
sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace sed 's/^[ \t]*//;s/[ \t]*$//' #strip leading/trailing whitespace
) )

Loading…
Cancel
Save