- owner: a user object, it's the owner of the item.
- private: boolean, true if the item is marked as private
- activities: map with activities related to the item. Every activity is a list of user objects.
+- comments: comment numbers
This properties are prefixed with "friendica_" in JSON responses and namespaced under "http://friendi.ca/schema/api/1/" in XML responses
'attendyes': [],
'attendno': [],
'attendmaybe': []
- }
+ },
+ 'friendica_comments': 12
},
// ...
]
<friendica:attendno/>
<friendica:attendmaybe/>
</friendica:activities>
+ <friendica:comments>21</friendica:comments>
</status>
<!-- ... -->
</statuses>
* count: alias for the rpp parameter
* since_id: returns statuses with ids greater than the given id
* max_id: returns statuses with ids lower or equal to the given id
+* exclude_replies: don't show replies (default: false)
#### Unsupported parameters
$data = [];
$count = 15;
+ $exclude_replies = !empty($_REQUEST['exclude_replies']);
if (!empty($_REQUEST['rpp'])) {
$count = $_REQUEST['rpp'];
} elseif (!empty($_REQUEST['count'])) {
$itemIds = [];
while($term = DBA::fetch($terms)){ $itemIds[] = $term['oid']; }
DBA::close($terms);
- $condition = ['id' => empty($itemIds) ? [0] : $itemIds ];
+ $condition = [$exclude_replies ? "`id` = `parent` AND " : ''];
+ $condition[0] .= empty($itemIds) ? '' : ' `id` IN ('.implode(", ", $itemIds).')' ;
+
} else {
$condition = ["`id` > ?
+ ". ($exclude_replies ? " AND `id` = `parent` " : ' ')."
AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `body` LIKE CONCAT('%',?,'%')",
$since_id, api_user(), $_REQUEST['q']];
$data['status'] = api_format_items(Item::inArray($statuses), $user_info);
+ bindComments($data['status']);
+
return api_format_data("statuses", $type, $data);
}
Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]);
}
}
+
+ bindComments($ret);
$data = ['status' => $ret];
switch ($type) {
return api_format_data("statuses", $type, $data);
}
+
/// @TODO move to top of file or somewhere better
api_register_func('api/statuses/home_timeline', 'api_statuses_home_timeline', true);
api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline', true);
$ret = api_format_items($r, $user_info, false, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, true, $type);
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
$ret = api_format_items(Item::inArray($statuses), $user_info, false, $type);
}
+ bindComments($ret);
+
$data = ['status' => $ret];
switch ($type) {
case "atom":
/// @TODO move to top of file or somewhere better
api_register_func('api/saved_searches/list', 'api_saved_searches_list', true);
+/*
+ * Bind comment numbers(friendica_comments: Int) on each statuses page of *_timeline / favorites / search
+ *
+ * @brief Number of comments
+ *
+ * @param object $data [Status, Status]
+ *
+ * @return void
+ */
+function bindComments(&$data){
+ if(count($data) == 0) return;
+
+ $ids = [];
+ $comments = [];
+ foreach($data as $item){ $ids[] = $item['id']; }
+
+ $sql = "SELECT `parent`,COUNT(*) as comments FROM `item`
+ WHERE `parent` IN ( %s ) AND `deleted` = %d AND `gravity`= %d GROUP BY `parent`";
+ $result = q($sql, implode(",", $ids), 0, GRAVITY_COMMENT);
+
+ foreach($result as $records) {
+ $comments[$records['parent']] = $records['comments'];
+ }
+
+ foreach($data as $idx => $item){
+ $id = $item['id'];
+ $data[$idx]['friendica_comments'] = isset($comments[$id]) ? $comments[$id] : 0;
+ }
+}
+
/*
@TODO Maybe open to implement?
To.Do: