Browse Source

implement view modes support, add stream mode

main
ghost 12 months ago
parent
commit
4d54186891
  1. 2
      .env
  2. 6
      README.md
  3. 16
      public/css/default.css
  4. 12
      src/Controller/ModuleController.php
  5. 24
      src/Controller/RoomController.php
  6. 2
      templates/default/layout.html.twig
  7. 2
      templates/default/module/post.html.twig
  8. 8
      templates/default/module/room.html.twig
  9. 12
      templates/default/module/rooms.html.twig
  10. 10
      templates/default/room/index.html.twig
  11. 2
      templates/default/room/list.html.twig

2
.env

@ -19,7 +19,7 @@ APP_ENV=dev
APP_SECRET=EDIT_ME APP_SECRET=EDIT_ME
###< symfony/framework-bundle ### ###< symfony/framework-bundle ###
APP_VERSION=1.5.7 APP_VERSION=1.6.0
APP_NAME=KevaChat APP_NAME=KevaChat

6
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"` * 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) * 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 ## 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. Project created by people for people: MIT License to use it for other needs e.g. new fork, chat instance or Kevacoin blockchain explorer.

16
public/css/default.css

@ -209,4 +209,20 @@ footer > form > output
display: block; display: block;
font-weight: bolder; font-weight: bolder;
margin-bottom: 16px; 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;
} }

12
src/Controller/ModuleController.php

@ -120,13 +120,7 @@ class ModuleController extends AbstractController
'list' => array_unique( 'list' => array_unique(
$list $list
), ),
'form' => 'request' => $request
[
'namespace' =>
[
'value' => $request->get('namespace')
]
]
] ]
); );
} }
@ -169,6 +163,7 @@ class ModuleController extends AbstractController
return $this->render( return $this->render(
'default/module/post.html.twig', 'default/module/post.html.twig',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'), 'sign' => $request->get('sign'),
'error' => $request->get('error'), 'error' => $request->get('error'),
@ -195,8 +190,7 @@ class ModuleController extends AbstractController
return $this->render( return $this->render(
'default/module/room.html.twig', 'default/module/room.html.twig',
[ [
'name' => $request->get('name'), 'request' => $request
'error' => $request->get('error')
] ]
); );
} }

24
src/Controller/RoomController.php

@ -26,6 +26,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace') ? $request->get('namespace') : $this->getParameter('app.kevacoin.room.namespace.default'), 'namespace' => $request->get('namespace') ? $request->get('namespace') : $this->getParameter('app.kevacoin.room.namespace.default'),
'_fragment' => 'latest' '_fragment' => 'latest'
] ]
@ -316,6 +317,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $this->getParameter('app.maintenance'), 'error' => $this->getParameter('app.maintenance'),
@ -362,6 +364,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $translator->trans('Namespace not found on this node!'), 'error' => $translator->trans('Namespace not found on this node!'),
@ -390,6 +393,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $translator->trans('Namespace for read only!'), 'error' => $translator->trans('Namespace for read only!'),
@ -404,6 +408,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => sprintf( 'error' => sprintf(
@ -421,6 +426,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => sprintf( 'error' => sprintf(
@ -438,6 +444,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $translator->trans('Message length out of KevaCoin protocol limits'), 'error' => $translator->trans('Message length out of KevaCoin protocol limits'),
@ -452,6 +459,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => sprintf( 'error' => sprintf(
@ -470,6 +478,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => sprintf( 'error' => sprintf(
@ -487,6 +496,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => sprintf( 'error' => sprintf(
@ -522,6 +532,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'error' => null, 'error' => null,
'message' => null, 'message' => null,
@ -534,6 +545,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $translator->trans('Internal error! Please feedback'), 'error' => $translator->trans('Internal error! Please feedback'),
@ -561,6 +573,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'), 'namespace' => $request->get('namespace'),
'message' => $request->get('message'), 'message' => $request->get('message'),
'error' => $this->getParameter('app.maintenance'), 'error' => $this->getParameter('app.maintenance'),
@ -604,8 +617,9 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, '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( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => sprintf( 'error' => sprintf(
$translator->trans('Room name does not match node requirements: %s'), $translator->trans('Room name does not match node requirements: %s'),
@ -638,6 +653,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => $translator->trans('Room with same name already exists on this node!') 'error' => $translator->trans('Room with same name already exists on this node!')
] ]
@ -650,6 +666,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => sprintf( 'error' => sprintf(
$translator->trans('Access denied for host %s!'), $translator->trans('Access denied for host %s!'),
@ -665,6 +682,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => sprintf( 'error' => sprintf(
$translator->trans('Access restricted for host %s!'), $translator->trans('Access restricted for host %s!'),
@ -681,6 +699,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => sprintf( 'error' => sprintf(
$translator->trans('Please wait for %s seconds before add new room!'), $translator->trans('Please wait for %s seconds before add new room!'),
@ -696,6 +715,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => sprintf( 'error' => sprintf(
$translator->trans('Insufficient funds, wallet: %s'), $translator->trans('Insufficient funds, wallet: %s'),
@ -729,6 +749,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_namespace', 'room_namespace',
[ [
'mode' => $request->get('mode'),
'namespace' => $namespace['namespaceId'], 'namespace' => $namespace['namespaceId'],
'error' => null, 'error' => null,
'message' => null, 'message' => null,
@ -741,6 +762,7 @@ class RoomController extends AbstractController
return $this->redirectToRoute( return $this->redirectToRoute(
'room_list', 'room_list',
[ [
'mode' => $request->get('mode'),
'name' => $name, 'name' => $name,
'error' => $translator->trans('Internal error! Please feedback') 'error' => $translator->trans('Internal error! Please feedback')
] ]

2
templates/default/layout.html.twig

@ -5,7 +5,7 @@
<title>{% block head_title_content %}{{ 'KevaChat' | trans }}{% endblock %}</title> <title>{% block head_title_content %}{{ 'KevaChat' | trans }}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{{ url('room_index') }}css/default.css?{{ app.version }}"/> <link rel="stylesheet" type="text/css" href="{{ url('room_index') }}css/default.css?{{ app.version }}"/>
</head> </head>
<body> <body data-mode="{% if request.get('mode') %}stream{% else %}webapp{% endif %}">
{% block header_container %} {% block header_container %}
<header> <header>
{% block header_content %} {% block header_content %}

2
templates/default/module/post.html.twig

@ -1,5 +1,5 @@
{% if enabled %} {% if enabled %}
<form name="post" action="{{ path('room_post', { namespace : namespace }) }}" method="post"> <form name="post" action="{{ path('room_post', { mode : mode, namespace : namespace }) }}" method="post">
{% if error %} {% if error %}
<output name="error" for="form-post-message">{{ error }}</output> <output name="error" for="form-post-message">{{ error }}</output>
{% endif %} {% endif %}

8
templates/default/module/room.html.twig

@ -1,7 +1,7 @@
<form name="room" action="{{ path('room_add') }}" method="post"> <form name="room" action="{{ path('room_add', { mode : request.get('mode') }) }}" method="post">
{% if error %} {% if request.get('error') %}
<output name="error" for="form-room-name">{{ error }}</output> <output name="error" for="form-room-name">{{ request.get('error') }}</output>
{% endif %} {% endif %}
<input type="text" name="name" id="form-room-name" value="{{ name }}" placeholder="{{ 'enter new room name...' | trans }}" /> <input type="text" name="name" id="form-room-name" value="{{ request.get('name') }}" placeholder="{{ 'enter new room name...' | trans }}" />
<button type="submit">{{ 'add' | trans }}</button> <button type="submit">{{ 'add' | trans }}</button>
</form> </form>

12
templates/default/module/rooms.html.twig

@ -1,14 +1,14 @@
<form name="rooms" action="{{ path('room_index') }}" method="get"> <form name="rooms" action="{{ path('room_index', { mode : request.get('mode') }) }}" method="get">
<input type="text" name="namespace" value="{{ form.namespace.value }}" placeholder="{{ 'join room by kevacoin namespace...' | trans }}" /> <input type="text" name="namespace" value="{{ request.get('namespace') }}" placeholder="{{ 'join room by kevacoin namespace...' | trans }}" />
</form> </form>
{% if list %} {% if list %}
{% for i, namespace in list %} {% for i, namespace in list %}
{% if i %}&bull;{% endif %} {% if i %}&bull;{% endif %}
<h2> <h2>
{% if namespace == form.namespace.value %} {% if namespace == request.get('namespace') %}
{{ namespace | keva_namespace_value }} {{ namespace | keva_namespace_value }}
{% else %} {% else %}
<a href="{{ path('room_namespace', { namespace : namespace, _fragment : 'latest' }) }}">{{ namespace | keva_namespace_value }}</a> <a href="{{ path('room_namespace', { mode : request.get('mode'), namespace : namespace, _fragment : 'latest' }) }}">{{ namespace | keva_namespace_value }}</a>
{% endif %} {% endif %}
</h2> </h2>
<sup> <sup>
@ -22,8 +22,8 @@
&bull; &bull;
{% endif %} {% endif %}
<h2> <h2>
{% if form.namespace.value %} {% if list %}
<a href="{{ path('room_list') }}">{{ 'more...' | trans }}</a> <a href="{{ path('room_list', { mode : request.get('mode') }) }}">{{ 'more...' | trans }}</a>
{% else %} {% else %}
{{ 'more...' | trans }} {{ 'more...' | trans }}
{% endif %} {% endif %}

10
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 %} {% import _self as self %}
{% if tree | length %} {% if tree | length %}
<ul> <ul>
@ -14,9 +14,9 @@
</strong> </strong>
{% endif %} {% endif %}
&bull; &bull;
<a rel="nofollow" href="{{ path('room_namespace', { namespace : namespace, _fragment : post.id }) }}" title="{{ post.time | date('c') }}">{{ post.time | format_ago }}</a> <a rel="nofollow" href="{{ path('room_namespace', { mode : mode, namespace : namespace, _fragment : post.id }) }}" title="{{ post.time | date('c') }}">{{ post.time | format_ago }}</a>
&bull; &bull;
<a rel="nofollow" href="{{ path('room_namespace', { namespace : namespace, txid : post.id, _fragment : post.id }) }}">{{ 'reply' | trans }}</a> <a rel="nofollow" href="{{ path('room_namespace', { mode : mode, namespace : namespace, txid : post.id, _fragment : post.id }) }}">{{ 'reply' | trans }}</a>
{% if post.pending %} {% if post.pending %}
<span title="{{ 'pending in pool' | trans }}"> <span title="{{ 'pending in pool' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16"> <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16">
@ -36,7 +36,7 @@
}} }}
</div> </div>
{% if post.tree | length %} {% if post.tree | length %}
{{ self.recursive_post_tree(namespace, post.tree) }} {{ self.recursive_post_tree(mode, namespace, post.tree) }}
{% endif %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}
@ -48,7 +48,7 @@
{% block head_title_content %}{{ request.get('namespace') | keva_namespace_value }} - {{ 'KevaChat' | trans }}{% endblock %} {% block head_title_content %}{{ request.get('namespace') | keva_namespace_value }} - {{ 'KevaChat' | trans }}{% endblock %}
{% block main_content %} {% block main_content %}
{% if tree %} {% if tree %}
{{ recursive_post_tree(request.get('namespace'), tree) }} {{ recursive_post_tree(request.get('mode'), request.get('namespace'), tree) }}
<a name="latest"></a> <a name="latest"></a>
{% else %} {% else %}
<ul> <ul>

2
templates/default/room/list.html.twig

@ -7,7 +7,7 @@
<li> <li>
<div> <div>
<strong> <strong>
<a href="{{ path('room_namespace', { namespace : room.namespace, _fragment : 'latest' }) }}">{{ room.namespace | keva_namespace_value }}</a> <a href="{{ path('room_namespace', { mode : request.get('mode'), namespace : room.namespace, _fragment : 'latest' }) }}">{{ room.namespace | keva_namespace_value }}</a>
</strong> </strong>
{{ room.total }} {{ room.total }}
<a href="{{ path('room_namespace', { namespace : room.namespace, feed : 'rss' }) }}" title="{{ 'RSS' | trans }}" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" fill="currentColor" viewBox="0 0 16 16"> <a href="{{ path('room_namespace', { namespace : room.namespace, feed : 'rss' }) }}" title="{{ 'RSS' | trans }}" target="_blank"><svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" fill="currentColor" viewBox="0 0 16 16">

Loading…
Cancel
Save