0 AS `has-categories`,
EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`) AS `has-media`,
(SELECT COUNT(*) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-comments`,
+ (SELECT COUNT(DISTINCT(`author-id`)) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6) AS `total-actors`,
`diaspora-interaction`.`interaction` AS `signed_text`,
`parent-item-uri`.`guid` AS `parent-guid`,
`parent-post`.`network` AS `parent-network`,
- [`GET /api/v1/timelines/public`](https://docs.joinmastodon.org/methods/timelines/)
- [`GET /api/v1/timelines/tag/:hashtag`](https://docs.joinmastodon.org/methods/timelines/)
- [`GET /api/v1/trends`](https://docs.joinmastodon.org/methods/instance/trends/)
+- [`GET /api/v1/trends/links`](https://github.com/mastodon/mastodon/pull/16917)
- [`GET /api/v1/trends/statuses`](https://docs.joinmastodon.org/methods/trends/#statuses)
- [`GET /api/v1/trends/tags`](https://docs.joinmastodon.org/methods/trends/#tags)
- [`GET /api/v2/search`](https://docs.joinmastodon.org/methods/search/)
- [`POST /api/v1/accounts/:id/remove_from_followers`](https://github.com/mastodon/mastodon/pull/16864)
- [`GET /api/v1/accounts/familiar_followers`](https://github.com/mastodon/mastodon/pull/17700)
- [`GET /api/v1/accounts/lookup`](https://github.com/mastodon/mastodon/pull/15740)
-- [`GET /api/v1/trends/links`](https://github.com/mastodon/mastodon/pull/16917)
- [`POST /api/v1/polls/:id/votes`](https://docs.joinmastodon.org/methods/statuses/polls/)
- [`GET /api/v1/featured_tags`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
- [`POST /api/v1/featured_tags`](https://docs.joinmastodon.org/methods/accounts/featured_tags/)
class Card extends BaseFactory
{
/**
- * @param int $uriId Uri-ID of the item
+ * @param int $uriId Uri-ID of the item
+ * @param array $history Link request history
*
* @return \Friendica\Object\Api\Mastodon\Card
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException*@throws \Exception
*/
- public function createFromUriId(int $uriId): \Friendica\Object\Api\Mastodon\Card
+ public function createFromUriId(int $uriId, array $history = []): \Friendica\Object\Api\Mastodon\Card
{
$item = Post::selectFirst(['body'], ['uri-id' => $uriId]);
if (!empty($item['body'])) {
}
}
- return new \Friendica\Object\Api\Mastodon\Card($data);
+ return new \Friendica\Object\Api\Mastodon\Card($data, $history);
}
}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\Api\Mastodon\Trends;
+
+use Friendica\Core\Protocol;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Post;
+use Friendica\Module\BaseApi;
+use Friendica\Util\DateTimeFormat;
+
+/**
+ * @see https://docs.joinmastodon.org/methods/trends/#links
+ */
+class Links extends BaseApi
+{
+ /**
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ protected function rawContent(array $request = [])
+ {
+ $request = $this->getRequest([
+ 'limit' => 10, // Maximum number of results to return. Defaults to 10.
+ ], $request);
+
+ $condition = ["EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread-view`.`uri-id` AND `type` = ? AND NOT `name` IS NULL AND NOT `description` IS NULL) AND NOT `private` AND `commented` > ? AND `created` > ?",
+ Post\Media::HTML, DateTimeFormat::utc('now -1 day'), DateTimeFormat::utc('now -1 week')];
+ $condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
+
+ $trending = [];
+ $statuses = Post::selectPostThread(['uri-id', 'total-comments', 'total-actors'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
+ while ($status = Post::fetch($statuses)) {
+ $history = [['day' => (string)time(), 'uses' => (string)$status['total-comments'], 'accounts' => (string)$status['total-actors']]];
+ $trending[] = DI::mstdnCard()->createFromUriId($status['uri-id'], $history)->toArray();
+ }
+ DBA::close($statuses);
+
+ System::jsonExit($trending);
+ }
+}
*/
protected function rawContent(array $request = [])
{
+ $uid = self::getCurrentUserID();
+
$request = $this->getRequest([
'limit' => 10, // Maximum number of results to return. Defaults to 10.
], $request);
$condition = DBA::mergeConditions($condition, ['network' => Protocol::FEDERATED]);
$trending = [];
- $statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-comments' => true]]);
+ $statuses = Post::selectPostThread(['uri-id'], $condition, ['limit' => $request['limit'], 'order' => ['total-actors' => true]]);
while ($status = Post::fetch($statuses)) {
- $trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id']);
+ $trending[] = DI::mstdnStatus()->createFromUriId($status['uri-id'], $uid);
}
DBA::close($statuses);
* @param array $attachment Attachment record
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public function __construct(array $attachment)
+ public function __construct(array $attachment, array $history = [])
{
$this->url = $attachment['url'] ?? '';
$this->title = $attachment['title'] ?? '';
$this->width = $attachment['width'] ?? 0;
$this->height = $attachment['height'] ?? 0;
$this->image = $attachment['image'] ?? '';
+ $this->history = $history;
}
/**
"has-categories" => "0",
"has-media" => "EXISTS(SELECT `id` FROM `post-media` WHERE `post-media`.`uri-id` = `post-thread`.`uri-id`)",
"total-comments" => "(SELECT COUNT(*) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6)",
+ "total-actors" => "(SELECT COUNT(DISTINCT(`author-id`)) FROM `post` WHERE `parent-uri-id` = `post-thread`.`uri-id` AND `gravity` = 6)",
"signed_text" => ["diaspora-interaction", "interaction"],
"parent-guid" => ["parent-item-uri", "guid"],
"parent-network" => ["parent-post", "network"],
'/timelines/public' => [Module\Api\Mastodon\Timelines\PublicTimeline::class, [R::GET ]],
'/timelines/tag/{hashtag}' => [Module\Api\Mastodon\Timelines\Tag::class, [R::GET ]],
'/trends' => [Module\Api\Mastodon\Trends\Tags::class, [R::GET ]],
- '/trends/links' => [Module\Api\Mastodon\Unimplemented::class, [R::GET ]], // not implemented
+ '/trends/links' => [Module\Api\Mastodon\Trends\Links::class, [R::GET ]],
'/trends/statuses' => [Module\Api\Mastodon\Trends\Statuses::class, [R::GET ]],
'/trends/tags' => [Module\Api\Mastodon\Trends\Tags::class, [R::GET ]],
],