Standards and unify variables

This commit is contained in:
Michael 2023-09-09 13:02:20 +00:00
parent 52db2b3da1
commit d1c00cf1f6
4 changed files with 42 additions and 42 deletions

View file

@ -159,6 +159,6 @@ class Channel extends Timeline
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.')); throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
} }
$this->max_id = $request['last_created'] ?? $this->max_id; $this->maxId = $request['last_created'] ?? $this->maxId;
} }
} }

View file

@ -196,6 +196,6 @@ class Community extends Timeline
} }
} }
$this->max_id = $request['last_commented'] ?? $this->max_id; $this->maxId = $request['last_commented'] ?? $this->maxId;
} }
} }

View file

@ -369,17 +369,17 @@ class Network extends Timeline
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
$this->max_id = $request['last_received'] ?? $this->max_id; $this->maxId = $request['last_received'] ?? $this->maxId;
break; break;
case 'created': case 'created':
$this->max_id = $request['last_created'] ?? $this->max_id; $this->maxId = $request['last_created'] ?? $this->maxId;
break; break;
case 'uriid': case 'uriid':
$this->max_id = $request['last_uriid'] ?? $this->max_id; $this->maxId = $request['last_uriid'] ?? $this->maxId;
break; break;
default: default:
self::$order = 'commented'; self::$order = 'commented';
$this->max_id = $request['last_commented'] ?? $this->max_id; $this->maxId = $request['last_commented'] ?? $this->maxId;
} }
} }
@ -421,42 +421,42 @@ class Network extends Timeline
if (!empty($this->itemUriId)) { if (!empty($this->itemUriId)) {
$conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => $this->itemUriId]); $conditionStrings = DBA::mergeConditions($conditionStrings, ['uri-id' => $this->itemUriId]);
} else { } else {
if (isset($this->max_id)) { if (isset($this->maxId)) {
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $this->max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $this->maxId]);
break; break;
case 'commented': case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $this->max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $this->maxId]);
break; break;
case 'created': case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $this->max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $this->maxId]);
break; break;
case 'uriid': case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $this->max_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $this->maxId]);
break; break;
} }
} }
if (isset($this->min_id)) { if (isset($this->minId)) {
switch (self::$order) { switch (self::$order) {
case 'received': case 'received':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", $this->min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` > ?", $this->minId]);
break; break;
case 'commented': case 'commented':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", $this->min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` > ?", $this->minId]);
break; break;
case 'created': case 'created':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", $this->min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` > ?", $this->minId]);
break; break;
case 'uriid': case 'uriid':
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", $this->min_id]); $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` > ?", $this->minId]);
break; break;
} }
} }
} }
if (isset($this->min_id) && !isset($this->max_id)) { if (isset($this->minId) && !isset($this->maxId)) {
// min_id quirk: querying in reverse order with min_id gets the most recent rows, regardless of how close // min_id quirk: querying in reverse order with min_id gets the most recent rows, regardless of how close
// they are to min_id. We change the query ordering to get the expected data, and we need to reverse the // they are to min_id. We change the query ordering to get the expected data, and we need to reverse the
// order of the results. // order of the results.
@ -468,7 +468,7 @@ class Network extends Timeline
$items = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params); $items = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
// min_id quirk, continued // min_id quirk, continued
if (isset($this->min_id) && !isset($this->max_id)) { if (isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items); $items = array_reverse($items);
} }

View file

@ -49,9 +49,9 @@ class Timeline extends BaseModule
/** @var string */ /** @var string */
protected $selectedTab; protected $selectedTab;
/** @var mixed */ /** @var mixed */
protected $min_id; protected $minId;
/** @var mixed */ /** @var mixed */
protected $max_id; protected $maxId;
/** @var string */ /** @var string */
protected $accountTypeString; protected $accountTypeString;
/** @var int */ /** @var int */
@ -119,14 +119,14 @@ class Timeline extends BaseModule
} }
if (!empty($request['item'])) { if (!empty($request['item'])) {
$item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]); $item = Post::selectFirst(['parent', 'parent-uri-id'], ['id' => $request['item']]);
$this->itemUriId = $item['parent-uri-id'] ?? 0; $this->itemUriId = $item['parent-uri-id'] ?? 0;
} else { } else {
$this->itemUriId = 0; $this->itemUriId = 0;
} }
$this->min_id = $request['min_id'] ?? null; $this->minId = $request['min_id'] ?? null;
$this->max_id = $request['max_id'] ?? null; $this->maxId = $request['max_id'] ?? null;
$this->noSharer = !empty($request['no_sharer']); $this->noSharer = !empty($request['no_sharer']);
} }
@ -139,11 +139,11 @@ class Timeline extends BaseModule
} }
$query_parameters = []; $query_parameters = [];
if (!empty($this->min_id)) { if (!empty($this->minId)) {
$query_parameters['min_id'] = $this->min_id; $query_parameters['min_id'] = $this->minId;
} }
if (!empty($this->max_id)) { if (!empty($this->maxId)) {
$query_parameters['max_id'] = $this->max_id; $query_parameters['max_id'] = $this->maxId;
} }
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : ''); $path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
@ -243,15 +243,15 @@ class Timeline extends BaseModule
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]); $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)", $this->session->getLocalUserId()]);
} }
if (isset($this->max_id)) { if (isset($this->maxId)) {
$condition = DBA::mergeConditions($condition, ["`created` < ?", $this->max_id]); $condition = DBA::mergeConditions($condition, ["`created` < ?", $this->maxId]);
} }
if (isset($this->min_id)) { if (isset($this->minId)) {
$condition = DBA::mergeConditions($condition, ["`created` > ?", $this->min_id]); $condition = DBA::mergeConditions($condition, ["`created` > ?", $this->minId]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset($this->max_id)) { if (!isset($this->maxId)) {
$params['order']['created'] = false; $params['order']['created'] = false;
} }
} }
@ -263,7 +263,7 @@ class Timeline extends BaseModule
} }
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty($this->itemUriId) && isset($this->min_id) && !isset($this->max_id)) { if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items); $items = array_reverse($items);
} }
@ -393,11 +393,11 @@ class Timeline extends BaseModule
// If we're looking at a "previous page", the lookup continues forward in time because the list is // If we're looking at a "previous page", the lookup continues forward in time because the list is
// sorted in chronologically decreasing order // sorted in chronologically decreasing order
if (isset($this->min_id)) { if (isset($this->minId)) {
$this->min_id = $items[0]['commented']; $this->minId = $items[0]['commented'];
} else { } else {
// In any other case, the lookup continues backwards in time // In any other case, the lookup continues backwards in time
$this->max_id = $items[count($items) - 1]['commented']; $this->maxId = $items[count($items) - 1]['commented'];
} }
$items = $this->selectItems(); $items = $this->selectItems();
@ -443,15 +443,15 @@ class Timeline extends BaseModule
$condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]); $condition = DBA::mergeConditions($condition, ["NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-thread-user-view`.`uri-id`)", $this->session->getLocalUserId()]);
} }
if (isset($this->max_id)) { if (isset($this->maxId)) {
$condition = DBA::mergeConditions($condition, ["`commented` < ?", $this->max_id]); $condition = DBA::mergeConditions($condition, ["`commented` < ?", $this->maxId]);
} }
if (isset($this->min_id)) { if (isset($this->minId)) {
$condition = DBA::mergeConditions($condition, ["`commented` > ?", $this->min_id]); $condition = DBA::mergeConditions($condition, ["`commented` > ?", $this->minId]);
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order // Previous page case: we want the items closest to min_id but for that we need to reverse the query order
if (!isset($this->max_id)) { if (!isset($this->maxId)) {
$params['order']['commented'] = false; $params['order']['commented'] = false;
} }
} }
@ -465,7 +465,7 @@ class Timeline extends BaseModule
} }
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order // Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
if (empty($this->itemUriId) && isset($this->min_id) && !isset($this->max_id)) { if (empty($this->itemUriId) && isset($this->minId) && !isset($this->maxId)) {
$items = array_reverse($items); $items = array_reverse($items);
} }