forked from friendica/friendica
Issue 15321: Fetch the latest posts from contacts
This commit is contained in:
parent
3ce6f51122
commit
88440436b7
6 changed files with 59 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ use Friendica\Core\L10n;
|
|||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
|
|
@ -214,6 +215,10 @@ class Profile extends BaseModule
|
|||
$this->updateContactFromProbe($contact['id']);
|
||||
}
|
||||
|
||||
if ($cmd === 'fetchoutbox') {
|
||||
Worker::add(Worker::PRIORITY_MEDIUM, 'FetchOutbox', $contact['id'], 0);
|
||||
}
|
||||
|
||||
if ($cmd === 'block') {
|
||||
if ($localRelationship->blocked) {
|
||||
// @TODO Backward compatibility, replace with $localRelationship->unblock()
|
||||
|
|
@ -560,6 +565,16 @@ class Profile extends BaseModule
|
|||
];
|
||||
}
|
||||
|
||||
if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
|
||||
$contact_actions['fetchoutbox'] = [
|
||||
'label' => $this->t('Fetch latest posts'),
|
||||
'url' => 'contact/' . $contact['id'] . '/fetchoutbox?t=' . $formSecurityToken,
|
||||
'title' => '',
|
||||
'sel' => '',
|
||||
'id' => 'fetchoutbox',
|
||||
];
|
||||
}
|
||||
|
||||
$contact_actions['block'] = [
|
||||
'label' => $localRelationship->blocked ? $this->t('Unblock') : $this->t('Block'),
|
||||
'url' => 'contact/' . $contact['id'] . '/block?t=' . $formSecurityToken,
|
||||
|
|
|
|||
|
|
@ -214,10 +214,11 @@ class ActivityPub
|
|||
*
|
||||
* @param string $url
|
||||
* @param integer $uid User ID
|
||||
* @param integer $max Maximum number of activities to fetch (0 = all)
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function fetchOutbox(string $url, int $uid)
|
||||
public static function fetchOutbox(string $url, int $uid, int $max = 0)
|
||||
{
|
||||
$data = HTTPSignature::fetch($url, $uid);
|
||||
if (empty($data)) {
|
||||
|
|
@ -235,9 +236,14 @@ class ActivityPub
|
|||
$items = [];
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($items as $activity) {
|
||||
$ldactivity = JsonLD::compact($activity);
|
||||
ActivityPub\Receiver::processActivity($ldactivity, '', $uid, true);
|
||||
if ($max > 0 && ++$count >= $max) {
|
||||
DI::logger()->info('Reached maximum number of activities to fetch', ['url' => $url, 'uid' => $uid, 'max' => $max]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
34
src/Worker/FetchOutbox.php
Normal file
34
src/Worker/FetchOutbox.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
|
||||
class FetchOutbox
|
||||
{
|
||||
/**
|
||||
* Fetch posts for a given contact..
|
||||
* @param int $cid Contact ID
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function execute(int $cid, int $uid)
|
||||
{
|
||||
DI::logger()->info('Start fetching posts for a given contact', ['cid' => $cid, 'uid' => $uid]);
|
||||
$account = Contact::getAccountById($cid, ['ap-outbox']);
|
||||
if (!isset($account['ap-outbox'])) {
|
||||
DI::logger()->info('No outbox found for the given contact', ['cid' => $cid, 'uid' => $uid]);
|
||||
return;
|
||||
}
|
||||
ActivityPub::fetchOutbox($account['ap-outbox'], $uid, DI::config()->get('system', 'max_feed_items'));
|
||||
DI::logger()->info('Fetched posts for a given contact', ['cid' => $cid, 'uid' => $uid]);
|
||||
}
|
||||
}
|
||||
|
|
@ -386,7 +386,7 @@ return [
|
|||
'/contact' => [
|
||||
'[/]' => [Module\Contact::class, [R::GET]],
|
||||
'/{id:\d+}[/]' => [Module\Contact\Profile::class, [R::GET, R::POST]],
|
||||
'/{id:\d+}/{action:block|ignore|collapse|update|updateprofile}'
|
||||
'/{id:\d+}/{action:block|ignore|collapse|update|updateprofile|fetchoutbox}'
|
||||
=> [Module\Contact\Profile::class, [R::GET]],
|
||||
'/{id:\d+}/advanced' => [Module\Contact\Advanced::class, [R::GET, R::POST]],
|
||||
'/{id:\d+}/conversations' => [Module\Contact\Conversations::class, [R::GET]],
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
{{if $lblsuggest}}<li role="menuitem"><a href="{{$contact_actions.suggest.url}}" title="{{$contact_actions.suggest.title}}">{{$contact_actions.suggest.label}}</a></li>{{/if}}
|
||||
{{if $poll_enabled}}<li role="menuitem"><a href="{{$contact_actions.update.url}}" title="{{$contact_actions.update.title}}">{{$contact_actions.update.label}}</a></li>{{/if}}
|
||||
{{if $contact_actions.updateprofile}}<li role="menuitem"><a href="{{$contact_actions.updateprofile.url}}" title="{{$contact_actions.updateprofile.title}}">{{$contact_actions.updateprofile.label}}</a></li>{{/if}}
|
||||
{{if $contact_actions.}}<li role="menuitem"><a href="{{$contact_actions.fetchoutbox.url}}" title="{{$contact_actions.fetchoutbox.title}}">{{$contact_actions.fetchoutbox.label}}</a></li>{{/if}}
|
||||
<li class="divider"></li>
|
||||
<li role="menuitem"><a href="#" title="{{$contact_actions.block.title}}" onclick="window.location.href='{{$contact_actions.block.url}}'; return false;">{{$contact_actions.block.label}}</a></li>
|
||||
<li role="menuitem"><a href="#" title="{{$contact_actions.ignore.title}}" onclick="window.location.href='{{$contact_actions.ignore.url}}'; return false;">{{$contact_actions.ignore.label}}</a></li>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
{{if $lblsuggest}}<li><a role="menuitem" href="{{$contact_actions.suggest.url}}" title="{{$contact_actions.suggest.title}}">{{$contact_actions.suggest.label}}</a></li>{{/if}}
|
||||
{{if $poll_enabled}}<li><a role="menuitem" href="{{$contact_actions.update.url}}" title="{{$contact_actions.update.title}}">{{$contact_actions.update.label}}</a></li>{{/if}}
|
||||
{{if $contact_actions.updateprofile}}<li><a role="menuitem" href="{{$contact_actions.updateprofile.url}}" title="{{$contact_actions.updateprofile.title}}">{{$contact_actions.updateprofile.label}}</a></li>{{/if}}
|
||||
{{if $contact_actions.fetchoutbox}}<li><a role="menuitem" href="{{$contact_actions.fetchoutbox.url}}" title="{{$contact_actions.fetchoutbox.title}}">{{$contact_actions.fetchoutbox.label}}</a></li>{{/if}}
|
||||
{{if $lblsuggest || $poll_enabled || $contact_actions.updateprofile}}
|
||||
<li class="divider"></li>
|
||||
{{/if}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue