]> git.mxchange.org Git - friendica.git/blob - src/Module/Api/Twitter/Statuses/Mentions.php
b1b50afb087ac6a36ea8061ed4c55269f7b9e94d
[friendica.git] / src / Module / Api / Twitter / Statuses / Mentions.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Api\Twitter\Statuses;
23
24 use Friendica\Database\DBA;
25 use Friendica\Module\BaseApi;
26 use Friendica\DI;
27 use Friendica\Model\Contact;
28 use Friendica\Model\Post;
29
30 /**
31  * Returns the most recent mentions.
32  *
33  * @see http://developer.twitter.com/doc/get/statuses/mentions
34  */
35 class Mentions extends BaseApi
36 {
37         public function rawContent()
38         {
39                 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
40                 $uid = BaseApi::getCurrentUserID();
41
42                 // get last network messages
43
44                 // params
45                 $since_id = intval($_REQUEST['since_id'] ?? 0);
46                 $max_id   = intval($_REQUEST['max_id']   ?? 0);
47                 $count    = intval($_REQUEST['count']    ?? 20);
48                 $page     = intval($_REQUEST['page']     ?? 1);
49
50                 $start = max(0, ($page - 1) * $count);
51
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` > ?";
55
56                 $condition = [
57                         GRAVITY_PARENT, GRAVITY_COMMENT,
58                         $uid,
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,
62                         $uid, $since_id,
63                 ];
64
65                 if ($max_id > 0) {
66                         $query .= " AND `id` <= ?";
67                         $condition[] = $max_id;
68                 }
69
70                 array_unshift($condition, $query);
71
72                 $params   = ['order' => ['id' => true], 'limit' => [$start, $count]];
73                 $statuses = Post::selectForUser($uid, [], $condition, $params);
74
75                 $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
76
77                 $ret = [];
78                 while ($status = DBA::fetch($statuses)) {
79                         $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
80                 }
81                 DBA::close($statuses);
82
83                 DI::apiResponse()->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
84         }
85 }