mirror of
https://github.com/friendica/friendica
synced 2025-04-25 02:30:11 +00:00
Use centralized function to set items seen
This commit is contained in:
parent
ab235e24ad
commit
f9740e180e
2 changed files with 35 additions and 30 deletions
|
@ -65,7 +65,7 @@ class Timeline extends BaseModule
|
|||
|
||||
/** @var App\Mode $mode */
|
||||
protected $mode;
|
||||
/** @var UserSession */
|
||||
/** @var IHandleUserSessions */
|
||||
protected $session;
|
||||
/** @var Database */
|
||||
protected $database;
|
||||
|
@ -267,7 +267,8 @@ class Timeline extends BaseModule
|
|||
$items = array_reverse($items);
|
||||
}
|
||||
|
||||
Item::update(['unseen' => false], ['unseen' => true, 'uid' => $uid, 'uri-id' => array_column($items, 'uri-id')]);
|
||||
$condition = ['unseen' => true, 'uid' => $uid, 'parent-uri-id' => array_column($items, 'uri-id')];
|
||||
$this->setItemsSeenByCondition($condition);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
@ -406,6 +407,9 @@ class Timeline extends BaseModule
|
|||
$selected_items = $items;
|
||||
}
|
||||
|
||||
$condition = ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'parent-uri-id' => array_column($selected_items, 'uri-id')];
|
||||
$this->setItemsSeenByCondition($condition);
|
||||
|
||||
return $selected_items;
|
||||
}
|
||||
|
||||
|
@ -471,4 +475,24 @@ class Timeline extends BaseModule
|
|||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets items as seen
|
||||
*
|
||||
* @param array $condition The array with the SQL condition
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function setItemsSeenByCondition(array $condition)
|
||||
{
|
||||
if (empty($condition)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$unseen = Post::exists($condition);
|
||||
|
||||
if ($unseen) {
|
||||
/// @todo handle huge "unseen" updates in the background to avoid timeout errors
|
||||
Item::update(['unseen' => false], $condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue