From da2f68776e85afd84439e98ed1f4c425876ccb5b Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sat, 30 Sep 2023 08:31:07 +1000 Subject: [PATCH] fix event rsvp's --- Code/Lib/Activity.php | 35 ++++++++++++++++++++++++----------- Code/Lib/Libzot.php | 3 ++- Code/Module/Event.php | 4 ++-- Code/Module/Like.php | 8 ++++---- include/event.php | 8 +++----- include/items.php | 18 ++++++++++++++++-- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 6d7cede1b..30494265e 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -275,7 +275,7 @@ class Activity if ($r) { xchan_query($r); $r = fetch_post_tags($r); - if ($r[0]['verb'] === 'Invite') { + if (in_array($r[0]['verb'], ['Invite', 'Undo'])) { return self::encode_activity($r[0], $activitypub); } return self::encode_item($r[0], $activitypub); @@ -834,15 +834,20 @@ class Activity // inReplyTo needs to be set in the activity for followup actions (Like, Dislike, Announce, etc.), // but *not* for comments and RSVPs, where it should only be present in the object - if (!in_array($activity['type'], ['Create', 'Update', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject'])) { + if (!in_array($activity['type'], ['Create', 'Update'])) { $activity['inReplyTo'] = $item['thr_parent']; } - // For comment approvals and rejections - if (in_array($activity['type'], ['Accept','Reject']) && is_string($item['obj']) && strlen($item['obj'])) { - $activity['inReplyTo'] = $item['thr_parent']; + if (in_array($activity['type'], ['Accept', 'Reject', 'TentativeAccept', 'TentativeReject'])) { + $activity['inReplyTo'] = set_activity_mid($item['thr_parent']); } + // @FIXME FEP-5624 set for comment approvals but not event approvals + // For comment approvals and rejections + // if (in_array($activity['type'], ['Accept','Reject']) && is_string($item['obj']) && strlen($item['obj'])) { + // $activity['inReplyTo'] = $item['thr_parent']; + // } + $cnv = get_iconfig($item['parent'], 'activitypub', 'context'); if (!$cnv) { $cnv = $activity['parent_mid']; @@ -2926,8 +2931,16 @@ class Activity return false; } + if (str_starts_with($item['mid'], z_root() . '/event/')) { + $item['mid'] = str_replace('/event/', '/item/', $item['mid']); + } + $item['parent_mid'] = $act->parent_id; + if (isset($item['parent_mid']) && str_starts_with($item['parent_mid'], z_root() . '/event/')) { + $item['parent_mid'] = str_replace('/event/', '/item/', $item['parent_mid']); + } + if (array_key_exists('published', $act->data) && $act->data['published']) { $item['created'] = datetime_convert('UTC', 'UTC', $act->data['published']); } elseif ($act->objprop('published')) { @@ -2955,11 +2968,6 @@ class Activity return false; } - if ($act->type === 'Invite' && $act->objprop('type') === 'Event') { - $item['mid'] = $item['parent_mid'] = $act->id; - } - - if (isset($act->replyto) && !empty($act->replyto)) { if (is_array($act->replyto) && isset($act->replyto['id'])) { $item['replyto'] = $act->replyto['id']; @@ -2973,6 +2981,8 @@ class Activity $item['mid'] = $act->id; + $item['mid'] = reverse_activity_mid($item['mid']); + $item['parent_mid'] = ($act->objprop('id')) ? $act->objprop('id') : $act->obj; // Something went horribly wrong. The activity object isn't a string but doesn't have an id. @@ -2982,6 +2992,8 @@ class Activity return false; } + $item['parent_mid'] = reverse_activity_mid($item['parent_mid']); + // over-ride the object timestamp with the activity if (isset($act->data['published']) && $act->data['published']) { @@ -3857,7 +3869,8 @@ class Activity } } - if (in_array($item['verb'], ['Accept', 'Reject'])) { + $objtype = $act->objprop('type',''); + if (in_array($item['verb'], ['Accept', 'Reject']) && !in_array($objtype, ['Invite', 'Event'])) { if (CommentApproval::doVerify($item, $channel, $act)) { return; } diff --git a/Code/Lib/Libzot.php b/Code/Lib/Libzot.php index 415d83d0b..374c1ecba 100644 --- a/Code/Lib/Libzot.php +++ b/Code/Lib/Libzot.php @@ -1749,7 +1749,8 @@ class Libzot } } - if (in_array($arr['verb'], ['Accept', 'Reject'])) { + $objtype = $act->objprop('type',''); + if (in_array($arr['verb'], ['Accept', 'Reject']) && !in_array($objtype, ['Invite', 'Event'])) { if (CommentApproval::doVerify($arr, $channel, $act)) { continue; } diff --git a/Code/Module/Event.php b/Code/Module/Event.php index c943fef4e..c64ecab38 100644 --- a/Code/Module/Event.php +++ b/Code/Module/Event.php @@ -29,13 +29,13 @@ class Event extends Controller $r = q( "select * from item where mid like '%s' $item_normal $sql_extra limit 1", - dbesc(z_root() . '/activity/' . $item_id . '%') + dbesc(z_root() . '/item/' . $item_id . '%') ); if (!$r) { $r = q( "select * from item where mid like '%s' $item_normal limit 1", - dbesc(z_root() . '/activity/' . $item_id . '%') + dbesc(z_root() . '/item/' . $item_id . '%') ); if ($r) { diff --git a/Code/Module/Like.php b/Code/Module/Like.php index 928cd58b4..ee1df8c61 100644 --- a/Code/Module/Like.php +++ b/Code/Module/Like.php @@ -18,7 +18,7 @@ class Like extends Controller { - public function get() + public function init() { $undo = false; @@ -171,7 +171,7 @@ class Like extends Controller $arr = []; $arr['uuid'] = $uuid; - $arr['mid'] = z_root() . (($is_rsvp) ? '/activity/' : '/item/' ) . $uuid; + $arr['mid'] = z_root() . '/item/' . $uuid; $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); if ($item['obj_type'] === ACTIVITY_OBJ_EVENT) { @@ -254,7 +254,7 @@ class Like extends Controller } $arr['parent'] = $item['parent']; - $arr['thr_parent'] = $item['mid']; + $arr['thr_parent'] = ($is_rsvp) ? reverse_activity_mid($item['mid']) : $item['mid']; $allow_cid = $item['allow_cid']; $allow_gid = $item['allow_gid']; $deny_cid = $item['deny_cid']; @@ -266,7 +266,7 @@ class Like extends Controller $arr['item_flags'] = $item['item_flags']; $arr['item_wall'] = $item['item_wall']; - $arr['parent_mid'] = $item['parent_mid']; + $arr['parent_mid'] = ($is_rsvp) ? reverse_activity_mid($item['parent_mid']) : $item['parent_mid']; $arr['owner_xchan'] = $thread_owner['xchan_hash']; $arr['author_xchan'] = $observer['xchan_hash']; $arr['created'] = $arr['edited'] = datetime_convert(); diff --git a/include/event.php b/include/event.php index 597fad86f..a49601231 100644 --- a/include/event.php +++ b/include/event.php @@ -137,7 +137,7 @@ function format_event_obj($jobject) ]); $event['content'] = replace_macros(Theme::get_template('event_item_content.tpl'), [ - '$description' => $object['content'], + '$description' => (($title) ? '' . $title . '' : '') . $object['content'], '$location_label' => t('Location:'), '$location' => ((array_path_exists('location/content', $object)) ? zidify_links(smilies(bbcode($object['location']['content']))) : EMPTY_STR) ]); @@ -1212,14 +1212,13 @@ function event_store_item($arr, $event) 'type' => 'Event', 'id' => z_root() . '/event/' . $r[0]['resource_id'], 'name' => $arr['summary'], -// 'summary' => bbcode($arr['summary']), // RFC3339 Section 4.3 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($arr['description']), 'location' => [ 'type' => 'Place', 'content' => $arr['location'] ], 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ], 'url' => [ [ 'mediaType' => 'text/calendar', 'href' => z_root() . '/events/ical/' . $event['event_hash'] ] ], - 'actor' => Activity::encode_person($r[0], false), + 'attributedTo' => Activity::encode_person($r[0], false), 'attachment' => Activity::encode_attachment($r[0]), 'tag' => Activity::encode_taxonomy($r[0]) ]; @@ -1371,14 +1370,13 @@ function event_store_item($arr, $event) 'type' => 'Event', 'id' => z_root() . '/event/' . $event['event_hash'], 'name' => $arr['summary'], -// 'summary' => bbcode($arr['summary']), // RFC3339 Section 4.3 'startTime' => (($arr['adjust']) ? datetime_convert('UTC', 'UTC', $arr['dtstart'], ATOM_TIME) : datetime_convert('UTC', 'UTC', $arr['dtstart'], 'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($arr['description']), 'location' => [ 'type' => 'Place', 'content' => bbcode($arr['location']) ], 'source' => [ 'content' => format_event_bbcode($arr), 'mediaType' => 'text/x-multicode' ], 'url' => [ [ 'mediaType' => 'text/calendar', 'href' => z_root() . '/events/ical/' . $event['event_hash'] ] ], - 'actor' => Activity::encode_person($z, false), + 'attributedTo' => Activity::encode_person($z, false), 'attachment' => Activity::encode_attachment($item_arr), 'tag' => Activity::encode_taxonomy($item_arr) ]; diff --git a/include/items.php b/include/items.php index e2fa8c181..b2f563fda 100644 --- a/include/items.php +++ b/include/items.php @@ -1610,8 +1610,9 @@ function item_store($arr, $deliver = true) { // find the parent and snarf the item id and ACL's // and anything else we need to inherit - $r = q("SELECT item_level FROM item WHERE mid = '%s' AND uid = %d ORDER BY id ASC LIMIT 1", + $r = q("SELECT item_level FROM item WHERE (mid = '%s' OR mid = '%s') AND uid = %d ORDER BY id ASC LIMIT 1", dbesc($arr['thr_parent']), + dbesc(reverse_activity_mid($arr['thr_parent'])), intval($arr['uid']) ); if($r) { @@ -1621,8 +1622,9 @@ function item_store($arr, $deliver = true) { $arr['item_level'] = 1; } - $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d ORDER BY id ASC LIMIT 1", + $r = q("SELECT * FROM item WHERE (mid = '%s' OR mid = '%s') AND uid = %d ORDER BY id ASC LIMIT 1", dbesc($arr['parent_mid']), + dbesc(reverse_activity_mid($arr['parent_mid'])), intval($arr['uid']) ); @@ -4827,3 +4829,15 @@ function copy_of_pubitem($channel,$mid) { } return $result; } + +function reverse_activity_mid($string) +{ + return str_replace(z_root() . '/activity/', z_root() . '/item/', $string); +} + +function set_activity_mid($string) +{ + return str_replace(z_root() . '/item/', z_root() . '/activity/', $string); +} + +