mirror of
https://github.com/friendica/friendica
synced 2024-11-10 09:02:53 +00:00
Merge pull request #10530 from annando/api-mail
API: Support for fetching mails with more "statuses" calls
This commit is contained in:
commit
72ab57f067
3 changed files with 34 additions and 15 deletions
|
@ -25,6 +25,7 @@ use Friendica\BaseFactory;
|
|||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -79,6 +80,10 @@ class Status extends BaseFactory
|
|||
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||
if (!$item) {
|
||||
$mail = DBA::selectFirst('mail', ['id'], ['uri-id' => $uriId, 'uid' => $uid]);
|
||||
if ($mail) {
|
||||
return $this->createFromMailId($mail['id']);
|
||||
}
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,25 +50,39 @@ class Context extends BaseApi
|
|||
|
||||
$id = $parameters['id'];
|
||||
|
||||
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
||||
if (!DBA::isResult($parent)) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
|
||||
$parents = [];
|
||||
$children = [];
|
||||
|
||||
$posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
|
||||
['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]], []);
|
||||
while ($post = Post::fetch($posts)) {
|
||||
if ($post['uri-id'] == $post['thr-parent-id']) {
|
||||
continue;
|
||||
}
|
||||
$parents[$post['uri-id']] = $post['thr-parent-id'];
|
||||
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
||||
if (DBA::isResult($parent)) {
|
||||
$posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
|
||||
['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||
while ($post = Post::fetch($posts)) {
|
||||
if ($post['uri-id'] == $post['thr-parent-id']) {
|
||||
continue;
|
||||
}
|
||||
$parents[$post['uri-id']] = $post['thr-parent-id'];
|
||||
|
||||
$children[$post['thr-parent-id']][] = $post['uri-id'];
|
||||
$children[$post['thr-parent-id']][] = $post['uri-id'];
|
||||
}
|
||||
DBA::close($posts);
|
||||
} else {
|
||||
$parent = DBA::selectFirst('mail', ['parent-uri-id'], ['uri-id' => $id, 'uid' => $uid]);
|
||||
if (DBA::isResult($parent)) {
|
||||
$posts = DBA::select('mail', ['uri-id', 'thr-parent-id'], ['parent-uri-id' => $parent['parent-uri-id']]);
|
||||
while ($post = DBA::fetch($posts)) {
|
||||
if ($post['uri-id'] == $post['thr-parent-id']) {
|
||||
continue;
|
||||
}
|
||||
$parents[$post['uri-id']] = $post['thr-parent-id'];
|
||||
|
||||
$children[$post['thr-parent-id']][] = $post['uri-id'];
|
||||
}
|
||||
DBA::close($posts);
|
||||
} else {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
}
|
||||
DBA::close($posts);
|
||||
|
||||
$statuses = ['ancestors' => [], 'descendants' => []];
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ class Direct extends BaseApi
|
|||
$params['order'] = ['uri-id'];
|
||||
}
|
||||
|
||||
$mails = DBA::select('mail', ['id'], $condition, $params);
|
||||
$mails = DBA::select('mail', ['id', 'uri-id'], $condition, $params);
|
||||
|
||||
$statuses = [];
|
||||
|
||||
|
|
Loading…
Reference in a new issue