1
1
Fork 0

More item calls have been replaced with the new functions

This commit is contained in:
Michael 2018-06-15 22:30:49 +00:00
parent 41d1f0173a
commit bb79b8f4ac
6 changed files with 54 additions and 132 deletions

View file

@ -391,98 +391,6 @@ function visible_activity($item) {
return true;
}
/**
* @brief SQL query for items
*
* @param int $uid user id
*/
function item_query($uid = 0) {
return "SELECT " . item_fieldlists() . " FROM `item` " .
item_joins($uid) . " WHERE " . item_condition();
}
/**
* @brief List of all data fields that are needed for displaying items
*/
function item_fieldlists() {
/*
These Fields are not added below (yet). They are here to for bug search.
`item`.`type`,
`item`.`extid`,
`item`.`changed`,
`item`.`moderated`,
`item`.`target-type`,
`item`.`target`,
`item`.`resource-id`,
`item`.`tag`,
`item`.`inform`,
`item`.`pubmail`,
`item`.`visible`,
`item`.`bookmark`,
`item`.`unseen`,
`item`.`deleted`,
`item`.`forum_mode`,
`item`.`mention`,
`item`.`global`,
`item`.`shadow`,
`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
*/
return "`item`.`author-id`,
`item`.`owner-id`,
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`,
`item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
`item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
`item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, `item`.`origin`,
`item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
`item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
`item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`author`.`url` AS `author-link`, `author`.`name` AS `author-name`, `author`.`thumb` AS `author-avatar`,
`owner`.`url` AS `owner-link`, `owner`.`name` AS `owner-name`, `owner`.`thumb` AS `owner-avatar`,
`contact`.`url` AS `contact-link`, `contact`.`name` AS `contact-name`, `contact`.`thumb` AS `contact-avatar`,
`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
`event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
`event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
`event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
`event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
`event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
`event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
}
/**
* @brief SQL join for contacts that are needed for displaying items
*
* @param int $uid user id
*/
function item_joins($uid = 0) {
return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND NOT `contact`.`blocked`
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0)
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
LEFT JOIN `event` ON `event-id` = `event`.`id`",
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid)
);
}
/**
* @brief SQL condition for items that are needed for displaying items
*/
function item_condition() {
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
}
/**
* "Render" a conversation or list of items for HTML display.
* There are two major forms of display:
@ -931,8 +839,6 @@ function item_photo_menu($item) {
$status_link = $profile_link . '?url=status';
$photos_link = $profile_link . '?url=photos';
$profile_link = $profile_link . '?url=profile';
} else {
$profile_link = Contact::magicLink($profile_link);
}
if ($cid && !$item['self']) {

View file

@ -738,14 +738,18 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
// Only act if it is a "real" post
// 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`
`parent-uri`, `uri`, `contact-id`, `network`
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
NOT (`author-link` IN ($profile_list)) LIMIT 1",
intval($itemid), dbesc(ACTIVITY_POST));
if (!$item)
return false;
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
if ($item[0]['network'] != NETWORK_FEED) {
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
} else {
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['contact-id']]);
}
// Generate the notification array
$params = [];

View file

@ -435,28 +435,33 @@ function networkFlatView(App $a, $update = 0)
}
}
if (strlen($file)) {
$sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
} else {
$sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
}
$pager_sql = networkPager($a, $update);
// show all items unthreaded in reverse created date order
$items = q("SELECT %s FROM `item` $sql_post_table %s
WHERE %s AND `item`.`uid` = %d
ORDER BY `item`.`id` DESC $pager_sql ",
item_fieldlists(), item_joins(local_user()), item_condition(),
intval(local_user())
);
if (strlen($file)) {
$condition = ["`term` = ? AND `otype` = ? AND `type` = ? AND `uid` = ?",
$file, TERM_OBJ_POST, TERM_FILE, local_user()];
$params = ['order' => ['tid' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$result = dba::select('term', ['oid'], $condition);
$posts = [];
while ($term = dba::fetch($result)) {
$posts[] = $term['oid'];
}
dba::close($terms);
$condition = ['uid' => local_user(), 'id' => $posts];
} else {
$condition = ['uid' => local_user()];
}
$params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$result = Item::select(local_user(), [], $condition, $params);
$items = dba::inArray($result);
$condition = ['unseen' => true, 'uid' => local_user()];
networkSetSeen($condition);
$mode = 'network-new';
$o .= networkConversation($a, $items, $mode, $update);
$o .= networkConversation($a, $items, 'network-new', $update);
return $o;
}

View file

@ -15,6 +15,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Temporal;
use Friendica\Util\XML;
@ -127,20 +128,14 @@ function ping_init(App $a)
$notifs = ping_get_notifications(local_user());
$items_unseen = q(
"SELECT `item`.`id`, `item`.`parent`, `item`.`verb`, `item`.`wall`, `item`.`author-name`,
`item`.`contact-id`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id` = `item`.`parent`
WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `pitem`.`parent` != 0
AND `item`.`contact-id` != %d
ORDER BY `item`.`created` DESC",
intval(local_user()),
intval(local_user())
);
$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true]];
$items = Item::select(local_user(), $fields, $condition, $params);
if (DBM::is_result($items_unseen)) {
if (DBM::is_result($items)) {
$items_unseen = dba::inArray($items);
$arr = ['items' => $items_unseen];
Addon::callHooks('network_ping', $arr);

View file

@ -238,6 +238,11 @@ class NotificationsManager extends BaseObject
$it['seen'] = ($it['unseen'] > 0 ? false : true);
}
// For feed items we use the user's contact, since the avatar is mostly self choosen.
if (!empty($it['network']) && $it['network'] == NETWORK_FEED) {
$it['author-avatar'] = $it['contact-avatar'];
}
// Depending on the identifier of the notification we need to use different defaults
switch ($ident) {
case 'system':
@ -399,8 +404,8 @@ class NotificationsManager extends BaseObject
$condition['unseen'] = true;
}
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);
@ -484,8 +489,8 @@ class NotificationsManager extends BaseObject
$condition[0] .= " AND `unseen`";
}
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);
@ -524,8 +529,8 @@ class NotificationsManager extends BaseObject
$condition['unseen'] = true;
}
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'created',
'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);

View file

@ -85,7 +85,7 @@ class Item extends BaseObject
$table = "`item` " . self::constructJoins($uid, $select_fields . $condition_string . $param_string, false);
$sql = "SELECT " . $select_fields . " FROM " . $table . $condition_string . $param_string;
//echo $sql;
return dba::p($sql, $condition);
}
@ -160,6 +160,13 @@ class Item extends BaseObject
*/
private static function fieldlist($selected)
{
/*
These Fields are not added below. They are here to for bug search.
'type', 'extid', 'changed', 'moderated', 'target-type', 'target', 'resource-id',
'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
'forum_mode', 'mention', 'global', 'shadow',
*/
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
'uri', 'thr-parent', 'parent-uri', 'content-warning',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',