From 4ff71fc0c7d28b8a843cc67eac1d9463afe575ee Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 22 Jan 2015 02:34:38 +0100 Subject: change mod/sharedwithme backend to use activity object - this is not backwards compatible --- include/attach.php | 103 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 76 insertions(+), 27 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 5ef3bea24..673e438bf 100644 --- a/include/attach.php +++ b/include/attach.php @@ -753,7 +753,7 @@ function attach_delete($channel_id, $resource) { $channel_address = (($c) ? $c[0]['channel_address'] : 'notfound'); - $r = q("SELECT hash, filename, flags, folder FROM attach WHERE hash = '%s' AND uid = %d limit 1", + $r = q("SELECT hash, flags, folder FROM attach WHERE hash = '%s' AND uid = %d limit 1", dbesc($resource), intval($channel_id) ); @@ -762,8 +762,6 @@ function attach_delete($channel_id, $resource) { if(! $r) return; - $url = get_parent_cloudpath($channel_id, $channel_address, $resource) . $r[0]['filename']; - // If resource is a directory delete everything in the directory recursive if($r[0]['flags'] & ATTACH_FLAG_DIR) { $x = q("SELECT hash, flags FROM attach WHERE folder = '%s' AND uid = %d", @@ -806,7 +804,7 @@ function attach_delete($channel_id, $resource) { intval($channel_id) ); - file_activity($channel_id, $resource, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', $url, 'drop', $no_activity=false); + file_activity($channel_id, $resource, $cloudpath='', $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'drop', $no_activity=false); } /** @@ -942,32 +940,76 @@ function pipe_streams($in, $out) { return $size; } -function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $url, $action, $no_activity) { +function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) { require_once('include/items.php'); - $url = rawurlencode($url); - $poster = get_app()->get_observer(); - $verb = ACTIVITY_FILE . '/' . $action . '/' . $hash; + switch($verb) { + case 'post': + $activity = ACTIVITY_POST; + $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($channel_id), + dbesc($hash) + ); + break; + case 'drop': + $activity = ACTIVITY_UPDATE; + break; + default: + return; + break; + } + + $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable'); $mid = item_message_id(); $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - if($action == 'post') { - //check if activity item exists - //if yes send drop activity and create a new one + $links = array( + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $url + ); - $r = q("SELECT * FROM item WHERE verb = '%s'", - dbesc($verb) + $objtype = ACTIVITY_OBJ_FILE; + + $object = array( + 'type' => ACTIVITY_OBJ_FILE, + 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'), + 'id' => $url, + 'link' => $links, + + 'hash' => $hash, + 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''), + 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''), + 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''), + 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''), + 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''), + 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''), + 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''), + 'created' => (($x[0]['created']) ? $x[0]['created'] : ''), + 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '') + ); + + $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); + + 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 LIKE '%s'", + dbesc(ACTIVITY_POST), + dbesc(ACTIVITY_OBJ_FILE), + dbesc('%"hash":"' . $hash . '"%') ); - if($r) { + if($y) { $dmid = item_message_id(); - $updateverb = ACTIVITY_FILE . '/drop/' . $hash . '#' . $mid; + + $object['mid'] = $mid; //attach mid for update object $arr = array(); @@ -979,14 +1021,17 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = $poster['xchan_hash']; $arr['title'] = ''; - $arr['allow_cid'] = $allow_cid; - $arr['allow_gid'] = $allow_gid; - $arr['deny_cid'] = $deny_cid; - $arr['deny_gid'] = $deny_gid; + //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'] = $updateverb; - $arr['body'] = $url; + $arr['verb'] = ACTIVITY_UPDATE; + $arr['obj_type'] = $objtype; + $arr['object'] = json_encode($object); + $arr['body'] = ''; $post = item_store($arr); $item_id = $post['item_id']; @@ -995,7 +1040,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d proc_run('php',"include/notifier.php","activity",$item_id); } - //call_hooks('post_local_end', $arr); + call_hooks('post_local_end', $arr); + + unset($object['mid']); //remove mid for new object //notice( t('File activity updated') . EOL); @@ -1025,9 +1072,11 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; $arr['item_restrict'] = ITEM_HIDDEN; - $arr['item_private'] = 0; - $arr['verb'] = $verb; - $arr['body'] = $url; + $arr['item_private'] = $private; + $arr['verb'] = $activity; + $arr['obj_type'] = $objtype; + $arr['object'] = json_encode($object); + $arr['body'] = ''; $post = item_store($arr); $item_id = $post['item_id']; @@ -1036,9 +1085,9 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d proc_run('php',"include/notifier.php","activity",$item_id); } - //call_hooks('post_local_end', $arr); + call_hooks('post_local_end', $arr); - //(($action === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); + //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); return; -- cgit v1.2.3 From 3731ff97ffa9d6c98c7287458edd783823f68305 Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 22 Jan 2015 04:57:59 +0100 Subject: make $links an array of links --- include/attach.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 673e438bf..a6757744f 100644 --- a/include/attach.php +++ b/include/attach.php @@ -968,7 +968,8 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - $links = array( + $links = array(); + $links[] = array( 'rel' => 'alternate', 'type' => 'text/html', 'href' => $url -- cgit v1.2.3 From d94114ec986ba1440b74d41bec8896db186f8eb2 Mon Sep 17 00:00:00 2001 From: marijus Date: Thu, 22 Jan 2015 12:12:42 +0100 Subject: add some mimetypes --- include/attach.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index a6757744f..c66ba40d5 100644 --- a/include/attach.php +++ b/include/attach.php @@ -64,6 +64,11 @@ function z_mime_content_type($filename) { 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'ogg' => 'application/ogg', + 'opus' => 'audio/ogg', + 'webm' => 'audio/webm', + 'webm' => 'video/webm', + 'mp4' => 'audio/mp4', + 'mp4' => 'video/mp4', // adobe 'pdf' => 'application/pdf', @@ -81,6 +86,22 @@ function z_mime_content_type($filename) { // open office 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'odb' => 'application/vnd.oasis.opendocument.base', + 'odb' => 'application/vnd.oasis.opendocument.database', + 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'otc' => 'application/vnd.oasis.opendocument.chart-template', + 'otf' => 'application/vnd.oasis.opendocument.formula-template', + 'oti' => 'application/vnd.oasis.opendocument.image-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web' ); $dot = strpos($filename, '.'); -- cgit v1.2.3 From 8789c96e78734cbc5420404eff149e514fe17ee7 Mon Sep 17 00:00:00 2001 From: marijus Date: Fri, 23 Jan 2015 14:50:39 +0100 Subject: some code restructure --- include/attach.php | 98 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 43 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index c66ba40d5..a201fd3d4 100644 --- a/include/attach.php +++ b/include/attach.php @@ -779,10 +779,12 @@ function attach_delete($channel_id, $resource) { intval($channel_id) ); - if(! $r) return; + $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource); + $object = get_file_activity_object($channel_id, $resource, $cloudpath); + // If resource is a directory delete everything in the directory recursive if($r[0]['flags'] & ATTACH_FLAG_DIR) { $x = q("SELECT hash, flags FROM attach WHERE folder = '%s' AND uid = %d", @@ -825,7 +827,8 @@ function attach_delete($channel_id, $resource) { intval($channel_id) ); - file_activity($channel_id, $resource, $cloudpath='', $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'drop', $no_activity=false); + file_activity($channel_id, $object, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'update', $no_activity=false); + } /** @@ -961,21 +964,15 @@ function pipe_streams($in, $out) { return $size; } -function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) { +function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) { require_once('include/items.php'); - $poster = get_app()->get_observer(); - switch($verb) { case 'post': $activity = ACTIVITY_POST; - $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", - intval($channel_id), - dbesc($hash) - ); break; - case 'drop': + case 'update': $activity = ACTIVITY_UPDATE; break; default: @@ -983,48 +980,25 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ break; } - $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable'); + $poster = get_app()->get_observer(); $mid = item_message_id(); - $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - - $links = array(); - $links[] = array( - 'rel' => 'alternate', - 'type' => 'text/html', - 'href' => $url - ); - $objtype = ACTIVITY_OBJ_FILE; - $object = array( - 'type' => ACTIVITY_OBJ_FILE, - 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'), - 'id' => $url, - 'link' => $links, + $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - 'hash' => $hash, - 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''), - 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''), - 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''), - 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''), - 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''), - 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''), - 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''), - 'created' => (($x[0]['created']) ? $x[0]['created'] : ''), - 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '') - ); + $jsonobject = json_encode($object); $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); 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 LIKE '%s'", + $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1", dbesc(ACTIVITY_POST), - dbesc(ACTIVITY_OBJ_FILE), - dbesc('%"hash":"' . $hash . '"%') + dbesc($objtype), + dbesc($jsonobject) ); if($y) { @@ -1033,6 +1007,8 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ $object['mid'] = $mid; //attach mid for update object + $ujsonobject = json_encode($object); + $arr = array(); $arr['aid'] = get_account_id(); @@ -1052,7 +1028,7 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ $arr['item_private'] = 0; $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = $objtype; - $arr['object'] = json_encode($object); + $arr['object'] = $ujsonobject; $arr['body'] = ''; $post = item_store($arr); @@ -1064,8 +1040,6 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ call_hooks('post_local_end', $arr); - unset($object['mid']); //remove mid for new object - //notice( t('File activity updated') . EOL); if($no_activity) { @@ -1097,7 +1071,7 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ $arr['item_private'] = $private; $arr['verb'] = $activity; $arr['obj_type'] = $objtype; - $arr['object'] = json_encode($object); + $arr['object'] = $jsonobject; $arr['body'] = ''; $post = item_store($arr); @@ -1114,3 +1088,41 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $ return; } + +function get_file_activity_object($channel_id, $hash, $cloudpath) { + + $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($channel_id), + dbesc($hash) + ); + + $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable'); + + $links = array(); + $links[] = array( + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $url + ); + + $object = array( + 'type' => ACTIVITY_OBJ_FILE, + 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'), + 'id' => $url, + 'link' => $links, + + 'hash' => $hash, + 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''), + 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''), + 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''), + 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''), + 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''), + 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''), + 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''), + 'created' => (($x[0]['created']) ? $x[0]['created'] : ''), + 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '') + ); + + return $object; + +} -- cgit v1.2.3 From b4f1cc5044c74432773a4796235a1907e1fcc470 Mon Sep 17 00:00:00 2001 From: marijus Date: Fri, 23 Jan 2015 15:03:19 +0100 Subject: we get the object info before it is deleted now --- include/attach.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index a201fd3d4..720c8da86 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1096,31 +1096,31 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { dbesc($hash) ); - $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable'); + $url = rawurlencode($cloudpath . $x[0]['filename']); $links = array(); $links[] = array( - 'rel' => 'alternate', + 'rel' => 'alternate', 'type' => 'text/html', 'href' => $url ); $object = array( 'type' => ACTIVITY_OBJ_FILE, - 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'), + 'title' => $x[0]['filename']), 'id' => $url, 'link' => $links, 'hash' => $hash, - 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''), - 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''), - 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''), - 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''), - 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''), - 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''), - 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''), - 'created' => (($x[0]['created']) ? $x[0]['created'] : ''), - 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '') + 'creator' => $x[0]['creator'], + 'filename' => $x[0]['filename'], + 'filetype' => $x[0]['filetype'], + 'filesize' => $x[0]['filesize'], + 'revision' => $x[0]['revision'], + 'folder' => $x[0]['folder'], + 'flags' => $x[0]['flags'], + 'created' => $x[0]['created'], + 'edited' => $x[0]['edited'] ); return $object; -- cgit v1.2.3 From ea209a84ab946ee320c1f1cc39b667e9da23abe6 Mon Sep 17 00:00:00 2001 From: marijus Date: Fri, 23 Jan 2015 15:06:30 +0100 Subject: typo --- include/attach.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 720c8da86..db42cd2a3 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1107,7 +1107,7 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { $object = array( 'type' => ACTIVITY_OBJ_FILE, - 'title' => $x[0]['filename']), + 'title' => $x[0]['filename'], 'id' => $url, 'link' => $links, -- cgit v1.2.3 From 0cbe64c3606312302ad5d3ef56df5d152983ee4e Mon Sep 17 00:00:00 2001 From: marijus Date: Sat, 24 Jan 2015 01:13:02 +0100 Subject: some more kiss --- include/attach.php | 116 +++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 65 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index db42cd2a3..153186312 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); @@ -1083,7 +1069,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, call_hooks('post_local_end', $arr); - //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); + (($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); return; -- cgit v1.2.3 From 43793540214ac6a578f8495c3cca41d831eb7536 Mon Sep 17 00:00:00 2001 From: marijus Date: Sat, 24 Jan 2015 01:15:54 +0100 Subject: disable notices --- include/attach.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 153186312..9c71beb23 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1031,7 +1031,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $update = false; - notice( t('File activity updated') . EOL); + //notice( t('File activity updated') . EOL); } @@ -1069,7 +1069,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, call_hooks('post_local_end', $arr); - (($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); + //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); return; -- cgit v1.2.3 From e4e990df06ef64dd08bdd6e6a78bf461dc97cc19 Mon Sep 17 00:00:00 2001 From: marijus Date: Sat, 24 Jan 2015 12:22:04 +0100 Subject: the old item must be removed before the new is created --- include/attach.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 9c71beb23..850f71f20 100644 --- a/include/attach.php +++ b/include/attach.php @@ -987,11 +987,18 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, dbesc($jsonobject) ); - if($y) { $update = true; $object['d_mid'] = $y[0]['mid']; //attach mid of the old object $u_jsonobject = json_encode($object); + + //we have got the relevant info - delete the old item before we create the new one + $z = q("DELETE FROM item WHERE obj_type = '%s' AND verb = '%s' AND mid = '%s'", + dbesc(ACTIVITY_OBJ_FILE), + dbesc(ACTIVITY_POST), + dbesc($y[0]['mid']) + ); + } if($update && $verb == 'post' ) { -- cgit v1.2.3 From 63f1ae5e204cdb615a0edb0d16c4c471c2f3264e Mon Sep 17 00:00:00 2001 From: marijus Date: Sat, 24 Jan 2015 14:35:21 +0100 Subject: optimize check query --- include/attach.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'include/attach.php') diff --git a/include/attach.php b/include/attach.php index 850f71f20..c7216df7a 100644 --- a/include/attach.php +++ b/include/attach.php @@ -981,10 +981,11 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $jsonobject = json_encode($object); //check if item for this object exists - $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1", + $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND resource_id = '%s' AND uid = %d LIMIT 1", dbesc(ACTIVITY_POST), dbesc($objtype), - dbesc($jsonobject) + dbesc($object['hash']), + intval(local_user()) ); if($y) { @@ -1026,6 +1027,8 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['verb'] = ACTIVITY_UPDATE; $arr['obj_type'] = $objtype; $arr['object'] = $u_jsonobject; + $arr['resource_id'] = $object['hash']; + $arr['resource_type'] = 'attach'; $arr['body'] = ''; $post = item_store($arr); @@ -1064,6 +1067,8 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $arr['item_private'] = $private; $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST); $arr['obj_type'] = $objtype; + $arr['resource_id'] = $object['hash']; + $arr['resource_type'] = 'attach'; $arr['object'] = (($update) ? $u_jsonobject : $jsonobject); $arr['body'] = ''; -- cgit v1.2.3