/**
* Name: WindowsPhonePush
* Description: Enable push notification to send information to Friendica Mobile app on Windows phone (count of unread timeline entries, text of last posting - if wished by user)
- * Version: 1.1
+ * Version: 2.0
* Author: Gerhard Seeber <http://friendica.seeber.at/profile/admin>
*
*
* Version history:
* 1.1 : addon crashed on php versions >= 5.4 as of removed deprecated call-time
* pass-by-reference used in function calls within function windowsphonepush_content
+ * 2.0 : adaption for supporting emphasizing new entries in app (count on tile cannot be read out,
+ * so we need to retrieve counter through show_settings secondly). Provide new function for
+ * calling from app to set the counter back after start (if user starts again before cronjob
+ * sets the counter back
+ * count only unseen elements which are not type=activity (likes and dislikes not seen as new elements)
*/
function windowsphonepush_settings_post($a,$post) {
if(! local_user() || (! x($_POST,'windowsphonepush-submit')))
return;
+ $enable = intval($_POST['windowsphonepush']);
+ set_pconfig(local_user(),'windowsphonepush','enable',$enable);
+
+ if($enable) {
+ set_pconfig(local_user(),'windowsphonepush','counterunseen', 0);
+ }
- set_pconfig(local_user(),'windowsphonepush','enable',intval($_POST['windowsphonepush']));
set_pconfig(local_user(),'windowsphonepush','senditemtext',intval($_POST['windowsphonepush-senditemtext']));
info( t('WindowsPhonePush settings updated.') . EOL);
} else {
// retrieve the number of unseen items and the id of the latest one (if there are more than
// one new entries since last poller run, only the latest one will be pushed)
- $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `item` WHERE `unseen` = 1 AND `uid` = %d",
+ $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `item` WHERE `unseen` = 1 AND `type` <> 'activity' AND `uid` = %d",
intval($rr['uid'])
);
$res_tile = send_tile_update($device_url, "", $count[0]['count'], "");
switch (trim($res_tile)) {
case "Received":
- // ok, count has been pushed
+ // ok, count has been pushed, let's save it in personal settings
+ set_pconfig($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']);
break;
case "QueueFull":
// maximum of 30 messages reached, server rejects any further push notification until device reconnects
* reading information from url and deciding which function to start
* show_settings = delivering settings to check
* update_settings = set the device_url
+ * update_counterunseen = set counter for unseen elements to zero
*
*/
function windowsphonepush_content(&$a) {
echo json_encode(array('status' => $ret));
killme();
break;
+ case "update_counterunseen":
+ $ret = windowsphonepush_updatecounterunseen();
+ header("Content-Type: application/json; charset=utf-8");
+ echo json_encode(array('status' => $ret));
+ killme();
+ break;
default:
echo "Fehler";
}
$device_url = get_pconfig(local_user(), 'windowsphonepush', 'device_url');
$senditemtext = get_pconfig(local_user(), 'windowsphonepush', 'senditemtext');
$lastpushid = get_pconfig(local_user(), 'windowsphonepush', 'lastpushid');
+ $counterunseen = get_pconfig(local_user(), 'windowsphonepush', 'counterunseen');
+ $addonversion = "2.0";
if (!$device_url)
$device_url = "";
'enable' => $enable,
'device_url' => $device_url,
'senditemtext' => $senditemtext,
- 'lastpushid' => $lastpushid));
+ 'lastpushid' => $lastpushid,
+ 'counterunseen' => $counterunseen,
+ 'addonversion' => $addonversion));
}
/*
return "Device-URL updated successfully!";
}
+/*
+ * update_counterunseen is used to reset the counter to zero from Windows Phone app
+ */
+function windowsphonepush_updatecounterunseen() {
+ if(! local_user()) {
+ return "Not Authenticated";
+ }
+
+ // no updating if user hasn't enabled the plugin
+ $enable = get_pconfig(local_user(), 'windowsphonepush', 'enable');
+ if(! $enable) {
+ return "Plug-in not enabled";
+ }
+
+ set_pconfig(local_user(),'windowsphonepush','counterunseen', 0);
+ return "Counter set to zero";
+}
+
/*
* helper function to login to the server with the specified Network credentials
* (mainly copied from api.php)