diff --git a/controller/smscontroller.php b/controller/smscontroller.php index e9c7022..948efa2 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -77,7 +77,7 @@ class SmsController extends Controller { * @NoAdminRequired * @NoCSRFRequired */ - public function getConversation ($phoneNumber) { + public function getConversation ($phoneNumber, $lastDate = 0) { $messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $phoneNumber); // @ TODO: filter correctly return new JSONResponse(array("conversation" => $messages)); diff --git a/js/script.js b/js/script.js index c4b23fb..b8b3b1e 100644 --- a/js/script.js +++ b/js/script.js @@ -12,6 +12,10 @@ // Some global vars to improve performances var selectedConversation = null; var curPhoneNumber = null; +var lastMsgDate = 0; + +var months = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', + 'Oct.', 'Nov.', 'Dec.']; // Source: http://www.sitepoint.com/url-parameters-jquery/ $.urlParam = function(name){ @@ -25,62 +29,85 @@ $.urlParam = function(name){ }; var refreshConversation = function() { - + $.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'), + { + 'phoneNumber': phoneNumber, + "lastDate": lastMsgDate + }, + function(jsondata, status) { + conversationBuf = formatConversation(jsondata); + $('.msg-endtag').addBefore(conversationBuf); + $('#app-content').scrollTop(1E10); + } + ); }; function fetchConversation(phoneNumber) { $.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'), - {'phoneNumber': phoneNumber}, + { + 'phoneNumber': phoneNumber + }, function(jsondata, status) { - // Improve jQuery performance - var conversationBuf = ""; - // Improve JS performance - var msgClass = ''; - var unixDate = ''; - var formatedDate = ''; - var formatedHour = '00'; - var formatedMin = '00'; - var months = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', - 'Oct.', 'Nov.', 'Dec.']; - - $.each(jsondata["conversation"], function(id, vals) { - if (vals["type"] == 1) { - msgClass = "msg-recv"; - } - else if (vals["type"] == 2) { - msgClass = "msg-sent"; - } - else { - msgClass = ''; - } - - // Multiplicate ID to permit date to use it properly - msgDate = new Date(id*1); - - formatedHour = msgDate.getHours(); - if (formatedHour < 10) { - formatedHour = '0' + formatedHour; - } - - formatedMin = msgDate.getMinutes(); - if (formatedMin < 10) { - formatedMin = '0' + formatedMin; - } - formatedDate = msgDate.getDate() + " " + months[msgDate.getMonth()] + " " + - formatedHour + ":" + formatedMin; - - conversationBuf += '