mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 07:56:23 +00:00
Permit to disable notifications from app settings directly
This fixes issue #89
This commit is contained in:
parent
4827856fe2
commit
74928c8e64
@ -24,6 +24,7 @@ $application->registerRoutes($this, array('routes' => array(
|
|||||||
array('name' => 'settings#set_country', 'url'=> '/set/country', 'verb' => 'POST'),
|
array('name' => 'settings#set_country', 'url'=> '/set/country', 'verb' => 'POST'),
|
||||||
array('name' => 'settings#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'),
|
array('name' => 'settings#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'),
|
||||||
array('name' => 'settings#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'),
|
array('name' => 'settings#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'),
|
||||||
|
array('name' => 'settings#set_notification_state', 'url'=> '/set/notification_state', 'verb' => 'POST'),
|
||||||
|
|
||||||
array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1
|
array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1
|
||||||
array('name' => 'api#push', 'url' => '/push', 'verb' => 'POST'), // Android API
|
array('name' => 'api#push', 'url' => '/push', 'verb' => 'POST'), // Android API
|
||||||
|
@ -34,6 +34,22 @@ class SettingsController extends Controller {
|
|||||||
$this->configMapper = $cfgMapper;
|
$this->configMapper = $cfgMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
function getSettings() {
|
||||||
|
$country = $this->configMapper->getKey("country");
|
||||||
|
if ($country === false) {
|
||||||
|
return new JSONResponse(array("status" => false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JSONResponse(array("status" => true,
|
||||||
|
"country" => $country,
|
||||||
|
"message_limit" => $this->configMapper->getMessageLimit(),
|
||||||
|
"notification_state" => $this->configMapper->getNotificationState()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
@ -45,20 +61,6 @@ class SettingsController extends Controller {
|
|||||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
function getSettings() {
|
|
||||||
$country = $this->configMapper->getKey("country");
|
|
||||||
if ($country === false) {
|
|
||||||
return new JSONResponse(array("status" => false));
|
|
||||||
}
|
|
||||||
$message_limit = $this->configMapper->getKey("message_limit");
|
|
||||||
return new JSONResponse(array("status" => true,
|
|
||||||
"country" => $country,
|
|
||||||
"message_limit" => $message_limit));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
@ -67,4 +69,14 @@ class SettingsController extends Controller {
|
|||||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
function setNotificationState($notification) {
|
||||||
|
if (!is_numeric($notification) || $notification < 0 || $notification > 2) {
|
||||||
|
return new JSONResponse(array("status" => false, "msg" => "Invalid notification state"));
|
||||||
|
}
|
||||||
|
$this->configMapper->set("notification_state", $notification);
|
||||||
|
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,15 @@ class ConfigMapper extends Mapper {
|
|||||||
}
|
}
|
||||||
return $limit;
|
return $limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNotificationState () {
|
||||||
|
$st = $this->getKey("notification_state");
|
||||||
|
// Default state is 1/enabled
|
||||||
|
if ($st === false) {
|
||||||
|
$st = 1;
|
||||||
|
}
|
||||||
|
return $st;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -39,7 +39,10 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
$scope.buttons = [
|
$scope.buttons = [
|
||||||
{text: "Send"}
|
{text: "Send"}
|
||||||
];
|
];
|
||||||
|
|
||||||
$scope.setting_msgLimit = 100;
|
$scope.setting_msgLimit = 100;
|
||||||
|
$scope.setting_enableNotifications = 1;
|
||||||
|
|
||||||
$scope.contacts = [];
|
$scope.contacts = [];
|
||||||
$scope.messages = [];
|
$scope.messages = [];
|
||||||
$scope.totalMessageCount = 0;
|
$scope.totalMessageCount = 0;
|
||||||
@ -55,6 +58,14 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
$.post(OC.generateUrl('/apps/ocsms/set/msglimit'),{'limit': $scope.setting_msgLimit});
|
$.post(OC.generateUrl('/apps/ocsms/set/msglimit'),{'limit': $scope.setting_msgLimit});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.setNotificationSetting = function () {
|
||||||
|
if ($scope.setting_enableNotifications < 0 || $scope.setting_enableNotifications > 2) {
|
||||||
|
$scope.setting_enableNotifications = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.post(OC.generateUrl('/apps/ocsms/set/notification_state'),{'notification': $scope.setting_enableNotifications});
|
||||||
|
};
|
||||||
|
|
||||||
// Conversations
|
// Conversations
|
||||||
$scope.loadConversation = function (contact) {
|
$scope.loadConversation = function (contact) {
|
||||||
OC.Util.History.pushState('phonenumber=' + contact.nav);
|
OC.Util.History.pushState('phonenumber=' + contact.nav);
|
||||||
@ -128,7 +139,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
if (document.hasFocus() == false) {
|
if (document.hasFocus() == false) {
|
||||||
g_unreadCountCurrentConv += fmt[0];
|
g_unreadCountCurrentConv += fmt[0];
|
||||||
document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
|
document.title = g_originalTitle + " (" + g_unreadCountCurrentConv + ")";
|
||||||
desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName);
|
$scope.desktopNotify(g_unreadCountCurrentConv + " unread message(s) in conversation with " + g_curContactName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -199,7 +210,7 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
* or if unreadCount changes
|
* or if unreadCount changes
|
||||||
*/
|
*/
|
||||||
if (g_unreadCountNotifStep == 0 || g_lastUnreadCountAllConv != g_unreadCountAllConv) {
|
if (g_unreadCountNotifStep == 0 || g_lastUnreadCountAllConv != g_unreadCountAllConv) {
|
||||||
desktopNotify(g_unreadCountAllConv + " unread message(s) for all conversations");
|
$scope.desktopNotify(g_unreadCountAllConv + " unread message(s) for all conversations");
|
||||||
g_unreadCountNotifStep = 12;
|
g_unreadCountNotifStep = 12;
|
||||||
g_lastUnreadCountAllConv = g_unreadCountAllConv;
|
g_lastUnreadCountAllConv = g_unreadCountAllConv;
|
||||||
}
|
}
|
||||||
@ -276,8 +287,12 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
$.getJSON(OC.generateUrl('/apps/ocsms/get/settings'), function(jsondata, status) {
|
$.getJSON(OC.generateUrl('/apps/ocsms/get/settings'), function(jsondata, status) {
|
||||||
if (jsondata['status'] == true) {
|
if (jsondata['status'] == true) {
|
||||||
$('#sel_intl_phone').val(jsondata["country"]);
|
$('#sel_intl_phone').val(jsondata["country"]);
|
||||||
|
|
||||||
$('input[name=setting_msg_per_page]').val(jsondata["message_limit"]);
|
$('input[name=setting_msg_per_page]').val(jsondata["message_limit"]);
|
||||||
|
$('select[name=setting_notif]').val(jsondata["notification_state"]);
|
||||||
|
|
||||||
$scope.setting_msgLimit = jsondata["message_limit"];
|
$scope.setting_msgLimit = jsondata["message_limit"];
|
||||||
|
$scope.setting_enableNotifications = jsondata["notification_state"];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -355,6 +370,29 @@ app.controller('OcSmsController', ['$scope', '$interval', '$timeout', '$compile'
|
|||||||
return [msgCount,buf];
|
return [msgCount,buf];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.desktopNotify = function (msg) {
|
||||||
|
if ($scope.setting_enableNotifications == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!("Notification" in window)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (Notification.permission === "granted") {
|
||||||
|
new Notification("ownCloud SMS - " + msg);
|
||||||
|
}
|
||||||
|
else if (Notification.permission !== 'denied') {
|
||||||
|
Notification.requestPermission(function (permission) {
|
||||||
|
if(!('permission' in Notification)) {
|
||||||
|
Notification.permission = permission;
|
||||||
|
}
|
||||||
|
if (permission === "granted") {
|
||||||
|
new Notification("ownCloud SMS - " + msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$interval($scope.refreshConversation, 10000);
|
$interval($scope.refreshConversation, 10000);
|
||||||
$interval($scope.checkNewMessages, 10000);
|
$interval($scope.checkNewMessages, 10000);
|
||||||
|
|
||||||
@ -412,25 +450,6 @@ function changeSelectedConversation(item) {
|
|||||||
g_selectedConversation.html(g_selectedConversation.attr("mailbox-label"));
|
g_selectedConversation.html(g_selectedConversation.attr("mailbox-label"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function desktopNotify(msg) {
|
|
||||||
if (!("Notification" in window)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (Notification.permission === "granted") {
|
|
||||||
new Notification("ownCloud SMS - " + msg);
|
|
||||||
}
|
|
||||||
else if (Notification.permission !== 'denied') {
|
|
||||||
Notification.requestPermission(function (permission) {
|
|
||||||
if(!('permission' in Notification)) {
|
|
||||||
Notification.permission = permission;
|
|
||||||
}
|
|
||||||
if (permission === "granted") {
|
|
||||||
new Notification("ownCloud SMS - " + msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(function ($, OC) {
|
(function ($, OC) {
|
||||||
// reset count and title
|
// reset count and title
|
||||||
window.onfocus = function () {
|
window.onfocus = function () {
|
||||||
|
@ -20,16 +20,27 @@ use \OCA\OcSms\Lib\CountryCodes;
|
|||||||
<button name="app settings" class="settings-button" data-apps-slide-toggle="#app-settings-content"></button>
|
<button name="app settings" class="settings-button" data-apps-slide-toggle="#app-settings-content"></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="app-settings-content">
|
<div id="app-settings-content">
|
||||||
<label for="setting_msg_per_page">Max messages on tab loading:</label>
|
<div><label for="setting_msg_per_page">Max messages on tab loading</label>
|
||||||
<input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="setting_msgLimit" ng-change="setMessageLimit()"></input>
|
<input type="number" min="10" max="10000" name="setting_msg_per_page" ng-model="setting_msgLimit" ng-change="setMessageLimit()"></input>
|
||||||
<span class="label-invalid-input" ng-if="setting_msgLimit == null || setting_msgLimit == undefined">Invalid message limit</span>
|
<span class="label-invalid-input" ng-if="setting_msgLimit == null || setting_msgLimit == undefined">Invalid message limit</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div><label for="intl_phone">Country code</label>
|
||||||
<select name="intl_phone" id="sel_intl_phone">
|
<select name="intl_phone" id="sel_intl_phone">
|
||||||
<?php foreach (CountryCodes::$codes as $code => $cval) { ?>
|
<?php foreach (CountryCodes::$codes as $code => $cval) { ?>
|
||||||
<option><?php p($code); ?></option>
|
<option><?php p($code); ?></option>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</select>
|
</select>
|
||||||
<button class="new-button primary icon-checkmark-white" ng-click="sendCountry();"></button>
|
<button class="new-button primary icon-checkmark-white" ng-click="sendCountry();"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for"setting_notif">Notification settings</label>
|
||||||
|
<select name="setting_notif" ng-model="setting_enableNotifications" ng-change="setNotificationSetting()">
|
||||||
|
<option value="1">Enable</option>
|
||||||
|
<option value="0">Disable</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div> <!-- app-settings-content -->
|
</div> <!-- app-settings-content -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user