From 6868c1fa85a012db6501ca655472f385bce913aa Mon Sep 17 00:00:00 2001 From: Greg Ross Date: Sun, 1 Jul 2018 13:29:29 -0400 Subject: [PATCH] Fix deleting conversations without a contact (#250) * Fix deleting converstatoins with a contact If a conversation does not have a contact, the delete function will fail as only the formatted phone number is passed in and the raw sms phone number is needed to execute the delete. --- controller/smscontroller.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/controller/smscontroller.php b/controller/smscontroller.php index e03456b..5b3acdc 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -145,7 +145,7 @@ class SmsController extends Controller { // Contact resolved if ($contactName != "" && isset($iContacts[$contactName])) { // forall numbers in iContacts - foreach($iContacts[$contactName] as $cnumber) { + foreach ($iContacts[$contactName] as $cnumber) { $messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry, $lastDate); $msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry); $phoneNumbers[] = PhoneNumberFormatter::format($configuredCountry, $cnumber); @@ -197,12 +197,18 @@ class SmsController extends Controller { // Contact resolved if ($contactName != "" && isset($iContacts[$contactName])) { // forall numbers in iContacts - foreach($iContacts[$contactName] as $cnumber) { + foreach ($iContacts[$contactName] as $cnumber) { $this->smsMapper->removeMessagesForPhoneNumber($this->userId, $cnumber); } } else { - $this->smsMapper->removeMessagesForPhoneNumber($this->userId, $contact); + // If we didn't match a contact we need to lookup the raw sms phone numbers associated with the formatted phone number that was passed in as $contact. + $phlist = $this->smsMapper->getAllPhoneNumbersForFPN($this->userId, $contact, $configuredCountry); + + // Loop through the returned list of phone numbers and delete them. + foreach ($phlist as $phnumber => $value) { + $this->smsMapper->removeMessagesForPhoneNumber($this->userId, $phnumber); + } } return new JSONResponse(array()); }