Merge pull request #10530 from annando/api-mail
API: Support for fetching mails with more "statuses" calls
This commit is contained in:
commit
72ab57f067
|
@ -25,6 +25,7 @@ use Friendica\BaseFactory;
|
||||||
use Friendica\Content\ContactSelector;
|
use Friendica\Content\ContactSelector;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Verb;
|
use Friendica\Model\Verb;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
@ -79,6 +80,10 @@ class Status extends BaseFactory
|
||||||
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
'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]]);
|
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
|
||||||
if (!$item) {
|
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 : '.'));
|
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'];
|
$id = $parameters['id'];
|
||||||
|
|
||||||
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
|
||||||
if (!DBA::isResult($parent)) {
|
|
||||||
DI::mstdnError()->RecordNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
$parents = [];
|
$parents = [];
|
||||||
$children = [];
|
$children = [];
|
||||||
|
|
||||||
$posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
|
$parent = Post::selectFirst(['parent-uri-id'], ['uri-id' => $id]);
|
||||||
['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]], []);
|
if (DBA::isResult($parent)) {
|
||||||
while ($post = Post::fetch($posts)) {
|
$posts = Post::selectPosts(['uri-id', 'thr-parent-id'],
|
||||||
if ($post['uri-id'] == $post['thr-parent-id']) {
|
['parent-uri-id' => $parent['parent-uri-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||||
continue;
|
while ($post = Post::fetch($posts)) {
|
||||||
}
|
if ($post['uri-id'] == $post['thr-parent-id']) {
|
||||||
$parents[$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' => []];
|
$statuses = ['ancestors' => [], 'descendants' => []];
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Direct extends BaseApi
|
||||||
$params['order'] = ['uri-id'];
|
$params['order'] = ['uri-id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$mails = DBA::select('mail', ['id'], $condition, $params);
|
$mails = DBA::select('mail', ['id', 'uri-id'], $condition, $params);
|
||||||
|
|
||||||
$statuses = [];
|
$statuses = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue