Browse Source

allow reply to namespace owned only

main
ghost 9 months ago
parent
commit
de316ba34f
  1. 60
      src/controller/room.php
  2. 4
      src/view/posts.gemini

60
src/controller/room.php

@ -265,13 +265,20 @@ class Room
$raw[] = $record; $raw[] = $record;
} }
// Get node namespaces
$namespaces = [];
foreach ((array) $this->_kevacoin->kevaListNamespaces() as $_namespace)
{
$namespaces[$_namespace['namespaceId']] = $_namespace['displayName'];
}
// Get posts // Get posts
$posts = []; $posts = [];
// Process // Process
foreach ($raw as $data) 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; $posts[$time] = $post;
} }
@ -298,16 +305,17 @@ class Room
// home // home
$this->_link( $this->_link(
'/' '=> / Home'
), ),
// post // post
isset($namespaces[$namespace]) ?
$this->_link( // @TODO $this->_link( // @TODO
sprintf( sprintf(
'/room/%s/{session}/post', '=> /room/%s/{session}/post Post',
$namespace $namespace
) )
), ) : null,
// subject // subject
$this->_namespace( $this->_namespace(
@ -343,6 +351,18 @@ class Room
return null; 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 // Prepare message
$message = trim( $message = trim(
urldecode( urldecode(
@ -499,7 +519,8 @@ class Room
array $data, array $data,
array $raw = [], array $raw = [],
?string $field = null, ?string $field = null,
?int &$time = 0 ?int &$time = 0,
bool $reply = false
): ?string ): ?string
{ {
// Validate required data // Validate required data
@ -642,15 +663,18 @@ class Room
} }
// Reply link // Reply link
$links[] = $this->_link( if ($reply)
sprintf( {
'/room/%s/%s/{session}/reply', $links[] = $this->_link(
$namespace, sprintf(
$data['txid'] '/room/%s/%s/{session}/reply',
), $namespace,
_('Reply'), $data['txid']
true ),
); _('Reply'),
true
);
}
// Build final view and save to result // Build final view and save to result
$result = preg_replace( $result = preg_replace(
@ -965,20 +989,20 @@ class Room
} }
// Find local name // 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( $this->_memory->set(
[ [
__METHOD__, __METHOD__,
$namespace $namespace
], ],
$record['displayName'], $_namespace['displayName'],
$cache + time() $cache + time()
); );
return $record['displayName']; return $_namespace['displayName'];
} }
} }

4
src/view/posts.gemini

@ -4,8 +4,8 @@
## Navigation ## Navigation
=> {home} Home {home}
=> {post} Post {post}
## Posts ## Posts

Loading…
Cancel
Save