fix event rsvp's

This commit is contained in:
Mike Macgirvin 2023-09-30 08:31:07 +10:00
parent f727fe1f63
commit da2f68776e
6 changed files with 51 additions and 25 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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();

View file

@ -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) ? '<strong>' . $title . '</strong>' : '') . $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)
];

View file

@ -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);
}