Skip to content

Commit 06d9c11

Browse files
committed
add silent notifs
1 parent 35d37fa commit 06d9c11

1 file changed

Lines changed: 53 additions & 19 deletions

File tree

core/class/mobile.class.php

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ public static function whoIsIq($iq)
8484
* Call by class notification
8585
* @return array
8686
*/
87-
public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version, $optionsNotif = [], $critical = false, $Iq = null, $specific = false)
87+
public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version, $optionsNotif = [], $critical = false, $Iq = null, $specific = false, $silent = false)
8888
{
8989
log::add('mobile', 'debug', '||┌──:fg-success: jsonPublish :/fg:──');
90+
log::add('mobile', 'debug', '||┌──:fg-success: PARAMS :/fg:──'.$silent);
9091
if (isset($Iq)) log::add('mobile', 'debug', '||| IQ for jsonPublish > ' . $Iq);
9192

9293
$dateNotif = date("Y-m-d H:i:s");
@@ -142,6 +143,20 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
142143
} else {
143144
$criticalString = 'false';
144145
}
146+
// $customData = [
147+
// 'title' => $titre,
148+
// 'body' => $message,
149+
// 'idNotif' => strval($idNotif),
150+
// 'channelId' => $channelId,
151+
// 'date' => $dateNotif,
152+
// 'critical' => $criticalString,
153+
// 'boxName' => $defaultName,
154+
// 'boxApiKey' => jeedom::getHardwareKey(),
155+
// "askParams" => $askParams,
156+
// 'textToDisplay' => 'none',
157+
// 'newDate' => $newDate,
158+
// 'horaireFormat' => $horaireFormat
159+
// ];
145160
$customData = [
146161
'title' => $titre,
147162
'body' => $message,
@@ -154,7 +169,8 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
154169
"askParams" => $askParams,
155170
'textToDisplay' => 'none',
156171
'newDate' => $newDate,
157-
'horaireFormat' => $horaireFormat
172+
'horaireFormat' => $horaireFormat,
173+
'silent' => $silent ? 'true' : 'false'
158174
];
159175

160176
$notification = [
@@ -171,14 +187,15 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
171187

172188
$apns = [
173189
'headers' => [
174-
'apns-priority' => '5',
190+
'apns-priority' => $silent ? '5' : '10',
175191
'apns-collapse-id' => strval($idNotif),
176-
'apns-push-type' => $channelId == 'specificChannel' ? 'background' : 'alert',
192+
'apns-push-type' => $silent ? 'background' : 'alert',
177193
'apns-topic' => 'com.jeedom.jeedomobile'
178194
],
179195
'payload' => [
180-
'aps' => [
196+
'aps' => array_merge([
181197
'content-available' => true,
198+
], $silent ? [] : [
182199
'sound' => [
183200
'name' => 'default',
184201
'critical' => $critical
@@ -188,21 +205,20 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
188205
'title' => $titre,
189206
'body' => $message
190207
]
191-
],
208+
]),
192209
'notifee_options' => [
193-
'ios' => [
194-
'sound' => 'default',
210+
'ios' => array_merge([
195211
'critical' => $critical,
196212
'foregroundPresentationOptions' => [
197-
'alert' => true,
198-
'badge' => true,
199-
'sound' => true
213+
'alert' => $silent ? false : true,
214+
'badge' => !$silent,
215+
'sound' => !$silent
200216
]
201-
]
217+
], $silent ? [] : ['sound' => 'default'])
202218
]
203219
]
204-
205220
];
221+
206222

207223

208224
if ($photo != null) {
@@ -280,11 +296,11 @@ public static function jsonPublish($os, $titre, $message, $type, $idNotif, $answ
280296
* Call by class execute
281297
* @return array
282298
*/
283-
public static function notification($arn, $os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version = 1, $optionsNotif = [], $critical = false, $Iq = null, $specific = false)
299+
public static function notification($arn, $os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version = 1, $optionsNotif = [], $critical = false, $Iq = null, $specific = false, $silent = false)
284300
{
285301
log::add('mobile', 'debug', '|┌──:fg-success: Notification en cours ! :/fg:──');
286302
if ($version == 2) {
287-
$publish = mobile::jsonPublish($os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version, $optionsNotif, $critical, $Iq, $specific);
303+
$publish = mobile::jsonPublish($os, $titre, $message, $type, $idNotif, $answer, $timeout, $token, $photo, $version, $optionsNotif, $critical, $Iq, $specific, $silent);
288304
if ($token != null) {
289305
if ($token == 'notifsBGDisabled') {
290306
log::add('mobile', 'debug', '|| [ERROR] NOTIFICATION NON ENVOYEE : LE SERVICE NOTIF EST DESACTIVE SUR LE TELEPHONE');
@@ -993,6 +1009,20 @@ public function postSave()
9931009
$cmd->setOrder($order);
9941010
$order++;
9951011
}
1012+
$cmd = $this->getCmd(null, 'notifSilent');
1013+
if (!is_object($cmd)) {
1014+
$cmd = new mobileCmd();
1015+
$cmd->setIsVisible(1);
1016+
$cmd->setName(__('Notification Silencieuse', __FILE__));
1017+
$cmd->setLogicalId('notifSilent');
1018+
$cmd->setGeneric_type('GENERIC_ACTION');
1019+
$cmd->setDisplay('icon', '<i class="icon far fa-comment"></i>');
1020+
$cmd->setDisplay('forceReturnLineAfter', 1);
1021+
$cmd->setDisplay('showIconAndNamedashboard', 1);
1022+
$cmd->setDisplay('showIconAndNamemobile', 1);
1023+
$cmd->setOrder($order);
1024+
$order++;
1025+
}
9961026
$cmd->setEqLogic_id($this->getId());
9971027
$cmd->setType('action');
9981028
$cmd->setSubType('message');
@@ -1182,13 +1212,17 @@ public function execute($_options = array())
11821212
}
11831213

11841214

1185-
if ($this->getLogicalId() == 'notif' || $this->getLogicalId() == 'notifCritical' || $this->getLogicalId() == 'notifSpecific') {
1215+
if ($this->getLogicalId() == 'notif' || $this->getLogicalId() == 'notifCritical' || $this->getLogicalId() == 'notifSpecific' || $this->getLogicalId() == 'notifSilent') {
11861216
$critical = false;
1217+
$silent = false;
11871218
$specific = false;
11881219
$defaultName = empty(config::byKey('name')) ? config::byKey('product_name') : config::byKey('name');
11891220
if ($this->getLogicalId() == 'notifCritical') {
11901221
$critical = true;
11911222
}
1223+
if ($this->getLogicalId() == 'notifSilent') {
1224+
$silent = true;
1225+
}
11921226
if ($this->getLogicalId() == 'notifSpecific') {
11931227
$specific = true;
11941228
$_options['title'] = 'getDeviceInformations';
@@ -1264,13 +1298,13 @@ public function execute($_options = array())
12641298
$keyFile = md5_file($newfile);
12651299
$url .= 'key=' . $keyFile . '&name=' . $nameFile;
12661300
log::add('mobile', 'debug', '| url > ' . $url);
1267-
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), $url, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific);
1301+
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), $url, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific, $silent);
12681302
} else {
1269-
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), null, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific);
1303+
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), null, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific, $silent);
12701304
}
12711305
}
12721306
} else {
1273-
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), null, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific);
1307+
mobile::notification($eqLogic->getConfiguration('notificationArn', null), $eqLogic->getConfiguration('type_mobile', null), $_options['title'], $_options['message'], $askType, $idNotif, $answer, $timeout, $eqLogic->getConfiguration('notificationRegistrationToken', null), null, $eqLogic->getConfiguration('appVersion', 1), $optionsNotif, $critical, $eqLogic->getLogicalId(), $specific, $silent);
12741308
}
12751309
} else {
12761310
log::add('mobile', 'debug', '| [ERROR] ARN non configuré ');

0 commit comments

Comments
 (0)