From b9641345a1ecd27225a26f6b8daac0a2ef36bf58 Mon Sep 17 00:00:00 2001 From: osaajani <> Date: Tue, 13 Apr 2021 02:33:30 +0200 Subject: [PATCH] do not duplicatd in progress msg --- controllers/publics/Discussion.php | 14 ++++++++++++-- templates/discussion/show.php | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/controllers/publics/Discussion.php b/controllers/publics/Discussion.php index 13d2031..7d4f215 100644 --- a/controllers/publics/Discussion.php +++ b/controllers/publics/Discussion.php @@ -220,8 +220,18 @@ namespace controllers\publics; if ($messages) { - $new_limit_date = (new \DateTime($messages[count($messages) - 1]['date']))->getTimestamp(); //Use latest message as the new limit date to search - $response['new_limit_date'] = $new_limit_date; + for ($i = count($messages); $i > 0; $i--) + { + $message = $messages[$i - 1]; + if ($message['type'] == 'inprogress') + { + continue; + } + + $new_limit_date = (new \DateTime($message['date']))->getTimestamp(); //Use latest not inprogress message as the new limit date to search + $response['new_limit_date'] = $new_limit_date; + break; + } } echo json_encode($response); diff --git a/templates/discussion/show.php b/templates/discussion/show.php index 31f15d6..caae5c6 100644 --- a/templates/discussion/show.php +++ b/templates/discussion/show.php @@ -87,6 +87,9 @@ jQuery('.discussion-container #load-message-spinner').remove(); jQuery('.discussion-container #send-message-spinner').remove(); + //We also remove all in-progress messages because they are added again in the new response if not sended yet, and if sended they should not appear in double + jQuery('.discussion-container .message-in-progress-container').remove(); + $.each(data.messages, function(key, message) { @@ -146,7 +149,7 @@ break; case 'inprogress' : var texte = '' + - '
' + + '
' + '
' + '
' + '
' + message.text + '
' +