diff --git a/composer.lock b/composer.lock index 3d0a238f..94cfaf21 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "732d54bca742e3ecdb2b544589550a37172c1258" + "reference": "6e8f346a2ee488655316d1e4139c27417d6b7e4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/732d54bca742e3ecdb2b544589550a37172c1258", - "reference": "732d54bca742e3ecdb2b544589550a37172c1258", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/6e8f346a2ee488655316d1e4139c27417d6b7e4d", + "reference": "6e8f346a2ee488655316d1e4139c27417d6b7e4d", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2019-05-27T17:53:41+00:00" + "time": "2019-05-29T20:52:05+00:00" }, { "name": "friendica/json-ld", diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 5c1c9f59..a8cb3009 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -731,8 +731,12 @@ class CoreRequestBuilder { ->selectAlias('sa.stream_id', 'streamaction_stream_id') ->selectAlias('sa.values', 'streamaction_values'); + $orX = $expr->orX(); + $orX->add($expr->eq($func->lower($pf . '.id'), $func->lower('sa.stream_id'))); + $orX->add($expr->eq($func->lower($pf . '.object_id'), $func->lower('sa.stream_id'))); + $andX = $expr->andX(); - $andX->add($expr->eq($func->lower($pf . '.id'), $func->lower('sa.stream_id'))); + $andX->add($orX); $andX->add( $expr->eq( $func->lower('sa.actor_id'), @@ -751,7 +755,6 @@ class CoreRequestBuilder { * @param array $data * * @return StreamAction - * @throws InvalidResourceException */ protected function parseStreamActionsLeftJoin(array $data): StreamAction { $new = []; @@ -763,10 +766,11 @@ class CoreRequestBuilder { $action = new StreamAction(); $action->importFromDatabase($new); - - if ($action->getId() === 0) { - throw new InvalidResourceException(); - } + $action->setDefaultValues( + [ + 'boosted' => false + ] + ); return $action; } diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php index 592a3389..745b30d3 100644 --- a/lib/Db/StreamRequest.php +++ b/lib/Db/StreamRequest.php @@ -524,7 +524,7 @@ class StreamRequest extends StreamRequestBuilder { } $cache = '[]'; - if ($stream->gotCache()) { + if ($stream->hasCache()) { $cache = json_encode($stream->getCache(), JSON_UNESCAPED_SLASHES); } diff --git a/lib/Db/StreamRequestBuilder.php b/lib/Db/StreamRequestBuilder.php index 1b5b68c6..910d4641 100644 --- a/lib/Db/StreamRequestBuilder.php +++ b/lib/Db/StreamRequestBuilder.php @@ -30,6 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Db; +use daita\MySmallPhpTools\Exceptions\CacheItemNotFoundException; use daita\MySmallPhpTools\Traits\TArrayTools; use Doctrine\DBAL\Query\QueryBuilder; use OCA\Social\AP; @@ -415,12 +416,21 @@ class StreamRequestBuilder extends CoreRequestBuilder { } catch (InvalidResourceException $e) { } - try { - $action = $this->parseStreamActionsLeftJoin($data); - $item->setAction($action); - } catch (InvalidResourceException $e) { + $action = $this->parseStreamActionsLeftJoin($data); + if ($item->hasCache()) { + $cache = $item->getCache(); + try { + $cachedItem = $cache->getItem($action->getStreamId()); + $cachedObject = $cachedItem->getObject(); + $cachedObject['action'] = $action; + $cachedItem->setContent(json_encode($cachedObject)); + $cache->updateItem($cachedItem, false); + } catch (CacheItemNotFoundException $e) { + } } + $item->setAction($action); + return $item; } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index d961f78c..8aa2f3c7 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -231,7 +231,7 @@ class Stream extends ACore implements JsonSerializable { /** * @return bool */ - public function gotCache(): bool { + public function hasCache(): bool { return ($this->cache !== null); } @@ -257,7 +257,7 @@ class Stream extends ACore implements JsonSerializable { public function addCacheItem(string $url): Stream { $cacheItem = new CacheItem($url); - if (!$this->gotCache()) { + if (!$this->hasCache()) { $this->setCache(new Cache()); } @@ -376,7 +376,7 @@ class Stream extends ACore implements JsonSerializable { $result, [ 'action' => ($this->hasAction()) ? $this->getAction() : [], - 'cache' => ($this->gotCache()) ? $this->getCache() : '', + 'cache' => ($this->hasCache()) ? $this->getCache() : '', 'publishedTime' => $this->getPublishedTime() ] ); diff --git a/lib/Model/StreamAction.php b/lib/Model/StreamAction.php index eb6c3098..4235960d 100644 --- a/lib/Model/StreamAction.php +++ b/lib/Model/StreamAction.php @@ -209,6 +209,23 @@ class StreamAction implements JsonSerializable { } + /** + * @param array $default + * + * @return StreamAction + */ + public function setDefaultValues(array $default): StreamAction { + $keys = array_keys($default); + foreach ($keys as $k) { + if (!array_key_exists($k, $this->values)) { + $this->values[$k] = $default[$k]; + } + } + + return $this; + } + + /** * @param array $data */ diff --git a/lib/Service/StreamQueueService.php b/lib/Service/StreamQueueService.php index a3308eca..ab14666b 100644 --- a/lib/Service/StreamQueueService.php +++ b/lib/Service/StreamQueueService.php @@ -177,7 +177,7 @@ class StreamQueueService { return; } - if (!$stream->gotCache()) { + if (!$stream->hasCache()) { $this->deleteCache($queue); return; diff --git a/src/components/TimelineContent.vue b/src/components/TimelineContent.vue new file mode 100644 index 00000000..a1796f0c --- /dev/null +++ b/src/components/TimelineContent.vue @@ -0,0 +1,220 @@ + + + + + diff --git a/src/components/TimelineEntry.vue b/src/components/TimelineEntry.vue index d9d64e92..a88147a3 100644 --- a/src/components/TimelineEntry.vue +++ b/src/components/TimelineEntry.vue @@ -1,70 +1,33 @@