diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html
index 5939067..3c52444 100644
--- a/src/app/pages/settings/settings.page.html
+++ b/src/app/pages/settings/settings.page.html
@@ -36,6 +36,20 @@
General
Edit
+
+
+ Default country prefix
+ The country prefix (i.e. +1 for USA) to be used with numbers missing it
+
+
+
+
Recordings
diff --git a/src/app/pages/settings/settings.page.scss b/src/app/pages/settings/settings.page.scss
index e69de29..772e3c9 100644
--- a/src/app/pages/settings/settings.page.scss
+++ b/src/app/pages/settings/settings.page.scss
@@ -0,0 +1,7 @@
+.phone-prefix-label {
+ max-width: none;
+}
+
+.phone-prefix {
+ min-width: 4em;
+}
\ No newline at end of file
diff --git a/src/app/pages/settings/settings.page.ts b/src/app/pages/settings/settings.page.ts
index f284a6a..7175563 100644
--- a/src/app/pages/settings/settings.page.ts
+++ b/src/app/pages/settings/settings.page.ts
@@ -90,4 +90,19 @@ export class SettingsPage {
this.editor.present();
}
+ /**
+ * Set the default country prefix to settings
+ */
+ setDefaultCountryPrefix(prefix: string) {
+ prefix = prefix.trim();
+ if (prefix) {
+ if (!prefix.startsWith('+')) {
+ prefix = '+' + prefix;
+ }
+ if (/^\+\d*$/g.test(prefix)) {
+ this.settings.defaultCountryPrefix = prefix;
+ }
+ }
+ }
+
}
diff --git a/src/app/services/contacts.service.ts b/src/app/services/contacts.service.ts
index 23efbcb..6c5e410 100644
--- a/src/app/services/contacts.service.ts
+++ b/src/app/services/contacts.service.ts
@@ -3,12 +3,14 @@ import { Injectable } from '@angular/core';
import { ContactPayload, Contacts, PhoneType } from '@capacitor-community/contacts';
import { PermissionState } from '@capacitor/core';
import { MessageBoxService } from './message-box.service';
+import { SettingsService } from './settings.service';
@Injectable()
export class ContactsService {
constructor(
- private mbs: MessageBoxService
+ private mbs: MessageBoxService,
+ private settings: SettingsService,
) {}
/**
@@ -20,7 +22,7 @@ export class ContactsService {
}
/**
- * Cleanup the given phone number by keeping only "+" and digits
+ * Cleanup the given phone number by keeping only "+" and digits.
*/
cleanupPhoneNumber(phoneNumber: string): string {
return phoneNumber.replace(/[^\d\+]/g, '');
@@ -42,13 +44,29 @@ export class ContactsService {
}
});
- // find and return the first match
- return res.contacts.find(item =>
- item.phones?.filter(i => i.number)
- .map(i => this.cleanupPhoneNumber(i.number!))
- .includes(phoneNumber)
- );
+ // find and return the first contact match
+ for (const contact of res.contacts) {
+ // get defined and cleaned contact numbers
+ const numbers = contact.phones?.filter(n => n).map(p => this.cleanupPhoneNumber(p!.number!));
+ if (numbers?.length) {
+
+ // search first the plain number...
+ for (const n of numbers) {
+ if (n === phoneNumber) return contact;
+ }
+
+ // ...then tries adding the default country prefix
+ // (special numbers could not have intl prefix)
+ if (this.settings.defaultCountryPrefix) {
+ for (const n of numbers) {
+ if (n[0] !== '+' && (this.settings.defaultCountryPrefix + n === phoneNumber)) return contact;
+ }
+ }
+ }
+ }
+
+ return undefined;
}
/**
diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts
index f83f660..0a68ed8 100644
--- a/src/app/services/settings.service.ts
+++ b/src/app/services/settings.service.ts
@@ -58,6 +58,12 @@ export class SettingsService {
@JsonProperty()
public seekTime: number = 10;
+ /**
+ * Default country phone prefix
+ */
+ @JsonProperty()
+ public defaultCountryPrefix: string = '';
+
/**
* Custom filename format
*/