mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-08 16:36:25 +00:00
Set unread message number on the window title
This commit is contained in:
parent
4fa5867e33
commit
68d8cb40ff
23
js/script.js
23
js/script.js
@ -13,7 +13,8 @@
|
|||||||
var selectedConversation = null;
|
var selectedConversation = null;
|
||||||
var curPhoneNumber = null;
|
var curPhoneNumber = null;
|
||||||
var lastMsgDate = 0;
|
var lastMsgDate = 0;
|
||||||
var originalTitle = '';
|
var unreadCount = 0;
|
||||||
|
var originalTitle = document.title;
|
||||||
|
|
||||||
$.urlParam = function(name){
|
$.urlParam = function(name){
|
||||||
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
|
||||||
@ -39,13 +40,15 @@ var refreshConversation = function() {
|
|||||||
"lastDate": lastMsgDate
|
"lastDate": lastMsgDate
|
||||||
},
|
},
|
||||||
function(jsondata, status) {
|
function(jsondata, status) {
|
||||||
conversationBuf = formatConversation(jsondata);
|
var fmt = formatConversation(jsondata);
|
||||||
|
conversationBuf = fmt[1];
|
||||||
if (conversationBuf != '') {
|
if (conversationBuf != '') {
|
||||||
$('.msg-endtag').before(conversationBuf);
|
$('.msg-endtag').before(conversationBuf);
|
||||||
$('#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) {
|
||||||
document.title = originalTitle + " (new messages !)";
|
unreadCount += fmt[0];
|
||||||
|
document.title = originalTitle + " (" + unreadCount + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +82,7 @@ function fetchConversation(phoneNumber) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
conversationBuf = formatConversation(jsondata);
|
conversationBuf = formatConversation(jsondata)[1];
|
||||||
conversationBuf += '<div class="msg-endtag"></div>';
|
conversationBuf += '<div class="msg-endtag"></div>';
|
||||||
if (typeof jsondata['contactName'] == 'undefined') {
|
if (typeof jsondata['contactName'] == 'undefined') {
|
||||||
$('#ocsms-phone-label').html(phoneNumberLabel);
|
$('#ocsms-phone-label').html(phoneNumberLabel);
|
||||||
@ -102,11 +105,14 @@ function fetchConversation(phoneNumber) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return (int) msgCount, (str) htmlConversation
|
||||||
function formatConversation(jsondata) {
|
function formatConversation(jsondata) {
|
||||||
// Improve jQuery performance
|
// Improve jQuery performance
|
||||||
var buf = "";
|
var buf = "";
|
||||||
// Improve JS performance
|
// Improve JS performance
|
||||||
var msgClass = '';
|
var msgClass = '';
|
||||||
|
|
||||||
|
var msgCount = 0;
|
||||||
var formatedDate = '';
|
var formatedDate = '';
|
||||||
var formatedHour = '00';
|
var formatedHour = '00';
|
||||||
var formatedMin = '00';
|
var formatedMin = '00';
|
||||||
@ -147,10 +153,11 @@ function formatConversation(jsondata) {
|
|||||||
buf += '<div><div class="' + msgClass + '"><div>' +
|
buf += '<div><div class="' + msgClass + '"><div>' +
|
||||||
vals["msg"] + '</div><div class="msg-date">' +
|
vals["msg"] + '</div><div class="msg-date">' +
|
||||||
formatedDate + '</div></div><div class="msg-spacer"></div></div>';
|
formatedDate + '</div></div><div class="msg-spacer"></div></div>';
|
||||||
|
msgCount++;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return buf;
|
return [msgCount,buf];
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeSelectedConversation(item) {
|
function changeSelectedConversation(item) {
|
||||||
@ -236,4 +243,10 @@ function fetchInitialPeerList(jsondata) {
|
|||||||
});
|
});
|
||||||
setInterval(refreshConversation, 10000);
|
setInterval(refreshConversation, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// reset count and title
|
||||||
|
window.onfocus = function () {
|
||||||
|
unreadCount = 0;
|
||||||
|
document.title = originalTitle;
|
||||||
|
};
|
||||||
})(jQuery, OC);
|
})(jQuery, OC);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user