Fix arguments

This commit is contained in:
Philipp Holzer 2019-10-26 04:33:59 +02:00
parent a72e65a760
commit fdc0236aa1
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 166 additions and 165 deletions

View file

@ -78,7 +78,7 @@ function notifications_content(App $a)
} }
$page = ($_REQUEST['page'] ?? 0) ?: 1; $page = ($_REQUEST['page'] ?? 0) ?: 1;
$show = $_REQUEST['show'] ?? 0; $show = ($_REQUEST['show'] ?? '' === 'all');
Nav::setSelected('notifications'); Nav::setSelected('notifications');

View file

@ -27,6 +27,9 @@ use Friendica\Network\HTTPException;
*/ */
final class Notify extends BaseObject final class Notify extends BaseObject
{ {
/** @var int The default limit of notifies per page */
const DEFAULT_PAGE_LIMIT = 80;
const NETWORK = 'network'; const NETWORK = 'network';
const SYSTEM = 'system'; const SYSTEM = 'system';
const PERSONAL = 'personal'; const PERSONAL = 'personal';
@ -113,7 +116,7 @@ final class Notify extends BaseObject
} }
/** /**
* @brief Get all notifications for local_user() * Get all notifications for local_user()
* *
* @param array $filter optional Array "column name"=>value: filter query by columns values * @param array $filter optional Array "column name"=>value: filter query by columns values
* @param array $order optional Array to order by * @param array $order optional Array to order by
@ -144,7 +147,7 @@ final class Notify extends BaseObject
} }
/** /**
* @brief Get one note for local_user() by $id value * Get one note for local_user() by $id value
* *
* @param int $id identity * @param int $id identity
* *
@ -181,7 +184,7 @@ final class Notify extends BaseObject
} }
/** /**
* @brief set seen state of all notifications of local_user() * Set seen state of all notifications of local_user()
* *
* @param bool $seen optional true or false. default true * @param bool $seen optional true or false. default true
* *
@ -219,7 +222,7 @@ final class Notify extends BaseObject
} }
/** /**
* @brief Format the notification query in an usable array * Format the notification query in an usable array
* *
* @param array $notifies The array from the db query * @param array $notifies The array from the db query
* @param string $ident The notifications identifier (e.g. network) * @param string $ident The notifications identifier (e.g. network)
@ -237,9 +240,8 @@ final class Notify extends BaseObject
*/ */
private function formatNotifies(array $notifies, string $ident = "") private function formatNotifies(array $notifies, string $ident = "")
{ {
$arr = []; $formattedNotifies = [];
if ($this->dba->isResult($notifies)) {
foreach ($notifies as $notify) { foreach ($notifies as $notify) {
// Because we use different db tables for the notification query // Because we use different db tables for the notification query
// we have sometimes $notify['unseen'] and sometimes $notify['seen]. // we have sometimes $notify['unseen'] and sometimes $notify['seen].
@ -290,7 +292,7 @@ final class Notify extends BaseObject
// Transform the different types of notification in an usable array // Transform the different types of notification in an usable array
switch ($notify['verb']) { switch ($notify['verb']) {
case Activity::LIKE: case Activity::LIKE:
$notify = [ $formattedNotify = [
'label' => 'like', 'label' => 'like',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -303,7 +305,7 @@ final class Notify extends BaseObject
break; break;
case Activity::DISLIKE: case Activity::DISLIKE:
$notify = [ $formattedNotify = [
'label' => 'dislike', 'label' => 'dislike',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -316,7 +318,7 @@ final class Notify extends BaseObject
break; break;
case Activity::ATTEND: case Activity::ATTEND:
$notify = [ $formattedNotify = [
'label' => 'attend', 'label' => 'attend',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -329,7 +331,7 @@ final class Notify extends BaseObject
break; break;
case Activity::ATTENDNO: case Activity::ATTENDNO:
$notify = [ $formattedNotify = [
'label' => 'attendno', 'label' => 'attendno',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -342,7 +344,7 @@ final class Notify extends BaseObject
break; break;
case Activity::ATTENDMAYBE: case Activity::ATTENDMAYBE:
$notify = [ $formattedNotify = [
'label' => 'attendmaybe', 'label' => 'attendmaybe',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -356,7 +358,7 @@ final class Notify extends BaseObject
case Activity::FRIEND: case Activity::FRIEND:
if (!isset($notify['object'])) { if (!isset($notify['object'])) {
$notify = [ $formattedNotify = [
'label' => 'friend', 'label' => 'friend',
'link' => $default_item_link, 'link' => $default_item_link,
'image' => $default_item_image, 'image' => $default_item_image,
@ -375,7 +377,7 @@ final class Notify extends BaseObject
$obj = XML::parseString($xmlHead . $notify['object']); $obj = XML::parseString($xmlHead . $notify['object']);
$notify['fname'] = $obj->title; $notify['fname'] = $obj->title;
$notify = [ $formattedNotify = [
'label' => 'friend', 'label' => 'friend',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
@ -388,7 +390,7 @@ final class Notify extends BaseObject
break; break;
default: default:
$notify = [ $formattedNotify = [
'label' => $default_item_label, 'label' => $default_item_label,
'link' => $default_item_link, 'link' => $default_item_link,
'image' => $default_item_image, 'image' => $default_item_image,
@ -400,17 +402,16 @@ final class Notify extends BaseObject
]; ];
} }
$arr[] = $notify; $formattedNotifies[] = $formattedNotify;
}
} }
return $arr; return $formattedNotifies;
} }
/** /**
* @brief Get network notifications * Get network notifications
* *
* @param int|string $seen If 0 only include notifications into the query * @param bool $seen False => only include notifications into the query
* which aren't marked as "seen" * which aren't marked as "seen"
* @param int $start Start the query at this point * @param int $start Start the query at this point
* @param int $limit Maximum number of query results * @param int $limit Maximum number of query results
@ -421,14 +422,14 @@ final class Notify extends BaseObject
* *
* @throws Exception * @throws Exception
*/ */
public function getNetworkNotifies(int $seen = 0, int $start = 0, int $limit = 80) public function getNetworkNotifies(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
{ {
$ident = self::NETWORK; $ident = self::NETWORK;
$notifies = []; $notifies = [];
$condition = ['wall' => false, 'uid' => local_user()]; $condition = ['wall' => false, 'uid' => local_user()];
if ($seen === 0) { if (!$seen) {
$condition['unseen'] = true; $condition['unseen'] = true;
} }
@ -451,9 +452,9 @@ final class Notify extends BaseObject
} }
/** /**
* @brief Get system notifications * Get system notifications
* *
* @param int|string $seen If 0 only include notifications into the query * @param bool $seen False => only include notifications into the query
* which aren't marked as "seen" * which aren't marked as "seen"
* @param int $start Start the query at this point * @param int $start Start the query at this point
* @param int $limit Maximum number of query results * @param int $limit Maximum number of query results
@ -464,13 +465,13 @@ final class Notify extends BaseObject
* *
* @throws Exception * @throws Exception
*/ */
public function getSystemNotifies(int $seen = 0, int $start = 0, int $limit = 80) public function getSystemNotifies(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
{ {
$ident = self::SYSTEM; $ident = self::SYSTEM;
$notifies = []; $notifies = [];
$filter = ['uid' => local_user()]; $filter = ['uid' => local_user()];
if ($seen === 0) { if (!$seen) {
$filter['seen'] = false; $filter['seen'] = false;
} }
@ -496,9 +497,9 @@ final class Notify extends BaseObject
} }
/** /**
* @brief Get personal notifications * Get personal notifications
* *
* @param int|string $seen If 0 only include notifications into the query * @param bool $seen False => only include notifications into the query
* which aren't marked as "seen" * which aren't marked as "seen"
* @param int $start Start the query at this point * @param int $start Start the query at this point
* @param int $limit Maximum number of query results * @param int $limit Maximum number of query results
@ -509,7 +510,7 @@ final class Notify extends BaseObject
* *
* @throws Exception * @throws Exception
*/ */
public function getPersonalNotifies(int $seen = 0, int $start = 0, int $limit = 80) public function getPersonalNotifies(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
{ {
$ident = self::PERSONAL; $ident = self::PERSONAL;
$notifies = []; $notifies = [];
@ -520,7 +521,7 @@ final class Notify extends BaseObject
$condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)", $condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
local_user(), public_contact(), $myurl . '\\]', $diasp_url . '\\]']; local_user(), public_contact(), $myurl . '\\]', $diasp_url . '\\]'];
if ($seen === 0) { if (!$seen) {
$condition[0] .= " AND `unseen`"; $condition[0] .= " AND `unseen`";
} }
@ -545,7 +546,7 @@ final class Notify extends BaseObject
/** /**
* @brief Get home notifications * @brief Get home notifications
* *
* @param int|string $seen If 0 only include notifications into the query * @param bool $seen False => only include notifications into the query
* which aren't marked as "seen" * which aren't marked as "seen"
* @param int $start Start the query at this point * @param int $start Start the query at this point
* @param int $limit Maximum number of query results * @param int $limit Maximum number of query results
@ -556,14 +557,14 @@ final class Notify extends BaseObject
* *
* @throws Exception * @throws Exception
*/ */
public function getHomeNotifies($seen = 0, int $start = 0, int $limit = 80) public function getHomeNotifies(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
{ {
$ident = self::HOME; $ident = self::HOME;
$notifies = []; $notifies = [];
$condition = ['wall' => false, 'uid' => local_user()]; $condition = ['wall' => false, 'uid' => local_user()];
if ($seen === 0) { if (!$seen) {
$condition['unseen'] = true; $condition['unseen'] = true;
} }
@ -601,7 +602,7 @@ final class Notify extends BaseObject
* @throws ImagickException * @throws ImagickException
* @throws Exception * @throws Exception
*/ */
public function getIntroNotifies($all = false, int $start = 0, int $limit = 80, int $id = 0) public function getIntroNotifies(bool $all = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT, int $id = 0)
{ {
/// @todo sanitize wording according to SELF::INTRO /// @todo sanitize wording according to SELF::INTRO
$ident = 'introductions'; $ident = 'introductions';