Browse Source

update room writable condition

main
ghost 9 months ago
parent
commit
11d2f35d49
  1. 21
      src/Controller/ModuleController.php
  2. 23
      src/Controller/RoomController.php
  3. 14
      templates/default/room/index.html.twig

21
src/Controller/ModuleController.php

@ -129,27 +129,6 @@ class ModuleController extends AbstractController @@ -129,27 +129,6 @@ class ModuleController extends AbstractController
Request $request
): Response
{
// Connect kevacoin
$client = new \Kevachat\Kevacoin\Client(
$this->getParameter('app.kevacoin.protocol'),
$this->getParameter('app.kevacoin.host'),
$this->getParameter('app.kevacoin.port'),
$this->getParameter('app.kevacoin.username'),
$this->getParameter('app.kevacoin.password')
);
// Check room own
$rooms = [];
foreach ((array) $client->kevaListNamespaces() as $value)
{
$rooms[] = $value['namespaceId'];
}
if (!in_array($request->get('namespace'), $rooms))
{
return new Response();
}
// Connect memcached
$memcached = new \Memcached();
$memcached->addServer(

23
src/Controller/RoomController.php

@ -319,13 +319,30 @@ class RoomController extends AbstractController @@ -319,13 +319,30 @@ class RoomController extends AbstractController
);
}
// Get own room list
$rooms = [];
foreach ((array) $client->kevaListNamespaces() as $value)
{
$rooms[] = $value['namespaceId'];
}
// HTML
return $this->render(
'default/room/index.html.twig',
[
'feed' => $feed,
'tree' => $tree,
'request' => $request
'feed' => $feed,
'tree' => $tree,
'writable' => in_array(
$request->get('namespace'),
$rooms
) && !in_array(
$request->get('namespace'),
explode(
'|',
$this->getParameter('app.kevacoin.room.namespaces.readonly')
)
),
'request' => $request
]
);
}

14
templates/default/room/index.html.twig

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
{% macro recursive_post_tree(mode, namespace, tree) %}
{% macro recursive_post_tree(mode, namespace, writable, tree) %}
{% import _self as self %}
{% if tree | length %}
<ul>
@ -23,8 +23,10 @@ @@ -23,8 +23,10 @@
</span>
{% else %}
<a rel="nofollow" href="{{ path('room_namespace', { mode : mode, namespace : namespace, _fragment : post.txid }) }}" title="{{ post.time | date('c') }}">{{ post.time | format_ago }}</a>
&bull;
<a rel="nofollow" href="{{ path('room_namespace', { mode : mode, namespace : namespace, txid : post.txid, _fragment : post.txid }) }}">{{ 'reply' | trans }}</a>
{% if writable %}
&bull;
<a rel="nofollow" href="{{ path('room_namespace', { mode : mode, namespace : namespace, txid : post.txid, _fragment : post.txid }) }}">{{ 'reply' | trans }}</a>
{% endif %}
{% endif %}
<small>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="currentColor" viewBox="0 0 16 16">
@ -41,7 +43,7 @@ @@ -41,7 +43,7 @@
}}
</div>
{% if post.tree is defined and post.tree | length %}
{{ self.recursive_post_tree(mode, namespace, post.tree) }}
{{ self.recursive_post_tree(mode, namespace, writable, post.tree) }}
{% endif %}
</li>
{% endfor %}
@ -53,7 +55,7 @@ @@ -53,7 +55,7 @@
{% block head_title_content %}{{ request.get('namespace') | keva_namespace_value }} - {{ app.name }}{% endblock %}
{% block main_content %}
{% if tree %}
{{ recursive_post_tree(request.get('mode'), request.get('namespace'), tree) }}
{{ recursive_post_tree(request.get('mode'), request.get('namespace'), writable, tree) }}
<a name="latest"></a>
{% else %}
<ul>
@ -66,6 +68,7 @@ @@ -66,6 +68,7 @@
{% endif %}
{% endblock %}
{% block footer_content %}
{% if writable %}
{{
render(
controller(
@ -76,4 +79,5 @@ @@ -76,4 +79,5 @@
)
)
}}
{% endif %}
{% endblock %}
Loading…
Cancel
Save