From 76dab3b2d7b8fb2609d54ab55c8b3114d8da661f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Jun 2018 18:09:33 +0000 Subject: [PATCH] Use gravity instead of verb --- boot.php | 3 ++- include/api.php | 55 ++++++++++++++++++++------------------- include/enotify.php | 4 +-- mod/item.php | 2 +- mod/network.php | 2 +- mod/photos.php | 1 + mod/profile.php | 13 ++++----- mod/subthread.php | 2 +- mod/tagger.php | 2 +- src/Model/Contact.php | 4 +-- src/Model/Item.php | 21 ++++++++------- src/Protocol/DFRN.php | 2 +- src/Protocol/Diaspora.php | 2 +- src/Protocol/OStatus.php | 2 +- 14 files changed, 59 insertions(+), 56 deletions(-) diff --git a/boot.php b/boot.php index ac21d108a3..64abdddca3 100644 --- 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); /* @}*/ /** diff --git a/include/api.php b/include/api.php index 819d2c75a0..2eaabd8242 100644 --- a/include/api.php +++ b/include/api.php @@ -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); diff --git a/include/enotify.php b/include/enotify.php index 00459ac5c0..be9468dd8f 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -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; diff --git a/mod/item.php b/mod/item.php index 2830cae2c9..0a3c3e2fa4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -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. diff --git a/mod/network.php b/mod/network.php index 61e4e779ed..442ae669ba 100644 --- a/mod/network.php +++ b/mod/network.php @@ -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 diff --git a/mod/photos.php b/mod/photos.php index f54bc62444..c0e1c7477a 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -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]; diff --git a/mod/profile.php b/mod/profile.php index a6075b01cf..8d156cbd64 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -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)) { diff --git a/mod/subthread.php b/mod/subthread.php index 0b6f4ecaaa..e05aa5fec8 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -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']; diff --git a/mod/tagger.php b/mod/tagger.php index 717c094776..a5e9b3715b 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -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']; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 973e5b5a21..fe9869c6f8 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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); diff --git a/src/Model/Item.php b/src/Model/Item.php index 6fe4a575dd..fe6dc5d1d4 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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'], diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 1047ffdfe2..0b8cb73827 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -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"], diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 29fb42a808..6ef529b7fe 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 2c826221e7..9aef0840c0 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -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