The inbox-status can now be archived for a whole server

This commit is contained in:
Michael 2022-12-31 23:42:00 +00:00
parent 7942881f7e
commit e21db0fe6d
7 changed files with 105 additions and 15 deletions

View file

@ -226,14 +226,11 @@ class APContact
$apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
$apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
self::unarchiveInbox($apcontact['inbox'], false);
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
$apcontact['sharedinbox'] = '';
if (!empty($compacted['as:endpoints'])) {
$apcontact['sharedinbox'] = (JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id') ?? '');
self::unarchiveInbox($apcontact['sharedinbox'], true);
}
$apcontact['featured'] = JsonLD::fetchElement($compacted, 'toot:featured', '@id');
@ -427,6 +424,12 @@ class APContact
$apcontact['gsid'] = null;
}
self::unarchiveInbox($apcontact['inbox'], false, $apcontact['gsid']);
if (!empty($apcontact['sharedinbox'])) {
self::unarchiveInbox($apcontact['sharedinbox'], true, $apcontact['gsid']);
}
if ($apcontact['url'] == $apcontact['alias']) {
$apcontact['alias'] = null;
}
@ -517,7 +520,7 @@ class APContact
{
if (!empty($apcontact['inbox'])) {
Logger::info('Set inbox status to failure', ['inbox' => $apcontact['inbox']]);
HTTPSignature::setInboxStatus($apcontact['inbox'], false);
HTTPSignature::setInboxStatus($apcontact['inbox'], false, false, $apcontact['gsid']);
}
if (!empty($apcontact['sharedinbox'])) {
@ -527,7 +530,7 @@ class APContact
if (!$available) {
// If all known personal inboxes are failing then set their shared inbox to failure as well
Logger::info('Set shared inbox status to failure', ['sharedinbox' => $apcontact['sharedinbox']]);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], false, true);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], false, true, $apcontact['gsid']);
}
}
}
@ -542,11 +545,11 @@ class APContact
{
if (!empty($apcontact['inbox'])) {
Logger::info('Set inbox status to success', ['inbox' => $apcontact['inbox']]);
HTTPSignature::setInboxStatus($apcontact['inbox'], true);
HTTPSignature::setInboxStatus($apcontact['inbox'], true, false, $apcontact['gsid']);
}
if (!empty($apcontact['sharedinbox'])) {
Logger::info('Set shared inbox status to success', ['sharedinbox' => $apcontact['sharedinbox']]);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], true, true);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], true, true, $apcontact['gsid']);
}
}
@ -555,15 +558,16 @@ class APContact
*
* @param string $url inbox url
* @param boolean $shared Shared Inbox
* @param int $gsid Global server id
* @return void
*/
private static function unarchiveInbox(string $url, bool $shared)
private static function unarchiveInbox(string $url, bool $shared, int $gsid = null)
{
if (empty($url)) {
return;
}
HTTPSignature::setInboxStatus($url, true, $shared);
HTTPSignature::setInboxStatus($url, true, $shared, $gsid);
}
/**

View file

@ -408,7 +408,7 @@ class GServer
['nurl' => Strings::normaliseLink($url)]);
Logger::info('Set failed status for existing server', ['url' => $url]);
if (self::isDefunct($gserver)) {
Contact::update(['archive' => true], ['gsid' => $gserver['id']]);
self::archiveContacts($gserver['id']);
}
return;
}
@ -418,6 +418,18 @@ class GServer
Logger::info('Set failed status for new server', ['url' => $url]);
}
/**
* Archive server related contacts and inboxes
*
* @param integer $gsid
* @return void
*/
private static function archiveContacts(int $gsid)
{
Contact::update(['archive' => true], ['gsid' => $gsid]);
DBA::update('inbox-status', ['archive' => true], ['gsid' => $gsid]);
}
/**
* Remove unwanted content from the given URL
*