sync fixes

This commit is contained in:
nobody 2022-03-31 12:21:52 -07:00
parent 1a36be9128
commit e480852a97
4 changed files with 70 additions and 13 deletions

View file

@ -2998,6 +2998,21 @@ class Activity
$s['body'] = ((self::bb_content($content, 'bbcode') && (!$response_activity)) ? self::bb_content($content, 'bbcode') : self::bb_content($content, 'content'));
}
// For the special snowflakes who can't figure out how to use attachments.
$quote_bbcode = false;
$quote_url = $act->get_property_obj('quoteUrl');
if ($quote_url) {
$quote_bbcode = self::get_quote_bbcode($quote_url);
}
elseif (isset($act->obj['quoteUrl'])) {
$quote_bbcode = self::get_quote_bbcode($act->obj['quoteUrl']);
}
if ($quote_bbcode) {
$s['body'] .= strlen($s['body']) ? '' : "\r\n\r\n";
$s['body'] .= $quote_bbcode;
}
// handle some of the more widely used of the numerous and varied ways of deleting something
@ -4051,6 +4066,11 @@ class Activity
$ret .= "\n\n" . '[audio]' . $a['href'] . '[/audio]';
}
}
if (array_key_exists('type', $a) && stripos($a['type'], 'activity') !== false) {
if (self::media_not_in_body($a['href'], $body)) {
$ret .= "\n\n" . get_quote_bbcode($a['href']);
}
}
}
return $ret;
@ -4402,4 +4422,31 @@ class Activity
'acceptsJoins' => 'litepub:acceptsJoins',
];
}
public static function get_quote_bbcode($url) {
$ret = '';
$a = self::fetch($url);
if ($a) {
$act = new ActivityStreams($a);
if ($act->is_valid()) {
$content = self::get_content($act->obj);
}
$ret .= "[share author='" . urlencode($act->actor['name']) .
"' profile='" . $act->actor['id'] .
"' avatar='" . $act->actor['icon']['url'] .
"' link='" . $act->obj['id'] .
"' auth='" . ((is_matrix_url($act->actor['id'])) ? 'true' : 'false') .
"' posted='" . $act->obj['published'] .
"' message_id='" . $act->obj['id'] .
"']";
$ret .= self::bb_content($content, 'content');
$ret .= '[/share]';
}
return $ret;
}
}

View file

@ -3,7 +3,7 @@
namespace Code\Lib;
/**
* @brief lowlevel implementation of Zot6 protocol.
* @brief lowlevel implementation of Nomad protocol.
*
*/
@ -94,9 +94,9 @@ class Libzot
}
/**
* @brief Builds a zot6 notification packet.
* @brief Builds a notification packet.
*
* Builds a zot6 notification packet that you can either store in the queue with
* Builds a notification packet that you can either store in the queue with
* a message array or call zot_zot to immediately zot it to the other side.
*
* @param array $channel
@ -1687,12 +1687,6 @@ class Libzot
// if any further changes are to be made, change a copy and not the original
$arr = $msg_arr;
// if (! $msg_arr['mid']) {
// logger('no mid2: ' . print_r($msg_arr,true));
// logger('recip: ' . $d);
// }
$DR = new DReport(z_root(), $sender, $d, $arr['mid']);
$channel = Channel::from_hash($d);
@ -2321,7 +2315,8 @@ class Libzot
if ($r) {
$arr['author_xchan'] = $r[0]['hubloc_hash'];
$r = self::zot_record_preferred($r);
$arr['author_xchan'] = $r['hubloc_hash'];
}
if ($signer) {

View file

@ -105,7 +105,7 @@ class Inbox extends Controller
Activity::actor_store($AS->obj['id'], $AS->obj);
}
if (is_array($AS->obj) && is_array($AS->obj['actor']) && array_key_exists('id', $AS->obj['actor']) && $AS->obj['actor']['id'] !== $AS->actor['id']) {
if (is_array($AS->obj) && array_key_exists('actor',$AS->obj) && is_array($AS->obj['actor']) && array_key_exists('id', $AS->obj['actor']) && $AS->obj['actor']['id'] !== $AS->actor['id']) {
Activity::actor_store($AS->obj['actor']['id'], $AS->obj['actor']);
if (!check_channelallowed($AS->obj['actor']['id'])) {
http_status_exit(403, 'Permission denied');

View file

@ -4784,9 +4784,24 @@ function sync_an_item($channel_id,$item_id) {
intval($item_id)
);
if($r) {
if (intval($r[0]['parent']) !== intval($r[0]['id'])) {
// sync the parent also. This prevents mis-deliveries from sync packets arriving out of order.
$y = q("select * from item where id = %d",
intval($r[0]['parent'])
);
if ($y) {
$r = array_merge($y,$r);
}
}
$encoded = [];
xchan_query($r);
$sync_item = fetch_post_tags($r);
Libsync::build_sync_packet($channel_id,array('item' => array(encode_item($sync_item[0],true))));
$sync_items = fetch_post_tags($r);
if ($sync_items) {
foreach ($sync_items as $i) {
$encoded[] = encode_item($i,true);
}
}
Libsync::build_sync_packet($channel_id,array('item' => $encoded));
}
}