|
|
|
@ -48,7 +48,7 @@ class Room
@@ -48,7 +48,7 @@ class Room
|
|
|
|
|
foreach ((array) $this->_kevacoin->kevaFilter($namespace['namespaceId']) as $record) |
|
|
|
|
{ |
|
|
|
|
// Is protocol compatible post |
|
|
|
|
if ($this->post($namespace['namespaceId'], $record['key'], 'txid')) |
|
|
|
|
if ($this->post($namespace['namespaceId'], $record['key'], [], 'txid')) |
|
|
|
|
{ |
|
|
|
|
$total++; |
|
|
|
|
} |
|
|
|
@ -136,33 +136,35 @@ class Room
@@ -136,33 +136,35 @@ class Room
|
|
|
|
|
|
|
|
|
|
public function posts(string $namespace): ?string |
|
|
|
|
{ |
|
|
|
|
// Get subject |
|
|
|
|
$subject = null; |
|
|
|
|
|
|
|
|
|
foreach ((array) $this->_kevacoin->kevaListNamespaces() as $record) |
|
|
|
|
// Get namespace records |
|
|
|
|
if (!$records = (array) $this->_kevacoin->kevaFilter($namespace)) |
|
|
|
|
{ |
|
|
|
|
if ($record['namespaceId'] == $namespace) |
|
|
|
|
{ |
|
|
|
|
$subject = $record['displayName']; |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get 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) |
|
|
|
|
{ |
|
|
|
|
if ($record['namespaceId'] == $namespace) |
|
|
|
|
{ |
|
|
|
|
$posts[] = $post; |
|
|
|
|
$subject = $record['displayName']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get template |
|
|
|
|
return str_replace( |
|
|
|
|
[ |
|
|
|
|
'{logo}', |
|
|
|
@ -185,7 +187,7 @@ class Room
@@ -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 |
|
|
|
|
if (!$record = (array) $this->_kevacoin->kevaGet($namespace, $key)) |
|
|
|
@ -239,9 +241,30 @@ class Room
@@ -239,9 +241,30 @@ class Room
|
|
|
|
|
$quote = null; |
|
|
|
|
if (preg_match('/^@([A-z0-9]{64})/', $record['value'], $mention)) |
|
|
|
|
{ |
|
|
|
|
// Message starts with mention |
|
|
|
|
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 |
|
|
|
|
$record['value'] = preg_replace('/^@([A-z0-9]{64})/', null, $record['value']); |
|
|
|
|