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

Prefix global variables with g_

This commit is contained in:
Loic Blot 2015-06-08 20:06:00 +00:00
parent 3998f82331
commit 54dbdc1011

View File

@ -10,17 +10,17 @@
// Some global vars to improve performances // Some global vars to improve performances
var selectedConversation = null; var g_selectedConversation = null;
var curPhoneNumber = null; var g_curPhoneNumber = null;
var curContactName = ''; var g_curContactName = '';
var lastMsgDate = 0; var g_lastMsgDate = 0;
var unreadCountCurrentConv = 0; var g_unreadCountCurrentConv = 0;
var unreadCountAllConv = 0; var g_unreadCountAllConv = 0;
var unreadCountNotifStep = 12; var g_unreadCountNotifStep = 12;
var lastUnreadCountAllConv = 0; var g_lastUnreadCountAllConv = 0;
var originalTitle = document.title; var g_originalTitle = document.title;
var ulContactList = $('.contact-list'); var g_ulContactList = $('.contact-list');
var app = angular.module('OcSms', []); var app = angular.module('OcSms', []);
function inArray(val, arr) { function inArray(val, arr) {
@ -73,7 +73,7 @@ $.urlParam = function(name){
var refreshConversation = function() { var refreshConversation = function() {
// if no conversation selected, then don't fetch page // if no conversation selected, then don't fetch page
if (curPhoneNumber == null) { if (g_curPhoneNumber == null) {
if ($('#app-content-header').is(':visible')) { if ($('#app-content-header').is(':visible')) {
$('#app-content-header').hide(); $('#app-content-header').hide();
} }
@ -81,8 +81,8 @@ var refreshConversation = function() {
} }
$.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'), $.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'),
{ {
'phoneNumber': curPhoneNumber, 'phoneNumber': g_curPhoneNumber,
"lastDate": lastMsgDate "lastDate": g_lastMsgDate
}, },
function(jsondata, status) { function(jsondata, status) {
var fmt = formatConversation(jsondata); var fmt = formatConversation(jsondata);
@ -92,9 +92,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) {
unreadCountCurrentConv += fmt[0]; g_unreadCountCurrentConv += fmt[0];
document.title = originalTitle + " (" + unreadCountCurrentConv + ")"; document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
desktopNotify(unreadCountCurrentConv + " unread message(s) in conversation with " + curContactName); desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName);
} }
} }
@ -108,9 +108,9 @@ var refreshConversation = function() {
}; };
var checkNewMessages = function() { var checkNewMessages = function() {
unreadCountAllConv = 0; g_unreadCountAllConv = 0;
$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'), $.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'),
{ 'lastDate': lastMsgDate }, { 'lastDate': g_lastMsgDate },
function(jsondata, status) { function(jsondata, status) {
var peerListBuf = ''; var peerListBuf = '';
var bufferedContacts = []; var bufferedContacts = [];
@ -137,15 +137,15 @@ var checkNewMessages = function() {
peerListBuf += '></div><a href="#" ng-click="loadConversation(' + idxVal2 + ');" mailbox-navigation="' + peerListBuf += '></div><a href="#" ng-click="loadConversation(' + idxVal2 + ');" mailbox-navigation="' +
idxVal2 + '" style="font-weight: bold;" mailbox-label="' + peerLabel + '">' + peerLabel + ' (' + val + ')</a></li>'; idxVal2 + '" style="font-weight: bold;" mailbox-label="' + peerLabel + '">' + peerLabel + ' (' + val + ')</a></li>';
ulContactList.prepend(peerListBuf); g_ulContactList.prepend(peerListBuf);
bufferedContacts.push(peerLabel); bufferedContacts.push(peerLabel);
// Re-set conversation because we reload the element // Re-set conversation because we reload the element
if (idxVal == curPhoneNumber) { if (idxVal == g_curPhoneNumber) {
changeSelectedConversation($("a[mailbox-navigation='" + idxVal + "']")); changeSelectedConversation($("a[mailbox-navigation='" + idxVal + "']"));
} }
unreadCountAllConv += parseInt(val); g_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) {
@ -155,7 +155,7 @@ var checkNewMessages = function() {
// phoneNumber must exist // phoneNumber must exist
if (phoneNumber != null) { if (phoneNumber != null) {
fetchConversation(phoneNumber); fetchConversation(phoneNumber);
unreadCountAllConv += val; g_unreadCountAllConv += val;
changeSelectedConversation($(this)); changeSelectedConversation($(this));
} }
event.preventDefault(); event.preventDefault();
@ -169,19 +169,19 @@ var checkNewMessages = function() {
* there is new messages in all conversations * there is new messages in all conversations
*/ */
if (unreadCountNotifStep > 0) { if (g_unreadCountNotifStep > 0) {
unreadCountNotifStep--; g_unreadCountNotifStep--;
} }
if (unreadCountAllConv > 0) { if (g_unreadCountAllConv > 0) {
/* /*
* We notify user every two minutes for all messages * We notify user every two minutes for all messages
* or if unreadCount changes * or if unreadCount changes
*/ */
if (unreadCountNotifStep == 0 || lastUnreadCountAllConv != unreadCountAllConv) { if (g_unreadCountNotifStep == 0 || g_lastUnreadCountAllConv != g_unreadCountAllConv) {
desktopNotify(unreadCountAllConv + " unread message(s) for all conversations"); desktopNotify(g_unreadCountAllConv + " unread message(s) for all conversations");
unreadCountNotifStep = 12; g_unreadCountNotifStep = 12;
lastUnreadCountAllConv = unreadCountAllConv; g_lastUnreadCountAllConv = g_unreadCountAllConv;
} }
} }
} }
@ -219,12 +219,12 @@ function fetchConversation(phoneNumber) {
conversationBuf += '<div class="msg-endtag"></div>'; conversationBuf += '<div class="msg-endtag"></div>';
if (typeof jsondata['contactName'] == 'undefined' || jsondata['contactName'] == '') { if (typeof jsondata['contactName'] == 'undefined' || jsondata['contactName'] == '') {
$('#ocsms-phone-label').html(phoneNumberLabel); $('#ocsms-phone-label').html(phoneNumberLabel);
curContactName = phoneNumberLabel; g_curContactName = phoneNumberLabel;
$('#ocsms-phone-opt-number').html(''); $('#ocsms-phone-opt-number').html('');
} }
else { else {
$('#ocsms-phone-label').html(jsondata['contactName']); $('#ocsms-phone-label').html(jsondata['contactName']);
curContactName = jsondata['contactName']; g_curContactName = jsondata['contactName'];
$('#ocsms-phone-opt-number').html(phoneNumberLabel); $('#ocsms-phone-opt-number').html(phoneNumberLabel);
} }
@ -237,7 +237,7 @@ function fetchConversation(phoneNumber) {
$('#app-content-wrapper').html(conversationBuf); $('#app-content-wrapper').html(conversationBuf);
$('#app-content').scrollTop(1E10); $('#app-content').scrollTop(1E10);
curPhoneNumber = phoneNumber; g_curPhoneNumber = phoneNumber;
} }
); );
} }
@ -269,8 +269,8 @@ function formatConversation(jsondata) {
// Store the greater msg date for refresher // Store the greater msg date for refresher
// Note: we divide by 100 because number compare too large integers // Note: we divide by 100 because number compare too large integers
if ((id/100) > (lastMsgDate/100)) { if ((id/100) > (g_lastMsgDate/100)) {
lastMsgDate = id; g_lastMsgDate = id;
} }
// Multiplicate ID to permit date to use it properly // Multiplicate ID to permit date to use it properly
@ -303,13 +303,13 @@ function changeSelectedConversation(item) {
return; return;
} }
if (selectedConversation != null) { if (g_selectedConversation != null) {
selectedConversation.parent().removeClass('selected'); g_selectedConversation.parent().removeClass('selected');
} }
selectedConversation = item; g_selectedConversation = item;
selectedConversation.parent().addClass('selected'); g_selectedConversation.parent().addClass('selected');
selectedConversation.css("font-weight", "normal"); g_selectedConversation.css("font-weight", "normal");
selectedConversation.html(selectedConversation.attr("mailbox-label")); g_selectedConversation.html(g_selectedConversation.attr("mailbox-label"));
} }
function fetchInitialPeerList(jsondata) { function fetchInitialPeerList(jsondata) {
@ -336,7 +336,7 @@ function fetchInitialPeerList(jsondata) {
} }
}); });
lastMsgDate = jsondata["lastRead"]; g_lastMsgDate = jsondata["lastRead"];
} }
function initDesktopNotifies() { function initDesktopNotifies() {
@ -382,7 +382,7 @@ function fetchInitialSettings() {
(function ($, OC) { (function ($, OC) {
$(document).ready(function () { $(document).ready(function () {
// Register real title // Register real title
originalTitle = document.title; g_originalTitle = document.title;
// Now bind the events when we click on the phone number // Now bind the events when we click on the phone number
$.getJSON(OC.generateUrl('/apps/ocsms/get/peerlist'), function(jsondata, status) { $.getJSON(OC.generateUrl('/apps/ocsms/get/peerlist'), function(jsondata, status) {
@ -412,7 +412,7 @@ function fetchInitialSettings() {
// reset count and title // reset count and title
window.onfocus = function () { window.onfocus = function () {
unreadCountCurrentConv = 0; g_unreadCountCurrentConv = 0;
document.title = originalTitle; document.title = g_originalTitle;
}; };
})(jQuery, OC); })(jQuery, OC);