kopia lustrzana https://github.com/nextcloud/social
commit
279d43638c
|
@ -169,12 +169,12 @@ class Timeline extends ExtendedBase {
|
|||
break;
|
||||
|
||||
case 'local':
|
||||
$stream = $this->streamRequest->getTimelineGlobal(0, $this->count, true);
|
||||
$stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, true);
|
||||
$this->outputStreams($stream);
|
||||
break;
|
||||
|
||||
case 'global':
|
||||
$stream = $this->streamRequest->getTimelineGlobal(0, $this->count, false);
|
||||
$stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, false);
|
||||
$this->outputStreams($stream);
|
||||
break;
|
||||
|
||||
|
|
|
@ -261,14 +261,17 @@ class ApiController extends Controller {
|
|||
*
|
||||
* @param string $timeline
|
||||
* @param int $limit
|
||||
*
|
||||
* @param int $max_id
|
||||
* @param int $min_id
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function timelines(string $timeline, int $limit = 20): DataResponse {
|
||||
public function timelines(string $timeline, int $limit = 20, int $max_id = 0, int $min_id = 0): DataResponse {
|
||||
$options = new TimelineOptions($this->request);
|
||||
$options->setFormat(Stream::FORMAT_LOCAL);
|
||||
$options->setTimeline($timeline);
|
||||
$options->setLimit($limit);
|
||||
$options->setMaxId($max_id);
|
||||
$options->setMinId($min_id);
|
||||
|
||||
try {
|
||||
$this->initViewer(true);
|
||||
|
|
|
@ -412,7 +412,7 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
*
|
||||
* @return Stream[]
|
||||
* @throws DateTimeException
|
||||
* @deprecated - use GetTimeline()
|
||||
* @deprecated - use getTimelineHome()
|
||||
*/
|
||||
public function getTimelineHome_dep(
|
||||
int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB
|
||||
|
@ -521,6 +521,37 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
return $this->getStreamsFromRequest($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should returns:
|
||||
* * All local public/federated posts
|
||||
*
|
||||
* @param TimelineOptions $options
|
||||
*
|
||||
* @return Stream[]
|
||||
* @throws DateTimeException
|
||||
*/
|
||||
public function getTimelinePublic(TimelineOptions $options): array {
|
||||
$qb = $this->getStreamSelectSql($options->getFormat());
|
||||
$qb->paginate($options);
|
||||
|
||||
$qb->limitToLocal($options->isLocal());
|
||||
$qb->limitToType(Note::TYPE);
|
||||
|
||||
$qb->linkToCacheActors('ca', 's.attributed_to_prim');
|
||||
$qb->leftJoinStreamAction();
|
||||
|
||||
$qb->selectDestFollowing('sd', '');
|
||||
$qb->innerJoinSteamDest('recipient', 'id_prim', 'sd', 's');
|
||||
$qb->limitToDest(ACore::CONTEXT_PUBLIC, 'recipient', 'to', 'sd');
|
||||
|
||||
$result = $this->getStreamsFromRequest($qb);
|
||||
if ($options->isInverted()) {
|
||||
$result = array_reverse($result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should returns:
|
||||
|
@ -532,8 +563,9 @@ class StreamRequest extends StreamRequestBuilder {
|
|||
*
|
||||
* @return Stream[]
|
||||
* @throws DateTimeException
|
||||
* @deprecated - use getTimelinePublic()
|
||||
*/
|
||||
public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true
|
||||
public function getTimelineGlobal_dep(int $since = 0, int $limit = 5, bool $localOnly = true
|
||||
): array {
|
||||
$qb = $this->getStreamSelectSql();
|
||||
$qb->limitPaginate($since, $limit);
|
||||
|
|
|
@ -61,6 +61,7 @@ class ACore extends Item implements JsonSerializable {
|
|||
const AS_USERNAME = 5;
|
||||
const AS_ACCOUNT = 6;
|
||||
const AS_STRING = 7;
|
||||
const AS_CONTENT = 8;
|
||||
const AS_TAGS = 10;
|
||||
|
||||
const FORMAT_ACTIVITYPUB = 1;
|
||||
|
@ -559,14 +560,16 @@ class ACore extends Item implements JsonSerializable {
|
|||
return $value;
|
||||
|
||||
case self::AS_STRING:
|
||||
// try to preserve some whitespace from the html tags
|
||||
$value = preg_replace("/\<br *\/?\>/", "\n", $value);
|
||||
$value = preg_replace("/\<\/?p>/", "\n", $value);
|
||||
|
||||
$value = strip_tags($value);
|
||||
$value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5);
|
||||
|
||||
return trim($value);
|
||||
return $value;
|
||||
|
||||
case self::AS_CONTENT:
|
||||
$value = strip_tags($value, ['a', 'p', 'span', 'br']);
|
||||
$value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5);
|
||||
|
||||
return $value;
|
||||
|
||||
case self::AS_USERNAME:
|
||||
$value = strip_tags($value);
|
||||
|
@ -654,6 +657,12 @@ class ACore extends Item implements JsonSerializable {
|
|||
$this->setLocal(($this->getInt('local', $data, 0) === 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function importFromCache(array $data) {
|
||||
$this->import($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $format
|
||||
|
|
|
@ -741,7 +741,7 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
|
|||
$result =
|
||||
[
|
||||
"username" => $this->getPreferredUsername(),
|
||||
"acct" => $this->getPreferredUsername(),
|
||||
"acct" => $this->getAccount(),
|
||||
"display_name" => $this->getDisplayName(),
|
||||
"locked" => $this->isLocked(),
|
||||
"bot" => $this->isBot(),
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace OCA\Social\Model\ActivityPub\Object;
|
|||
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Stream;
|
||||
|
||||
|
@ -72,26 +73,25 @@ class Announce extends Stream implements JsonSerializable {
|
|||
$this->setAttributedTo($this->getActorId());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function importFromDatabase(array $data) {
|
||||
parent::importFromDatabase($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
$result = parent::jsonSerialize();
|
||||
//$result['actor'] = $this->getAttributedTo();
|
||||
public function exportAsLocal(): array {
|
||||
$result = parent::exportAsLocal();
|
||||
|
||||
if ($this->hasCache()) {
|
||||
$cache = $this->getCache();
|
||||
if ($object = $cache->getItem($this->getObjectId())) {
|
||||
$object = $object->getObject();
|
||||
/** @var Stream $item */
|
||||
$item = AP::$activityPub->getItemFromType($this->get('type', $object, Stream::TYPE));
|
||||
$item->importFromCache($object);
|
||||
$result['reblog'] = $item->exportAsLocal();
|
||||
$result['content'] = $item->getContent();
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ use daita\MySmallPhpTools\Model\CacheItem;
|
|||
use DateTime;
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
use OCA\Social\Model\StreamAction;
|
||||
use OCA\Social\Traits\TDetails;
|
||||
|
||||
|
@ -424,7 +425,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
|||
}
|
||||
|
||||
$this->setActivityId($this->validate(self::AS_ID, 'activity_id', $data, ''));
|
||||
$this->setContent($this->validate(self::AS_STRING, 'content', $data, ''));
|
||||
$this->setContent($this->validate(self::AS_CONTENT, 'content', $data, ''));
|
||||
$this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, ''));
|
||||
$this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, ''));
|
||||
$this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));
|
||||
|
@ -436,6 +437,15 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
|||
$this->setCache($cache);
|
||||
}
|
||||
|
||||
public function importFromCache(array $data) {
|
||||
parent::importFromCache($data);
|
||||
|
||||
$actor = new Person();
|
||||
$actor->importFromCache($data['actor_info']);
|
||||
$this->setActor($actor);
|
||||
$this->setCompleteDetails(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
|
@ -480,7 +490,23 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
|||
* @return array
|
||||
*/
|
||||
public function exportAsLocal(): array {
|
||||
$actions = ($this->hasAction()) ? $this->getAction()->getValues() : [];
|
||||
$favorited = false;
|
||||
$reblogged = false;
|
||||
foreach ($actions as $action => $value) {
|
||||
if ($value) {
|
||||
switch ($action) {
|
||||
case StreamAction::BOOSTED:
|
||||
$reblogged = true;
|
||||
break;
|
||||
case StreamAction::LIKED:
|
||||
$favorited = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = [
|
||||
"local" => $this->isLocal(),
|
||||
"content" => $this->getContent(),
|
||||
"sensitive" => $this->isSensitive(),
|
||||
"spoiler_text" => $this->getSpoilerText(),
|
||||
|
@ -491,8 +517,8 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
|||
'replies_count' => 0,
|
||||
'reblogs_count' => 0,
|
||||
'favourites_count' => 0,
|
||||
'favourited' => false,
|
||||
'reblogged' => false,
|
||||
'favourited' => $favorited,
|
||||
'reblogged' => $reblogged,
|
||||
'muted' => false,
|
||||
'bookmarked' => false,
|
||||
'uri' => $this->getId(),
|
||||
|
@ -504,7 +530,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
|||
// TODO - store created_at full string with milliseconds ?
|
||||
if ($this->hasActor()) {
|
||||
$actor = $this->getActor();
|
||||
$result['account'] = $actor;
|
||||
$result['account'] = $actor->exportAsLocal();
|
||||
}
|
||||
|
||||
return array_merge(parent::exportAsLocal(), $result);
|
||||
|
|
|
@ -426,9 +426,9 @@ class StreamService {
|
|||
public function getTimeline(TimelineOptions $options): array {
|
||||
if ($options->getTimeline() === 'home') {
|
||||
return $this->streamRequest->getTimelineHome($options);
|
||||
} else if ($options->getTimeline() === 'public') {
|
||||
return $this->streamRequest->getTimelinePublic($options);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -480,7 +480,7 @@ class StreamService {
|
|||
* @deprecated
|
||||
*/
|
||||
public function getStreamLocalTimeline(int $since = 0, int $limit = 5): array {
|
||||
return $this->streamRequest->getTimelineGlobal($since, $limit, true);
|
||||
return $this->streamRequest->getTimelineGlobal_dep($since, $limit, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -518,7 +518,7 @@ class StreamService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public function getStreamGlobalTimeline(int $since = 0, int $limit = 5): array {
|
||||
return $this->streamRequest->getTimelineGlobal($since, $limit, false);
|
||||
return $this->streamRequest->getTimelineGlobal_dep($since, $limit, false);
|
||||
}
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue