mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 07:56:23 +00:00
rename app.js to legacy.js, move globals to app.js in Sms object and helpers to a dedicated file
This commit is contained in:
parent
4f01b5c467
commit
20b77148c7
2
js/app.min.js
vendored
2
js/app.min.js
vendored
File diff suppressed because one or more lines are too long
7
js/devel/README.md
Normal file
7
js/devel/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Generate bundle
|
||||
|
||||
Use uglifyjs to generate app.min.js bundle
|
||||
|
||||
```
|
||||
uglifyjs devel/*.js > app.min.js
|
||||
```
|
45
js/devel/app.js
Normal file
45
js/devel/app.js
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Nextcloud - Phone Sync
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @copyright Loic Blot 2014-2017
|
||||
*/
|
||||
|
||||
var Sms = {
|
||||
selectedConversation: null,
|
||||
unreadCountCurrentConv: 0,
|
||||
unreadCountAllConv: 0,
|
||||
unreadCountNotifStep: 12,
|
||||
lastUnreadCountAllConv: 0,
|
||||
originalTitle: document.title
|
||||
};
|
||||
|
||||
var ContactRenderer = {
|
||||
generateColor: function (input) {
|
||||
if (typeof input === 'undefined') {
|
||||
return '';
|
||||
}
|
||||
// Check if core has the new color generator
|
||||
if (typeof input.toHsl === 'function') {
|
||||
var hsl = input.toHsl();
|
||||
return 'hsl(' + hsl[0] + ', ' + hsl[1] + '%, ' + hsl[2] + '%)';
|
||||
} else {
|
||||
// If not, we use the old one
|
||||
/* global md5 */
|
||||
var hash = md5(input).substring(0, 4),
|
||||
maxRange = parseInt('ffff', 16),
|
||||
hue = parseInt(hash, 16) / maxRange * 256;
|
||||
return 'hsl(' + hue + ', 90%, 65%)';
|
||||
}
|
||||
},
|
||||
generateFirstCharacter: function (input) {
|
||||
if (input.charAt(0) === '+') {
|
||||
return '#';
|
||||
}
|
||||
|
||||
return input.charAt(0);
|
||||
}
|
||||
};
|
29
js/devel/helpers.js
Normal file
29
js/devel/helpers.js
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Nextcloud - Phone Sync
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @copyright Loic Blot 2014-2017
|
||||
*/
|
||||
|
||||
function inArray(val, arr) {
|
||||
return ($.inArray(val, arr) !== -1);
|
||||
}
|
||||
|
||||
function arrayUnique(arr) {
|
||||
return arr.filter(function (item, i, arr) {
|
||||
return i === arr.indexOf(item);
|
||||
});
|
||||
}
|
||||
|
||||
function toBool(str) {
|
||||
if (str === "true") {
|
||||
return true;
|
||||
}
|
||||
else if (str === "false") {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
@ -8,37 +8,8 @@
|
||||
* @copyright Loic Blot 2014-2017
|
||||
*/
|
||||
|
||||
|
||||
// Some global vars to improve performances
|
||||
var g_selectedConversation = null;
|
||||
var g_unreadCountCurrentConv = 0;
|
||||
var g_unreadCountAllConv = 0;
|
||||
var g_unreadCountNotifStep = 12;
|
||||
var g_lastUnreadCountAllConv = 0;
|
||||
var g_originalTitle = document.title;
|
||||
|
||||
var app = angular.module('OcSms', []);
|
||||
|
||||
function inArray(val, arr) {
|
||||
return ($.inArray(val, arr) !== -1);
|
||||
}
|
||||
|
||||
function arrayUnique(arr) {
|
||||
return arr.filter(function (item, i, arr) {
|
||||
return i === arr.indexOf(item);
|
||||
});
|
||||
}
|
||||
|
||||
function toBool(str) {
|
||||
if (str === "true") {
|
||||
return true;
|
||||
}
|
||||
else if (str === "false") {
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
app.directive('toInt', function () {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
@ -52,33 +23,11 @@ app.directive('toInt', function() {
|
||||
|
||||
// Imported from contact app
|
||||
app.filter('peerColor', function () {
|
||||
return function(input) {
|
||||
if (typeof input === 'undefined') {
|
||||
return '';
|
||||
}
|
||||
// Check if core has the new color generator
|
||||
if (typeof input.toHsl === 'function') {
|
||||
var hsl = input.toHsl();
|
||||
return 'hsl('+hsl[0]+', '+hsl[1]+'%, '+hsl[2]+'%)';
|
||||
} else {
|
||||
// If not, we use the old one
|
||||
/* global md5 */
|
||||
var hash = md5(input).substring(0, 4),
|
||||
maxRange = parseInt('ffff', 16),
|
||||
hue = parseInt(hash, 16) / maxRange * 256;
|
||||
return 'hsl(' + hue + ', 90%, 65%)';
|
||||
}
|
||||
};
|
||||
return ContactRenderer.generateColor;
|
||||
});
|
||||
|
||||
app.filter('firstCharacter', function () {
|
||||
return function(input) {
|
||||
if (input.charAt(0) === '+') {
|
||||
return '#';
|
||||
}
|
||||
|
||||
return input.charAt(0);
|
||||
};
|
||||
return ContactRenderer.generateFirstCharacter;
|
||||
});
|
||||
|
||||
|
||||
@ -206,9 +155,9 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
$('#app-content').scrollTop(1E10);
|
||||
// This will blink the tab because there is new messages
|
||||
if (document.hasFocus() === false) {
|
||||
g_unreadCountCurrentConv += parseInt(fmt[0]);
|
||||
document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
|
||||
$scope.desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + $scope.selectedContact.label);
|
||||
Sms.unreadCountCurrentConv += parseInt(fmt[0]);
|
||||
document.title = Sms.originalTitle + " (" + Sms.unreadCountCurrentConv + ")";
|
||||
$scope.desktopNotify(Sms.unreadCountCurrentConv + " unread message(s) in conversation with " + $scope.selectedContact.label);
|
||||
}
|
||||
|
||||
}
|
||||
@ -218,7 +167,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
);
|
||||
};
|
||||
$scope.checkNewMessages = function () {
|
||||
g_unreadCountAllConv = 0;
|
||||
Sms.unreadCountAllConv = 0;
|
||||
$.getJSON($scope.generateUrl('/front-api/v1/new_messages'),
|
||||
{'lastDate': $scope.lastContactListMsgDate},
|
||||
function (jsondata, status) {
|
||||
@ -259,7 +208,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
changeSelectedConversation($("a[mailbox-navigation='" + id + "']"));
|
||||
}
|
||||
|
||||
g_unreadCountAllConv += parseInt(val);
|
||||
Sms.unreadCountAllConv += parseInt(val);
|
||||
}
|
||||
});
|
||||
|
||||
@ -269,19 +218,19 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
* there is new messages in all conversations
|
||||
*/
|
||||
|
||||
if (g_unreadCountNotifStep > 0) {
|
||||
g_unreadCountNotifStep--;
|
||||
if (Sms.unreadCountNotifStep > 0) {
|
||||
Sms.unreadCountNotifStep--;
|
||||
}
|
||||
|
||||
if (g_unreadCountAllConv > 0) {
|
||||
if (Sms.unreadCountAllConv > 0) {
|
||||
/*
|
||||
* We notify user every two minutes for all messages
|
||||
* or if unreadCount changes
|
||||
*/
|
||||
if (g_unreadCountNotifStep === 0 || g_lastUnreadCountAllConv !== g_unreadCountAllConv) {
|
||||
$scope.desktopNotify(g_unreadCountAllConv + " unread message(s) for all conversations");
|
||||
g_unreadCountNotifStep = 12;
|
||||
g_lastUnreadCountAllConv = g_unreadCountAllConv;
|
||||
if (Sms.unreadCountNotifStep === 0 || Sms.lastUnreadCountAllConv !== Sms.unreadCountAllConv) {
|
||||
$scope.desktopNotify(Sms.unreadCountAllConv + " unread message(s) for all conversations");
|
||||
Sms.unreadCountNotifStep = 12;
|
||||
Sms.lastUnreadCountAllConv = Sms.unreadCountAllConv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -475,7 +424,12 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
$scope.lastConvMessageDate = id;
|
||||
|
||||
// Multiplicate ID to permit date to use it properly
|
||||
$scope.addConversationMessage({'id': id, 'type': msgClass, 'date': new Date(id * 1), 'content': vals['msg']});
|
||||
$scope.addConversationMessage({
|
||||
'id': id,
|
||||
'type': msgClass,
|
||||
'date': new Date(id * 1),
|
||||
'content': vals['msg']
|
||||
});
|
||||
buf = true;
|
||||
msgCount++;
|
||||
}
|
||||
@ -512,7 +466,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
||||
|
||||
$timeout(function () {
|
||||
// Register real title
|
||||
g_originalTitle = document.title;
|
||||
Sms.originalTitle = document.title;
|
||||
|
||||
// Now bind the events when we click on the phone number
|
||||
$.getJSON($scope.generateUrl('/front-api/v1/peerlist'), function (jsondata, status) {
|
||||
@ -555,20 +509,20 @@ function changeSelectedConversation(item) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_selectedConversation != null) {
|
||||
g_selectedConversation.parent().removeClass('selected');
|
||||
if (Sms.selectedConversation != null) {
|
||||
Sms.selectedConversation.parent().removeClass('selected');
|
||||
}
|
||||
g_selectedConversation = item;
|
||||
g_selectedConversation.parent().addClass('selected');
|
||||
g_selectedConversation.css("font-weight", "normal");
|
||||
g_selectedConversation.html(g_selectedConversation.attr("mailbox-label"));
|
||||
Sms.selectedConversation = item;
|
||||
Sms.selectedConversation.parent().addClass('selected');
|
||||
Sms.selectedConversation.css("font-weight", "normal");
|
||||
Sms.selectedConversation.html(Sms.selectedConversation.attr("mailbox-label"));
|
||||
}
|
||||
|
||||
(function ($, OC) {
|
||||
// reset count and title
|
||||
window.onfocus = function () {
|
||||
g_unreadCountCurrentConv = 0;
|
||||
document.title = g_originalTitle;
|
||||
Sms.unreadCountCurrentConv = 0;
|
||||
document.title = Sms.originalTitle;
|
||||
};
|
||||
})(jQuery, OC);
|
||||
|
Loading…
x
Reference in New Issue
Block a user