diff --git a/src/Factory/Api/Mastodon/Card.php b/src/Factory/Api/Mastodon/Card.php index cc160b1022..1505fa8529 100644 --- a/src/Factory/Api/Mastodon/Card.php +++ b/src/Factory/Api/Mastodon/Card.php @@ -40,6 +40,8 @@ class Card extends BaseFactory $item = Post::selectFirst(['nody'], ['uri-id' => $uriId]); if (!empty($item['body'])) { $data = BBCode::getAttachmentData($item['body']); + } else { + $data = []; } foreach (Post\Media::getByURIId($uriId, [Post\Media::HTML]) as $attached) { diff --git a/src/Module/Api/Mastodon/Statuses/Context.php b/src/Module/Api/Mastodon/Statuses/Context.php index bf49d265ca..5615e41cc9 100644 --- a/src/Module/Api/Mastodon/Statuses/Context.php +++ b/src/Module/Api/Mastodon/Statuses/Context.php @@ -54,7 +54,8 @@ class Context extends BaseApi $parents = []; $children = []; - $posts = Post::select(['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']], [], false); + $posts = Post::select(['uri-id', 'thr-parent-id'], + ['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]], [], false); while ($post = Post::fetch($posts)) { if ($post['uri-id'] == $post['thr-parent-id']) { continue; @@ -67,12 +68,24 @@ class Context extends BaseApi $statuses = ['ancestors' => [], 'descendants' => []]; + $ancestors = []; foreach (self::getParents($id, $parents) as $ancestor) { - $statuses['ancestors'][] = DI::mstdnStatus()->createFromUriId($ancestor, $uid); + $ancestors[$ancestor] = DI::mstdnStatus()->createFromUriId($ancestor, $uid); } + ksort($ancestors); + foreach ($ancestors as $ancestor) { + $statuses['ancestors'][] = $ancestor; + } + + $descendants = []; foreach (self::getChildren($id, $children) as $descendant) { - $statuses['descendants'][] = DI::mstdnStatus()->createFromUriId($descendant, $uid); + $descendants[] = DI::mstdnStatus()->createFromUriId($descendant, $uid); + } + + ksort($descendants); + foreach ($descendants as $descendant) { + $statuses['descendants'][] = $descendant; } System::jsonExit($statuses); diff --git a/src/Module/OAuth/Token.php b/src/Module/OAuth/Token.php index 6e574a8af1..1d0b43cd67 100644 --- a/src/Module/OAuth/Token.php +++ b/src/Module/OAuth/Token.php @@ -55,7 +55,7 @@ class Token extends BaseApi $condition = ['application-id' => $application['id'], 'code' => $code]; - $token = DBA::selectFirst('application-token', ['access_token'], $condition); + $token = DBA::selectFirst('application-token', ['access_token', 'created_at'], $condition); if (!DBA::isResult($token)) { Logger::warning('Token not found', $condition); DI::mstdnError()->RecordNotFound();