aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Activity.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib/Activity.php')
-rw-r--r--Zotlabs/Lib/Activity.php122
1 files changed, 73 insertions, 49 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 992ade200..835909849 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -120,6 +120,7 @@ class Activity {
}
$h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), false);
+ $start_timestamp = microtime(true);
$x = z_fetch_url($url, true, $redirects, ['headers' => $h]);
}
@@ -142,8 +143,14 @@ class Activity {
logger('returned: ' . json_encode($y, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOGGER_DEBUG);
if (isset($y['type']) && ActivityStreams::is_an_actor($y['type'])) {
+ logger('logger_stats_data cmd:Actor_fetch' . ' start:' . $start_timestamp . ' ' . 'end:' . microtime(true) . ' meta:' . $url . '#' . random_string(16));
+ btlogger('actor fetch');
+ $y['actor_cache_date'] = datetime_convert();
XConfig::Set($y['id'], 'system', 'actor_record', $y);
}
+ else {
+ logger('logger_stats_data cmd:Activity_fetch' . ' start:' . $start_timestamp . ' ' . 'end:' . microtime(true) . ' meta:' . $url . '#' . random_string(16));
+ }
return json_decode($x['body'], true);
}
@@ -151,6 +158,8 @@ class Activity {
logger('fetch failed: ' . $url);
logger($x['body']);
}
+
+
return null;
}
@@ -543,7 +552,7 @@ class Activity {
$ret['commentPolicy'] .= 'until=' . datetime_convert('UTC', 'UTC', $i['comments_closed'], ATOM_TIME);
}
- $ret['attributedTo'] = $i['author']['xchan_url'];
+ $ret['attributedTo'] = self::encode_person($i['author'], false);
if ($i['mid'] !== $i['parent_mid']) {
$ret['inReplyTo'] = ((strpos($i['thr_parent'], 'http') === 0) ? $i['thr_parent'] : z_root() . '/item/' . urlencode($i['thr_parent']));
@@ -1369,7 +1378,7 @@ class Activity {
// store their xchan and hubloc
- self::actor_store($person_obj['id'], $person_obj);
+ self::actor_store($person_obj);
// Find any existing abook record
@@ -1600,15 +1609,7 @@ class Activity {
}
- static function actor_store($url, $person_obj = null, $force = false) {
-
- if ($person_obj === null) {
- $tgt = self::fetch($url);
- if (is_array($tgt) && ActivityStreams::is_an_actor($tgt['type'])) {
- self::actor_store($tgt['id'], $tgt);
- }
- return;
- }
+ static function actor_store($person_obj, $force = false) {
if (!is_array($person_obj)) {
return;
@@ -1618,13 +1619,14 @@ class Activity {
if (array_key_exists('movedTo',$person_obj) && $person_obj['movedTo'] && ! is_array($person_obj['movedTo'])) {
$tgt = self::fetch($person_obj['movedTo']);
if (is_array($tgt)) {
- self::actor_store($person_obj['movedTo'],$tgt);
+ self::actor_store($tgt);
ActivityPub::move($person_obj['id'],$tgt);
}
return;
}
*/
+ $url = null;
$ap_hubloc = null;
$hublocs = self::get_actor_hublocs($url);
@@ -1645,7 +1647,7 @@ class Activity {
if ($ap_hubloc) {
// we already have a stored record. Determine if it needs updating.
if ($ap_hubloc['hubloc_updated'] < datetime_convert('UTC', 'UTC', ' now - 3 days') || $force) {
- $person_obj = self::fetch($url);
+ $person_obj = self::get_cached_actor($url);
}
else {
return;
@@ -1668,11 +1670,6 @@ class Activity {
return;
}
- // store the actor record in XConfig
-
- // we already store this in Activity::fetch()
- // XConfig::Set($url, 'system', 'actor_record', $person_obj);
-
$name = $person_obj['name'] ?? '';
if (!$name) {
$name = $person_obj['preferredUsername'] ?? '';
@@ -1697,7 +1694,7 @@ class Activity {
$webfinger_addr = escape_tags($person_obj['preferredUsername']) . '@' . $hostname;
}
- $icon = z_root() . '/' . get_default_profile_photo(300);
+ $icon = null;
if (isset($person_obj['icon'])) {
if (is_array($person_obj['icon'])) {
if (array_key_exists('url', $person_obj['icon'])) {
@@ -1807,6 +1804,9 @@ class Activity {
'xchan_addr' => $webfinger_addr,
'xchan_url' => $profile,
'xchan_name' => escape_tags($name),
+ 'xchan_photo_l' => z_root() . '/' . get_default_profile_photo(),
+ 'xchan_photo_m' => z_root() . '/' . get_default_profile_photo(80),
+ 'xchan_photo_s' => z_root() . '/' . get_default_profile_photo(48),
'xchan_name_date' => datetime_convert(),
'xchan_network' => 'activitypub',
'xchan_pubforum' => intval($group_actor)
@@ -1846,16 +1846,9 @@ class Activity {
}
}
- $photos = import_xchan_photo($icon, $url);
- q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
- dbescdate(datetime_convert('UTC', 'UTC', $photos[5])),
- dbesc($photos[0]),
- dbesc($photos[1]),
- dbesc($photos[2]),
- dbesc($photos[3]),
- dbesc($url)
- );
-
+ if ($icon) {
+ Master::Summon(['Xchan_photo', bin2hex($icon), bin2hex($url)]);
+ }
}
static function create_action($channel, $observer_hash, $act) {
@@ -2281,6 +2274,7 @@ class Activity {
}
static function decode_note($act) {
+
$response_activity = false;
$s = [];
@@ -2307,7 +2301,7 @@ class Activity {
}
// ensure we store the original actor
- self::actor_store($act->actor['id'], $act->actor);
+ self::actor_store($act->actor);
$s['owner_xchan'] = $act->actor['id'];
$s['author_xchan'] = $act->actor['id'];
@@ -2351,7 +2345,7 @@ class Activity {
$s['expires'] = datetime_convert('UTC', 'UTC', $act->obj['expires']);
}
- if ($act->type === 'Invite' && $act->objprop('type') === 'Event') {
+ if (in_array($act->type, ['Invite', 'Create']) && $act->objprop('type') === 'Event') {
$s['mid'] = $s['parent_mid'] = $act->id;
}
@@ -2362,6 +2356,9 @@ class Activity {
$s['mid'] = $act->id;
$s['uuid'] = ((!empty($act->data['diaspora:guid'])) ? $act->data['diaspora:guid'] : uuid_from_url($s['mid']));
+ $s['parent_mid'] = $act->objprop('id') ?: $act->obj;
+
+/*
if ($act->objprop('inReplyTo')) {
$s['parent_mid'] = $act->objprop('inReplyTo');
}
@@ -2372,7 +2369,7 @@ class Activity {
logger('response activity without parent_mid or thr_parent');
return;
}
-
+*/
// over-ride the object timestamp with the activity
if (isset($act->data['published'])) {
@@ -2390,30 +2387,30 @@ class Activity {
}
// ensure we store the original actor
- self::actor_store($obj_actor['id'], $obj_actor);
+ self::actor_store($obj_actor);
$mention = self::get_actor_bbmention($obj_actor['id']);
if ($act->type === 'Like') {
- $content['content'] = sprintf(t('Likes %1$s\'s %2$s'), $mention, $act->obj['type']) . "\n\n" . $content['content'] ?? '';
+ $content['content'] = sprintf(t('Likes %1$s\'s %2$s'), $mention, $act->obj['type']) . EOL . EOL . ($content['content'] ?? '');
}
if ($act->type === 'Dislike') {
- $content['content'] = sprintf(t('Doesn\'t like %1$s\'s %2$s'), $mention, $act->obj['type']) . "\n\n" . $content['content'] ?? '';
+ $content['content'] = sprintf(t('Doesn\'t like %1$s\'s %2$s'), $mention, $act->obj['type']) . EOL . EOL . ($content['content'] ?? '');
}
// handle event RSVPs
if (($act->objprop('type') === 'Event') || ($act->objprop('type') === 'Invite' && array_path_exists('object/type', $act->obj) && $act->obj['object']['type'] === 'Event')) {
if ($act->type === 'Accept') {
- $content['content'] = sprintf(t('Will attend %s\'s event'), $mention) . EOL . EOL . $content['content'];
+ $content['content'] = sprintf(t('Will attend %s\'s event'), $mention) . EOL . EOL . ($content['content'] ?? '');
}
if ($act->type === 'Reject') {
- $content['content'] = sprintf(t('Will not attend %s\'s event'), $mention) . EOL . EOL . $content['content'];
+ $content['content'] = sprintf(t('Will not attend %s\'s event'), $mention) . EOL . EOL . ($content['content'] ?? '');
}
if ($act->type === 'TentativeAccept') {
- $content['content'] = sprintf(t('May attend %s\'s event'), $mention) . EOL . EOL . $content['content'];
+ $content['content'] = sprintf(t('May attend %s\'s event'), $mention) . EOL . EOL . ($content['content'] ?? '');
}
if ($act->type === 'TentativeReject') {
- $content['content'] = sprintf(t('May not attend %s\'s event'), $mention) . EOL . EOL . $content['content'];
+ $content['content'] = sprintf(t('May not attend %s\'s event'), $mention) . EOL . EOL . ($content['content'] ?? '');
}
}
@@ -2596,11 +2593,11 @@ class Activity {
if (!$response_activity) {
if ($act->type === 'Announce') {
$s['author_xchan'] = self::get_attributed_to_actor_url($act);
- $s['mid'] = $act->obj['id'];
+ $s['mid'] = $act->objprop('id') ?: $act->obj;
// Do not force new thread if the announce is from a group actor
if ($act->actor['type'] !== 'Group') {
- $s['parent_mid'] = $act->obj['id'];
+ $s['parent_mid'] = $act->objprop('id') ?: $act->obj;
}
}
@@ -2903,6 +2900,10 @@ class Activity {
set_iconfig($s, 'activitypub', 'recips', $act->raw_recips);
}
+ if ($act->objprop('type') === 'Event' && $act->objprop('timezone')) {
+ set_iconfig($s, 'event', 'timezone', $act->objprop('timezone'), true);
+ }
+
$hookinfo = [
'act' => $act,
's' => $s
@@ -3007,7 +3008,7 @@ class Activity {
$allowed = true;
// reject public stream comments that weren't sent by the conversation owner
- if ($is_sys_channel && $item['owner_xchan'] !== $observer_hash && !$fetch_parents) {
+ if ($is_sys_channel && $item['owner_xchan'] !== $observer_hash && !$fetch_parents && empty($item['item_fetched'])) {
$allowed = false;
}
}
@@ -3143,8 +3144,6 @@ class Activity {
$fetch = false;
- // TODO: debug
- // if (perm_is_allowed($channel['channel_id'],$observer_hash,'send_stream') && (PConfig::Get($channel['channel_id'],'system','hyperdrive',true) || $act->type === 'Announce')) {
if (perm_is_allowed($channel['channel_id'], $observer_hash, 'send_stream') || $is_sys_channel) {
$fetch = (($fetch_parents) ? self::fetch_and_store_parents($channel, $observer_hash, $item, $force) : false);
}
@@ -3162,7 +3161,7 @@ class Activity {
return;
}
-/*
+
if ($parent[0]['parent_mid'] !== $item['parent_mid']) {
$item['thr_parent'] = $item['parent_mid'];
}
@@ -3170,7 +3169,7 @@ class Activity {
$item['thr_parent'] = $parent[0]['parent_mid'];
}
$item['parent_mid'] = $parent[0]['parent_mid'];
-*/
+
/*
*
@@ -3263,7 +3262,12 @@ class Activity {
}
}
- if (is_array($x) && $x['item_id']) {
+ if ($x['success']) {
+
+ if (check_item_source($channel['channel_id'], $x['item']) && in_array($x['item']['obj_type'], ['Event', ACTIVITY_OBJ_EVENT])) {
+ event_addtocal($x['item_id'], $channel['channel_id']);
+ }
+
if ($is_child_node) {
if ($item['owner_xchan'] === $channel['channel_hash']) {
// We are the owner of this conversation, so send all received comments back downstream
@@ -3384,7 +3388,7 @@ class Activity {
}
if (is_array($a->actor) && array_key_exists('id', $a->actor)) {
- self::actor_store($a->actor['id'], $a->actor);
+ self::actor_store($a->actor);
}
$replies = null;
@@ -4035,7 +4039,8 @@ class Activity {
$cache_url = ((strpos($id, '#')) ? substr($id, 0, strpos($id, '#')) : $id);
$actor = XConfig::Get($cache_url, 'system', 'actor_record');
- if ($actor) {
+ if ($actor && isset($actor['actor_cache_date']) && $actor['actor_cache_date'] > datetime_convert('UTC', 'UTC', ' now - 3 days')) {
+ unset($actor['actor_cache_date']);
return $actor;
}
@@ -4050,6 +4055,25 @@ class Activity {
return $hookdata['actor'];
}
+ static function get_actor($actor_id) {
+ // remove fragment
+ $actor_id = ((strpos($actor_id, '#')) ? substr($actor_id, 0, strpos($actor_id, '#')) : $actor_id);
+
+ $actor = self::get_cached_actor($actor_id);
+
+ if ($actor) {
+ return $actor;
+ }
+
+ $actor = self::fetch($actor_id);
+
+ if ($actor) {
+ return $actor;
+ }
+
+ return null;
+ }
+
static function get_unknown_actor($act) {
// try other get_actor providers (e.g. diaspora)