1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 07:56:23 +00:00
ocsms/js/devel/conversation.js
2018-09-08 00:04:49 +02:00

64 lines
1.7 KiB
JavaScript

/**
* Nextcloud - Phone Sync
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @copyright Loic Blot 2014-2018
*/
var Conversation = 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);
}
);
}
}
});