From 55ffa4634a3f4d418d4e4dfbc4e9c5e0bf080295 Mon Sep 17 00:00:00 2001 From: ghost Date: Thu, 25 Jan 2024 22:56:18 +0200 Subject: [PATCH] sort messages by timestamp desc --- src/controller/room.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/controller/room.php b/src/controller/room.php index a95b4de..56db23f 100644 --- a/src/controller/room.php +++ b/src/controller/room.php @@ -147,12 +147,15 @@ class Room foreach ($records as $record) { - if ($post = $this->post($namespace, $record['key'], $records)) + if ($post = $this->post($namespace, $record['key'], $records, null, $time)) { - $posts[] = $post; + $posts[$time] = $post; } } + // Sort posts by time + krsort($posts); + // Get subject $subject = null; @@ -187,7 +190,7 @@ class Room ); } - public function post(string $namespace, string $key, array $posts = [], ?string $field = null): ?string + public function post(string $namespace, string $key, array $posts = [], ?string $field = null, ?int &$time = 0): ?string { // Check record exists if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) @@ -271,6 +274,9 @@ class Room } } + // Return timestamp + $time = $matches[1]; + // Build final view and send to response return str_replace( [