fix comment edits

This commit is contained in:
Mike Macgirvin 2022-12-28 12:51:30 +11:00
parent 9a9b850028
commit d2771649a8
5 changed files with 32 additions and 18 deletions

View file

@ -5,6 +5,7 @@ namespace Code\Daemon;
use Code\Lib\Config;
use Code\Lib\IConfig;
use Code\Lib\Libzot;
use Code\Lib\ObjCache;
use Code\Lib\Queue;
use Code\Lib\Activity;
use Code\Lib\ActivityStreams;
@ -343,16 +344,18 @@ class Notifier implements DaemonInterface
return;
}
$m = get_iconfig($target_item, 'activitypub', 'signed_data');
// $m = get_iconfig($target_item, 'activitypub', 'signed_data');
$m = ($cmd === 'edit_post') ? '' : ObjCache::Get($target_item['mid'] . '.nomad');
// Re-use existing signature unless the activity type changed to a Tombstone, which won't verify.
if ($m && (! intval($target_item['item_deleted']))) {
self::$encoded_item = json_decode($m, true);
} else {
self::$encoded_item = array_merge(Activity::ap_context(), Activity::encode_activity($target_item, true));
self::$encoded_item['signature'] = LDSignatures::sign(self::$encoded_item, self::$channel);
}
logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG);
logger('encoded: ' . print_r(self::$encoded_item, true), LOGGER_DEBUG);

View file

@ -292,22 +292,22 @@ class CommentApproval
protected function get_parent()
{
$result = q("select mid, replyto from item where mid = '%s'",
$results = q("select mid, replyto from item where mid = '%s'",
dbesc($this->item['parent_mid'])
);
if ($result) {
$item = array_shift($result);
if ($results) {
$item = array_shift($results);
if($item['replyto']) {
// Not a Twitter-like platform. Use the conversation parent
return $item['mid'];
}
else {
$result = q("select mid from item where mid = '%s'",
$results = q("select mid from item where mid = '%s'",
dbesc($this->item['thr_parent'])
);
if ($result) {
if ($results) {
// Twitter-like platform. Use the immediate parent
$item = array_shift($result);
$item = array_shift($results);
return $item['mid'];
}
}

View file

@ -1368,10 +1368,11 @@ class Libzot
$arr['comment_policy'] = 'authenticated';
}
if (isset($AS->meta['signed_data'])) {
IConfig::Set($arr, 'activitypub', 'signed_data', $AS->meta['signed_data'], false);
ObjCache::Set($arr['mid'] . '.nomad', $AS->meta['signed_data']);
// IConfig::Set($arr, 'activitypub', 'signed_data', $AS->meta['signed_data'], false);
$j = json_decode($AS->meta['signed_data'], true);
if ($j) {
ObjCache::Set($arr['mid'], json_encode(JSalmon::unpack($j['data'])));
ObjCache::Set($arr['mid'], json_encode(JSalmon::unpack($j['data'])), false);
// IConfig::Set($arr, 'activitypub', 'rawmsg', json_encode(JSalmon::unpack($j['data'])), false);
}
}
@ -1967,7 +1968,6 @@ class Libzot
// reactions such as like and dislike could have an mid with /activity/ in it.
// Check for both forms in order to prevent duplicates.
$r = q(
"select * from item where mid in ('%s','%s') and uid = %d limit 1",
dbesc($arr['mid']),
@ -1986,11 +1986,13 @@ class Libzot
continue;
} // Maybe it has been edited?
elseif ($arr['edited'] > $r[0]['edited'] || $arr['approved'] !== $r[0]['approved']) {
elseif ($arr['edited'] > $r[0]['edited'] || ($arr['edited'] === $r[0]['edited'] && $arr['approved'] !== $r[0]['approved'])) {
$arr['id'] = $r[0]['id'];
$arr['uid'] = $channel['channel_id'];
if (post_is_importable($channel['channel_id'], $arr, $abook)) {
// ObjCache::Set($arr['mid'], $act->meta['signed_data']);
// IConfig::Set($arr, 'activitypub', 'signed_data', $act->meta['signed_data'], false);
ObjCache::Set($arr['mid'] . '.nomad', $act->meta['signed_data']);
$item_result = self::update_imported_item($sender, $arr, $r[0], $channel['channel_id'], $tag_delivery);
$DR->update('updated');
$result[] = $DR->get();
@ -2045,7 +2047,8 @@ class Libzot
if (str_contains($arr['body'], "#^[")) {
$arr['body'] = str_replace("#^[", "[", $arr['body']);
}
// ObjCache::Set($arr['mid'], $act->meta['signed_data']);
// IConfig::Set($arr, 'activitypub', 'signed_data', $act->meta['signed_data'], false);
ObjCache::Set($arr['mid'] . '.nomad', $act->meta['signed_data']);
$item_result = item_store($arr);
if ($item_result['success']) {
$item_id = $item_result['item_id'];
@ -2213,7 +2216,8 @@ class Libzot
}
if (isset($AS->meta) && isset($AS->meta['signed_data']) && $AS->meta['signed_data']) {
IConfig::Set($arr, 'activitystreams', 'signed_data', $AS->meta['signed_data'], false);
// IConfig::Set($arr, 'activitypub', 'signed_data', $AS->meta['signed_data'], false);
ObjCache::Set($arr['mid'] . '.nomad', $AS->meta['signed_data']);
}
logger('FOF Activity received: ' . print_r($arr, true), LOGGER_DATA, LOG_DEBUG);

View file

@ -1618,6 +1618,13 @@ class Item extends Controller
if ($orig_post) {
$datarray['id'] = $post_id;
q("delete from item where verb in ('Accept', 'Reject') and obj = '%s' and uid = %d",
dbesc('"', $datarray['mid'] . '"'),
intval($this->channel['channel_id'])
);
unset($datarray['approved']);
$x = item_store_update($datarray);
if ($x['success']) {

View file

@ -571,7 +571,7 @@ function get_item_elements($x) {
$arr['comment_policy'] = (($x['comment_scope']) ? htmlspecialchars($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts');
$arr['sig'] = (($x['signature']) ? htmlspecialchars($x['signature'], ENT_COMPAT,'UTF-8',false) : '');
$arr['approved'] = (($x['appproved']) ? htmlspecialchars($x['approved'], ENT_COMPAT,'UTF-8',false) : '');
// fix old-style signatures imported from hubzilla via polling and zot_feed
// so they verify.
@ -2083,7 +2083,7 @@ function item_store_update($arr, $deliver = true) {
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : $orig[0]['location']);
$arr['uuid'] = ((x($arr,'uuid')) ? notags(trim($arr['uuid'])) : $orig[0]['uuid']);
$arr['approved'] = ((x($arr,'approved')) ? notags(trim($arr['approved'])) : $orig[0]['approved']);
$arr['approved'] = ((x($arr,'approved')) ? notags(trim($arr['approved'])) : '');
$arr['lat'] = ((x($arr,'lat')) ? floatval($arr['lat']) : $orig[0]['lat']);
$arr['lon'] = ((x($arr,'lon')) ? floatval($arr['lon']) : $orig[0]['lon']);
$arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : $orig[0]['verb']);