Browse Source

implement success sending page

main
ghost 9 months ago
parent
commit
a7f54c22f3
  1. 51
      src/controller/room.php
  2. 32
      src/server.php
  3. 13
      src/view/sent.gemini

51
src/controller/room.php

@ -207,24 +207,24 @@ class Room
); );
} }
public function post(string $namespace, ?string $txid, int $session, string $message): bool public function post(string $namespace, ?string $txid, int $session, string $message): ?string
{ {
// Validate funds available yet // Validate funds available yet
if (1 > $this->_kevacoin->getBalance()) if (1 > $this->_kevacoin->getBalance())
{ {
return false; return null;
} }
// Validate session exists // Validate session exists
if (!$this->_memory->get($session)) if (!$this->_memory->get($session))
{ {
return false; return null;
} }
// Validate value format allowed in settings // Validate value format allowed in settings
if (!preg_match((string) $this->_config->kevachat->post->value->regex, $message)) if (!preg_match((string) $this->_config->kevachat->post->value->regex, $message))
{ {
return false; return null;
} }
// Prepare message // Prepare message
@ -245,29 +245,58 @@ class Room
// Validate final message length // Validate final message length
if (mb_strlen($message) < 1 || mb_strlen($message) > 3072) if (mb_strlen($message) < 1 || mb_strlen($message) > 3072)
{ {
return false; return null;
} }
// Send message // Send message
if (!$this->_kevacoin->kevaPut( if
(
$txid = $this->_kevacoin->kevaPut(
$namespace, $namespace,
sprintf( sprintf(
'%s@anon', '%s@anon',
time() time()
), ),
$message $message
)) )
)
{ {
return false;
}
// Cleanup memory // Cleanup memory
$this->_memory->delete( $this->_memory->delete(
$session $session
); );
// Success // Success
return true; return $txid;
}
return null;
}
public function sent(string $namespace, string $txid)
{
return str_replace(
[
'{logo}',
'{txid}',
'{room}'
],
[
file_get_contents(
__DIR__ . '/../../logo.ascii'
),
$txid,
$this->_link(
sprintf(
'/room/%s',
$namespace
)
)
],
file_get_contents(
__DIR__ . '/../view/sent.gemini'
)
);
} }
private function _post(string $namespace, string $key, array $posts = [], ?string $field = null, ?int &$time = 0): ?string private function _post(string $namespace, string $key, array $posts = [], ?string $field = null, ?int &$time = 0): ?string

32
src/server.php

@ -197,17 +197,12 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
); );
// Success, redirect to this room page // Success, redirect to this room page
if ($room->post($matches[1], null, $matches[2], $request->getQuery())) if ($txid = $room->post($matches[1], null, $matches[2], $request->getQuery()))
{ {
$response->setCode( if ($result = $room->sent($matches[1], $txid))
30 {
); $response->setContent(
$result
$response->setMeta(
sprintf(
'/room/%s',
$matches[1]
)
); );
return $response; return $response;
@ -215,6 +210,7 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
} }
} }
} }
}
// New post reply request // New post reply request
else if (preg_match('/^\/room\/(N[A-z0-9]{33})\/([A-z0-9]{64})\/([\d]+)\/reply$/', $request->getPath(), $matches)) else if (preg_match('/^\/room\/(N[A-z0-9]{33})\/([A-z0-9]{64})\/([\d]+)\/reply$/', $request->getPath(), $matches))
@ -246,17 +242,12 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
); );
// Success, redirect to this room page // Success, redirect to this room page
if ($room->post($matches[1], $matches[2], $matches[3], $request->getQuery())) if ($txid = $room->post($matches[1], $matches[2], $matches[3], $request->getQuery()))
{ {
$response->setCode( if ($result = $room->sent($matches[1], $txid))
30 {
); $response->setContent(
$result
$response->setMeta(
sprintf(
'/room/%s',
$matches[1]
)
); );
return $response; return $response;
@ -265,6 +256,7 @@ foreach ((array) scandir(__DIR__ . '/../host') as $host)
} }
} }
} }
}
// Set default response // Set default response
include_once __DIR__ . '/controller/error.php'; include_once __DIR__ . '/controller/error.php';

13
src/view/sent.gemini

@ -0,0 +1,13 @@
```{logo}```
# Success!
Your publication has been successfully sent to DHT pool:
```
{txid}
```
Please, wait few minutes for new block to update
=> {room} Continue
Loading…
Cancel
Save