3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Twitter\Statuses;
24 use Friendica\Database\DBA;
25 use Friendica\Module\BaseApi;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Post;
31 * Returns the most recent mentions.
33 * @see http://developer.twitter.com/doc/get/statuses/mentions
35 class Mentions extends BaseApi
37 protected function rawContent(array $request = [])
39 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
40 $uid = BaseApi::getCurrentUserID();
42 // get last network messages
45 $since_id = $_REQUEST['since_id'] ?? 0;
46 $max_id = $_REQUEST['max_id'] ?? 0;
47 $count = $_REQUEST['count'] ?? 20;
48 $page = $_REQUEST['page'] ?? 1;
50 $start = max(0, ($page - 1) * $count);
52 $query = "`gravity` IN (?, ?) AND `uri-id` IN
53 (SELECT `uri-id` FROM `post-user-notification` WHERE `uid` = ? AND `notification-type` & ? != 0 ORDER BY `uri-id`)
54 AND (`uid` = 0 OR (`uid` = ? AND NOT `global`)) AND `id` > ?";
57 GRAVITY_PARENT, GRAVITY_COMMENT,
59 Post\UserNotification::TYPE_EXPLICIT_TAGGED | Post\UserNotification::TYPE_IMPLICIT_TAGGED |
60 Post\UserNotification::TYPE_THREAD_COMMENT | Post\UserNotification::TYPE_DIRECT_COMMENT |
61 Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT,
66 $query .= " AND `id` <= ?";
67 $condition[] = $max_id;
70 array_unshift($condition, $query);
72 $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
73 $statuses = Post::selectForUser($uid, [], $condition, $params);
75 $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
78 while ($status = DBA::fetch($statuses)) {
79 $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
81 DBA::close($statuses);
83 $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));