mirror of
https://github.com/friendica/friendica
synced 2025-04-27 08:30:10 +00:00
Display featured posts for contacts
This commit is contained in:
parent
8669f12176
commit
75bc4eccb7
21 changed files with 172 additions and 118 deletions
|
@ -38,6 +38,7 @@ use Friendica\DI;
|
|||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Network;
|
||||
|
@ -1455,11 +1456,26 @@ class Contact
|
|||
}
|
||||
|
||||
if ($thread_mode) {
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), ['uri-id', 'gravity', 'parent-uri-id', 'thr-parent-id', 'author-id'], $condition, $params));
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), ['uri-id'], $condition, $params));
|
||||
|
||||
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'commented', local_user());
|
||||
if ($pager->getStart() == 0) {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, local_user());
|
||||
$pinned = DBA::selectToArray('collection-view', ['uri-id'], ['cid' => $cdata['public']]);
|
||||
$items = array_merge($items, $pinned);
|
||||
}
|
||||
|
||||
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', local_user());
|
||||
} else {
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params));
|
||||
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
|
||||
|
||||
if ($pager->getStart() == 0) {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, local_user());
|
||||
$condition = ["`uri-id` IN (SELECT `uri-id` FROM `collection-view` WHERE `cid` = ?)", $cdata['public']];
|
||||
$pinned = Post::toArray(Post::selectForUser(local_user(), $fields, $condition, $params));
|
||||
//$items = $pinned;
|
||||
$items = array_merge($pinned, $items);
|
||||
}
|
||||
|
||||
$o .= DI::conversation()->create($items, 'contact-posts', $update);
|
||||
}
|
||||
|
@ -2252,6 +2268,10 @@ class Contact
|
|||
$new_pubkey = $ret['pubkey'] ?? '';
|
||||
|
||||
if ($uid == 0) {
|
||||
if ($ret['network'] == Protocol::ACTIVITYPUB) {
|
||||
ActivityPub\Processor::fetchFeaturedPosts($ret['url']);
|
||||
}
|
||||
|
||||
$ret['last-item'] = Probe::getLastUpdate($ret);
|
||||
Logger::info('Fetched last item', ['id' => $id, 'probed_url' => $ret['url'], 'last-item' => $ret['last-item'], 'callstack' => System::callstack(20)]);
|
||||
}
|
||||
|
|
|
@ -488,39 +488,6 @@ class Post
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select pinned rows from the post-thread-user table for a given user
|
||||
*
|
||||
* @param integer $uid User ID
|
||||
* @param array $selected Array of selected fields, empty for all
|
||||
* @param array $condition Array of fields for condition
|
||||
* @param array $params Array of several parameters
|
||||
*
|
||||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectPinned(int $uid, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
$postthreaduser = DBA::select('post-thread-user', ['uri-id'], ['uid' => $uid, 'pinned' => true]);
|
||||
if (!DBA::isResult($postthreaduser)) {
|
||||
return $postthreaduser;
|
||||
}
|
||||
|
||||
$pinned = [];
|
||||
while ($useritem = DBA::fetch($postthreaduser)) {
|
||||
$pinned[] = $useritem['uri-id'];
|
||||
}
|
||||
DBA::close($postthreaduser);
|
||||
|
||||
if (empty($pinned)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions(['uri-id' => $pinned, 'uid' => $uid, 'gravity' => GRAVITY_PARENT], $condition);
|
||||
|
||||
return self::selectForUser($uid, $selected, $condition, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update existing post entries
|
||||
*
|
||||
|
|
|
@ -123,31 +123,4 @@ class ThreadUser
|
|||
{
|
||||
DBA::update('post-thread-user', ['ignored' => $ignored], ['uri-id' => $uri_id, 'uid' => $uid], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uri_id
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getPinned(int $uri_id, int $uid)
|
||||
{
|
||||
$threaduser = DBA::selectFirst('post-thread-user', ['pinned'], ['uri-id' => $uri_id, 'uid' => $uid]);
|
||||
if (empty($threaduser)) {
|
||||
return false;
|
||||
}
|
||||
return (bool)$threaduser['pinned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uri_id
|
||||
* @param int $uid
|
||||
* @param int $pinned
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function setPinned(int $uri_id, int $uid, int $pinned)
|
||||
{
|
||||
DBA::update('post-thread-user', ['pinned' => $pinned], ['uri-id' => $uri_id, 'uid' => $uid], true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue