From 4d54186891354ededc784a2505b7a3294ece4bee Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 11 Dec 2023 21:25:25 +0200 Subject: [PATCH] implement view modes support, add stream mode --- .env | 2 +- README.md | 6 ++++++ public/css/default.css | 16 ++++++++++++++++ src/Controller/ModuleController.php | 12 +++--------- src/Controller/RoomController.php | 24 +++++++++++++++++++++++- templates/default/layout.html.twig | 2 +- templates/default/module/post.html.twig | 2 +- templates/default/module/room.html.twig | 8 ++++---- templates/default/module/rooms.html.twig | 12 ++++++------ templates/default/room/index.html.twig | 10 +++++----- templates/default/room/list.html.twig | 2 +- 11 files changed, 67 insertions(+), 29 deletions(-) diff --git a/.env b/.env index 6545f5a..286503f 100644 --- a/.env +++ b/.env @@ -19,7 +19,7 @@ APP_ENV=dev APP_SECRET=EDIT_ME ###< symfony/framework-bundle ### -APP_VERSION=1.5.7 +APP_VERSION=1.6.0 APP_NAME=KevaChat diff --git a/README.md b/README.md index 7a1b983..be5cb93 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,12 @@ Application package contain settings preset, just few steps required to launch: * Create at least one room namespace with Web UI or CLI `kevacoin-cli keva_namespace "sandbox"` * Provide at least one namespace for default chat room to `env`.`APP_KEVACOIN_ROOM_NAMESPACE_DEFAULT` (for homepage redirects) +## Modes + +KevaChat supported following `mode` in `GET` requests: + +* `stream` - useful for iframe integrations on external websites to create news feed or support chats + ## Contribution Project created by people for people: MIT License to use it for other needs e.g. new fork, chat instance or Kevacoin blockchain explorer. diff --git a/public/css/default.css b/public/css/default.css index 5538255..bef1348 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -209,4 +209,20 @@ footer > form > output display: block; font-weight: bolder; margin-bottom: 16px; +} + +/* apply mode corrections */ +body[data-mode="stream"] > header +{ + display: none; +} + +body[data-mode="stream"] > main +{ + padding-top: 0; +} + +body[data-mode="stream"] > main ul li div a[name] +{ + top: -16px; } \ No newline at end of file diff --git a/src/Controller/ModuleController.php b/src/Controller/ModuleController.php index db3c2cd..0df09a3 100644 --- a/src/Controller/ModuleController.php +++ b/src/Controller/ModuleController.php @@ -120,13 +120,7 @@ class ModuleController extends AbstractController 'list' => array_unique( $list ), - 'form' => - [ - 'namespace' => - [ - 'value' => $request->get('namespace') - ] - ] + 'request' => $request ] ); } @@ -169,6 +163,7 @@ class ModuleController extends AbstractController return $this->render( 'default/module/post.html.twig', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'sign' => $request->get('sign'), 'error' => $request->get('error'), @@ -195,8 +190,7 @@ class ModuleController extends AbstractController return $this->render( 'default/module/room.html.twig', [ - 'name' => $request->get('name'), - 'error' => $request->get('error') + 'request' => $request ] ); } diff --git a/src/Controller/RoomController.php b/src/Controller/RoomController.php index 75447d7..5fdcf1d 100644 --- a/src/Controller/RoomController.php +++ b/src/Controller/RoomController.php @@ -26,6 +26,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace') ? $request->get('namespace') : $this->getParameter('app.kevacoin.room.namespace.default'), '_fragment' => 'latest' ] @@ -316,6 +317,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $this->getParameter('app.maintenance'), @@ -362,6 +364,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $translator->trans('Namespace not found on this node!'), @@ -390,6 +393,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $translator->trans('Namespace for read only!'), @@ -404,6 +408,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => sprintf( @@ -421,6 +426,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => sprintf( @@ -438,6 +444,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $translator->trans('Message length out of KevaCoin protocol limits'), @@ -452,6 +459,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => sprintf( @@ -470,6 +478,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => sprintf( @@ -487,6 +496,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => sprintf( @@ -522,6 +532,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'error' => null, 'message' => null, @@ -534,6 +545,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $translator->trans('Internal error! Please feedback'), @@ -561,6 +573,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $request->get('namespace'), 'message' => $request->get('message'), 'error' => $this->getParameter('app.maintenance'), @@ -604,8 +617,9 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, - 'error' => $translator->trans('Name length out of KevaCoin protocol limits') + 'error' => $translator->trans('Name length out of KevaCoin protocol limits') ] ); } @@ -616,6 +630,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => sprintf( $translator->trans('Room name does not match node requirements: %s'), @@ -638,6 +653,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => $translator->trans('Room with same name already exists on this node!') ] @@ -650,6 +666,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => sprintf( $translator->trans('Access denied for host %s!'), @@ -665,6 +682,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => sprintf( $translator->trans('Access restricted for host %s!'), @@ -681,6 +699,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => sprintf( $translator->trans('Please wait for %s seconds before add new room!'), @@ -696,6 +715,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => sprintf( $translator->trans('Insufficient funds, wallet: %s'), @@ -729,6 +749,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_namespace', [ + 'mode' => $request->get('mode'), 'namespace' => $namespace['namespaceId'], 'error' => null, 'message' => null, @@ -741,6 +762,7 @@ class RoomController extends AbstractController return $this->redirectToRoute( 'room_list', [ + 'mode' => $request->get('mode'), 'name' => $name, 'error' => $translator->trans('Internal error! Please feedback') ] diff --git a/templates/default/layout.html.twig b/templates/default/layout.html.twig index 8d73ec6..93df2d4 100644 --- a/templates/default/layout.html.twig +++ b/templates/default/layout.html.twig @@ -5,7 +5,7 @@ {% block head_title_content %}{{ 'KevaChat' | trans }}{% endblock %} - + {% block header_container %}
{% block header_content %} diff --git a/templates/default/module/post.html.twig b/templates/default/module/post.html.twig index 4ba91ae..34f2f39 100644 --- a/templates/default/module/post.html.twig +++ b/templates/default/module/post.html.twig @@ -1,5 +1,5 @@ {% if enabled %} -
+ {% if error %} {{ error }} {% endif %} diff --git a/templates/default/module/room.html.twig b/templates/default/module/room.html.twig index e125a24..1abcda8 100644 --- a/templates/default/module/room.html.twig +++ b/templates/default/module/room.html.twig @@ -1,7 +1,7 @@ - - {% if error %} - {{ error }} + + {% if request.get('error') %} + {{ request.get('error') }} {% endif %} - +
\ No newline at end of file diff --git a/templates/default/module/rooms.html.twig b/templates/default/module/rooms.html.twig index c5d555a..4da4810 100644 --- a/templates/default/module/rooms.html.twig +++ b/templates/default/module/rooms.html.twig @@ -1,14 +1,14 @@ -
- + +
{% if list %} {% for i, namespace in list %} {% if i %}•{% endif %}

- {% if namespace == form.namespace.value %} + {% if namespace == request.get('namespace') %} {{ namespace | keva_namespace_value }} {% else %} - {{ namespace | keva_namespace_value }} + {{ namespace | keva_namespace_value }} {% endif %}

@@ -22,8 +22,8 @@ • {% endif %}

- {% if form.namespace.value %} - {{ 'more...' | trans }} + {% if list %} + {{ 'more...' | trans }} {% else %} {{ 'more...' | trans }} {% endif %} diff --git a/templates/default/room/index.html.twig b/templates/default/room/index.html.twig index 783dd62..4cc078e 100644 --- a/templates/default/room/index.html.twig +++ b/templates/default/room/index.html.twig @@ -1,4 +1,4 @@ -{% macro recursive_post_tree(namespace, tree) %} +{% macro recursive_post_tree(mode, namespace, tree) %} {% import _self as self %} {% if tree | length %}
    @@ -14,9 +14,9 @@ {% endif %} • - {{ post.time | format_ago }} + {{ post.time | format_ago }} • - {{ 'reply' | trans }} + {{ 'reply' | trans }} {% if post.pending %} @@ -36,7 +36,7 @@ }} {% if post.tree | length %} - {{ self.recursive_post_tree(namespace, post.tree) }} + {{ self.recursive_post_tree(mode, namespace, post.tree) }} {% endif %} {% endfor %} @@ -48,7 +48,7 @@ {% block head_title_content %}{{ request.get('namespace') | keva_namespace_value }} - {{ 'KevaChat' | trans }}{% endblock %} {% block main_content %} {% if tree %} - {{ recursive_post_tree(request.get('namespace'), tree) }} + {{ recursive_post_tree(request.get('mode'), request.get('namespace'), tree) }} {% else %}