pubstream comments and a few other bugfixes that were discovered along the way

This commit is contained in:
zotlabs
2017-11-26 18:29:24 -08:00
parent e1fdac3278
commit 0e91810ed6
12 changed files with 206 additions and 79 deletions

View File

@@ -1749,22 +1749,6 @@ function item_store($arr, $allow_exec = false, $deliver = true) {
intval($arr['uid'])
);
// perhaps the system channel owns the post and it's a pubstream item
if(! $r) {
$s = q("select channel_id from channel where channel_system = 1 limit 1");
if($s) {
$r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d ORDER BY id ASC LIMIT 1",
dbesc($arr['parent_mid']),
intval($s[0]['channel_id'])
);
}
if($r) {
$arr['uid'] = $r[0]['uid'];
$arr['aid'] = 0;
}
}
if($r) {
// in case item_store was killed before the parent's parent attribute got set,
@@ -4725,3 +4709,59 @@ function item_create_edit_activity($post) {
\Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_activity', $post_id));
}
/**
* @brief copies an entire conversation from the pubstream to this channel's stream
* which will allow you to interact with it.
*/
function copy_of_pubitem($channel,$mid) {
$result = null;
$syschan = get_sys_channel();
// logger('copy_of_pubitem: ' . $channel['channel_id'] . ' mid: ' . $mid);
$r = q("select * from item where mid = '%s' and uid = %d limit 1",
dbesc($mid),
intval($channel['channel_id'])
);
if($r) {
logger('exists');
$item = fetch_post_tags($r,true);
return $item[0];
}
$r = q("select * from item where parent_mid = (select parent_mid from item where mid = '%s' and uid = %d ) order by id ",
dbesc($mid),
intval($syschan['channel_id'])
);
if($r) {
$items = fetch_post_tags($r,true);
foreach($items as $rv) {
$d = q("select id from item where mid = '%s' and uid = %d limit 1",
dbesc($rv['mid']),
intval($channel['channel_id'])
);
if($d) {
continue;
}
unset($rv['id']);
unset($rv['parent']);
$rv['aid'] = $channel['channel_account_id'];
$rv['uid'] = $channel['channel_id'];
$x = item_store($rv);
if($x['item_id'] && $x['item']['mid'] === $mid) {
$result = $x['item'];
}
}
}
return $result;
}