Browse Source

implement success sending page

main
ghost 10 months ago
parent
commit
a7f54c22f3
  1. 57
      src/controller/room.php
  2. 40
      src/server.php
  3. 13
      src/view/sent.gemini

57
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
$this->_memory->delete(
$session
);
// Success
return $txid;
} }
// Cleanup memory return null;
$this->_memory->delete( }
$session
);
// Success public function sent(string $namespace, string $txid)
return true; {
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

40
src/server.php

@ -197,20 +197,16 @@ 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;
}
} }
} }
} }
@ -246,20 +242,16 @@ 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;
}
} }
} }
} }

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