Use gravity instead of verb

This commit is contained in:
Michael 2018-06-27 18:09:33 +00:00
parent 8c2f91573a
commit 76dab3b2d7
14 changed files with 59 additions and 56 deletions

View file

@ -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);
/* @}*/
/**

View 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);

View 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;

View 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.

View 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

View 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];

View 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)) {

View 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'];

View 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'];

View 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);

View 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;
$item['gravity'] = GRAVITY_PARENT;
} elseif (activity_match($item['verb'], ACTIVITY_POST)) {
$item['gravity'] = 6;
$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'],

View 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"],

View 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;

View 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