some more kiss

This commit is contained in:
marijus 2015-01-24 01:13:02 +01:00
parent ea209a84ab
commit 0cbe64c360
2 changed files with 58 additions and 93 deletions

View File

@ -968,18 +968,6 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
require_once('include/items.php'); 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(); $poster = get_app()->get_observer();
$mid = item_message_id(); $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; $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
$jsonobject = json_encode($object);
$private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0);
if($verb == 'post') { $jsonobject = json_encode($object);
//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) { //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)
);
$dmid = item_message_id();
$object['mid'] = $mid; //attach mid for update object if($y) {
$update = true;
$object['d_mid'] = $y[0]['mid']; //attach mid of the old object
$u_jsonobject = json_encode($object);
}
$ujsonobject = json_encode($object); if($update && $verb == 'post' ) {
//send update activity and create a new one
$arr = array(); $u_mid = item_message_id();
$arr['aid'] = get_account_id(); $arr = array();
$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); $arr['aid'] = get_account_id();
$item_id = $post['item_id']; $arr['uid'] = $channel_id;
$arr['mid'] = $u_mid;
if($item_id) { $arr['parent_mid'] = $u_mid;
proc_run('php',"include/notifier.php","activity",$item_id); $arr['item_flags'] = $item_flags;
} $arr['author_xchan'] = $poster['xchan_hash'];
$arr['owner_xchan'] = $poster['xchan_hash'];
call_hooks('post_local_end', $arr); $arr['title'] = '';
//updates should be visible to everybody -> perms may have changed
//notice( t('File activity updated') . EOL); $arr['allow_cid'] = '';
$arr['allow_gid'] = '';
if($no_activity) { $arr['deny_cid'] = '';
return; $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);
$update = false;
notice( t('File activity updated') . EOL);
} }
if($no_activity) { 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['deny_gid'] = $deny_gid;
$arr['item_restrict'] = ITEM_HIDDEN; $arr['item_restrict'] = ITEM_HIDDEN;
$arr['item_private'] = $private; $arr['item_private'] = $private;
$arr['verb'] = $activity; $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST);
$arr['obj_type'] = $objtype; $arr['obj_type'] = $objtype;
$arr['object'] = $jsonobject; $arr['object'] = (($update) ? $u_jsonobject : $jsonobject);
$arr['body'] = ''; $arr['body'] = '';
$post = item_store($arr); $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); 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; return;

View File

@ -24,38 +24,17 @@ function sharedwithme_content(&$a) {
foreach($x as $xx) { foreach($x as $xx) {
$object = json_decode($xx['object'],true); $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 $d_mid = $object['d_mid'];
$update = (($object['mid']) ? true : false); $u_mid = $xx['mid'];
if($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),
$mid = $object['mid']; dbesc(ACTIVITY_POST),
dbesc($d_mid),
unset($object['mid']); //remove mid from object to match the post activity object dbesc(ACTIVITY_UPDATE),
dbesc($u_mid)
$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)
);
}
} }