1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

Port refreshConversation to conversation.js

This commit is contained in:
Loic Blot 2018-09-07 08:08:29 +02:00 committed by Loïc Blot
parent 80c4c2e3c2
commit a7a15af70a
3 changed files with 59 additions and 40 deletions

View File

@ -15,7 +15,8 @@ var Conversation = new Vue({
isConvLoading: false, isConvLoading: false,
messages: [], messages: [],
lastConvMessageDate: 0, lastConvMessageDate: 0,
totalMessageCount: 0 totalMessageCount: 0,
refreshIntervalId: null
}, },
methods: { methods: {
fetch: function (contact) { fetch: function (contact) {
@ -54,6 +55,39 @@ var Conversation = new Vue({
self.isConvLoading = false; self.isConvLoading = false;
$('#app-conversation').scrollTop(1E10); $('#app-conversation').scrollTop(1E10);
// If refreshInterval is already bound, clear previous
if (self.refreshIntervalId !== null) {
clearInterval(self.refreshIntervalId);
}
self.refreshIntervalId = setInterval(self.refresh, 10000);
}
);
},
refresh: function () {
var self = this;
$.getJSON(Sms.generateURL('/front-api/v1/conversation'),
{
'phoneNumber': Conversation.selectedContact.nav,
"lastDate": Conversation.lastConvMessageDate
},
function (jsondata, status) {
var fmt = self.formatConversation(jsondata);
var conversationBuf = fmt[1];
if (conversationBuf === true) {
$('#app-conversation').scrollTop(1E10);
// This will blink the tab because there is new messages
if (document.hasFocus() === false) {
Sms.unreadCountCurrentConv += parseInt(fmt[0]);
document.title = Sms.originalTitle + " (" + Sms.unreadCountCurrentConv + ")";
SmsNotifications.notify(Sms.unreadCountCurrentConv + " unread message(s) in conversation with "
+ Conversation.selectedContact.label);
}
}
self.totalMessageCount = jsondata['msgCount'] !== undefined ? parseInt(jsondata['msgCount']) : 0;
} }
); );
}, },
@ -117,6 +151,9 @@ var Conversation = new Vue({
"phoneNumber": this.selectedContact.label "phoneNumber": this.selectedContact.label
}, function (data) { }, function (data) {
self.messages.splice(i, 1); self.messages.splice(i, 1);
if (self.messages.length === 0) {
self.clear();
}
}); });
return; return;
} }
@ -125,15 +162,20 @@ var Conversation = new Vue({
removeConversation: function () { removeConversation: function () {
var self = this; var self = this;
$.post(Sms.generateURL('/delete/conversation'), {"contact": self.selectedContact.label}, function (data) { $.post(Sms.generateURL('/delete/conversation'), {"contact": self.selectedContact.label}, function (data) {
// Reinit main window self.clear();
self.selectedContact.label = "";
self.selectedContact.opt_numbers = "";
self.selectedContact.avatar = undefined;
ContactList.removeContact(self.selectedContact);
self.messages = [];
self.selectedContact = {};
OC.Util.History.pushState('');
}); });
},
clear: function () {
// Reinit main window
this.selectedContact.label = "";
this.selectedContact.opt_numbers = "";
this.selectedContact.avatar = undefined;
ContactList.removeContact(this.selectedContact);
this.messages = [];
this.selectedContact = {};
OC.Util.History.pushState('');
clearInterval(this.refreshIntervalId);
this.refreshIntervalId = null;
} }
}, },
computed: { computed: {

View File

@ -16,33 +16,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
{text: "Send"} {text: "Send"}
]; ];
$scope.totalMessageCount = 0;
$scope.lastSearch = ''; $scope.lastSearch = '';
$scope.refreshConversation = function () {
$.getJSON(Sms.generateURL('/ocsms/front-api/v1/conversation'),
{
'phoneNumber': Conversation.selectedContact.nav,
"lastDate": Conversation.lastConvMessageDate
},
function (jsondata, status) {
var fmt = $scope.formatConversation(jsondata);
var conversationBuf = fmt[1];
if (conversationBuf === true) {
$('#app-conversation').scrollTop(1E10);
// This will blink the tab because there is new messages
if (document.hasFocus() === false) {
Sms.unreadCountCurrentConv += parseInt(fmt[0]);
document.title = Sms.originalTitle + " (" + Sms.unreadCountCurrentConv + ")";
SmsNotifications.notify(Sms.unreadCountCurrentConv + " unread message(s) in conversation with " + Conversation.selectedContact.label);
}
}
$scope.totalMessageCount = jsondata['msgCount'] !== undefined ? parseInt(jsondata['msgCount']) : 0;
}
);
};
$scope.checkNewMessages = function () { $scope.checkNewMessages = function () {
Sms.unreadCountAllConv = 0; Sms.unreadCountAllConv = 0;
$.getJSON(Sms.generateURL('/front-api/v1/new_messages'), $.getJSON(Sms.generateURL('/front-api/v1/new_messages'),
@ -125,7 +100,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
} }
}); });
$interval($scope.refreshConversation, 10000);
$interval($scope.checkNewMessages, 10000); $interval($scope.checkNewMessages, 10000);
$timeout(function () { $timeout(function () {
@ -134,7 +108,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
SmsNotifications.init(); SmsNotifications.init();
$scope.checkNewMessages(); $scope.checkNewMessages();
$scope.refreshConversation();
}); });
} }
]); ]);

View File

@ -22,16 +22,20 @@ use \OCA\OcSms\Lib\CountryCodes;
<div id="app-contacts-loader" class="icon-loading" v-if="isContactsLoading"> <div id="app-contacts-loader" class="icon-loading" v-if="isContactsLoading">
</div> </div>
<div v-if="!isContactsLoading"> <div v-if="!isContactsLoading">
<div class="contact-list-no-contact" v-if="orderedContacts.length == 0 && !isContactsLoading"><?php p($l->t('No contact found.'));?></div> <div class="contact-list-no-contact" v-if="orderedContacts.length == 0">
<ul class="contact-list" v-if="orderedContacts.length > 0"> <?php p($l->t('No contact found.'));?>
</div>
<div v-if="orderedContacts.length > 0">
<ul class="contact-list">
<li v-for="contact in orderedContacts" peer-label="{{ contact.label }}" v-on:click="loadConversation(contact);" href="#"> <li v-for="contact in orderedContacts" peer-label="{{ contact.label }}" v-on:click="loadConversation(contact);" href="#">
<img class="ocsms-plavatar" v-bind:src="{{ contact.avatar }}" v-if="contact.avatar !== undefined" /> <img class="ocsms-plavatar" :src="contact.avatar" v-if="contact.avatar !== undefined" />
<div class="ocsms-plavatar" v-if="contact.avatar === undefined" v-bind:style="{'backgroundColor': getContactColor(contact.uid) }">{{ contact.label | firstCharacter }}</div> <div class="ocsms-plavatar" v-if="contact.avatar === undefined" v-bind:style="{'backgroundColor': getContactColor(contact.uid) }">{{ contact.label | firstCharacter }}</div>
<a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a> <a class="ocsms-plname" style="{{ contact.unread > 0 ? 'font-weight:bold;' : ''}}" mailbox-label="{{ contact.label }}" mailbox-navigation="{{ contact.nav }}">{{ contact.label }}{{ contact.unread > 0 ? ' (' + contact.unread + ') ' : '' }}</a>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
</div>
<div id="app-settings"> <div id="app-settings">
<div id="app-settings-header"> <div id="app-settings-header">
<button name="app settings" class="settings-button" data-apps-slide-toggle="#app-settings-content"> <button name="app settings" class="settings-button" data-apps-slide-toggle="#app-settings-content">
@ -77,7 +81,7 @@ use \OCA\OcSms\Lib\CountryCodes;
<div id="app-content-header" v-if="!isConvLoading && messages.length > 0" <div id="app-content-header" v-if="!isConvLoading && messages.length > 0"
v-bind:style="{'backgroundColor': getContactColor(selectedContact.uid) }"> v-bind:style="{'backgroundColor': getContactColor(selectedContact.uid) }">
<div id="ocsms-contact-avatar"> <div id="ocsms-contact-avatar">
<img class="ocsms-plavatar-big" v-if="selectedContact.avatar !== undefined" v-bind:src="{{ selectedContact.avatar }}" /> <img class="ocsms-plavatar-big" v-if="selectedContact.avatar !== undefined" :src="selectedContact.avatar" />
<div class="ocsms-plavatar-big" v-if="selectedContact.avatar === undefined">{{ selectedContact.label | firstCharacter }}</div> <div class="ocsms-plavatar-big" v-if="selectedContact.avatar === undefined">{{ selectedContact.label | firstCharacter }}</div>
</div> </div>
<div id="ocsms-contact-details"> <div id="ocsms-contact-details">