From 8eacfbc5705410ebd098a5bd790c7b7355ab65fc Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 May 2021 19:53:19 +0000 Subject: [PATCH] Fix context order / notice fixed --- src/Factory/Api/Mastodon/Card.php | 2 ++ src/Module/Api/Mastodon/Statuses/Context.php | 19 ++++++++++++++++--- src/Module/OAuth/Token.php | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Factory/Api/Mastodon/Card.php b/src/Factory/Api/Mastodon/Card.php index cc160b102..1505fa852 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 bf49d265c..5615e41cc 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 6e574a8af..1d0b43cd6 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();