diff --git a/js/devel/contactlist.js b/js/devel/contactlist.js index 4bbc067..c4045e5 100644 --- a/js/devel/contactlist.js +++ b/js/devel/contactlist.js @@ -24,12 +24,9 @@ var ContactList = new Vue({ // phoneNumber must exist if (contact.nav !== null) { - this.fetchConversation(contact); + ContactList.fetchConversation(contact); Sms.selectConversation($("a[mailbox-navigation='" + contact.nav + "']")); } - }, - fetchConversation: function (contact) { - // @TODO } }, computed: { diff --git a/js/devel/conversation.js b/js/devel/conversation.js new file mode 100644 index 0000000..e0ef89c --- /dev/null +++ b/js/devel/conversation.js @@ -0,0 +1,64 @@ +/** + * Nextcloud - Phone Sync + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Loic Blot + * @copyright Loic Blot 2014-2018 + */ + +var ContactList = new Vue({ + el: '#ocsms-app-content', + data: { + selectedContact: {}, + isConvLoading: false, + messages: [], + lastConvMessageDate: 0 + }, + created: function () { + }, + methods: { + fetchConversation: function (contact) { + // If contact is not null, we will fetch a conversation for a new contact + if (contact != null) { + this.selectedContact = contact; + this.isConvLoading = true; + } + + this.messages = []; + this.lastConvMessageDate = 0; + + var self = this; + $.getJSON(Sms.generateURL('/front-api/v1/conversation'), {'phoneNumber': $scope.selectedContact.nav}, + function (jsondata, status) { + var phoneNumberLabel = self.selectedContact.nav; + + if (typeof jsondata['phoneNumbers'] !== 'undefined') { + var phoneNumberList = arrayUnique(jsondata['phoneNumbers']); + phoneNumberLabel = phoneNumberList.toString(); + } + + // Reinit messages before showing conversation + app.formatConversation(jsondata); + + $scope.$apply(function () { + if (typeof jsondata['contactName'] === 'undefined' || jsondata['contactName'] === '') { + self.selectedContact.label = phoneNumberLabel; + self.selectedContact.opt_numbers = ""; + } + else { + self.selectedContact.label = jsondata['contactName']; + self.selectedContact.opt_numbers = phoneNumberLabel; + } + + self.totalMessageCount = jsondata['msgCount'] !== undefined ? jsondata['msgCount'] : 0; + self.isConvLoading = false; + }); + + $('#ocsms-app-content').scrollTop(1E10); + } + ); + }; + } +}); \ No newline at end of file diff --git a/js/devel/legacy.js b/js/devel/legacy.js index 6d3c2d1..2c9ad06 100644 --- a/js/devel/legacy.js +++ b/js/devel/legacy.js @@ -35,17 +35,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile' $scope.selectedContact = {}; $scope.lastSearch = ''; - // Conversations - $scope.loadConversation = function (contact) { - OC.Util.History.pushState('phonenumber=' + contact.nav); - - // phoneNumber must exist - if (contact.nav !== null) { - $scope.fetchConversation(contact); - Sms.selectConversation($("a[mailbox-navigation='" + contact.nav + "']")); - } - }; - $scope.fetchConversation = function (contact) { // If contact is not null, we will fetch a conversation for a new contact if (contact != null) {