Move notify to the new paradigm

- Remove unused frion notify template
- Update API test
This commit is contained in:
Hypolite Petovan 2021-09-18 01:08:29 -04:00
parent 1b4e3564a5
commit 47acb6a278
25 changed files with 150 additions and 925 deletions

View file

@ -2,7 +2,7 @@
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@ -24,7 +24,7 @@ namespace Friendica\Object\Api\Friendica;
use Friendica\BaseDataTransferObject;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Model\Notification as NotificationModel;
use Friendica\Navigation\Notifications\Entity\Notify;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
@ -37,8 +37,6 @@ class Notification extends BaseDataTransferObject
{
/** @var integer */
protected $id;
/** @var string */
protected $hash;
/** @var integer */
protected $type;
/** @var string Full name of the contact subject */
@ -78,21 +76,37 @@ class Notification extends BaseDataTransferObject
/** @var string Message (Plaintext) */
protected $msg_plain;
public function __construct(NotificationModel $notify)
public function __construct(Notify $Notify)
{
// map each notify attribute to the entity
foreach ($notify->toArray() as $key => $value) {
$this->{$key} = $value;
$this->id = $Notify->id;
$this->type = $Notify->type;
$this->name = $Notify->name;
$this->url = $Notify->url->__toString();
$this->photo = $Notify->photo->__toString();
$this->date = DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL));
$this->msg = $Notify->msg;
$this->uid = $Notify->uid;
$this->link = $Notify->link->__toString();
$this->iid = $Notify->itemId;
$this->parent = $Notify->parent;
$this->seen = $Notify->seen;
$this->verb = $Notify->verb;
$this->otype = $Notify->otype;
$this->name_cache = $Notify->name_cache;
$this->msg_cache = $Notify->msg_cache;
$this->timestamp = $Notify->date->format('U');
$this->date_rel = Temporal::getRelativeDate($this->date);
try {
$this->msg_html = BBCode::convert($this->msg, false);
} catch (\Exception $e) {
$this->msg_html = '';
}
// add additional attributes for the API
try {
$this->timestamp = strtotime(DateTimeFormat::local($this->date));
$this->msg_html = BBCode::convert($this->msg, false);
$this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
} catch (\Exception $e) {
$this->msg_plain = '';
}
$this->date_rel = Temporal::getRelativeDate($this->date);
}
}

View file

@ -1,143 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Object\Notification;
/**
* A view-only object for printing item notifications to the frontend
*/
class Notification implements \JsonSerializable
{
const SYSTEM = 'system';
const PERSONAL = 'personal';
const NETWORK = 'network';
const INTRO = 'intro';
const HOME = 'home';
/** @var string */
private $label = '';
/** @var string */
private $link = '';
/** @var string */
private $image = '';
/** @var string */
private $url = '';
/** @var string */
private $text = '';
/** @var string */
private $when = '';
/** @var string */
private $ago = '';
/** @var boolean */
private $seen = false;
/**
* @return string
*/
public function getLabel()
{
return $this->label;
}
/**
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* @return string
*/
public function getWhen()
{
return $this->when;
}
/**
* @return string
*/
public function getAgo()
{
return $this->ago;
}
/**
* @return bool
*/
public function isSeen()
{
return $this->seen;
}
public function __construct(array $data)
{
$this->label = $data['label'] ?? '';
$this->link = $data['link'] ?? '';
$this->image = $data['image'] ?? '';
$this->url = $data['url'] ?? '';
$this->text = $data['text'] ?? '';
$this->when = $data['when'] ?? '';
$this->ago = $data['ago'] ?? '';
$this->seen = $data['seen'] ?? false;
}
/**
* @inheritDoc
*/
public function jsonSerialize()
{
return get_object_vars($this);
}
/**
* @return array
*/
public function toArray()
{
return get_object_vars($this);
}
}