Browse Source

Use "received" instead of "created" when displaying posts in creation order

pull/7348/head
Michael 1 week ago
parent
commit
6bb418c5a7

+ 8
- 8
config/dbstructure.config.php View File

@@ -34,7 +34,7 @@
34 34
 use Friendica\Database\DBA;
35 35
 
36 36
 if (!defined('DB_UPDATE_VERSION')) {
37
-	define('DB_UPDATE_VERSION', 1316);
37
+	define('DB_UPDATE_VERSION', 1317);
38 38
 }
39 39
 
40 40
 return [
@@ -672,15 +672,15 @@ return [
672 672
 			"extid" => ["extid(191)"],
673 673
 			"uid_id" => ["uid", "id"],
674 674
 			"uid_contactid_id" => ["uid", "contact-id", "id"],
675
-			"uid_created" => ["uid", "created"],
675
+			"uid_received" => ["uid", "received"],
676 676
 			"uid_commented" => ["uid", "commented"],
677 677
 			"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
678 678
 			"uid_network_received" => ["uid", "network", "received"],
679 679
 			"uid_network_commented" => ["uid", "network", "commented"],
680 680
 			"uid_thrparent" => ["uid", "thr-parent(190)"],
681 681
 			"uid_parenturi" => ["uid", "parent-uri(190)"],
682
-			"uid_contactid_created" => ["uid", "contact-id", "created"],
683
-			"authorid_created" => ["author-id", "created"],
682
+			"uid_contactid_received" => ["uid", "contact-id", "received"],
683
+			"authorid_received" => ["author-id", "received"],
684 684
 			"ownerid" => ["owner-id"],
685 685
 			"contact-id" => ["contact-id"],
686 686
 			"uid_uri" => ["uid", "uri(190)"],
@@ -1256,15 +1256,15 @@ return [
1256 1256
 		"indexes" => [
1257 1257
 			"PRIMARY" => ["iid"],
1258 1258
 			"uid_network_commented" => ["uid", "network", "commented"],
1259
-			"uid_network_created" => ["uid", "network", "created"],
1259
+			"uid_network_received" => ["uid", "network", "received"],
1260 1260
 			"uid_contactid_commented" => ["uid", "contact-id", "commented"],
1261
-			"uid_contactid_created" => ["uid", "contact-id", "created"],
1261
+			"uid_contactid_received" => ["uid", "contact-id", "received"],
1262 1262
 			"contactid" => ["contact-id"],
1263 1263
 			"ownerid" => ["owner-id"],
1264 1264
 			"authorid" => ["author-id"],
1265
-			"uid_created" => ["uid", "created"],
1265
+			"uid_received" => ["uid", "received"],
1266 1266
 			"uid_commented" => ["uid", "commented"],
1267
-			"uid_wall_created" => ["uid", "wall", "created"],
1267
+			"uid_wall_received" => ["uid", "wall", "received"],
1268 1268
 			"private_wall_origin_commented" => ["private", "wall", "origin", "commented"],
1269 1269
 		]
1270 1270
 	],

+ 4
- 4
include/api.php View File

@@ -1107,7 +1107,7 @@ function api_statuses_update($type)
1107 1107
 		if ($throttle_day > 0) {
1108 1108
 			$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
1109 1109
 
1110
-			$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
1110
+			$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
1111 1111
 			$posts_day = DBA::count('thread', $condition);
1112 1112
 
1113 1113
 			if ($posts_day > $throttle_day) {
@@ -1121,7 +1121,7 @@ function api_statuses_update($type)
1121 1121
 		if ($throttle_week > 0) {
1122 1122
 			$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
1123 1123
 
1124
-			$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
1124
+			$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
1125 1125
 			$posts_week = DBA::count('thread', $condition);
1126 1126
 
1127 1127
 			if ($posts_week > $throttle_week) {
@@ -1135,7 +1135,7 @@ function api_statuses_update($type)
1135 1135
 		if ($throttle_month > 0) {
1136 1136
 			$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
1137 1137
 
1138
-			$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
1138
+			$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
1139 1139
 			$posts_month = DBA::count('thread', $condition);
1140 1140
 
1141 1141
 			if ($posts_month > $throttle_month) {
@@ -5057,7 +5057,7 @@ function api_get_announce($item)
5057 5057
 	$fields = ['author-id', 'author-name', 'author-link', 'author-avatar'];
5058 5058
 	$activity = Item::activityToIndex(ACTIVITY2_ANNOUNCE);
5059 5059
 	$condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'activity' => $activity];
5060
-	$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['created' => true]]);
5060
+	$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]);
5061 5061
 	if (!DBA::isResult($announce)) {
5062 5062
 		return [];
5063 5063
 	}

+ 14
- 14
include/conversation.php View File

@@ -800,12 +800,12 @@ function conversation_fetch_comments($thread_items) {
800 800
 	$parentlines = [];
801 801
 	$lineno = 0;
802 802
 	$actor = [];
803
-	$created = '';
803
+	$received = '';
804 804
 
805 805
 	while ($row = Item::fetch($thread_items)) {
806
-		if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['created'] > $created) && ($row['thr-parent'] == $row['parent-uri'])) {
806
+		if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
807 807
 			$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
808
-			$created = $row['created'];
808
+			$received = $row['received'];
809 809
 		}
810 810
 
811 811
 		if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
@@ -1316,7 +1316,7 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
1316 1316
 function sort_item_children(array $items)
1317 1317
 {
1318 1318
 	$result = $items;
1319
-	usort($result, 'sort_thr_created_rev');
1319
+	usort($result, 'sort_thr_received_rev');
1320 1320
 	foreach ($result as $k => $i) {
1321 1321
 		if (isset($result[$k]['children'])) {
1322 1322
 			$result[$k]['children'] = sort_item_children($result[$k]['children']);
@@ -1401,13 +1401,13 @@ function smart_flatten_conversation(array $parent)
1401 1401
 
1402 1402
 /**
1403 1403
  * Expands a flat list of items into corresponding tree-like conversation structures,
1404
- * sort the top-level posts either on "created" or "commented", and finally
1404
+ * sort the top-level posts either on "received" or "commented", and finally
1405 1405
  * append all the items at the top level (???)
1406 1406
  *
1407 1407
  * @brief Expands a flat item list into a conversation array for display
1408 1408
  *
1409 1409
  * @param array  $item_list A list of items belonging to one or more conversations
1410
- * @param string $order     Either on "created" or "commented"
1410
+ * @param string $order     Either on "received" or "commented"
1411 1411
  * @return array
1412 1412
  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
1413 1413
  */
@@ -1439,8 +1439,8 @@ function conv_sort(array $item_list, $order)
1439 1439
 		}
1440 1440
 	}
1441 1441
 
1442
-	if (stristr($order, 'created')) {
1443
-		usort($parents, 'sort_thr_created');
1442
+	if (stristr($order, 'received')) {
1443
+		usort($parents, 'sort_thr_received');
1444 1444
 	} elseif (stristr($order, 'commented')) {
1445 1445
 		usort($parents, 'sort_thr_commented');
1446 1446
 	}
@@ -1477,27 +1477,27 @@ function conv_sort(array $item_list, $order)
1477 1477
 }
1478 1478
 
1479 1479
 /**
1480
- * @brief usort() callback to sort item arrays by the created key
1480
+ * @brief usort() callback to sort item arrays by the received key
1481 1481
  *
1482 1482
  * @param array $a
1483 1483
  * @param array $b
1484 1484
  * @return int
1485 1485
  */
1486
-function sort_thr_created(array $a, array $b)
1486
+function sort_thr_received(array $a, array $b)
1487 1487
 {
1488
-	return strcmp($b['created'], $a['created']);
1488
+	return strcmp($b['received'], $a['received']);
1489 1489
 }
1490 1490
 
1491 1491
 /**
1492
- * @brief usort() callback to reverse sort item arrays by the created key
1492
+ * @brief usort() callback to reverse sort item arrays by the received key
1493 1493
  *
1494 1494
  * @param array $a
1495 1495
  * @param array $b
1496 1496
  * @return int
1497 1497
  */
1498
-function sort_thr_created_rev(array $a, array $b)
1498
+function sort_thr_received_rev(array $a, array $b)
1499 1499
 {
1500
-	return strcmp($a['created'], $b['created']);
1500
+	return strcmp($a['received'], $b['received']);
1501 1501
 }
1502 1502
 
1503 1503
 /**

+ 4
- 4
mod/network.php View File

@@ -704,11 +704,11 @@ function networkThreadedView(App $a, $update, $parent)
704 704
 	}
705 705
 
706 706
 	if ($datequery) {
707
-		$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created <= '%s' ",
707
+		$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
708 708
 				DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
709 709
 	}
710 710
 	if ($datequery2) {
711
-		$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created >= '%s' ",
711
+		$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
712 712
 				DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
713 713
 	}
714 714
 
@@ -718,8 +718,8 @@ function networkThreadedView(App $a, $update, $parent)
718 718
 
719 719
 	// Normal conversation view
720 720
 	if ($order === 'post') {
721
-		$ordering = '`created`';
722
-		$order_mode = 'created';
721
+		$ordering = '`received`';
722
+		$order_mode = 'received';
723 723
 	} else {
724 724
 		$ordering = '`commented`';
725 725
 		$order_mode = 'commented';

+ 1
- 1
mod/ping.php View File

@@ -123,7 +123,7 @@ function ping_init(App $a)
123 123
 		$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()];
124 124
 		$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
125 125
 			'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'wall'];
126
-		$params = ['order' => ['created' => true]];
126
+		$params = ['order' => ['received' => true]];
127 127
 		$items = Item::selectForUser(local_user(), $fields, $condition, $params);
128 128
 
129 129
 		if (DBA::isResult($items)) {

+ 1
- 1
mod/search.php View File

@@ -186,7 +186,7 @@ function search_content(App $a) {
186 186
 		$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))
187 187
 			AND `otype` = ? AND `type` = ? AND `term` = ?",
188 188
 			local_user(), TERM_OBJ_POST, TERM_HASHTAG, $search];
189
-		$params = ['order' => ['created' => true],
189
+		$params = ['order' => ['received' => true],
190 190
 			'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
191 191
 		$terms = DBA::select('term', ['oid'], $condition, $params);
192 192
 

+ 3
- 3
src/Core/NotificationsManager.php View File

@@ -394,7 +394,7 @@ class NotificationsManager extends BaseObject
394 394
 
395 395
 		$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
396 396
 			'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
397
-		$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
397
+		$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
398 398
 
399 399
 		$items = Item::selectForUser(local_user(), $fields, $condition, $params);
400 400
 
@@ -485,7 +485,7 @@ class NotificationsManager extends BaseObject
485 485
 
486 486
 		$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
487 487
 			'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
488
-		$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
488
+		$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
489 489
 
490 490
 		$items = Item::selectForUser(local_user(), $fields, $condition, $params);
491 491
 
@@ -527,7 +527,7 @@ class NotificationsManager extends BaseObject
527 527
 
528 528
 		$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
529 529
 			'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
530
-		$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
530
+		$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
531 531
 		$items = Item::selectForUser(local_user(), $fields, $condition, $params);
532 532
 
533 533
 		if (DBA::isResult($items)) {

+ 1
- 1
src/Model/Contact.php View File

@@ -1616,7 +1616,7 @@ class Contact extends BaseObject
1616 1616
 
1617 1617
 		$pager = new Pager($a->query_string);
1618 1618
 
1619
-		$params = ['order' => ['created' => true],
1619
+		$params = ['order' => ['received' => true],
1620 1620
 			'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1621 1621
 
1622 1622
 		if ($thread_mode) {

+ 7
- 15
src/Model/Item.php View File

@@ -1650,7 +1650,7 @@ class Item extends BaseObject
1650 1650
 				Logger::log('duplicated item with the same guid found. '.print_r($item,true));
1651 1651
 				return 0;
1652 1652
 			}
1653
-		} else {
1653
+		} elseif ($item['network'] == Protocol::OSTATUS) {
1654 1654
 			// Check for an existing post with the same content. There seems to be a problem with OStatus.
1655 1655
 			$condition = ["`body` = ? AND `network` = ? AND `created` = ? AND `contact-id` = ? AND `uid` = ?",
1656 1656
 					$item['body'], $item['network'], $item['created'], $item['contact-id'], $item['uid']];
@@ -2905,19 +2905,11 @@ class Item extends BaseObject
2905 2905
 		if ($network != "") {
2906 2906
 			$condition[0] .= " AND `network` = ?";
2907 2907
 			$condition[] = $network;
2908
-
2909
-			/*
2910
-			 * There is an index "uid_network_received" but not "uid_network_created"
2911
-			 * This avoids the creation of another index just for one purpose.
2912
-			 * And it doesn't really matter wether to look at "received" or "created"
2913
-			 */
2914
-			$condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
2915
-			$condition[] = $days;
2916
-		} else {
2917
-			$condition[0] .= " AND `created` < UTC_TIMESTAMP() - INTERVAL ? DAY";
2918
-			$condition[] = $days;
2919 2908
 		}
2920 2909
 
2910
+		$condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
2911
+		$condition[] = $days;
2912
+
2921 2913
 		$items = self::select(['file', 'resource-id', 'starred', 'type', 'id', 'post-type'], $condition);
2922 2914
 
2923 2915
 		if (!DBA::isResult($items)) {
@@ -2967,10 +2959,10 @@ class Item extends BaseObject
2967 2959
 	public static function firstPostDate($uid, $wall = false)
2968 2960
 	{
2969 2961
 		$condition = ['uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
2970
-		$params = ['order' => ['created' => false]];
2971
-		$thread = DBA::selectFirst('thread', ['created'], $condition, $params);
2962
+		$params = ['order' => ['received' => false]];
2963
+		$thread = DBA::selectFirst('thread', ['received'], $condition, $params);
2972 2964
 		if (DBA::isResult($thread)) {
2973
-			return substr(DateTimeFormat::local($thread['created']), 0, 10);
2965
+			return substr(DateTimeFormat::local($thread['received']), 0, 10);
2974 2966
 		}
2975 2967
 		return false;
2976 2968
 	}

+ 5
- 5
src/Module/Profile.php View File

@@ -252,7 +252,7 @@ class Profile extends BaseModule
252 252
 					AND `item`.`wall`
253 253
 					$sql_extra4
254 254
 					$sql_extra
255
-				ORDER BY `item`.`created` DESC",
255
+				ORDER BY `item`.`received` DESC",
256 256
 				$a->profile['profile_uid'],
257 257
 				GRAVITY_ACTIVITY
258 258
 			);
@@ -276,10 +276,10 @@ class Profile extends BaseModule
276 276
 			}
277 277
 
278 278
 			if (!empty($datequery)) {
279
-				$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
279
+				$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
280 280
 			}
281 281
 			if (!empty($datequery2)) {
282
-				$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
282
+				$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
283 283
 			}
284 284
 
285 285
 			// Does the profile page belong to a forum?
@@ -326,7 +326,7 @@ class Profile extends BaseModule
326 326
 					$sql_extra3
327 327
 					$sql_extra
328 328
 					$sql_extra2
329
-				ORDER BY `thread`.`created` DESC
329
+				ORDER BY `thread`.`received` DESC
330 330
 				$pager_sql",
331 331
 				$a->profile['profile_uid']
332 332
 			);
@@ -351,7 +351,7 @@ class Profile extends BaseModule
351 351
 
352 352
 		$items = DBA::toArray($items_stmt);
353 353
 
354
-		$o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
354
+		$o .= conversation($a, $items, $pager, 'profile', $update, false, 'received', $a->profile['profile_uid']);
355 355
 
356 356
 		if (!$update) {
357 357
 			$o .= $pager->renderMinimal(count($items));

+ 1
- 1
src/Protocol/DFRN.php View File

@@ -257,7 +257,7 @@ class DFRN
257 257
 			STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
258 258
 			WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
259 259
 			AND `item`.`visible` $sql_extra
260
-			ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
260
+			ORDER BY `item`.`parent` ".$sort.", `item`.`received` ASC LIMIT 0, 300",
261 261
 			intval($owner_id),
262 262
 			DBA::escape($check_date),
263 263
 			DBA::escape($sort)

+ 2
- 2
src/Protocol/OStatus.php View File

@@ -2219,7 +2219,7 @@ class OStatus
2219 2219
 		$check_date = DateTimeFormat::utc($last_update);
2220 2220
 		$authorid = Contact::getIdForURL($owner["url"], 0, true);
2221 2221
 
2222
-		$condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
2222
+		$condition = ["`uid` = ? AND `received` > ? AND NOT `deleted`
2223 2223
 			AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
2224 2224
 			$owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN];
2225 2225
 
@@ -2234,7 +2234,7 @@ class OStatus
2234 2234
 			$condition[] = $authorid;
2235 2235
 		}
2236 2236
 
2237
-		$params = ['order' => ['created' => true], 'limit' => $max_items];
2237
+		$params = ['order' => ['received' => true], 'limit' => $max_items];
2238 2238
 
2239 2239
 		if ($filter === 'posts') {
2240 2240
 			$ret = Item::selectThread([], $condition, $params);

Loading…
Cancel
Save