issue with conversation fetch

This commit is contained in:
Mike Macgirvin 2023-08-23 08:03:42 +10:00
parent 5ce032f11f
commit c163be1863
16 changed files with 141 additions and 39 deletions

View file

@ -53,7 +53,7 @@ class Gprobe implements DaemonInterface
if ((!in_array('zot6', $protocols)) && (!in_array('nomad', $protocols))) {
$href = Webfinger::nomad_url(punify($address));
if ($href) {
$zf = Zotfinger::exec($href, $channel);
$zf = Zotfinger::post($href, $channel);
}
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid']) && isset($zf['data']) && $zf['data']) {
$xc = Libzot::import_xchan($zf['data']);

View file

@ -32,9 +32,10 @@ class Queue implements DaemonInterface
db_quoteinterval('1 MONTH')
);
}
logger('Removing ' . count($oldqItems) . ' old queue entries');
}
logger('Removing ' . count($oldqItems) . ' old queue entries');
q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s",
db_utcnow(),
db_quoteinterval('3 DAY')

View file

@ -349,7 +349,7 @@ class ActivityStreams
$x = Activity::fetch($url, $channel);
if ($x === null && strpos($url, '/channel/')) {
// look for other nomadic channels which might be alive
$zf = Zotfinger::exec($url, $channel);
$zf = Zotfinger::post($url, $channel);
$url = $zf['signature']['signer'];
$x = Activity::fetch($url, $channel);

View file

@ -365,7 +365,7 @@ class Libzot
return false;
}
$record = Zotfinger::exec($url, $channel);
$record = Zotfinger::post($url, $channel);
// Check the HTTP signature
@ -693,7 +693,7 @@ class Libzot
return $result;
}
$record = Zotfinger::exec($id);
$record = Zotfinger::post($id);
// Check the HTTP signature
@ -2150,7 +2150,7 @@ class Libzot
logger('fetching conversation: ' . $mid, LOGGER_DEBUG);
// Use Zotfinger to create a signed request
$a = Zotfinger::exec($mid, $channel);
$a = Zotfinger::post($mid, $channel);
logger('received conversation: ' . print_r($a, true), LOGGER_DATA);

View file

@ -122,7 +122,7 @@ class Libzotdir
$href = Webfinger::nomad_url(punify($ud['ud_addr']));
if ($href) {
$zf = Zotfinger::exec($href);
$zf = Zotfinger::post($href);
}
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
$xc = Libzot::import_xchan($zf['data'], 0, $ud);

View file

@ -157,28 +157,40 @@ class Share
{
$obj = [];
if (! $this->item) {
if (!$this->item) {
return $obj;
}
$obj['type'] = $this->item['obj_type'];
$obj['id'] = $this->item['mid'];
$obj['content'] = bbcode($this->item['body']);
$obj['type'] = $this->item['obj_type'];
$obj['id'] = $this->item['mid'];
$obj['content'] = bbcode($this->item['body']);
$obj['source'] = [
'mediaType' => $this->item['mimetype'],
'content' => $this->item['body']
'content' => $this->item['body']
];
$obj['name'] = $this->item['title'];
$obj['published'] = $this->item['created'];
$obj['updated'] = $this->item['edited'];
$obj['attributedTo'] = ((str_starts_with($this->item['author']['xchan_hash'], 'http'))
$obj['name'] = $this->item['title'];
$obj['published'] = $this->item['created'];
$obj['updated'] = $this->item['edited'];
$obj['attributedTo'] = ((str_starts_with($this->item['author']['xchan_hash'], 'http'))
? $this->item['author']['xchan_hash']
: $this->item['author']['xchan_url']);
return $obj;
}
public function get_obj()
{
if (!$this->item || $this->item['obj_type'] !== 'Question') {
return null;
}
$obj = is_array($this->item['obj']) ? $this->item['obj'] : json_decode($this->item['obj'], true);
if (is_null($obj)) {
return null;
}
return $obj;
}
public function get_attach()
{
return $this->attach;
@ -208,14 +220,9 @@ class Share
}
$special_object = in_array($this->item['obj_type'], [ ACTIVITY_OBJ_PHOTO, 'Event', 'Question' ]);
// These objects cannot currently be embedded.
// Return a link instead.
if ($special_object) {
return (
(in_array($this->item['author']['network'],['nomad','zot6']))
? '[zrl=' . $this->item['plink'] . ']' . $this->item['plink'] . '[/zrl]'
: '[url=' . $this->item['plink'] . ']' . $this->item['plink'] . '[/url]'
);
$object = is_array($this->item['obj']) ? $this->item['obj'] : json_decode($this->item['obj'], true);
$special = (($object['source']) ? $object['source']['content'] : $object['body']);
}
if (str_contains($this->item['body'], "[/share]")) {

View file

@ -119,12 +119,22 @@ class ThreadItem
$locktype = intval($item['item_private']);
$shareable = ((($conv->get_profile_owner() == local_channel() && local_channel()) && (! intval($item['item_private']))) ? true : false);
$repeatable = false;
// allow an exemption for sharing stuff from your private feeds
if ($item['author']['xchan_network'] === 'rss') {
$shareable = true;
}
if ($item['obj_type'] === 'Question') {
if ($shareable) {
$shareable = false;
// $repeatable = true;
}
}
if ($item['item_restrict'] & 2) {
$privacy_warning = true;
$lock = t('This comment is part of a private conversation, yet was shared with the public. Discretion advised.');
@ -315,10 +325,13 @@ class ThreadItem
$share = $embed = EMPTY_STR;
if ($shareable) {
$share = t('Repeat This');
$embed = t('Share this');
}
if ($repeatable) {
$share = t('Repeat This');
}
$dreport = '';
$keep_reports = intval(get_config('system', 'expire_delivery_reports'));

View file

@ -3,13 +3,11 @@
namespace Code\Lib;
use Code\Web\HTTPSig;
use Code\Lib\Channel;
use Code\Lib\Url;
class Zotfinger
{
public static function exec($resource, $channel = null, $verify = true, $recurse = true)
public static function post($resource, $channel = null, $verify = true, $recurse = true)
{
if (!$resource) {
@ -62,7 +60,7 @@ class Zotfinger
if ($hubs) {
foreach ($hubs as $hub) {
if ($hub['hubloc_id_url'] !== $resource and !$hub['hubloc_deleted']) {
$rzf = self::exec($hub['hubloc_id_url'],$channel,$verify);
$rzf = self::post($hub['hubloc_id_url'],$channel,$verify);
if ($rzf) {
return $rzf;
}
@ -88,5 +86,83 @@ class Zotfinger
return false;
}
public static function get($resource, $channel = null, $verify = true, $recurse = true)
{
if (!$resource) {
return false;
}
$m = parse_url($resource);
if ($m['host'] !== punify($m['host'])) {
$resource = str_replace($m['host'], punify($m['host']), $resource);
$m['host'] = punify($m['host']);
}
$accepts = Libzot::getAccepts();
if ($channel && $m) {
$headers = [
'Accept' => $accepts,
'Content-Type' => 'application/x-nomad+json',
'X-Zot-Token' => random_string(),
'Host' => $m['host'],
'(request-target)' => 'get ' . get_request_string($resource)
];
$h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], Channel::url($channel), false);
}
else {
$h = ['Accept: ' . $accepts];
}
$result = [];
$x = Url::get($resource, ['headers' => $h]);
if (in_array(intval($x['return_code']), [ 404, 410 ]) && $recurse) {
// The resource has been deleted or doesn't exist at this location.
// Try to find another nomadic resource for this channel and return that.
// First, see if there's a hubloc for this site. Fetch that record to
// obtain the nomadic identity hash. Then use that to find any additional
// nomadic locations.
$h = Activity::get_actor_hublocs($resource, 'nomad');
if ($h) {
// mark this location deleted
hubloc_delete($h[0]);
$hubs = Activity::get_actor_hublocs($h[0]['hubloc_hash']);
if ($hubs) {
foreach ($hubs as $hub) {
if ($hub['hubloc_id_url'] !== $resource && !$hub['hubloc_deleted']) {
$rzf = self::get($hub['hubloc_id_url'],$channel,$verify);
if ($rzf) {
return $rzf;
}
}
}
}
}
}
if ($x['success']) {
if ($verify) {
$result['signature'] = HTTPSig::verify($x, EMPTY_STR, 'zot6');
}
$result['data'] = json_decode($x['body'], true);
if ($result['data'] && is_array($result['data']) && array_key_exists('encrypted', $result['data']) && $result['data']['encrypted']) {
$result['data'] = json_decode(Crypto::unencapsulate($result['data'], get_config('system', 'prvkey')), true);
}
return $result;
}
return false;
}
}

View file

@ -290,7 +290,7 @@ class Activity extends Controller
http_status_exit(404, 'Not found');
}
$x = array_merge(Activity::ap_context(), $i);
$x = array_merge(ZlibActivity::ap_context(), $i);
$headers = [];
$headers['Content-Type'] = 'application/x-nomad+json';

View file

@ -76,7 +76,7 @@ class Chanview extends Controller
if ($_REQUEST['address']) {
$href = Webfinger::nomad_url(punify($_REQUEST['address']));
if ($href) {
$zf = Zotfinger::exec($href, $channel);
$zf = Zotfinger::post($href, $channel);
}
if (is_array($zf) && array_path_exists('signature/signer', $zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) {
$xc = Libzot::import_xchan($zf['data']);

View file

@ -28,7 +28,7 @@ class Zot_probe extends Controller
$resource = $_GET['resource'];
$channel = (($_GET['authf']) ? App::get_channel() : null);
$x = Zotfinger::exec($resource, $channel);
$x = Zotfinger::get($resource, $channel);
$o .= '<pre>' . htmlspecialchars(print_array($x)) . '</pre>';

View file

@ -35,7 +35,7 @@ class Zotfinger extends Controller
$resource = trim(escape_tags($_GET['resource']));
$do_import = ((intval($_GET['import']) && is_site_admin()) ? true : false);
$j = Zfinger::exec($resource, $channel);
$j = Zfinger::post($resource, $channel);
if ($do_import && $j) {
$x = Libzot::import_xchan($j['data']);

View file

@ -105,7 +105,6 @@ class HTTPSig
'content_valid' => false
];
$headers = self::find_headers($data, $body);
if (!$headers) {
@ -427,7 +426,7 @@ class HTTPSig
// Since we're inside a function that is fetching keys with which to verify signatures,
// this is necessary to prevent infinite loops.
$z = Zotfinger::exec($l['href'], null, false);
$z = Zotfinger::post($l['href'], null, false);
if ($z) {
$i = Libzot::import_xchan($z['data']);
if ($i['success']) {
@ -493,7 +492,7 @@ class HTTPSig
// Since we're inside a function that is fetching keys with which to verify signatures,
// this is necessary to prevent infinite loops.
$z = Zotfinger::exec($l['href'], null, false);
$z = Zotfinger::post($l['href'], null, false);
if ($z) {
$i = Libzot::import_xchan($z['data']);
if ($i['success']) {

View file

@ -625,7 +625,7 @@ function discover_resource(string $resource, $protocol = '', $verify = true)
if ($link['rel'] == PROTOCOL_NOMAD && ((! $protocol) || (strtolower($protocol) == 'nomad'))) {
logger('nomad found for ' . $resource, LOGGER_DEBUG);
$record = Zotfinger::exec($link['href'], null, $verify);
$record = Zotfinger::post($link['href'], null, $verify);
// Check the HTTP signature
@ -661,7 +661,7 @@ function discover_resource(string $resource, $protocol = '', $verify = true)
if ($link['rel'] === PROTOCOL_ZOT6 && ((! $protocol) || (strtolower($protocol) === 'zot6'))) {
logger('zot6 found for ' . $resource, LOGGER_DEBUG);
$record = Zotfinger::exec($link['href'], null, $verify);
$record = Zotfinger::post($link['href'], null, $verify);
// Check the HTTP signature
@ -694,7 +694,7 @@ function discover_resource(string $resource, $protocol = '', $verify = true)
}
if (str_starts_with($resource, 'http') && !$x) {
$record = Zotfinger::exec($resource, null, $verify);
$record = Zotfinger::post($resource, null, $verify);
// Check the HTTP signature

View file

@ -155,6 +155,9 @@
{{if $item.embed}}
<a class="dropdown-item" href="#" onclick="jotEmbed({{$item.id}},{{$item.item_type}}); return false"><i class="generic-icons-nav fa fa-fw fa-share" title="{{$item.embed}}"></i>{{$item.embed}}</a>
{{/if}}
{{if $item.share}}
<a class="dropdown-item" href="#" onclick="jotShare({{$item.id}},{{$item.item_type}}); return false"><i class="generic-icons-nav fa fa-fw fa-share" title="{{$item.share}}"></i>{{$item.share}}</a>
{{/if}}
{{if $item.plink}}
<a class="dropdown-item" href="{{$item.plink.href}}" title="{{$item.plink.title}}" class="u-url"><i class="generic-icons-nav fa fa-fw fa-external-link"></i>{{$item.plink.title}}</a>
{{/if}}

View file

@ -124,6 +124,9 @@
{{if $item.embed}}
<a class="dropdown-item" href="#" onclick="jotEmbed({{$item.id}},{{$item.item_type}}); return false"><i class="generic-icons-nav fa fa-fw fa-share" title="{{$item.embed}}"></i>{{$item.embed}}</a>
{{/if}}
{{if $item.share}}
<a class="dropdown-item" href="#" onclick="jotShare({{$item.id}},{{$item.item_type}}); return false"><i class="generic-icons-nav fa fa-fw fa-share" title="{{$item.share}}"></i>{{$item.share}}</a>
{{/if}}
{{if $item.plink}}
<a class="dropdown-item" href="{{$item.plink.href}}" title="{{$item.plink.title}}" class="u-url"><i class="generic-icons-nav fa fa-fw fa-external-link"></i>{{$item.plink.title}}</a>
{{/if}}