]> git.mxchange.org Git - friendica.git/commitdiff
The fetch function now centrally controls the content
authorMichael <heluecht@pirati.ca>
Sun, 24 Jun 2018 10:48:29 +0000 (10:48 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 24 Jun 2018 10:48:29 +0000 (10:48 +0000)
14 files changed:
include/api.php
include/conversation.php
mod/acl.php
mod/display.php
mod/network.php
mod/notes.php
mod/ping.php
mod/profile.php
mod/search.php
mod/starred.php
src/Core/NotificationsManager.php
src/Model/Contact.php
src/Model/Item.php
src/Object/Post.php

index a5088756ae20625d8e71b0edd96af539467e5ee0..819d2c75a00c624488586eabbb02d633ad3081c8 100644 (file)
@@ -2078,7 +2078,7 @@ function api_statuses_mentions($type)
        $start = ($page - 1) * $count;
 
        $condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `author-id` != ?
-               AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = ? AND `mention` AND NOT `ignored`)",
+               AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `thread`.`uid` = ? AND `thread`.`mention` AND NOT `thread`.`ignored`)",
                api_user(), ACTIVITY_POST, $since_id, $user_info['pid'], api_user()];
 
        if ($max_id > 0) {
index 08220d4bb2c1c9fc541b122d43f29e6000831d9b..1112447d5048537d079b1f2030a6aa683041588d 100644 (file)
@@ -562,15 +562,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
                                        continue;
                                }
 
-                               if ($item['network'] == NETWORK_FEED) {
-                                       $item['author-avatar'] = $item['contact-avatar'];
-                                       $item['author-name'] = $item['contact-name'];
-                                       $item['owner-avatar'] = $item['contact-avatar'];
-                                       $item['owner-name'] = $item['contact-name'];
-                               }
-
-                               $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']);
-                               if ($item['author-link'] && !$item['author-name']) {
+                               $profile_name = $item['author-name'];
+                               if (!empty($item['author-link']) && empty($item['author-name'])) {
                                        $profile_name = $item['author-link'];
                                }
 
index ede69403290146950f49dfe4ae8ac121884bc728..c16b3bab6efc879cf8e7cb8e217b2060e774697c 100644 (file)
@@ -260,7 +260,7 @@ function acl_content(App $a)
                $params = ['order' => ['author-name' => true]];
                $authors = Item::selectForUser(local_user(), ['author-link'], $condition, $params);
                $item_authors = [];
-               while ($author = dba::fetch($authors)) {
+               while ($author = Item::fetch($authors)) {
                        $item_authors[$author['author-link']] = $author['author-link'];
                }
                dba::close($authors);
index 6a07fa17622b631978b3c9e8e59a0f8baf6c1715..919b12fbc3e2e0454f5c5b510844dc6feafb02aa 100644 (file)
@@ -347,7 +347,7 @@ function display_content(App $a, $update = false, $update_uid = 0)
                Item::update(['unseen' => false], $condition);
        }
 
-       $items = conv_sort(dba::inArray($items_obj), "`commented`");
+       $items = conv_sort(Item::inArray($items_obj), "`commented`");
 
        if (!$update) {
                $o .= "<script> var netargs = '?f=&item_id=" . $item_id . "'; </script>";
index 61d957e1ad6ff594f98ffe3ff55dd049d591170f..61e4e779ed366c5b657cb3ce86cf5c5b118c8a94 100644 (file)
@@ -456,7 +456,7 @@ function networkFlatView(App $a, $update = 0)
 
        $params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
        $result = Item::selectForUser(local_user(), [], $condition, $params);
-       $items = dba::inArray($result);
+       $items = Item::inArray($result);
 
        $condition = ['unseen' => true, 'uid' => local_user()];
        networkSetSeen($condition);
index 69b544472f6bba4013659fc3087ce6be29f9e75e..99114add8c87a6e2971f65f0795b19d3b17eca3d 100644 (file)
@@ -73,7 +73,7 @@ function notes_content(App $a, $update = false)
        if (DBM::is_result($r)) {
                $parents_arr = [];
 
-               while ($rr = dba::fetch($r)) {
+               while ($rr = Item::fetch($r)) {
                        $parents_arr[] = $rr['item_id'];
                }
                dba::close($r);
@@ -81,7 +81,7 @@ function notes_content(App $a, $update = false)
                $condition = ['uid' => local_user(), 'parent' => $parents_arr];
                $result = Item::selectForUser(local_user(), [], $condition);
                if (DBM::is_result($result)) {
-                       $items = conv_sort(dba::inArray($result), 'commented');
+                       $items = conv_sort(Item::inArray($result), 'commented');
                        $o .= conversation($a, $items, 'notes', $update);
                }
        }
index 06d83a1d9a073d8870dc2f2570ca004c391c71e6..8028d69ed268be7bcda84be3a3aa1299472675b5 100644 (file)
@@ -135,7 +135,7 @@ function ping_init(App $a)
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
                if (DBM::is_result($items)) {
-                       $items_unseen = dba::inArray($items);
+                       $items_unseen = Item::inArray($items);
                        $arr = ['items' => $items_unseen];
                        Addon::callHooks('network_ping', $arr);
 
index 49d6fe261d2b2ca761ca1406c7c958c7de2c8970..a6075b01cf22cc3d2cff1a6609d49ac871c26dd3 100644 (file)
@@ -339,7 +339,7 @@ function profile_content(App $a, $update = 0)
 
                $condition = ['uid' => $a->profile['profile_uid'], 'parent' => $parents_arr];
                $result = Item::selectForUser($a->profile['profile_uid'], [], $condition);
-               $items = conv_sort(dba::inArray($result), 'created');
+               $items = conv_sort(Item::inArray($result), 'created');
        } else {
                $items = [];
        }
index d64ce7d0e17eafe34edad6e7e7320ca7eba2d574..974680d2a087d39ab838aa1f675eab8352be5f42 100644 (file)
@@ -214,7 +214,7 @@ function search_content(App $a) {
                if (!empty($itemids)) {
                        $params = ['order' => ['id' => true]];
                        $items = Item::selectForUser(local_user(), [], ['id' => $itemids], $params);
-                       $r = dba::inArray($items);
+                       $r = Item::inArray($items);
                } else {
                        $r = [];
                }
@@ -227,7 +227,7 @@ function search_content(App $a) {
                $params = ['order' => ['id' => true],
                        'limit' => [$a->pager['start'], $a->pager['itemspage']]];
                $items = Item::selectForUser(local_user(), [], $condition, $params);
-               $r = dba::inArray($items);
+               $r = Item::inArray($items);
        }
 
        if (!DBM::is_result($r)) {
index 78ba4ce61ef121e2d429dc21fad6006f33461914..443308c27729962b50ce41554527e15f53820672 100644 (file)
@@ -21,7 +21,7 @@ function starred_init(App $a) {
                killme();
        }
 
-       $item = Item::selectForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
+       $item = Item::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $message_id]);
        if (!DBM::is_result($item)) {
                killme();
        }
index 8020a281b0e91d8b2d55333cbbd2bc9239fdd1ad..507d4db1317280aa31169c0224a67c02fe96fa71 100644 (file)
@@ -410,7 +410,7 @@ class NotificationsManager extends BaseObject
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
                if (DBM::is_result($items)) {
-                       $notifs = $this->formatNotifs(dba::inArray($items), $ident);
+                       $notifs = $this->formatNotifs(Item::inArray($items), $ident);
                }
 
                $arr = [
@@ -495,7 +495,7 @@ class NotificationsManager extends BaseObject
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
                if (DBM::is_result($items)) {
-                       $notifs = $this->formatNotifs(dba::inArray($items), $ident);
+                       $notifs = $this->formatNotifs(Item::inArray($items), $ident);
                }
 
                $arr = [
@@ -535,7 +535,7 @@ class NotificationsManager extends BaseObject
                $items = Item::selectForUser(local_user(), $fields, $condition, $params);
 
                if (DBM::is_result($items)) {
-                       $notifs = $this->formatNotifs(dba::inArray($items), $ident);
+                       $notifs = $this->formatNotifs(Item::inArray($items), $ident);
                }
 
                $arr = [
index 6a24b7da9ff9ed6a62d793ffd8b647919217ed20..973e5b5a21fcba90c1e550747d469c1204b697f3 100644 (file)
@@ -1070,7 +1070,7 @@ class Contact extends BaseObject
                        'limit' => [$a->pager['start'], $a->pager['itemspage']]];
                $r = Item::selectForUser(local_user(), [], $condition, $params);
 
-               $items = dba::inArray($r);
+               $items = Item::inArray($r);
 
                $o = conversation($a, $items, 'contact-posts', false);
 
index d4c5e81704aaf08f5b0e9fae328f5b77380e4e6c..d6bfef39fba978fbfe2180ffddc3231cf9660d22 100644 (file)
@@ -34,15 +34,15 @@ require_once 'include/text.php';
 class Item extends BaseObject
 {
        // Field list that is used to display the items
-       const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
+       const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network',
                        'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
                        'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach',
                        'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id',
-                       'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
+                       'author-id', 'author-link', 'author-name', 'author-avatar',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar',
                        'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
-                       'network', 'url', 'name', 'writable', 'self', 'cid', 'alias',
+                       'writable', 'self', 'cid', 'alias',
                        'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
                        'event-summary', 'event-desc', 'event-location', 'event-type',
                        'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
@@ -66,6 +66,33 @@ class Item extends BaseObject
        {
                $row = dba::fetch($stmt);
 
+               // We prefer the data from the user's contact over the public one
+               if (!empty($row['author-link']) && !empty($row['contact-link']) &&
+                       ($row['author-link'] == $row['contact-link'])) {
+                       if (isset($row['author-avatar']) && !empty($row['contact-avatar'])) {
+                               $row['author-avatar'] = $row['contact-avatar'];
+                       }
+                       if (isset($row['author-name']) && !empty($row['contact-name'])) {
+                               $row['author-name'] = $row['contact-name'];
+                       }
+               }
+
+               if (!empty($row['owner-link']) && !empty($row['contact-link']) &&
+                       ($row['owner-link'] == $row['contact-link'])) {
+                       if (isset($row['owner-avatar']) && !empty($row['contact-avatar'])) {
+                               $row['owner-avatar'] = $row['contact-avatar'];
+                       }
+                       if (isset($row['owner-name']) && !empty($row['contact-name'])) {
+                               $row['owner-name'] = $row['contact-name'];
+                       }
+               }
+
+               // We can always comment on posts from these networks
+               if (isset($row['writable']) && !empty($row['network']) &&
+                       in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
+                       $row['writable'] = true;
+               }
+
                return $row;
        }
 
@@ -334,14 +361,14 @@ class Item extends BaseObject
                        'id' => 'item_id', 'network'];
 
                $fields['author'] = ['url' => 'author-link', 'name' => 'author-name',
-                       'thumb' => 'author-avatar', 'nick' => 'author-nick', 'network' => 'author-network'];
+                       'thumb' => 'author-avatar', 'nick' => 'author-nick'];
 
                $fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name',
-                       'thumb' => 'owner-avatar', 'nick' => 'owner-nick', 'network' => 'owner-network'];
+                       'thumb' => 'owner-avatar', 'nick' => 'owner-nick'];
 
                $fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
-                       'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
-                       'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', 'network' => 'contact-network'];
+                       'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
+                       'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id'];
 
                $fields['parent-item'] = ['guid' => 'parent-guid', 'network' => 'parent-network'];
 
@@ -1126,8 +1153,9 @@ class Item extends BaseObject
                                $user = dba::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
                                if (DBM::is_result($user)) {
                                        $self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']);
-                                       logger("'myself' is ".$self." for parent ".$parent_id." checking against ".$item['author-link']." and ".$item['owner-link'], LOGGER_DEBUG);
-                                       if ((normalise_link($item['author-link']) == $self) || (normalise_link($item['owner-link']) == $self)) {
+                                       $self_id = Contact::getIdForURL($self, 0, true);
+                                       logger("'myself' is ".$self_id." for parent ".$parent_id." checking against ".$item['author-id']." and ".$item['owner-id'], LOGGER_DEBUG);
+                                       if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) {
                                                dba::update('thread', ['mention' => true], ['iid' => $parent_id]);
                                                logger("tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG);
                                        }
index bceee38444ca4f88bcec7caf08198b7b236df91b..594b18af88590e41f013de0943c4d82708ca3032 100644 (file)
@@ -198,16 +198,8 @@ class Post extends BaseObject
 
                $filer = (($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) ? L10n::t("save to folder") : false);
 
-               if ($item['network'] == NETWORK_FEED) {
-                       $item['author-avatar'] = $item['contact-avatar'];
-                       $item['author-name'] = $item['contact-name'];
-                       $item['owner-avatar'] = $item['contact-avatar'];
-                       $item['owner-name'] = $item['contact-name'];
-               }
-
-               $diff_author = !link_compare($item['url'], $item['author-link']);
-               $profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
-               if ($item['author-link'] && (!$item['author-name'])) {
+               $profile_name = htmlentities($item['author-name']);
+               if (!empty($item['author-link']) && empty($item['author-name'])) {
                        $profile_name = $item['author-link'];
                }