aboutsummaryrefslogtreecommitdiffstats
path: root/include/notifier.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/notifier.php')
-rw-r--r--include/notifier.php237
1 files changed, 69 insertions, 168 deletions
diff --git a/include/notifier.php b/include/notifier.php
index b7830285a..50981df9d 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -44,7 +44,6 @@ require_once('include/html2plain.php');
* expire (in items.php)
* like (in like.php, poke.php)
* mail (in message.php)
- * suggest (in fsuggest.php)
* tag (in photos.php, poke.php, tagger.php)
* tgroup (in items.php)
* wall-new (in photos.php, item.php)
@@ -52,11 +51,14 @@ require_once('include/html2plain.php');
* and ITEM_ID is the id of the item in the database that needs to be sent to others.
*
* ZOT
+ * permission_create abook_id
* permission_update abook_id
* refresh_all channel_id
* purge_all channel_id
* expire channel_id
* relay item_id (item was relayed to owner, we will deliver it as owner)
+ * single_activity item_id (deliver to a singleton network from the appropriate clone)
+ * single_mail mail_id (deliver to a singleton network from the appropriate clone)
* location channel_id
* request channel_id xchan_hash message_id
* rating xlink_id
@@ -66,6 +68,12 @@ require_once('include/html2plain.php');
require_once('include/cli_startup.php');
require_once('include/zot.php');
require_once('include/queue_fn.php');
+require_once('include/session.php');
+require_once('include/datetime.php');
+require_once('include/items.php');
+require_once('include/bbcode.php');
+require_once('include/identity.php');
+require_once('include/Contact.php');
function notifier_run($argv, $argc){
@@ -73,15 +81,10 @@ function notifier_run($argv, $argc){
$a = get_app();
- require_once("session.php");
- require_once("datetime.php");
- require_once('include/items.php');
- require_once('include/bbcode.php');
if($argc < 3)
return;
-
logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
$cmd = $argv[1];
@@ -93,7 +96,6 @@ function notifier_run($argv, $argc){
if(! $item_id)
return;
- require_once('include/identity.php');
$sys = get_sys_channel();
$deliveries = array();
@@ -108,87 +110,8 @@ function notifier_run($argv, $argc){
}
- if($cmd == 'permission_update' || $cmd == 'permission_create') {
- // Get the recipient
- $r = q("select abook.*, hubloc.* from abook
- left join hubloc on hubloc_hash = abook_xchan
- where abook_id = %d and abook_self = 0
- and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0 limit 1",
- intval($item_id),
- intval(HUBLOC_FLAGS_DELETED),
- intval(HUBLOC_OFFLINE)
- );
-
- if($r) {
- // Get the sender
- $s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
- intval($r[0]['abook_channel'])
- );
- if($s) {
- $perm_update = array('sender' => $s[0], 'recipient' => $r[0], 'success' => false, 'deliveries' => '');
-
- if($cmd == 'permission_create')
- call_hooks('permissions_create',$perm_update);
- else
- call_hooks('permissions_update',$perm_update);
-
- if($perm_update['success'] && $perm_update['deliveries'])
- $deliveries[] = $perm_update['deliveries'];
-
- if(! $perm_update['success']) {
- // send a refresh message to each hub they have registered here
- $h = q("select * from hubloc where hubloc_hash = '%s'
- and not (hubloc_flags & %d) > 0 and not (hubloc_status & %d) > 0",
- dbesc($r[0]['hubloc_hash']),
- intval(HUBLOC_FLAGS_DELETED),
- intval(HUBLOC_OFFLINE)
- );
- if($h) {
- foreach($h as $hh) {
- if(in_array($hh['hubloc_url'],$dead_hubs)) {
- logger('skipping dead hub: ' . $hh['hubloc_url'], LOGGER_DEBUG);
- continue;
- }
-
- $data = zot_build_packet($s[0],'refresh',array(array(
- 'guid' => $hh['hubloc_guid'],
- 'guid_sig' => $hh['hubloc_guid_sig'],
- 'url' => $hh['hubloc_url'])
- ));
- if($data) {
- $hash = random_string();
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg )
- values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
- dbesc($hash),
- intval($s[0]['channel_account_id']),
- intval($s[0]['channel_id']),
- dbesc('zot'),
- dbesc($hh['hubloc_callback']),
- intval(1),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($data),
- dbesc('')
- );
- $deliveries[] = $hash;
- }
- }
-
- }
- }
-
- if($deliveries)
- do_delivery($deliveries);
- }
- }
- return;
- }
-
-
- $expire = false;
$request = false;
$mail = false;
- $fsuggest = false;
$top_level = false;
$location = false;
$recipients = array();
@@ -237,51 +160,42 @@ function notifier_run($argv, $argc){
$packet_type = 'request';
$normal_mode = false;
}
- elseif($cmd === 'expire') {
-
- // FIXME
- // This will require a special zot packet containing a list of item message_id's to be expired.
- // This packet will be public, since we cannot selectively deliver here.
- // We need the handling on this end to create the array, and the handling on the remote end
- // to verify permissions (for each item) and process it. Until this is complete, the expire feature will be disabled.
-
- return;
-
- $normal_mode = false;
- $expire = true;
- $items = q("SELECT * FROM item WHERE uid = %d AND item_wall = 1
- AND item_deleted = 1 AND `changed` > %s - INTERVAL %s",
- intval($item_id),
- db_utcnow(), db_quoteinterval('10 MINUTE')
+ elseif($cmd == 'permission_update' || $cmd == 'permission_create') {
+ // Get the (single) recipient
+ $r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_self = 0",
+ intval($item_id)
);
- $uid = $item_id;
- $item_id = 0;
- if(! $items)
- return;
+ if($r) {
+ $uid = $r[0]['abook_channel'];
+ // Get the sender
+ $channel = channelx_by_n($uid);
+ if($channel) {
+ $perm_update = array('sender' => $channel, 'recipient' => $r[0], 'success' => false, 'deliveries' => '');
- }
- elseif($cmd === 'suggest') {
- $normal_mode = false;
- $fsuggest = true;
+ if($cmd == 'permission_create')
+ call_hooks('permissions_create',$perm_update);
+ else
+ call_hooks('permissions_update',$perm_update);
- $suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
- intval($item_id)
- );
- if(! count($suggest))
- return;
- $uid = $suggest[0]['uid'];
- $recipients[] = $suggest[0]['cid'];
- $item = $suggest[0];
+ if($perm_update['success']) {
+ if($perm_update['deliveries']) {
+ $deliveries[] = $perm_update['deliveries'];
+ do_delivery($deliveries);
+ }
+ return;
+ }
+ else {
+ $recipients[] = $r[0]['abook_xchan'];
+ $private = false;
+ $packet_type = 'refresh';
+ }
+ }
+ }
}
elseif($cmd === 'refresh_all') {
logger('notifier: refresh_all: ' . $item_id);
- $s = q("select * from channel where channel_id = %d limit 1",
- intval($item_id)
- );
- if($s)
- $channel = $s[0];
$uid = $item_id;
- $recipients = array();
+ $channel = channelx_by_n($item_id);
$r = q("select abook_xchan from abook where abook_channel = %d",
intval($item_id)
);
@@ -464,9 +378,12 @@ function notifier_run($argv, $argc){
// if our parent is a tag_delivery recipient, uplink to the original author causing
// a delivery fork.
- if(intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) {
- logger('notifier: uplinking this item');
- proc_run('php','include/notifier.php','uplink',$item_id);
+ if(($parent_item) && intval($parent_item['item_uplink']) && (! $top_level_post) && ($cmd !== 'uplink')) {
+ // don't uplink a relayed post to the relay owner
+ if($parent_item['source_xchan'] !== $parent_item['owner_xchan']) {
+ logger('notifier: uplinking this item');
+ proc_run('php','include/notifier.php','uplink',$item_id);
+ }
}
$private = false;
@@ -605,10 +522,8 @@ function notifier_run($argv, $argc){
'relay_to_owner' => $relay_to_owner,
'uplink' => $uplink,
'cmd' => $cmd,
- 'expire' => $expire,
'mail' => $mail,
'location' => $location,
- 'fsuggest' => $fsuggest,
'request' => $request,
'normal_mode' => $normal_mode,
'packet_type' => $packet_type,
@@ -628,52 +543,38 @@ function notifier_run($argv, $argc){
// default: zot protocol
-
$hash = random_string();
+ $packet = null;
+
if($packet_type === 'refresh' || $packet_type === 'purge') {
- $n = zot_build_packet($channel,$packet_type);
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
- dbesc($hash),
- intval($channel['channel_account_id']),
- intval($channel['channel_id']),
- dbesc('zot'),
- dbesc($hub['hubloc_callback']),
- intval(1),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($n),
- dbesc('')
- );
+ $packet = zot_build_packet($channel,$packet_type);
}
elseif($packet_type === 'request') {
- $n = zot_build_packet($channel,'request',$env_recips,$hub['hubloc_sitekey'],$hash,array('message_id' => $request_message_id));
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
- dbesc($hash),
- intval($channel['channel_account_id']),
- intval($channel['channel_id']),
- dbesc('zot'),
- dbesc($hub['hubloc_callback']),
- intval(1),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($n),
- dbesc('')
+ $packet = zot_build_packet($channel,$packet_type,$env_recips,$hub['hubloc_sitekey'],$hash,
+ array('message_id' => $request_message_id)
);
}
+
+ if($packet) {
+ queue_insert(array(
+ 'hash' => $hash,
+ 'account_id' => $channel['channel_account_id'],
+ 'channel_id' => $channel['channel_id'],
+ 'posturl' => $hub['hubloc_callback'],
+ 'notify' => $packet
+ ));
+ }
else {
- $n = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash);
- q("insert into outq ( outq_hash, outq_account, outq_channel, outq_driver, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
- dbesc($hash),
- intval($target_item['aid']),
- intval($target_item['uid']),
- dbesc('zot'),
- dbesc($hub['hubloc_callback']),
- intval(1),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($n),
- dbesc(json_encode($encoded_item))
- );
+ $packet = zot_build_packet($channel,'notify',$env_recips,(($private) ? $hub['hubloc_sitekey'] : null),$hash);
+ queue_insert(array(
+ 'hash' => $hash,
+ 'account_id' => $target_item['aid'],
+ 'channel_id' => $target_item['uid'],
+ 'posturl' => $hub['hubloc_callback'],
+ 'notify' => $packet,
+ 'msg' => json_encode($encoded_item)
+ ));
+
// only create delivery reports for normal undeleted items
if(is_array($target_item) && array_key_exists('postopts',$target_item) && (! $target_item['item_deleted'])) {
q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_result, dreport_time, dreport_xchan, dreport_queue ) values ( '%s','%s','%s','%s','%s','%s','%s' ) ",