mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
Use angular to load conversations instead of a pure string buffer and show choose conversation only if no messages to show
This commit is contained in:
parent
fed6cb864a
commit
d075e7f58a
201
js/public/app.js
201
js/public/app.js
@ -40,7 +40,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
{text: "Send"}
|
{text: "Send"}
|
||||||
];
|
];
|
||||||
$scope.contacts = [];
|
$scope.contacts = [];
|
||||||
$scope.messages = []
|
$scope.messages = [];
|
||||||
$scope.sendCountry = function () {
|
$scope.sendCountry = function () {
|
||||||
$.post(OC.generateUrl('/apps/ocsms/set/country'),{'country': $('select[name=intl_phone]').val()});
|
$.post(OC.generateUrl('/apps/ocsms/set/country'),{'country': $('select[name=intl_phone]').val()});
|
||||||
};
|
};
|
||||||
@ -66,8 +66,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
phoneNumberLabel = phoneNumberList.toString();
|
phoneNumberLabel = phoneNumberList.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var conversationBuf = formatConversation(jsondata)[1];
|
$scope.formatConversation(jsondata);
|
||||||
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);
|
||||||
g_curContactName = phoneNumberLabel;
|
g_curContactName = phoneNumberLabel;
|
||||||
@ -89,13 +88,50 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
$('#ocsms-conversation-removal').show();
|
$('#ocsms-conversation-removal').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#app-content-wrapper').html(conversationBuf);
|
|
||||||
$('#app-content').scrollTop(1E10);
|
$('#app-content').scrollTop(1E10);
|
||||||
|
|
||||||
g_curPhoneNumber = phoneNumber;
|
g_curPhoneNumber = phoneNumber;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
$scope.refreshConversation = function() {
|
||||||
|
// if no conversation selected, then don't fetch page
|
||||||
|
if (g_curPhoneNumber == null) {
|
||||||
|
if ($('#app-content-header').is(':visible')) {
|
||||||
|
$('#app-content-header').hide();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'),
|
||||||
|
{
|
||||||
|
'phoneNumber': g_curPhoneNumber,
|
||||||
|
"lastDate": g_lastMsgDate
|
||||||
|
},
|
||||||
|
function(jsondata, status) {
|
||||||
|
var fmt = $scope.formatConversation(jsondata);
|
||||||
|
conversationBuf = fmt[1];
|
||||||
|
if (conversationBuf == true) {
|
||||||
|
$('#app-content').scrollTop(1E10);
|
||||||
|
// This will blink the tab because there is new messages
|
||||||
|
if (document.hasFocus() == false) {
|
||||||
|
g_unreadCountCurrentConv += fmt[0];
|
||||||
|
document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
|
||||||
|
desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
setMessageCountInfo(jsondata);
|
||||||
|
if ($('#ocsms-conversation-removal').is(':hidden')) {
|
||||||
|
$('#ocsms-conversation-removal').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($('#app-content-header').is(':hidden')) {
|
||||||
|
$('#app-content-header').show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
$scope.checkNewMessages = function() {
|
$scope.checkNewMessages = function() {
|
||||||
g_unreadCountAllConv = 0;
|
g_unreadCountAllConv = 0;
|
||||||
$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'),
|
$.getJSON(OC.generateUrl('/apps/ocsms/get/new_messages'),
|
||||||
@ -247,7 +283,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
});
|
});
|
||||||
|
|
||||||
g_lastMsgDate = jsondata["lastRead"];
|
g_lastMsgDate = jsondata["lastRead"];
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.initDesktopNotifies = function () {
|
$scope.initDesktopNotifies = function () {
|
||||||
@ -260,9 +296,63 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
Notification.permission = permission;
|
Notification.permission = permission;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return (int) msgCount, (str) htmlConversation
|
||||||
|
$scope.formatConversation = function (jsondata) {
|
||||||
|
// Improve jQuery performance
|
||||||
|
var buf = false;
|
||||||
|
// Improve JS performance
|
||||||
|
var msgClass = '';
|
||||||
|
|
||||||
|
var msgCount = 0;
|
||||||
|
var formatedDate = '';
|
||||||
|
var formatedHour = '00';
|
||||||
|
var formatedMin = '00';
|
||||||
|
var months = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.',
|
||||||
|
'Oct.', 'Nov.', 'Dec.'];
|
||||||
|
|
||||||
|
$.each(jsondata["conversation"], function(id, vals) {
|
||||||
|
if (vals["type"] == 1) {
|
||||||
|
msgClass = "recv";
|
||||||
|
}
|
||||||
|
else if (vals["type"] == 2) {
|
||||||
|
msgClass = "sent";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msgClass = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the greater msg date for refresher
|
||||||
|
// Note: we divide by 100 because number compare too large integers
|
||||||
|
if ((id/100) > (g_lastMsgDate/100)) {
|
||||||
|
g_lastMsgDate = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplicate ID to permit date to use it properly
|
||||||
|
msgDate = new Date(id*1);
|
||||||
|
|
||||||
|
formatedHour = msgDate.getHours();
|
||||||
|
if (formatedHour < 10) {
|
||||||
|
formatedHour = '0' + formatedHour;
|
||||||
|
}
|
||||||
|
|
||||||
|
formatedMin = msgDate.getMinutes();
|
||||||
|
if (formatedMin < 10) {
|
||||||
|
formatedMin = '0' + formatedMin;
|
||||||
|
}
|
||||||
|
formatedDate = msgDate.getDate() + " " + months[msgDate.getMonth()] + " " +
|
||||||
|
formatedHour + ":" + formatedMin;
|
||||||
|
|
||||||
|
$scope.addConversationMessage({'id': id, 'type': msgClass, 'date': formatedDate, 'content': vals['msg']});
|
||||||
|
buf = true;
|
||||||
|
msgCount++;
|
||||||
|
|
||||||
|
});
|
||||||
|
return [msgCount,buf];
|
||||||
}
|
}
|
||||||
|
|
||||||
//$interval(refreshConversation, 10000);
|
$interval($scope.refreshConversation, 10000);
|
||||||
$interval($scope.checkNewMessages, 10000);
|
$interval($scope.checkNewMessages, 10000);
|
||||||
|
|
||||||
$timeout(function () {
|
$timeout(function () {
|
||||||
@ -305,46 +395,6 @@ $.urlParam = function(name){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var refreshConversation = function() {
|
|
||||||
// if no conversation selected, then don't fetch page
|
|
||||||
if (g_curPhoneNumber == null) {
|
|
||||||
if ($('#app-content-header').is(':visible')) {
|
|
||||||
$('#app-content-header').hide();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$.getJSON(OC.generateUrl('/apps/ocsms/get/conversation'),
|
|
||||||
{
|
|
||||||
'phoneNumber': g_curPhoneNumber,
|
|
||||||
"lastDate": g_lastMsgDate
|
|
||||||
},
|
|
||||||
function(jsondata, status) {
|
|
||||||
var fmt = formatConversation(jsondata);
|
|
||||||
conversationBuf = fmt[1];
|
|
||||||
if (conversationBuf != '') {
|
|
||||||
$('.msg-endtag').before(conversationBuf);
|
|
||||||
$('#app-content').scrollTop(1E10);
|
|
||||||
// This will blink the tab because there is new messages
|
|
||||||
if (document.hasFocus() == false) {
|
|
||||||
g_unreadCountCurrentConv += fmt[0];
|
|
||||||
document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
|
|
||||||
desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
setMessageCountInfo(jsondata);
|
|
||||||
if ($('#ocsms-conversation-removal').is(':hidden')) {
|
|
||||||
$('#ocsms-conversation-removal').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($('#app-content-header').is(':hidden')) {
|
|
||||||
$('#app-content-header').show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
function setMessageCountInfo(jsondata) {
|
function setMessageCountInfo(jsondata) {
|
||||||
if (typeof jsondata['msgCount'] != 'undefined') {
|
if (typeof jsondata['msgCount'] != 'undefined') {
|
||||||
if (jsondata['msgCount'] == 1) {
|
if (jsondata['msgCount'] == 1) {
|
||||||
@ -359,63 +409,6 @@ function setMessageCountInfo(jsondata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return (int) msgCount, (str) htmlConversation
|
|
||||||
function formatConversation(jsondata) {
|
|
||||||
// Improve jQuery performance
|
|
||||||
var buf = "";
|
|
||||||
// Improve JS performance
|
|
||||||
var msgClass = '';
|
|
||||||
|
|
||||||
var msgCount = 0;
|
|
||||||
var formatedDate = '';
|
|
||||||
var formatedHour = '00';
|
|
||||||
var formatedMin = '00';
|
|
||||||
var months = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.',
|
|
||||||
'Oct.', 'Nov.', 'Dec.'];
|
|
||||||
|
|
||||||
$.each(jsondata["conversation"], function(id, vals) {
|
|
||||||
if (vals["type"] == 1) {
|
|
||||||
msgClass = "msg-recv";
|
|
||||||
}
|
|
||||||
else if (vals["type"] == 2) {
|
|
||||||
msgClass = "msg-sent";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
msgClass = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the greater msg date for refresher
|
|
||||||
// Note: we divide by 100 because number compare too large integers
|
|
||||||
if ((id/100) > (g_lastMsgDate/100)) {
|
|
||||||
g_lastMsgDate = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiplicate ID to permit date to use it properly
|
|
||||||
msgDate = new Date(id*1);
|
|
||||||
|
|
||||||
formatedHour = msgDate.getHours();
|
|
||||||
if (formatedHour < 10) {
|
|
||||||
formatedHour = '0' + formatedHour;
|
|
||||||
}
|
|
||||||
|
|
||||||
formatedMin = msgDate.getMinutes();
|
|
||||||
if (formatedMin < 10) {
|
|
||||||
formatedMin = '0' + formatedMin;
|
|
||||||
}
|
|
||||||
formatedDate = msgDate.getDate() + " " + months[msgDate.getMonth()] + " " +
|
|
||||||
formatedHour + ":" + formatedMin;
|
|
||||||
|
|
||||||
buf += '<div><div class="' + msgClass + '"><div>' +
|
|
||||||
vals["msg"] + '</div>' +
|
|
||||||
'<div style="display: block;" id="ocsms-message-removal" class="icon-delete svn delete action" ng-click="removeConversationMessage(' + id + ');"></div>' +
|
|
||||||
'<div class="msg-date">' + formatedDate + '</div>' +
|
|
||||||
'</div><div class="msg-spacer"></div></div>';
|
|
||||||
msgCount++;
|
|
||||||
|
|
||||||
});
|
|
||||||
return [msgCount,buf];
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeSelectedConversation(item) {
|
function changeSelectedConversation(item) {
|
||||||
if (item === 'undefined' || item == null) {
|
if (item === 'undefined' || item == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -37,10 +37,10 @@ use \OCA\OcSms\Lib\CountryCodes;
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div id="app-content-wrapper">
|
<div id="app-content-wrapper">
|
||||||
<div id="ocsms-empty-conversation">Please choose a conversation on the left menu</div>
|
<div ng-show="messages.length == 0" id="ocsms-empty-conversation">Please choose a conversation on the left menu</div>
|
||||||
<div ng-repeat="message in messages">
|
<div ng-repeat="message in messages">
|
||||||
<div class="msg-{{ message.type }}">{{ message.content }}
|
<div class="msg-{{ message.type }}">
|
||||||
<div>
|
<div>{{ message.content }}</div>
|
||||||
<div style="display: block;" id="ocsms-message-removal" class="icon-delete svn delete action" ng-click="removeConversationMessage({{ message.id }});"></div>
|
<div style="display: block;" id="ocsms-message-removal" class="icon-delete svn delete action" ng-click="removeConversationMessage({{ message.id }});"></div>
|
||||||
<div class="msg-date">{{ message.date }}</div>
|
<div class="msg-date">{{ message.date }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user