Fix API result, add PHPDoc and cleanup object construction

Fix missing getters
fix data array
fix missing "$" for template-variables
Remove lazy-loaded parent notification instance (for now..)
This commit is contained in:
Philipp Holzer 2020-01-25 20:00:58 +01:00
parent 4c5856da2b
commit 74f3a2f90c
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
7 changed files with 203 additions and 218 deletions

View File

@ -5909,16 +5909,21 @@ function api_friendica_notification($type)
$notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]); $notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]);
if ($type == "xml") { if ($type == "xml") {
$xmlnotes = []; $xmlnotes = false;
if (!empty($notifications)) { if (!empty($notifications)) {
foreach ($notifications as $notification) { foreach ($notifications as $notification) {
$xmlnotes[] = ["@attributes" => $notification->toArray()]; $xmlnotes[] = ["@attributes" => $notification->toArray()];
} }
} }
$notifications = $xmlnotes; $result = $xmlnotes;
} elseif (count($notifications) > 0) {
$result = $notifications->getArrayCopy();
} else {
$result = false;
} }
return api_format_data("notes", $type, ['note' => $notifications->getArrayCopy()]);
return api_format_data("notes", $type, ['note' => $result]);
} }
/** /**

View File

@ -19,6 +19,12 @@ use Friendica\Object\Notification\Introduction;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/**
* Factory for creating notification objects based on introductions
* Currently, there are two main types of introduction based notifications:
* - Friend suggestion
* - Friend/Follower request
*/
class IntroductionFactory extends BaseFactory class IntroductionFactory extends BaseFactory
{ {
/** @var Database */ /** @var Database */

View File

@ -23,6 +23,14 @@ use Friendica\Util\Temporal;
use Friendica\Util\XML; use Friendica\Util\XML;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/**
* Factory for creating notification objects based on items
* Currently, there are the following types of item based notifications:
* - network
* - system
* - home
* - personal
*/
class NotificationFactory extends BaseFactory class NotificationFactory extends BaseFactory
{ {
/** @var Database */ /** @var Database */
@ -93,97 +101,89 @@ class NotificationFactory extends BaseFactory
// Transform the different types of notification in an usable array // Transform the different types of notification in an usable array
switch ($item['verb'] ?? '') { switch ($item['verb'] ?? '') {
case Activity::LIKE: case Activity::LIKE:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'like', 'label' => 'like',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']), 'text' => $this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
case Activity::DISLIKE: case Activity::DISLIKE:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'dislike', 'label' => 'dislike',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']), 'text' => $this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
case Activity::ATTEND: case Activity::ATTEND:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'attend', 'label' => 'attend',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']), 'text' => $this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
case Activity::ATTENDNO: case Activity::ATTENDNO:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'attendno', 'label' => 'attendno',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']), 'text' => $this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
case Activity::ATTENDMAYBE: case Activity::ATTENDMAYBE:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'attendmaybe', 'label' => 'attendmaybe',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']), 'text' => $this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
case Activity::FRIEND: case Activity::FRIEND:
if (!isset($item['object'])) { if (!isset($item['object'])) {
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'friend', 'label' => 'friend',
$item['link'], 'link' => $item['link'],
$item['image'], 'image' => $item['image'],
$item['url'], 'url' => $item['url'],
$item['text'], 'text' => $item['text'],
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
} }
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = XML::parseString($xmlHead . $item['object']); $obj = XML::parseString($xmlHead . $item['object']);
$item['fname'] = $obj->title; $item['fname'] = $obj->title;
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification([
'friend', 'label' => 'friend',
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
$item['author-link'], 'url' => $item['author-link'],
$this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']), 'text' => $this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
$item['when'] ?? '', 'when' => $item['when'],
$item['ago'] ?? '', 'ago' => $item['ago'],
$item['seen'] ?? false); 'seen' => $item['seen']]);
default: default:
return new \Friendica\Object\Notification\Notification( return new \Friendica\Object\Notification\Notification($item);
$item['label'],
$item['link'],
$item['image'],
$item['url'],
$item['text'],
$item['when'] ?? '',
$item['ago'] ?? '',
$item['seen'] ?? false);
break; break;
} }
} }
@ -215,15 +215,15 @@ class NotificationFactory extends BaseFactory
$notifications = $this->notification->select($conditions, $params); $notifications = $this->notification->select($conditions, $params);
foreach ($notifications as $notification) { foreach ($notifications as $notification) {
$formattedNotifications[] = new \Friendica\Object\Notification\Notification( $formattedNotifications[] = new \Friendica\Object\Notification\Notification([
'notification', 'label' => 'notification',
$this->baseUrl->get(true) . '/notification/view/' . $notification->id, 'link' => $this->baseUrl->get(true) . '/notification/view/' . $notification->id,
Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO), 'image' => Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
$notification->url, 'url' => $notification->url,
strip_tags(BBCode::convert($notification->msg)), 'text' => strip_tags(BBCode::convert($notification->msg)),
DateTimeFormat::local($notification->date, 'r'), 'when' => DateTimeFormat::local($notification->date, 'r'),
Temporal::getRelativeDate($notification->date), 'ago' => Temporal::getRelativeDate($notification->date),
$notification->seen); 'seen' => $notification->seen]);
} }
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->warning('Select failed.', ['conditions' => $conditions, 'exception' => $e]); $this->logger->warning('Select failed.', ['conditions' => $conditions, 'exception' => $e]);

View File

@ -46,8 +46,6 @@ class Notification extends BaseModel
{ {
/** @var \Friendica\Repository\Notification */ /** @var \Friendica\Repository\Notification */
private $repo; private $repo;
/** @var $this */
private $parentInst;
public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notification $repo, array $data = []) public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notification $repo, array $data = [])
{ {
@ -118,28 +116,6 @@ class Notification extends BaseModel
} }
} }
public function __get($name)
{
$this->checkValid();
$return = null;
switch ($name) {
case 'parent':
if (!empty($this->parent)) {
$this->parentInst = $this->parentInst ?? $this->repo->getByID($this->parent);
$return = $this->parentInst;
}
break;
default:
$return = parent::__get($name);
break;
}
return $return;
}
public function __set($name, $value) public function __set($name, $value)
{ {
parent::__set($name, $value); parent::__set($name, $value);

View File

@ -25,7 +25,7 @@ class Introductions extends BaseNotifications
$all = DI::args()->get(2) == 'all'; $all = DI::args()->get(2) == 'all';
$notifications = [ $notifications = [
'ident' => 'introductions', 'ident' => 'introductions',
'notifications' => DI::factNotIntro()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id), 'notifications' => DI::factNotIntro()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
]; ];
@ -64,32 +64,32 @@ class Introductions extends BaseNotifications
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
// We have to distinguish between these two because they use different data. // We have to distinguish between these two because they use different data.
switch ($notification['label']) { switch ($notification->getLabel()) {
case 'friend_suggestion': case 'friend_suggestion':
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
'$type' => $notification->getLabel(), '$type' => $notification->getLabel(),
'str_notification_type' => DI::l10n()->t('Notification type:'), '$str_notification_type' => DI::l10n()->t('Notification type:'),
'str_type' => $notification->getType(), '$str_type' => $notification->getType(),
'$intro_id' => $notification->getIntroId(), '$intro_id' => $notification->getIntroId(),
'$lbl_madeby' => DI::l10n()->t('Suggested by:'), '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
'$madeby' => $notification->getMadeBy(), '$madeby' => $notification->getMadeBy(),
'$madeby_url' => $notification->getMadeByUrl(), '$madeby_url' => $notification->getMadeByUrl(),
'$madeby_zrl' => $notification->getMadeByZrl(), '$madeby_zrl' => $notification->getMadeByZrl(),
'$madeby_addr' => $notification->getMadeByAddr(), '$madeby_addr' => $notification->getMadeByAddr(),
'$contact_id' => $notification->getContactId(), '$contact_id' => $notification->getContactId(),
'$photo' => $notification->getPhoto(), '$photo' => $notification->getPhoto(),
'$fullname' => $notification->getName(), '$fullname' => $notification->getName(),
'$url' => $notification->getUrl(), '$url' => $notification->getUrl(),
'$zrl' => $notification->getZrl(), '$zrl' => $notification->getZrl(),
'$lbl_url' => DI::l10n()->t('Profile URL'), '$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $notification->getAddr(), '$addr' => $notification->getAddr(),
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''], '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
'$knowyou' => $notification->getKnowYou(), '$knowyou' => $notification->getKnowYou(),
'$approve' => DI::l10n()->t('Approve'), '$approve' => DI::l10n()->t('Approve'),
'$note' => $notification->getNote(), '$note' => $notification->getNote(),
'$request' => $notification->getRequest(), '$request' => $notification->getRequest(),
'$ignore' => DI::l10n()->t('Ignore'), '$ignore' => DI::l10n()->t('Ignore'),
'$discard' => DI::l10n()->t('Discard'), '$discard' => DI::l10n()->t('Discard'),
]); ]);
break; break;
@ -108,12 +108,12 @@ class Introductions extends BaseNotifications
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
$knowyou = ($notification->getKnowYou() ? DI::l10n()->t('yes') : DI::l10n()->t('no')); $knowyou = ($notification->getKnowYou() ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']); $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification->getName(), $notification->getName());
$helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']); $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification->getName());
} elseif ($notification->getNetwork() === Protocol::DIASPORA) { } elseif ($notification->getNetwork() === Protocol::DIASPORA) {
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']); $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification->getName(), $notification->getName());
$helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']); $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification->getName());
} }
$dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl'); $dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl');
@ -136,10 +136,10 @@ class Introductions extends BaseNotifications
$action = 'dfrn_confirm'; $action = 'dfrn_confirm';
} }
$header = $notification['name']; $header = $notification->getName();
if ($notification['addr'] != '') { if ($notification->getAddr() != '') {
$header .= ' <' . $notification['addr'] . '>'; $header .= ' <' . $notification->getAddr() . '>';
} }
$header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')'; $header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
@ -151,39 +151,39 @@ class Introductions extends BaseNotifications
} }
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$type' => $notification->getLabel(), '$type' => $notification->getLabel(),
'$header' => $header, '$header' => $header,
'str_notification_type' => DI::l10n()->t('Notification type:'), '$str_notification_type' => DI::l10n()->t('Notification type:'),
'str_type' => $notification->getType(), '$str_type' => $notification->getType(),
'$dfrn_text' => $dfrn_text, '$dfrn_text' => $dfrn_text,
'$dfrn_id' => $notification->getDfrnId(), '$dfrn_id' => $notification->getDfrnId(),
'$uid' => $notification->getUid(), '$uid' => $notification->getUid(),
'$intro_id' => $notification->getIntroId(), '$intro_id' => $notification->getIntroId(),
'$contact_id' => $notification->getContactId(), '$contact_id' => $notification->getContactId(),
'$photo' => $notification->getPhoto(), '$photo' => $notification->getPhoto(),
'$fullname' => $notification->getName(), '$fullname' => $notification->getName(),
'$location' => $notification->getLocation(), '$location' => $notification->getLocation(),
'$lbl_location' => DI::l10n()->t('Location:'), '$lbl_location' => DI::l10n()->t('Location:'),
'$about' => $notification->getAbout(), '$about' => $notification->getAbout(),
'$lbl_about' => DI::l10n()->t('About:'), '$lbl_about' => DI::l10n()->t('About:'),
'$keywords' => $notification->getKeywords(), '$keywords' => $notification->getKeywords(),
'$lbl_keywords' => DI::l10n()->t('Tags:'), '$lbl_keywords' => DI::l10n()->t('Tags:'),
'$gender' => $notification->getGender(), '$gender' => $notification->getGender(),
'$lbl_gender' => DI::l10n()->t('Gender:'), '$lbl_gender' => DI::l10n()->t('Gender:'),
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''], '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
'$url' => $notification->getUrl(), '$url' => $notification->getUrl(),
'$zrl' => $notification->getZrl(), '$zrl' => $notification->getZrl(),
'$lbl_url' => DI::l10n()->t('Profile URL'), '$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $notification->getAddr(), '$addr' => $notification->getAddr(),
'$lbl_knowyou' => $lbl_knowyou, '$lbl_knowyou' => $lbl_knowyou,
'$lbl_network' => DI::l10n()->t('Network:'), '$lbl_network' => DI::l10n()->t('Network:'),
'$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()), '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
'$knowyou' => $knowyou, '$knowyou' => $knowyou,
'$approve' => DI::l10n()->t('Approve'), '$approve' => DI::l10n()->t('Approve'),
'$note' => $notification->getNote(), '$note' => $notification->getNote(),
'$ignore' => DI::l10n()->t('Ignore'), '$ignore' => DI::l10n()->t('Ignore'),
'$discard' => $discard, '$discard' => $discard,
'$action' => $action, '$action' => $action,
]); ]);
break; break;
} }

View File

@ -12,7 +12,7 @@ class Introduction implements \JsonSerializable
/** @var string */ /** @var string */
private $type = ''; private $type = '';
/** @var integer */ /** @var integer */
private $intro_id = 0; private $intro_id = -1;
/** @var string */ /** @var string */
private $madeBy = ''; private $madeBy = '';
/** @var string */ /** @var string */
@ -22,7 +22,7 @@ class Introduction implements \JsonSerializable
/** @var string */ /** @var string */
private $madeByAddr = ''; private $madeByAddr = '';
/** @var integer */ /** @var integer */
private $contactId = 0; private $contactId = -1;
/** @var string */ /** @var string */
private $photo = ''; private $photo = '';
/** @var string */ /** @var string */
@ -34,29 +34,29 @@ class Introduction implements \JsonSerializable
/** @var boolean */ /** @var boolean */
private $hidden = false; private $hidden = false;
/** @var integer */ /** @var integer */
private $postNewFriend = 0; private $postNewFriend = -1;
/** @var string */ /** @var boolean */
private $knowYou = ''; private $knowYou = false;
/** @var string */ /** @var string */
private $note = ''; private $note = '';
/** @var string */ /** @var string */
private $request = ''; private $request = '';
/** @var string */
private $dfrnId;
/** @var string */
private $addr;
/** @var string */
private $network;
/** @var int */ /** @var int */
private $uid; private $dfrnId = -1;
/** @var string */ /** @var string */
private $keywords; private $addr = '';
/** @var string */ /** @var string */
private $gender; private $network = '';
/** @var int */
private $uid = -1;
/** @var string */ /** @var string */
private $location; private $keywords = '';
/** @var string */ /** @var string */
private $about; private $gender = '';
/** @var string */
private $location = '';
/** @var string */
private $about = '';
/** /**
* @return string * @return string
@ -261,26 +261,26 @@ class Introduction implements \JsonSerializable
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
$this->label = $data['label'] ?? ''; $this->label = $data['label'] ?? '';
$this->type = $data['str_$type'] ?? ''; $this->type = $data['str_type'] ?? '';
$this->intro_id = $data['$intro_id'] ?? ''; $this->intro_id = $data['$intro_id'] ?? -1;
$this->madeBy = $data['$madeBy'] ?? ''; $this->madeBy = $data['madeBy'] ?? '';
$this->madeByUrl = $data['$madeByUrl'] ?? ''; $this->madeByUrl = $data['madeByUrl'] ?? '';
$this->madeByZrl = $data['$madeByZrl'] ?? ''; $this->madeByZrl = $data['madeByZrl'] ?? '';
$this->madeByAddr = $data['$madeByAddr'] ?? ''; $this->madeByAddr = $data['madeByAddr'] ?? '';
$this->contactId = $data['$contactId'] ?? ''; $this->contactId = $data['contactId'] ?? '';
$this->photo = $data['$photo'] ?? ''; $this->photo = $data['photo'] ?? '';
$this->name = $data['$name'] ?? ''; $this->name = $data['name'] ?? '';
$this->url = $data['$url'] ?? ''; $this->url = $data['url'] ?? '';
$this->zrl = $data['$zrl'] ?? ''; $this->zrl = $data['zrl'] ?? '';
$this->hidden = $data['$hidden'] ?? ''; $this->hidden = $data['hidden'] ?? false;
$this->postNewFriend = $data['$postNewFriend'] ?? ''; $this->postNewFriend = $data['postNewFriend'] ?? '';
$this->knowYou = $data['$knowYou'] ?? ''; $this->knowYou = $data['knowYou'] ?? false;
$this->note = $data['$note'] ?? ''; $this->note = $data['note'] ?? '';
$this->request = $data['$request'] ?? ''; $this->request = $data['request'] ?? '';
$this->dfrnId = $data['dfrn_id'] ?? ''; $this->dfrnId = $data['dfrn_id'] ?? -1;
$this->addr = $data['addr'] ?? ''; $this->addr = $data['addr'] ?? '';
$this->network = $data['network'] ?? ''; $this->network = $data['network'] ?? '';
$this->uid = $data['uid'] ?? ''; $this->uid = $data['uid'] ?? -1;
$this->keywords = $data['keywords'] ?? ''; $this->keywords = $data['keywords'] ?? '';
$this->gender = $data['gender'] ?? ''; $this->gender = $data['gender'] ?? '';
$this->location = $data['location'] ?? ''; $this->location = $data['location'] ?? '';

View File

@ -94,18 +94,16 @@ class Notification implements \JsonSerializable
return $this->seen; return $this->seen;
} }
public function __construct(string $label = '', string $link = '', string $image = '', public function __construct(array $data)
string $url = '', string $text = '',
string $when = '', string $ago = '', bool $seen = false)
{ {
$this->label = $label; $this->label = $data['label'] ?? '';
$this->link = $link; $this->link = $data['link'] ?? '';
$this->image = $image; $this->image = $data['image'] ?? '';
$this->url = $url; $this->url = $data['url'] ?? '';
$this->text = $text; $this->text = $data['text'] ?? '';
$this->when = $when; $this->when = $data['when'] ?? '';
$this->ago = $ago; $this->ago = $data['ago'] ?? '';
$this->seen = $seen; $this->seen = $data['seen'] ?? false;
} }
/** /**