]> git.mxchange.org Git - friendica.git/commitdiff
Use gravity instead of verb
authorMichael <heluecht@pirati.ca>
Wed, 27 Jun 2018 18:09:33 +0000 (18:09 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 27 Jun 2018 18:09:33 +0000 (18:09 +0000)
14 files changed:
boot.php
include/api.php
include/enotify.php
mod/item.php
mod/network.php
mod/photos.php
mod/profile.php
mod/subthread.php
mod/tagger.php
src/Model/Contact.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/OStatus.php

index ac21d108a3cd0c25a929ed77dd8ccde88fcd340b..64abdddca36f0084a767d3b5b3761069d79d8731 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -451,8 +451,9 @@ define('ACTIVITY_OBJ_QUESTION', 'http://activityschema.org/object/question');
  * @{
  */
 define('GRAVITY_PARENT',       0);
-define('GRAVITY_LIKE',         3);
+define('GRAVITY_ACTIVITY',     3);
 define('GRAVITY_COMMENT',      6);
+define('GRAVITY_UNKNOWN',      9);
 /* @}*/
 
 /**
index 819d2c75a00c624488586eabbb02d633ad3081c8..2eaabd82429ce70306e70ab267e8f7d17b101d22 100644 (file)
@@ -1270,8 +1270,8 @@ function api_status_show($type)
        }
 
        // get last public wall message
-       $condition = ["`owner-id` = ? AND `uid` = ? AND `type` != 'activity' ".$privacy_sql,
-               $user_info['pid'], api_user()];
+       $condition = ['owner-id' => $user_info['pid'], 'uid' => api_user(),
+               'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
        $lastwall = dba::selectFirst('item', [], $condition, ['order' => ['id' => true]]);
 
        if (DBM::is_result($lastwall)) {
@@ -1355,8 +1355,8 @@ function api_users_show($type)
 
        $user_info = api_get_user($a);
 
-       $condition = ["`owner-id` = ? AND `uid` = ? AND `verb` = ? AND `type` != 'activity' AND NOT `private`",
-               $user_info['pid'], api_user(), ACTIVITY_POST];
+       $condition = ['owner-id' => $user_info['pid'], 'uid' => api_user(),
+               'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT], 'private' => false];
        $lastwall = dba::selectFirst('item', [], $condition, ['order' => ['id' => true]]);
 
        if (DBM::is_result($lastwall)) {
@@ -1534,10 +1534,10 @@ function api_search($type)
 
        $start = $page * $count;
 
-       $condition = ["`verb` = ? AND `item`.`id` > ?
+       $condition = ["`gravity` IN (?, ?) AND `item`.`id` > ?
                AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))
                AND `item`.`body` LIKE CONCAT('%',?,'%')",
-               ACTIVITY_POST, $since_id, api_user(), $_REQUEST['q']];
+               GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, api_user(), $_REQUEST['q']];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `item`.`id` <= ?";
@@ -1597,7 +1597,8 @@ function api_statuses_home_timeline($type)
 
        $start = $page * $count;
 
-       $condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ?", api_user(), ACTIVITY_POST, $since_id];
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ?",
+               api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `item`.`id` <= ?";
@@ -1680,8 +1681,8 @@ function api_statuses_public_timeline($type)
        $sql_extra = '';
 
        if ($exclude_replies && !$conversation_id) {
-               $condition = ["`verb` = ? AND `iid` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall`",
-                       ACTIVITY_POST, $since_id];
+               $condition = ["`gravity` IN (?, ?) AND `iid` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall`",
+                       GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
                if ($max_id > 0) {
                        $condition[0] .= " AND `thread`.`iid` <= ?";
@@ -1693,8 +1694,8 @@ function api_statuses_public_timeline($type)
 
                $r = Item::inArray($statuses);
        } else {
-               $condition = ["`verb` = ? AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
-                       ACTIVITY_POST, $since_id];
+               $condition = ["`gravity` IN (?, ?) AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
+                       GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
                if ($max_id > 0) {
                        $condition[0] .= " AND `item`.`id` <= ?";
@@ -1756,8 +1757,8 @@ function api_statuses_networkpublic_timeline($type)
        }
        $start = ($page - 1) * $count;
 
-       $condition = ["`uid` = 0 AND `verb` = ? AND `thread`.`iid` > ? AND NOT `private`",
-               ACTIVITY_POST, $since_id];
+       $condition = ["`uid` = 0 AND `gravity` IN (?, ?) AND `thread`.`iid` > ? AND NOT `private`",
+               GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `thread`.`iid` <= ?";
@@ -1829,10 +1830,10 @@ function api_statuses_show($type)
        $id = $item['id'];
 
        if ($conversation) {
-               $condition = ['parent' => $id, 'verb' => ACTIVITY_POST];
+               $condition = ['parent' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
                $params = ['order' => ['id' => true]];
        } else {
-               $condition = ['id' => $id, 'verb' => ACTIVITY_POST];
+               $condition = ['id' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
                $params = [];
        }
 
@@ -1908,8 +1909,8 @@ function api_conversation_show($type)
 
        $id = $parent['id'];
 
-       $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `verb` = ? AND `item`.`id` > ?",
-               $id, api_user(), ACTIVITY_POST, $since_id];
+       $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `item`.`id` > ?",
+               $id, api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `item`.`id` <= ?";
@@ -2077,9 +2078,9 @@ function api_statuses_mentions($type)
 
        $start = ($page - 1) * $count;
 
-       $condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `author-id` != ?
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `author-id` != ?
                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()];
+               api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['pid'], api_user()];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `item`.`id` <= ?";
@@ -2145,8 +2146,8 @@ function api_statuses_user_timeline($type)
        }
        $start = ($page - 1) * $count;
 
-       $condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `item`.`contact-id` = ?",
-               api_user(), ACTIVITY_POST, $since_id, $user_info['cid']];
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `item`.`contact-id` = ?",
+               api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['cid']];
 
        if ($user_info['self'] == 1) {
                $condition[0] .= ' AND `item`.`wall` ';
@@ -2299,8 +2300,8 @@ function api_favorites($type)
 
                $start = $page*$count;
 
-               $condition = ["`uid` = ? AND `verb` = ? AND `id` > ? AND `starred`",
-                       api_user(), ACTIVITY_POST, $since_id];
+               $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `starred`",
+                       api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
                $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
 
@@ -3099,8 +3100,8 @@ function api_lists_statuses($type)
 
        $start = $page * $count;
 
-       $condition = ["`uid` = ? AND `verb` = ? AND `id` > ? AND `group_member`.`gid` = ?",
-               api_user(), ACTIVITY_POST, $since_id, $_REQUEST['list_id']];
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group_member`.`gid` = ?",
+               api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $_REQUEST['list_id']];
 
        if ($max_id > 0) {
                $condition[0] .= " AND `item`.`id` <= ?";
@@ -4630,8 +4631,8 @@ function prepare_photo_data($type, $scale, $photo_id)
        $data['photo']['friendica_activities'] = api_format_items_activities($item, $type);
 
        // retrieve comments on photo
-       $condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
-               $item[0]['parent'], api_user(), ACTIVITY_POST];
+       $condition = ["`parent` = ? AND `uid` = ? AND (`gravity` IN (?, ?) OR `type`='photo')",
+               $item[0]['parent'], api_user(), GRAVITY_PARENT, GRAVITY_COMMENT];
 
        $statuses = Item::selectForUser(api_user(), [], $condition);
 
index 00459ac5c09f5fbd8b78d6bab49c1fa5edc12e4b..be9468dd8fb3231d5c6180bdb81ef8e87752f383 100644 (file)
@@ -740,9 +740,9 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
        // We need the additional check for the "local_profile" because of mixed situations on connector networks
        $item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
                        `parent-uri`, `uri`, `contact-id`, `network`
-                       FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
+                       FROM `item` WHERE `id` = %d AND `gravity` IN (%d, %d) AND
                                NOT (`author-id` IN ($contact_list)) LIMIT 1",
-               intval($itemid), dbesc(ACTIVITY_POST));
+               intval($itemid), intval(GRAVITY_PARENT), intval(GRAVITY_COMMENT));
        if (!$item)
                return false;
 
index 2830cae2c920ec3bfdc20fbe630ca4df7ef40b8e..0a3c3e2fa49508f09f18b64d68a82587494bc0df 100644 (file)
@@ -567,7 +567,7 @@ function item_post(App $a) {
                $network = NETWORK_DFRN;
        }
 
-       $gravity = ($parent ? 6 : 0);
+       $gravity = ($parent ? GRAVITY_COMMENT : GRAVITY_PARENT);
 
        // even if the post arrived via API we are considering that it
        // originated on this site by default for determining relayability.
index 61e4e779ed366c5b657cb3ce86cf5c5b118c8a94..442ae669babfe0ee25bc8f22bee449d341a45468 100644 (file)
@@ -756,7 +756,7 @@ function networkThreadedView(App $a, $update, $parent)
                        // Load all unseen items
                        $sql_extra4 = "`item`.`unseen`";
                        if (Config::get("system", "like_no_comment")) {
-                               $sql_extra4 .= " AND `item`.`verb` = '".ACTIVITY_POST."'";
+                               $sql_extra4 .= " AND `item`.`gravity` IN (" . GRAVITY_PARENT . "," . GRAVITY_COMMENT . ")";
                        }
                        if ($order === 'post') {
                                // Only show toplevel posts when updating posts in this order mode
index f54bc62444263252a1f7e55acd8696dd382d7afa..c0e1c7477ad434000e73ee2cc9c45e5ccb582a11 100644 (file)
@@ -640,6 +640,7 @@ function photos_post(App $a)
                                        $arr['deny_gid']      = $p[0]['deny_gid'];
                                        $arr['visible']       = 1;
                                        $arr['verb']          = ACTIVITY_TAG;
+                                       $arr["gravity"]       = GRAVITY_PARENT;
                                        $arr['object-type']   = ACTIVITY_OBJ_PERSON;
                                        $arr['target-type']   = ACTIVITY_OBJ_IMAGE;
                                        $arr['tag']           = $tagged[4];
index a6075b01cf22cc3d2cff1a6609d49ac871c26dd3..8d156cbd64f9681b1b5b7d36d1339edcaa38aac8 100644 (file)
@@ -243,17 +243,14 @@ function profile_content(App $a, $update = 0)
 
                $r = q("SELECT distinct(parent) AS `item_id`, `item`.`network` AS `item_network`, `item`.`created`
                        FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                       AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
-                       WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND
-                       (`item`.`deleted` = 0 OR item.verb = '" . ACTIVITY_LIKE . "'
-                       OR item.verb = '" . ACTIVITY_DISLIKE . "' OR item.verb = '" . ACTIVITY_ATTEND . "'
-                       OR item.verb = '" . ACTIVITY_ATTENDNO . "' OR item.verb = '" . ACTIVITY_ATTENDMAYBE . "')
-                       AND `item`.`moderated` = 0
-                       AND `item`.`wall` = 1
+                       AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
+                       WHERE `item`.`uid` = %d AND `item`.`visible` AND
+                       (NOT `item`.`deleted` OR `item`.`gravity` = %d)
+                       AND NOT `item`.`moderated` AND `item`.`wall`
                        $sql_extra4
                        $sql_extra
                        ORDER BY `item`.`created` DESC",
-                       intval($a->profile['profile_uid'])
+                       intval($a->profile['profile_uid']), intval(GRAVITY_ACTIVITY)
                );
 
                if (!DBM::is_result($r)) {
index 0b6f4ecaaaad33d0289752603d9aacf61dc15fd5..e05aa5fec83588de0155dfabbe406cc91042f539 100644 (file)
@@ -125,7 +125,7 @@ EOT;
        $arr['type'] = 'activity';
        $arr['wall'] = $item['wall'];
        $arr['origin'] = 1;
-       $arr['gravity'] = GRAVITY_LIKE;
+       $arr['gravity'] = GRAVITY_ACTIVITY;
        $arr['parent'] = $item['id'];
        $arr['parent-uri'] = $item['uri'];
        $arr['thr-parent'] = $item['uri'];
index 717c0947769d47b9fb30bd6101332e4a90c22e47..a5e9b3715b12dd8f929bb19a56183aad02ee82cd 100644 (file)
@@ -121,7 +121,7 @@ EOT;
        $arr['contact-id'] = $contact['id'];
        $arr['type'] = 'activity';
        $arr['wall'] = $item['wall'];
-       $arr['gravity'] = GRAVITY_COMMENT;
+       $arr['gravity'] = GRAVITY_ACTIVITY;
        $arr['parent'] = $item['id'];
        $arr['parent-uri'] = $item['uri'];
        $arr['owner-name'] = $item['author-name'];
index 973e5b5a21fcba90c1e550747d469c1204b697f3..fe9869c6f88065386a8a918b11ac88e555e5096a 100644 (file)
@@ -1064,8 +1064,8 @@ class Contact extends BaseObject
 
                $contact = ($r[0]["contact-type"] == ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
 
-               $condition = ["`$contact` = ? AND `verb` = ? AND " . $sql,
-                       $author_id, ACTIVITY_POST, local_user()];
+               $condition = ["`$contact` = ? AND `gravity` IN (?, ?) AND " . $sql,
+                       $author_id, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
                $params = ['order' => ['created' => true],
                        'limit' => [$a->pager['start'], $a->pager['itemspage']]];
                $r = Item::selectForUser(local_user(), [], $condition, $params);
index 6fe4a575dd9fa6ffdb55a1039bb3fe48ab95a4c7..fe6dc5d1d47a81ccd657e7ae536fa563f88c2c5c 100644 (file)
@@ -953,18 +953,21 @@ class Item extends BaseObject
                        $item['parent-uri'] = $item['thr-parent'];
                }
 
-               if (x($item, 'gravity')) {
+               $item['type'] = defaults($item, 'type', 'remote');
+
+               if (isset($item['gravity'])) {
                        $item['gravity'] = intval($item['gravity']);
                } elseif ($item['parent-uri'] === $item['uri']) {
-                       $item['gravity'] = 0;
-               } elseif (activity_match($item['verb'],ACTIVITY_POST)) {
-                       $item['gravity'] = 6;
+                       $item['gravity'] = GRAVITY_PARENT;
+               } elseif (activity_match($item['verb'], ACTIVITY_POST)) {
+                       $item['gravity'] = GRAVITY_COMMENT;
+               } elseif ($item['type'] == 'activity') {
+                       $item['gravity'] = GRAVITY_ACTIVITY;
                } else {
-                       $item['gravity'] = 6;   // extensible catchall
+                       $item['gravity'] = GRAVITY_UNKNOWN;   // Should not happen
+                       logger('Unknown gravity for verb: ' . $item['verb'] . ' - type: ' . $item['type'], LOGGER_DEBUG);
                }
 
-               $item['type'] = defaults($item, 'type', 'remote');
-
                $uid = intval($item['uid']);
 
                // check for create date and expire time
@@ -1219,7 +1222,7 @@ class Item extends BaseObject
                                        logger('$force_parent=true, reply converted to top-level post.');
                                        $parent_id = 0;
                                        $item['parent-uri'] = $item['uri'];
-                                       $item['gravity'] = 0;
+                                       $item['gravity'] = GRAVITY_PARENT;
                                } else {
                                        logger('item parent '.$item['parent-uri'].' for '.$item['uid'].' was not found - ignoring item');
                                        return 0;
@@ -2644,7 +2647,7 @@ EOT;
                        'type'          => 'activity',
                        'wall'          => $item['wall'],
                        'origin'        => 1,
-                       'gravity'       => GRAVITY_LIKE,
+                       'gravity'       => GRAVITY_ACTIVITY,
                        'parent'        => $item['id'],
                        'parent-uri'    => $item['uri'],
                        'thr-parent'    => $item['uri'],
index 1047ffdfe282a9584ad0f1fccf18280cd3123af5..0b8cb738272633da736b30e7127d4d2aa30c1159 100644 (file)
@@ -2310,7 +2310,7 @@ class DFRN
                        ) {
                                $is_like = true;
                                $item["type"] = "activity";
-                               $item["gravity"] = GRAVITY_LIKE;
+                               $item["gravity"] = GRAVITY_ACTIVITY;
                                // only one like or dislike per person
                                // splitted into two queries for performance issues
                                $condition = ['uid' => $item["uid"], 'author-id' => $item["author-id"],
index 29fb42a8089f2ddeb2d30f296f145825d84324d2..6ef529b7fef8714e37ee9014b35c1e5aa82236c9 100644 (file)
@@ -2049,7 +2049,7 @@ class Diaspora
 
                $datarray["type"] = "activity";
                $datarray["verb"] = $verb;
-               $datarray["gravity"] = GRAVITY_LIKE;
+               $datarray["gravity"] = GRAVITY_ACTIVITY;
                $datarray["parent-uri"] = $parent_item["uri"];
 
                $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
index 2c826221e7ad69b8922984ec2baee2f28f7f5417..9aef0840c0fc24630f2f5a85dd91dc993dc049a9 100644 (file)
@@ -451,7 +451,7 @@ class OStatus
 
                                $item["verb"] = ACTIVITY_LIKE;
                                $item["parent-uri"] = $orig_uri;
-                               $item["gravity"] = GRAVITY_LIKE;
+                               $item["gravity"] = GRAVITY_ACTIVITY;
                        }
 
                        // http://activitystrea.ms/schema/1.0/rsvp-yes