. * */ namespace Friendica\Factory\Api\Mastodon; use Friendica\BaseFactory; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Notification as ModelNotification; class Notification extends BaseFactory { public function createFromNotifyId(int $id) { $notification = DBA::selectFirst('notify', [], ['id' => $id]); if (!DBA::isResult($notification)) { return null; } $cid = Contact::getIdForURL($notification['url'], 0, false); if (empty($cid)) { return null; } /* follow = Someone followed you follow_request = Someone requested to follow you mention = Someone mentioned you in their status reblog = Someone boosted one of your statuses favourite = Someone favourited one of your statuses poll = A poll you have voted in or created has ended status = Someone you enabled notifications for has posted a status */ switch ($notification['type']) { case ModelNotification\Type::INTRO: $type = 'follow_request'; break; case ModelNotification\Type::WALL: case ModelNotification\Type::COMMENT: case ModelNotification\Type::MAIL: case ModelNotification\Type::TAG_SELF: case ModelNotification\Type::POKE: $type = 'mention'; break; case ModelNotification\Type::SHARE: $type = 'status'; break; default: return null; } $account = DI::mstdnAccount()->createFromContactId($cid); if (!empty($notification['uri-id'])) { try { $status = DI::mstdnStatus()->createFromUriId($notification['uri-id'], $notification['uid']); } catch (\Throwable $th) { $status = null; } } else { $status = null; } return new \Friendica\Object\Api\Mastodon\Notification($id, $type, $notification['date'], $account, $status); } }