diff options
-rw-r--r-- | include/attach.php | 114 | ||||
-rw-r--r-- | mod/sharedwithme.php | 39 |
2 files changed, 59 insertions, 94 deletions
diff --git a/include/attach.php b/include/attach.php index db42cd2a3..9c71beb23 100644 --- a/include/attach.php +++ b/include/attach.php @@ -968,18 +968,6 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, require_once('include/items.php'); - switch($verb) { - case 'post': - $activity = ACTIVITY_POST; - break; - case 'update': - $activity = ACTIVITY_UPDATE; - break; - default: - return; - break; - } - $poster = get_app()->get_observer(); $mid = item_message_id(); @@ -988,65 +976,63 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; + $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); + $jsonobject = json_encode($object); - $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); + //check if item for this object exists + $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1", + dbesc(ACTIVITY_POST), + dbesc($objtype), + dbesc($jsonobject) + ); - if($verb == 'post') { - //check if activity item exists - //if yes send update (drop) activity and create a new one - $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1", - dbesc(ACTIVITY_POST), - dbesc($objtype), - dbesc($jsonobject) - ); - if($y) { + if($y) { + $update = true; + $object['d_mid'] = $y[0]['mid']; //attach mid of the old object + $u_jsonobject = json_encode($object); + } - $dmid = item_message_id(); - - $object['mid'] = $mid; //attach mid for update object - - $ujsonobject = json_encode($object); - - $arr = array(); - - $arr['aid'] = get_account_id(); - $arr['uid'] = $channel_id; - $arr['mid'] = $dmid; - $arr['parent_mid'] = $dmid; - $arr['item_flags'] = $item_flags; - $arr['author_xchan'] = $poster['xchan_hash']; - $arr['owner_xchan'] = $poster['xchan_hash']; - $arr['title'] = ''; - //updates must be visible to everybody -> perms may have changed - $arr['allow_cid'] = ''; - $arr['allow_gid'] = ''; - $arr['deny_cid'] = ''; - $arr['deny_gid'] = ''; - $arr['item_restrict'] = ITEM_HIDDEN; - $arr['item_private'] = 0; - $arr['verb'] = ACTIVITY_UPDATE; - $arr['obj_type'] = $objtype; - $arr['object'] = $ujsonobject; - $arr['body'] = ''; - - $post = item_store($arr); - $item_id = $post['item_id']; - - if($item_id) { - proc_run('php',"include/notifier.php","activity",$item_id); - } + if($update && $verb == 'post' ) { + //send update activity and create a new one + + $u_mid = item_message_id(); + + $arr = array(); + + $arr['aid'] = get_account_id(); + $arr['uid'] = $channel_id; + $arr['mid'] = $u_mid; + $arr['parent_mid'] = $u_mid; + $arr['item_flags'] = $item_flags; + $arr['author_xchan'] = $poster['xchan_hash']; + $arr['owner_xchan'] = $poster['xchan_hash']; + $arr['title'] = ''; + //updates should be visible to everybody -> perms may have changed + $arr['allow_cid'] = ''; + $arr['allow_gid'] = ''; + $arr['deny_cid'] = ''; + $arr['deny_gid'] = ''; + $arr['item_restrict'] = ITEM_HIDDEN; + $arr['item_private'] = 0; + $arr['verb'] = ACTIVITY_UPDATE; + $arr['obj_type'] = $objtype; + $arr['object'] = $u_jsonobject; + $arr['body'] = ''; + + $post = item_store($arr); + $item_id = $post['item_id']; + if($item_id) { + proc_run('php',"include/notifier.php","activity",$item_id); + } - call_hooks('post_local_end', $arr); + call_hooks('post_local_end', $arr); - //notice( t('File activity updated') . EOL); + $update = false; - if($no_activity) { - return; - } + //notice( t('File activity updated') . EOL); - } } if($no_activity) { @@ -1069,9 +1055,9 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['deny_gid'] = $deny_gid; $arr['item_restrict'] = ITEM_HIDDEN; $arr['item_private'] = $private; - $arr['verb'] = $activity; + $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST); $arr['obj_type'] = $objtype; - $arr['object'] = $jsonobject; + $arr['object'] = (($update) ? $u_jsonobject : $jsonobject); $arr['body'] = ''; $post = item_store($arr); diff --git a/mod/sharedwithme.php b/mod/sharedwithme.php index bbb9c2aef..8b7d2661c 100644 --- a/mod/sharedwithme.php +++ b/mod/sharedwithme.php @@ -24,38 +24,17 @@ function sharedwithme_content(&$a) { foreach($x as $xx) { $object = json_decode($xx['object'],true); - $hash = $object['hash']; - //If object has a mid it's an update activity - the inlcuded mid is the latest and should not be removed - $update = (($object['mid']) ? true : false); + $d_mid = $object['d_mid']; + $u_mid = $xx['mid']; - if($update) { - - $mid = $object['mid']; - - unset($object['mid']); //remove mid from object to match the post activity object - - $y = q("DELETE FROM item WHERE (mid != '%s' AND obj_type = '%s') AND (object = '%s' AND verb = '%s') OR (object = '%s' AND verb = '%s')", - dbesc($mid), - dbesc(ACTIVITY_OBJ_FILE), - dbesc(json_encode($object)), - dbesc(ACTIVITY_POST), - dbesc($xx['object']), - dbesc(ACTIVITY_UPDATE) - ); - - } - - else { - - $z = q("DELETE FROM item WHERE (obj_type = '%s' AND object = '%s') AND (verb = '%s' OR verb = '%s')", - dbesc(ACTIVITY_OBJ_FILE), - dbesc($xx['object']), - dbesc(ACTIVITY_POST), - dbesc(ACTIVITY_UPDATE) - ); - - } + $y = q("DELETE FROM item WHERE obj_type = '%s' AND (verb = '%s' AND mid = '%s') OR (verb = '%s' AND mid = '%s')", + dbesc(ACTIVITY_OBJ_FILE), + dbesc(ACTIVITY_POST), + dbesc($d_mid), + dbesc(ACTIVITY_UPDATE), + dbesc($u_mid) + ); } |