1
0
mirror of https://github.com/nextcloud/ocsms.git synced 2026-08-21 21:32:59 +00:00

Contactlist should be ready now

This commit is contained in:
Loic Blot
2018-09-06 22:44:29 +02:00
committed by Loïc Blot
parent 7da623e334
commit ffdb597b1e
5 changed files with 225 additions and 83 deletions
+70 -31
View File
@@ -16,38 +16,77 @@ var ContactList = new Vue({
},
created: function () {
this.contacts = [];
var self = this;
// Now bind the events when we click on the phone number
$.getJSON(Sms.generateURL('/front-api/v1/peerlist'), function (jsondata, status) {
app.fetchInitialPeerList(jsondata);
var pnParam = $.urlParam('phonenumber');
if (pnParam != null) {
var urlPhoneNumber = decodeURIComponent(pnParam);
if (urlPhoneNumber != null) {
// If no contact when loading, creating a new contact from urlPhoneNumber
if (app.selectedContact.nav === undefined) {
app.selectedContact.label = urlPhoneNumber;
app.selectedContact.nav = urlPhoneNumber;
app.selectedContact.avatar = undefined;
// Now let's loop through the contact list and see if we can find the rest of the details
for (var i = 0; i < $scope.contacts.length; i++) {
if (self.contacts[i].nav === urlPhoneNumber) {
app.selectedContact = self.contacts[i];
break;
}
}
}
app.fetchConversation(app.selectedContact);
Sms.selectConversation($("a[mailbox-navigation='" + urlPhoneNumber + "']"));
}
}
});
this.fetch();
},
methods: {
fetch: function () {
var 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
var bufferedContacts = [];
Sms.photoVersion = jsondata["photo_version"];
$.each(jsondata['phonelist'], function (id, val) {
var peerLabel;
if (typeof jsondata['contacts'][id] === 'undefined') {
peerLabel = id;
}
else {
peerLabel = jsondata['contacts'][id];
}
if (!inArray(peerLabel, bufferedContacts)) {
var contactObj = {
'label': peerLabel,
'nav': id,
'unread': 0,
'lastmsg': parseInt(val)
};
if (typeof(jsondata['photos'][peerLabel]) !== 'undefined') {
contactObj['avatar'] = jsondata['photos'][peerLabel];
}
if (typeof jsondata['uids'][peerLabel] !== 'undefined') {
contactObj.uid = jsondata['uids'][peerLabel];
} else {
contactObj.uid = peerLabel;
}
ContactList.addContact(contactObj);
bufferedContacts.push(peerLabel);
}
});
self.isContactsLoading = false;
Sms.lastContactListMsgDate = jsondata["lastRead"];
Sms.lastMessageDate = jsondata["lastMessage"];
var pnParam = $.urlParam('phonenumber');
if (pnParam != null) {
var urlPhoneNumber = decodeURIComponent(pnParam);
if (urlPhoneNumber != null) {
// If no contact when loading, creating a new contact from urlPhoneNumber
if (app.selectedContact.nav === undefined) {
app.selectedContact.label = urlPhoneNumber;
app.selectedContact.nav = urlPhoneNumber;
app.selectedContact.avatar = undefined;
// Now let's loop through the contact list and see if we can find the rest of the details
for (var i = 0; i < self.contacts.length; i++) {
if (self.contacts[i].nav === urlPhoneNumber) {
app.selectedContact = self.contacts[i];
break;
}
}
}
app.fetchConversation(app.selectedContact);
Sms.selectConversation($("a[mailbox-navigation='" + urlPhoneNumber + "']"));
}
}
});
},
// Conversations
loadConversation: function (contact) {
OC.Util.History.pushState('phonenumber=' + contact.nav);
@@ -88,7 +127,7 @@ var ContactList = new Vue({
},
computed: {
orderedContacts: function () {
return _.orderBy(this.contacts, SmsSettings.contactOrderBy, SmsSettings.reverseContactOrder)
return _.orderBy(this.contacts, [SmsSettings.contactOrderBy], [SmsSettings.reverseContactOrder ? 'desc' : 'asc'])
}
}
});
-45
View File
@@ -229,51 +229,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
}
};
$scope.fetchInitialPeerList = function (jsondata) {
// Use a buffer for better jQuery performance
var bufferedContacts = [];
Sms.photoVersion = jsondata["photo_version"];
$.each(jsondata['phonelist'], function (id, val) {
var peerLabel;
if (typeof jsondata['contacts'][id] === 'undefined') {
peerLabel = id;
}
else {
peerLabel = jsondata['contacts'][id];
}
if (!inArray(peerLabel, bufferedContacts)) {
var contactObj = {
'label': peerLabel,
'nav': id,
'unread': 0,
'lastmsg': parseInt(val)
};
if (typeof(jsondata['photos'][peerLabel]) !== 'undefined') {
contactObj['avatar'] = jsondata['photos'][peerLabel];
}
if (typeof jsondata['uids'][peerLabel] !== 'undefined') {
contactObj.uid = jsondata['uids'][peerLabel];
} else {
contactObj.uid = peerLabel;
}
ContactList.addContact(contactObj);
bufferedContacts.push(peerLabel);
}
});
$scope.$apply(function () {
$scope.isContactsLoading = false;
});
Sms.lastContactListMsgDate = jsondata["lastRead"];
Sms.lastMessageDate = jsondata["lastMessage"];
};
// Return (int) msgCount, (str) htmlConversation
$scope.formatConversation = function (jsondata) {
// Improve jQuery performance