2021-12-03 03:01:39 +00:00
|
|
|
<?php
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Daemon;
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Lib\Activity;
|
|
|
|
use Code\Lib\ActivityStreams;
|
|
|
|
use Code\Lib\ASCollection;
|
|
|
|
use Code\Lib\Channel;
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2022-11-27 09:15:28 +00:00
|
|
|
class Convo implements DaemonInterface
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2022-11-20 01:19:52 +00:00
|
|
|
/**
|
|
|
|
* @param int $argc
|
|
|
|
* @param array $argv
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run(int $argc, array $argv): void
|
2021-12-03 03:01:39 +00:00
|
|
|
{
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
logger('convo invoked: ' . print_r($argv, true));
|
2020-10-21 00:57:34 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if ($argc != 4) {
|
|
|
|
killme();
|
|
|
|
}
|
2020-09-23 01:10:11 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
$id = $argv[1];
|
|
|
|
$channel_id = intval($argv[2]);
|
|
|
|
$contact_hash = $argv[3];
|
2020-09-23 04:09:16 +00:00
|
|
|
|
2022-01-25 01:26:12 +00:00
|
|
|
$channel = Channel::from_id($channel_id);
|
2021-12-03 03:01:39 +00:00
|
|
|
if (! $channel) {
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
$r = q(
|
|
|
|
"SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash
|
2020-09-23 01:10:11 +00:00
|
|
|
WHERE abook_channel = %d and abook_xchan = '%s' LIMIT 1",
|
2021-12-03 03:01:39 +00:00
|
|
|
intval($channel_id),
|
|
|
|
dbesc($contact_hash)
|
|
|
|
);
|
|
|
|
if (! $r) {
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact = array_shift($r);
|
|
|
|
|
|
|
|
$obj = new ASCollection($id, $channel);
|
|
|
|
|
|
|
|
$messages = $obj->get();
|
|
|
|
|
|
|
|
if ($messages) {
|
|
|
|
foreach ($messages as $message) {
|
|
|
|
if (is_string($message)) {
|
|
|
|
$message = Activity::fetch($message, $channel);
|
|
|
|
}
|
2022-10-20 20:00:55 +00:00
|
|
|
// set client flag because comments will probably just be objects and not full-blown activities
|
2021-12-03 03:01:39 +00:00
|
|
|
// and that lets us use implied_create
|
|
|
|
$AS = new ActivityStreams($message, null, true);
|
|
|
|
if ($AS->is_valid() && is_array($AS->obj)) {
|
|
|
|
$item = Activity::decode_note($AS, true);
|
2022-11-19 23:38:12 +00:00
|
|
|
if ($item) {
|
|
|
|
Activity::store($channel, $contact['abook_xchan'], $AS, $item, true, true);
|
|
|
|
}
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 01:10:11 +00:00
|
|
|
}
|