sort messages by timestamp desc

This commit is contained in:
ghost 2024-01-25 22:56:18 +02:00
parent d09f940f4b
commit 55ffa4634a

View File

@ -147,12 +147,15 @@ class Room
foreach ($records as $record) 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 // Get subject
$subject = null; $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 // Check record exists
if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) 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 // Build final view and send to response
return str_replace( return str_replace(
[ [