From 65fbdb9729eec184b8e09dcf67503b3c4bc95308 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 28 Jan 2024 06:53:23 +0200 Subject: [PATCH] fix pending rooms display --- .env | 2 +- src/Controller/RoomController.php | 90 ++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/.env b/.env index f109fcc..6d1cfbc 100644 --- a/.env +++ b/.env @@ -19,7 +19,7 @@ APP_ENV=dev APP_SECRET=EDIT_ME ###< symfony/framework-bundle ### -APP_VERSION=1.8.1 +APP_VERSION=1.8.2 APP_NAME=KevaChat diff --git a/src/Controller/RoomController.php b/src/Controller/RoomController.php index 86b2a9d..a911a1b 100644 --- a/src/Controller/RoomController.php +++ b/src/Controller/RoomController.php @@ -65,29 +65,33 @@ class RoomController extends AbstractController continue; } - // Calculate room totals - $total = 0; - - foreach ((array) $client->kevaFilter($value['namespaceId']) as $post) - { - // Skip values with meta keys - if (str_starts_with($post['key'], '_')) - { - continue; - } - - // Require valid kevachat meta - if ($this->_post($post)) - { - $total++; - } - } - // Add to room list - $list[] = + $list[$value['namespaceId']] = // keep unique [ 'namespace' => $value['namespaceId'], - 'total' => $total, + 'total' => $this->_total( + $value['namespaceId'] + ), + 'pinned' => in_array( + $value['namespaceId'], + (array) explode( + '|', + $this->getParameter('app.kevacoin.room.namespaces.pinned') + ) + ) + ]; + } + + // Get rooms contain pending data + foreach ((array) $client->kevaPending() as $value) + { + // Add to room list + $list[$value['namespace']] = // keep unique + [ + 'namespace' => $value['namespace'], + 'total' => $this->_total( + $value['namespace'] + ), 'pinned' => in_array( $value['namespaceId'], (array) explode( @@ -918,4 +922,50 @@ class RoomController extends AbstractController return $tree; } + + private function _total(string $namespace): int + { + // Connect kevacoin + $client = new \Kevachat\Kevacoin\Client( + $this->getParameter('app.kevacoin.protocol'), + $this->getParameter('app.kevacoin.host'), + $this->getParameter('app.kevacoin.port'), + $this->getParameter('app.kevacoin.username'), + $this->getParameter('app.kevacoin.password') + ); + + $raw = []; + + // Get pending + foreach ((array) $client->kevaPending() as $pending) + { + // Ignore other namespaces + if ($pending['namespace'] != $namespace) + { + continue; + } + + $raw[] = $pending; + } + + // Get records + foreach ((array) $this->_kevacoin->kevaFilter($namespace) as $record) + { + $raw[] = $record; + } + + // Count begin + $total = 0; + + foreach ($raw as $data) + { + // Is valid post + if ($this->_post($data)) + { + $total++; + } + } + + return $total; + } } \ No newline at end of file