]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/NotificationsManager.php
Fix session size problems
[friendica.git] / src / Core / NotificationsManager.php
index be6fae6cb36e76caed543256d3bb1cec8163a6af..a6a5c24e013f060944beaa54f50e0612480e18a4 100644 (file)
@@ -36,7 +36,7 @@ class NotificationsManager extends BaseObject
         *  - msg_plain: message as plain text string
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private function _set_extra($notes)
+       private function _set_extra(array $notes)
        {
                $rets = [];
                foreach ($notes as $n) {
@@ -73,10 +73,10 @@ class NotificationsManager extends BaseObject
 
                $dbFilter = array_merge($filter, ['uid' => local_user()]);
 
-               $r = DBA::select('notify', [], $dbFilter, $order, $params);
+               $stmtNotifies = DBA::select('notify', [], $dbFilter, $params);
 
-               if (DBA::isResult($r)) {
-                       return $this->_set_extra($r);
+               if (DBA::isResult($stmtNotifies)) {
+                       return $this->_set_extra(DBA::toArray($stmtNotifies));
                }
 
                return false;
@@ -91,9 +91,9 @@ class NotificationsManager extends BaseObject
         */
        public function getByID($id)
        {
-               $r = DBA::selectFirst('notify', ['id' => $id, 'uid' => local_user()]);
-               if (DBA::isResult($r)) {
-                       return $this->_set_extra($r)[0];
+               $stmtNotify = DBA::selectFirst('notify', [], ['id' => $id, 'uid' => local_user()]);
+               if (DBA::isResult($stmtNotify)) {
+                       return $this->_set_extra([$stmtNotify])[0];
                }
                return null;
        }
@@ -108,7 +108,13 @@ class NotificationsManager extends BaseObject
         */
        public function setSeen($note, $seen = true)
        {
-               return DBA::update('notify', ['seen' => $seen], ['link' => $note['link'], 'parent' => $note['parent'], 'otype' => $note['otype'], 'uid' => local_user()]);
+               return DBA::update('notify', ['seen' => $seen], [
+                       '(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
+                       $note['link'],
+                       $note['parent'],
+                       $note['otype'],
+                       local_user()
+               ]);
        }
 
        /**
@@ -388,7 +394,7 @@ class NotificationsManager extends BaseObject
 
                $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
                        'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
-               $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
 
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
@@ -423,22 +429,22 @@ class NotificationsManager extends BaseObject
                $notifs = [];
                $sql_seen = "";
 
+               $filter = ['uid' => local_user()];
                if ($seen === 0) {
-                       $filter = ['`uid` = ? AND NOT `seen`', local_user()];
-               } else {
-                       $filter = ['uid' => local_user()];
+                       $filter['seen'] = false;
                }
 
                $params = [];
+               $params['order'] = ['date' => 'DESC'];
                $params['limit'] = [$start, $limit];
 
-               $r = DBA::select('notify',
+               $stmtNotifies = DBA::select('notify',
                        ['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'],
                        $filter,
                        $params);
 
-               if (DBA::isResult($r)) {
-                       $notifs = $this->formatNotifs(DBA::toArray($r), $ident);
+               if (DBA::isResult($stmtNotifies)) {
+                       $notifs = $this->formatNotifs(DBA::toArray($stmtNotifies), $ident);
                }
 
                $arr = [
@@ -479,7 +485,7 @@ class NotificationsManager extends BaseObject
 
                $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
                        'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
-               $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
 
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
@@ -521,7 +527,7 @@ class NotificationsManager extends BaseObject
 
                $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
                        'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
-               $params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
                if (DBA::isResult($items)) {
@@ -543,6 +549,7 @@ class NotificationsManager extends BaseObject
         *                      which aren't marked as ignored
         * @param int  $start   Start the query at this point
         * @param int  $limit   Maximum number of query results
+        * @param int  $id      When set, only the introduction with this id is displayed
         *
         * @return array with
         *    string 'ident' => Notification identifier
@@ -550,18 +557,24 @@ class NotificationsManager extends BaseObject
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public function introNotifs($all = false, $start = 0, $limit = 80)
+       public function introNotifs($all = false, $start = 0, $limit = 80, $id = 0)
        {
                $ident = 'introductions';
                $notifs = [];
                $sql_extra = "";
 
-               if (!$all) {
-                       $sql_extra = " AND `ignore` = 0 ";
+               if (empty($id)) {
+                       if (!$all) {
+                               $sql_extra = " AND NOT `ignore` ";
+                       }
+
+                       $sql_extra .= " AND NOT `intro`.`blocked` ";
+               } else {
+                       $sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
                }
 
                /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
-               $r = q(
+               $stmtNotifies = DBA::p(
                        "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
                                `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
                                `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
@@ -572,14 +585,14 @@ class NotificationsManager extends BaseObject
                                LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
                                LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
                                LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
-                       WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0
-                       LIMIT %d, %d",
-                       intval($_SESSION['uid']),
-                       intval($start),
-                       intval($limit)
+                       WHERE `intro`.`uid` = ? $sql_extra
+                       LIMIT ?, ?",
+                       $_SESSION['uid'],
+                       $start,
+                       $limit
                );
-               if (DBA::isResult($r)) {
-                       $notifs = $this->formatIntros($r);
+               if (DBA::isResult($stmtNotifies)) {
+                       $notifs = $this->formatIntros(DBA::toArray($stmtNotifies));
                }
 
                $arr = [