mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-09 08:56:10 +00:00
Add notification for unread messages for all conversations.
WARN: one bug is present, and we need to handle it differently
This commit is contained in:
parent
690421713d
commit
da948926ab
22
js/script.js
22
js/script.js
@ -14,7 +14,8 @@ var selectedConversation = null;
|
|||||||
var curPhoneNumber = null;
|
var curPhoneNumber = null;
|
||||||
var curContactName = '';
|
var curContactName = '';
|
||||||
var lastMsgDate = 0;
|
var lastMsgDate = 0;
|
||||||
var unreadCount = 0;
|
var unreadCountCurrentConv = 0;
|
||||||
|
var unreadCountAllConv = 0;
|
||||||
var originalTitle = document.title;
|
var originalTitle = document.title;
|
||||||
|
|
||||||
$.urlParam = function(name){
|
$.urlParam = function(name){
|
||||||
@ -48,9 +49,9 @@ var refreshConversation = function() {
|
|||||||
$('#app-content').scrollTop(1E10);
|
$('#app-content').scrollTop(1E10);
|
||||||
// This will blink the tab because there is new messages
|
// This will blink the tab because there is new messages
|
||||||
if (document.hasFocus() == false) {
|
if (document.hasFocus() == false) {
|
||||||
unreadCount += fmt[0];
|
unreadCountCurrentConv += fmt[0];
|
||||||
document.title = originalTitle + " (" + unreadCount + ")";
|
document.title = originalTitle + " (" + unreadCountCurrentConv + ")";
|
||||||
desktopNotify(unreadCount + " unread message(s) in conversation with " + curContactName);
|
desktopNotify(unreadCountCurrentConv + " unread message(s) in conversation with " + curContactName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ var refreshConversation = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var checkNewMessages = function() {
|
var checkNewMessages = function() {
|
||||||
|
unreadCountAllConv = 0;
|
||||||
$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'),
|
$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'),
|
||||||
{ 'lastDate': lastMsgDate },
|
{ 'lastDate': lastMsgDate },
|
||||||
function(jsondata, status) {
|
function(jsondata, status) {
|
||||||
@ -82,16 +84,20 @@ var checkNewMessages = function() {
|
|||||||
fn = jsondata['contacts'][id];
|
fn = jsondata['contacts'][id];
|
||||||
peerLabel = fn;
|
peerLabel = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($.inArray(peerLabel, bufferedContacts) == -1) {
|
if ($.inArray(peerLabel, bufferedContacts) == -1) {
|
||||||
$("a[mailbox-label='" + peerLabel + "']").remove();
|
$("a[mailbox-label='" + peerLabel + "']").remove();
|
||||||
peerListBuf = '<li><a href="#" mailbox-navigation="' + idxVal2 + '" style="font-weight: bold;" mailbox-label="' + peerLabel + '">' + peerLabel + ' (' + val + ')</a></li>';
|
peerListBuf = '<li><a href="#" mailbox-navigation="' + idxVal2 + '" style="font-weight: bold;" mailbox-label="' + peerLabel + '">' + peerLabel + ' (' + val + ')</a></li>';
|
||||||
$('#app-mailbox-peers ul').prepend(peerListBuf);
|
$('#app-mailbox-peers ul').prepend(peerListBuf);
|
||||||
bufferedContacts.push(peerLabel);
|
bufferedContacts.push(peerLabel);
|
||||||
|
|
||||||
|
// Re-set conversation because we reload the element
|
||||||
if (idxVal == curPhoneNumber) {
|
if (idxVal == curPhoneNumber) {
|
||||||
changeSelectedConversation($("a[mailbox-navigation='" + idxVal + "']"));
|
changeSelectedConversation($("a[mailbox-navigation='" + idxVal + "']"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unreadCountAllConv += parseInt(val);
|
||||||
|
|
||||||
// Now bind the events when we click on the phone number
|
// Now bind the events when we click on the phone number
|
||||||
$("a[mailbox-navigation='" + idxVal + "']").on('click', function (event) {
|
$("a[mailbox-navigation='" + idxVal + "']").on('click', function (event) {
|
||||||
var phoneNumber = $(this).attr('mailbox-navigation');
|
var phoneNumber = $(this).attr('mailbox-navigation');
|
||||||
@ -100,12 +106,16 @@ var checkNewMessages = function() {
|
|||||||
// phoneNumber must exist
|
// phoneNumber must exist
|
||||||
if (phoneNumber != null) {
|
if (phoneNumber != null) {
|
||||||
fetchConversation(phoneNumber);
|
fetchConversation(phoneNumber);
|
||||||
changeSelectedConversation($(this));
|
unreadCountAllConv += val;changeSelectedConversation($(this));
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (unreadCountAllConv > 0) {
|
||||||
|
desktopNotify(unreadCountAllConv + " unread message(s) for all conversations");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -348,7 +358,7 @@ function desktopNotify(msg) {
|
|||||||
|
|
||||||
// reset count and title
|
// reset count and title
|
||||||
window.onfocus = function () {
|
window.onfocus = function () {
|
||||||
unreadCount = 0;
|
unreadCountCurrentConv = 0;
|
||||||
document.title = originalTitle;
|
document.title = originalTitle;
|
||||||
};
|
};
|
||||||
})(jQuery, OC);
|
})(jQuery, OC);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user