From de316ba34f318bedc83bb833b94ad84a962e6d18 Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 25 Feb 2024 11:40:12 +0200 Subject: [PATCH] allow reply to namespace owned only --- src/controller/room.php | 60 ++++++++++++++++++++++++++++------------- src/view/posts.gemini | 4 +-- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/controller/room.php b/src/controller/room.php index abdd69e..54b5344 100644 --- a/src/controller/room.php +++ b/src/controller/room.php @@ -265,13 +265,20 @@ class Room $raw[] = $record; } + // Get node namespaces + $namespaces = []; + foreach ((array) $this->_kevacoin->kevaListNamespaces() as $_namespace) + { + $namespaces[$_namespace['namespaceId']] = $_namespace['displayName']; + } + // Get posts $posts = []; // Process foreach ($raw as $data) { - if ($post = $this->_post($namespace, $data, $raw, null, $time)) + if ($post = $this->_post($namespace, $data, $raw, null, $time, isset($namespaces[$namespace]))) { $posts[$time] = $post; } @@ -298,16 +305,17 @@ class Room // home $this->_link( - '/' + '=> / Home' ), // post + isset($namespaces[$namespace]) ? $this->_link( // @TODO sprintf( - '/room/%s/{session}/post', + '=> /room/%s/{session}/post Post', $namespace ) - ), + ) : null, // subject $this->_namespace( @@ -343,6 +351,18 @@ class Room return null; } + // Validate room + $namespaces = []; + foreach ((array) $this->_kevacoin->kevaListNamespaces() as $_namespace) + { + $namespaces[$_namespace['namespaceId']] = $_namespace['displayName']; + } + + if (!isset($namespaces[$namespace])) + { + return null; + } + // Prepare message $message = trim( urldecode( @@ -499,7 +519,8 @@ class Room array $data, array $raw = [], ?string $field = null, - ?int &$time = 0 + ?int &$time = 0, + bool $reply = false ): ?string { // Validate required data @@ -642,15 +663,18 @@ class Room } // Reply link - $links[] = $this->_link( - sprintf( - '/room/%s/%s/{session}/reply', - $namespace, - $data['txid'] - ), - _('Reply'), - true - ); + if ($reply) + { + $links[] = $this->_link( + sprintf( + '/room/%s/%s/{session}/reply', + $namespace, + $data['txid'] + ), + _('Reply'), + true + ); + } // Build final view and save to result $result = preg_replace( @@ -965,20 +989,20 @@ class Room } // Find local name - foreach ((array) $this->_kevacoin->kevaListNamespaces() as $record) + foreach ((array) $this->_kevacoin->kevaListNamespaces() as $_namespace) { - if ($record['namespaceId'] == $namespace) + if ($_namespace['namespaceId'] == $namespace) { $this->_memory->set( [ __METHOD__, $namespace ], - $record['displayName'], + $_namespace['displayName'], $cache + time() ); - return $record['displayName']; + return $_namespace['displayName']; } } diff --git a/src/view/posts.gemini b/src/view/posts.gemini index bf84fb6..59b14d6 100644 --- a/src/view/posts.gemini +++ b/src/view/posts.gemini @@ -4,8 +4,8 @@ ## Navigation -=> {home} Home -=> {post} Post +{home} +{post} ## Posts