Skip to content

Commit

Permalink
automatically add medias as link if phone does not support mms
Browse files Browse the repository at this point in the history
  • Loading branch information
osaajani committed Apr 16, 2021
1 parent 4cd52ae commit 878d820
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 39 deletions.
2 changes: 0 additions & 2 deletions adapters/TestAdapter.php
Expand Up @@ -167,8 +167,6 @@ public function send(string $destination, string $text, bool $flash = false, boo

$uid = uniqid();

$medias = [];

$at = (new \DateTime())->format('Y-m-d H:i:s');
$success = file_put_contents($this->test_file_write, json_encode(['uid' => $uid, 'at' => $at, 'destination' => $destination, 'text' => $text, 'flash' => $flash, 'mms' => $mms, 'medias' => $medias]) . "\n", FILE_APPEND);
if (false === $success)
Expand Down
4 changes: 2 additions & 2 deletions controllers/internals/Scheduled.php
Expand Up @@ -338,7 +338,7 @@ public function get_smss_to_send()
{
if (null === $phone_to_use)
{
if ($scheduled['mms'])
if ($scheduled['mms'] && count($users_mms_phones))
{
$rnd_key = array_rand($users_mms_phones[$scheduled['id_user']]);
$random_phone = $users_mms_phones[$scheduled['id_user']][$rnd_key];
Expand Down Expand Up @@ -408,7 +408,7 @@ public function get_smss_to_send()

if (null === $phone_to_use)
{
if ($scheduled['mms'])
if ($scheduled['mms'] && count($users_mms_phones))
{
$rnd_key = array_rand($users_mms_phones[$scheduled['id_user']]);
$random_phone = $users_mms_phones[$scheduled['id_user']][$rnd_key];
Expand Down
12 changes: 12 additions & 0 deletions controllers/internals/Sended.php
Expand Up @@ -229,6 +229,18 @@ public function send(\adapters\AdapterInterface $adapter, int $id_user, int $id_
];
}

//If adapter does not support mms and the message is a mms, add medias as link
if (!$adapter::meta_support_mms_sending() && $mms)
{
$media_urls = [];
foreach ($media_uris as $media_uri)
{
$media_urls[] = STATIC_HTTP_URL . '/data/public/' . $media_uri['path'];
}

$text .= "\n" . join(' - ', $media_urls);
}

$response = $adapter->send($destination, $text, $flash, $mms, $media_uris);

if ($response['error'])
Expand Down
25 changes: 0 additions & 25 deletions controllers/publics/Api.php
Expand Up @@ -333,31 +333,6 @@ public function post_scheduled()
return $this->json($return);
}

if ($id_phone && $mms && !$this->internal_phone->support_mms($id_phone, $this->internal_phone::MMS_SENDING))
{
$return = self::DEFAULT_RETURN;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'mms : You try to send a mms with a phone that does not support mms.';
$this->auto_http_code(false);

return $this->json($return);
}

//if try to send mms and no available phone support mms, return error
if (!$id_phone && $mms)
{
$phones_supporting_mms = $this->internal_phone->gets_phone_supporting_mms_for_user($this->user['id'], $this->internal_phone::MMS_SENDING);
if (!count($phones_supporting_mms))
{
$return = self::DEFAULT_RETURN;
$return['error'] = self::ERROR_CODES['INVALID_PARAMETER'];
$return['message'] = self::ERROR_MESSAGES['INVALID_PARAMETER'] . 'mms : You try to send a mms but you dont have any phone supporting mms. Please add at least one phone supporting mms before trying to send one.';
$this->auto_http_code(false);

return $this->json($return);
}
}

if ($mms)
{
foreach ($files_arrays as $file)
Expand Down
7 changes: 0 additions & 7 deletions controllers/publics/Discussion.php
Expand Up @@ -106,13 +106,6 @@ public function get_messages($number, $transaction_id)

$id_user = $_SESSION['user']['id'];

if ($since && !($since = date('Y-m-d H:i:s', $since)))
{
echo json_encode(['transaction_id' => $transaction_id, 'messages' => [], 'error' => true, 'error_message' => 'Not a valid date.']);

return false;
}

$sendeds = $this->internal_sended->gets_by_destination_and_user($id_user, $number);
$receiveds = $this->internal_received->gets_by_origin_and_user($id_user, $number);
$scheduleds = $this->internal_scheduled->gets_before_date_for_number_and_user($id_user, $now, $number);
Expand Down
3 changes: 3 additions & 0 deletions env.prod.php.dist
@@ -1,5 +1,8 @@
<?php
$env = [
//Public static URL
'STATIC_HTTP_URL' => '%APP_STATIC_HTTP_URL%',

//Database access
'DATABASE_HOST' => '%APP_DATABASE_HOST%',
'DATABASE_NAME' => '%APP_DATABASE_NAME%',
Expand Down
6 changes: 3 additions & 3 deletions templates/discussion/show.php
Expand Up @@ -134,7 +134,7 @@ function getmessages ()
var texte = '' +
'<div class="clearfix message-container" id="' + message.uid + '">' +
'<div class="discussion-message message-received">' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-text">' + message.text.replace(/\n/g,"<br>") + '</div>' +
medias_html +
'<div class="discussion-message-date">' + message.date + '</div>' +
'</div>' +
Expand All @@ -150,7 +150,7 @@ function getmessages ()
var texte = '' +
'<div class="clearfix message-container" id="' + message.uid + '">' +
'<div class="discussion-message message-sended">' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-text">' + message.text.replace(/\n/g,"<br>") + '</div>' +
medias_html +
'<div class="discussion-message-date">' + message.date + ' ' + (message.status == 'delivered' ? '<span class="message-status fa fa-check-circle fa-fw text-success"></span>' : (message.status == 'failed' ? '<span class="message-status fa fa-times-circle fa-fw text-danger"></span>' : '<span class="message-status fa fa-clock-o fa-fw text-info"></span>' )) + '</div>' +
'</div>' +
Expand All @@ -161,7 +161,7 @@ function getmessages ()
'<div class="clearfix message-container message-in-progress-container" id="' + message.uid + '">' +
'<div class="discussion-message message-sended">' +
'<div class="message-in-progress-hover"><i class="fa fa-spinner fa-spin"></i></div>' +
'<div class="discussion-message-text">' + message.text + '</div>' +
'<div class="discussion-message-text">' + message.text.replace(/\n/g,"<br>") + '</div>' +
medias_html +
'<div class="discussion-message-date">' + message.date + '</div>' +
'</div>' +
Expand Down

0 comments on commit 878d820

Please sign in to comment.