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\Contact;
28 use Friendica\Model\Notification as ModelNotification;
30 class Notification extends BaseFactory
32 public function create(int $id)
34 $notification = DBA::selectFirst('notify', [], ['id' => $id]);
35 if (!DBA::isResult($notification)) {
39 $cid = Contact::getIdForURL($notification['url'], 0, false);
45 follow = Someone followed you
46 follow_request = Someone requested to follow you
47 mention = Someone mentioned you in their status
48 reblog = Someone boosted one of your statuses
49 favourite = Someone favourited one of your statuses
50 poll = A poll you have voted in or created has ended
51 status = Someone you enabled notifications for has posted a status
54 switch ($notification['type']) {
55 case ModelNotification\Type::INTRO:
56 $type = 'follow_request';
59 case ModelNotification\Type::WALL:
60 case ModelNotification\Type::COMMENT:
61 case ModelNotification\Type::MAIL:
62 case ModelNotification\Type::TAG_SELF:
63 case ModelNotification\Type::POKE:
67 case ModelNotification\Type::SHARE:
75 $account = DI::mstdnAccount()->createFromContactId($cid);
77 if (!empty($notification['uri-id'])) {
79 $status = DI::mstdnStatus()->createFromUriId($notification['uri-id'], $notification['uid']);
80 } catch (\Throwable $th) {
87 return new \Friendica\Object\Api\Mastodon\Notification($id, $type, $notification['date'], $account, $status);