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\Factory\Api\Mastodon;
24 use Friendica\BaseFactory;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Post;
28 use Friendica\Model\Verb;
29 use Friendica\Protocol\Activity;
31 class Notification extends BaseFactory
33 public function createFromNotificationId(int $id)
35 $notification = DBA::selectFirst('notification', [], ['id' => $id]);
36 if (!DBA::isResult($notification)) {
40 follow = Someone followed you
41 follow_request = Someone requested to follow you
42 mention = Someone mentioned you in their status
43 reblog = Someone boosted one of your statuses
44 favourite = Someone favourited one of your statuses
45 poll = A poll you have voted in or created has ended
46 status = Someone you enabled notifications for has posted a status
49 if (($notification['vid'] == Verb::getID(Activity::ANNOUNCE)) &&
50 in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
52 } elseif (in_array($notification['vid'], [Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE)]) &&
53 in_array($notification['type'], [Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT])) {
55 } elseif ($notification['type'] == Post\UserNotification::NOTIF_SHARED) {
57 } elseif (in_array($notification['type'], [Post\UserNotification::NOTIF_EXPLICIT_TAGGED,
58 Post\UserNotification::NOTIF_IMPLICIT_TAGGED, Post\UserNotification::NOTIF_DIRECT_COMMENT,
59 Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT])) {
65 $account = DI::mstdnAccount()->createFromContactId($notification['actor-id']);
67 if (!empty($notification['target-uri-id'])) {
69 $status = DI::mstdnStatus()->createFromUriId($notification['target-uri-id'], $notification['uid']);
70 } catch (\Throwable $th) {
77 return new \Friendica\Object\Api\Mastodon\Notification($id, $type, $notification['created'], $account, $status);