1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

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.
This commit is contained in:
Greg Ross 2018-07-01 13:29:29 -04:00 committed by Loïc Blot
parent abad21c131
commit 6868c1fa85

View File

@ -145,7 +145,7 @@ class SmsController extends Controller {
// Contact resolved // Contact resolved
if ($contactName != "" && isset($iContacts[$contactName])) { if ($contactName != "" && isset($iContacts[$contactName])) {
// forall numbers in iContacts // forall numbers in iContacts
foreach($iContacts[$contactName] as $cnumber) { foreach ($iContacts[$contactName] as $cnumber) {
$messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry, $lastDate); $messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry, $lastDate);
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry); $msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber, $configuredCountry);
$phoneNumbers[] = PhoneNumberFormatter::format($configuredCountry, $cnumber); $phoneNumbers[] = PhoneNumberFormatter::format($configuredCountry, $cnumber);
@ -197,12 +197,18 @@ class SmsController extends Controller {
// Contact resolved // Contact resolved
if ($contactName != "" && isset($iContacts[$contactName])) { if ($contactName != "" && isset($iContacts[$contactName])) {
// forall numbers in iContacts // forall numbers in iContacts
foreach($iContacts[$contactName] as $cnumber) { foreach ($iContacts[$contactName] as $cnumber) {
$this->smsMapper->removeMessagesForPhoneNumber($this->userId, $cnumber); $this->smsMapper->removeMessagesForPhoneNumber($this->userId, $cnumber);
} }
} }
else { 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()); return new JSONResponse(array());
} }