From 5e48961a52ce3d466106c02351ce24ee8ead5a20 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sat, 10 Nov 2018 18:27:54 +0100 Subject: [PATCH] js code quality --- js/devel/contactlist.js | 4 ++-- js/devel/conversation.js | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/js/devel/contactlist.js b/js/devel/contactlist.js index 16c03f3..2316776 100644 --- a/js/devel/contactlist.js +++ b/js/devel/contactlist.js @@ -31,8 +31,8 @@ var ContactList = new Vue({ this.lastTotalUnreadCount = 0; }, fetch: function () { - var self = this; - // Now bind the events when we click on the phone number + let self = this; + // Now bind the events when we click on the phone number $.getJSON(Sms.generateURL('/front-api/v1/peerlist'), function (jsondata, status) { // Use a buffer for better jQuery performance let bufferedContacts = []; diff --git a/js/devel/conversation.js b/js/devel/conversation.js index 7d100a7..7e0c9ac 100644 --- a/js/devel/conversation.js +++ b/js/devel/conversation.js @@ -29,14 +29,14 @@ var Conversation = new Vue({ this.messages = []; this.lastConvMessageDate = 0; - var self = this; - $.getJSON(Sms.generateURL('/front-api/v1/conversation'), {'phoneNumber': self.selectedContact.nav}, + let self = this; + $.getJSON(Sms.generateURL('/front-api/v1/conversation'), {'phoneNumber': self.selectedContact.nav}, function (jsondata, status) { - var phoneNumberLabel = self.selectedContact.nav; + let phoneNumberLabel = self.selectedContact.nav; - if (typeof jsondata['phoneNumbers'] !== 'undefined') { - var phoneNumberList = arrayUnique(jsondata['phoneNumbers']); - phoneNumberLabel = phoneNumberList.toString(); + if (typeof jsondata['phoneNumbers'] !== 'undefined') { + const phoneNumberList = arrayUnique(jsondata['phoneNumbers']); + phoneNumberLabel = phoneNumberList.toString(); } // Reinit messages before showing conversation @@ -97,11 +97,11 @@ var Conversation = new Vue({ // Return (int) msgCount, (str) htmlConversation formatConversation: function (jsondata) { // Improve jQuery performance - var buf = false; - // Improve JS performance - var msgClass = ''; - var msgCount = 0; - var self = this; + let buf = false; + // Improve JS performance + let msgClass = ''; + let msgCount = 0; + let self = this; $.each(jsondata["conversation"], function (id, vals) { if (vals["type"] == 1) { @@ -138,10 +138,11 @@ var Conversation = new Vue({ */ addConversationMessage: function (msg) { this.messages.push(msg); + console.log(this.messages); }, removeConversationMessage: function (msgId) { - var len = this.messages.length; - var self = this; + const len = this.messages.length; + let self = this; for (var i = 0; i < len; i++) { var curMsg = this.messages[i]; if (curMsg['id'] === msgId) {