mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 07:56:23 +00:00
Port refreshConversation to conversation.js
This commit is contained in:
parent
80c4c2e3c2
commit
a7a15af70a
@ -15,7 +15,8 @@ var Conversation = new Vue({
|
||||
isConvLoading: false,
|
||||
messages: [],
|
||||
lastConvMessageDate: 0,
|
||||
totalMessageCount: 0
|
||||
totalMessageCount: 0,
|
||||
refreshIntervalId: null
|
||||
},
|
||||
methods: {
|
||||
fetch: function (contact) {
|
||||
@ -54,6 +55,39 @@ var Conversation = new Vue({
|
||||
self.isConvLoading = false;
|
||||
|
||||
$('#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
|
||||
}, function (data) {
|
||||
self.messages.splice(i, 1);
|
||||
if (self.messages.length === 0) {
|
||||
self.clear();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -125,15 +162,20 @@ var Conversation = new Vue({
|
||||
removeConversation: function () {
|
||||
var self = this;
|
||||
$.post(Sms.generateURL('/delete/conversation'), {"contact": self.selectedContact.label}, function (data) {
|
||||
// Reinit main window
|
||||
self.selectedContact.label = "";
|
||||
self.selectedContact.opt_numbers = "";
|
||||
self.selectedContact.avatar = undefined;
|
||||
ContactList.removeContact(self.selectedContact);
|
||||
self.messages = [];
|
||||
self.selectedContact = {};
|
||||
OC.Util.History.pushState('');
|
||||
self.clear();
|
||||
});
|
||||
},
|
||||
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: {
|
||||
|
@ -16,33 +16,8 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
{text: "Send"}
|
||||
];
|
||||
|
||||
$scope.totalMessageCount = 0;
|
||||
$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 () {
|
||||
Sms.unreadCountAllConv = 0;
|
||||
$.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);
|
||||
|
||||
$timeout(function () {
|
||||
@ -134,7 +108,6 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
|
||||
SmsNotifications.init();
|
||||
$scope.checkNewMessages();
|
||||
$scope.refreshConversation();
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
@ -22,14 +22,18 @@ use \OCA\OcSms\Lib\CountryCodes;
|
||||
<div id="app-contacts-loader" class="icon-loading" v-if="isContactsLoading">
|
||||
</div>
|
||||
<div v-if="!isContactsLoading">
|
||||
<div class="contact-list-no-contact" v-if="orderedContacts.length == 0 && !isContactsLoading"><?php p($l->t('No contact found.'));?></div>
|
||||
<ul class="contact-list" v-if="orderedContacts.length > 0">
|
||||
<div class="contact-list-no-contact" 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="#">
|
||||
<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>
|
||||
<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>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="app-settings">
|
||||
@ -77,7 +81,7 @@ use \OCA\OcSms\Lib\CountryCodes;
|
||||
<div id="app-content-header" v-if="!isConvLoading && messages.length > 0"
|
||||
v-bind:style="{'backgroundColor': getContactColor(selectedContact.uid) }">
|
||||
<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>
|
||||
<div id="ocsms-contact-details">
|
||||
|
Loading…
x
Reference in New Issue
Block a user