Browse Source

sort messages by timestamp desc

main
ghost 9 months ago
parent
commit
55ffa4634a
  1. 12
      src/controller/room.php

12
src/controller/room.php

@ -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(
[ [

Loading…
Cancel
Save