|
|
@ -48,7 +48,7 @@ class Room |
|
|
|
foreach ((array) $this->_kevacoin->kevaFilter($namespace['namespaceId']) as $record) |
|
|
|
foreach ((array) $this->_kevacoin->kevaFilter($namespace['namespaceId']) as $record) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Is protocol compatible post |
|
|
|
// Is protocol compatible post |
|
|
|
if ($this->post($namespace['namespaceId'], $record['key'], 'txid')) |
|
|
|
if ($this->post($namespace['namespaceId'], $record['key'], [], 'txid')) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$total++; |
|
|
|
$total++; |
|
|
|
} |
|
|
|
} |
|
|
@ -136,33 +136,35 @@ class Room |
|
|
|
|
|
|
|
|
|
|
|
public function posts(string $namespace): ?string |
|
|
|
public function posts(string $namespace): ?string |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Get subject |
|
|
|
// Get namespace records |
|
|
|
$subject = null; |
|
|
|
if (!$records = (array) $this->_kevacoin->kevaFilter($namespace)) |
|
|
|
|
|
|
|
|
|
|
|
foreach ((array) $this->_kevacoin->kevaListNamespaces() as $record) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($record['namespaceId'] == $namespace) |
|
|
|
return null; |
|
|
|
{ |
|
|
|
|
|
|
|
$subject = $record['displayName']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get posts |
|
|
|
// Get posts |
|
|
|
$posts = []; |
|
|
|
$posts = []; |
|
|
|
|
|
|
|
|
|
|
|
foreach ((array) $this->_kevacoin->kevaFilter($namespace) as $record) |
|
|
|
foreach ($records as $record) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (empty($record['key'])) |
|
|
|
if ($post = $this->post($namespace, $record['key'], $records)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
continue; |
|
|
|
$posts[] = $post; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($post = $this->post($namespace, $record['key'])) |
|
|
|
// Get subject |
|
|
|
|
|
|
|
$subject = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach ((array) $this->_kevacoin->kevaListNamespaces() as $record) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$posts[] = $post; |
|
|
|
if ($record['namespaceId'] == $namespace) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$subject = $record['displayName']; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get template |
|
|
|
return str_replace( |
|
|
|
return str_replace( |
|
|
|
[ |
|
|
|
[ |
|
|
|
'{logo}', |
|
|
|
'{logo}', |
|
|
@ -185,7 +187,7 @@ class Room |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function post(string $namespace, string $key, ?string $field = null): ?string |
|
|
|
public function post(string $namespace, string $key, array $posts = [], ?string $field = null): ?string |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Check record exists |
|
|
|
// Check record exists |
|
|
|
if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) |
|
|
|
if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) |
|
|
@ -239,9 +241,30 @@ class Room |
|
|
|
$quote = null; |
|
|
|
$quote = null; |
|
|
|
if (preg_match('/^@([A-z0-9]{64})/', $record['value'], $mention)) |
|
|
|
if (preg_match('/^@([A-z0-9]{64})/', $record['value'], $mention)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
// Message starts with mention |
|
|
|
if (!empty($mention[1])) |
|
|
|
if (!empty($mention[1])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$quote = '@' . $mention[1]; // @TODO replace to post message by txid |
|
|
|
// Use original mention as quote by default |
|
|
|
|
|
|
|
$quote = $mention[1]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try to replace with post message by txid |
|
|
|
|
|
|
|
foreach ($posts as $post) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if ($post['txid'] == $quote) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Strip folding |
|
|
|
|
|
|
|
$quote = |
|
|
|
|
|
|
|
trim( |
|
|
|
|
|
|
|
preg_replace( |
|
|
|
|
|
|
|
'/^@([A-z0-9]{64})/', |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
$post['value'] |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Remove mention from message |
|
|
|
// Remove mention from message |
|
|
|
$record['value'] = preg_replace('/^@([A-z0-9]{64})/', null, $record['value']); |
|
|
|
$record['value'] = preg_replace('/^@([A-z0-9]{64})/', null, $record['value']); |
|
|
|