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 @@ -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

6
README.md

@ -50,6 +50,12 @@ Application package contain settings preset, just few steps required to launch: @@ -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.

16
public/css/default.css

@ -210,3 +210,19 @@ footer > form > output @@ -210,3 +210,19 @@ footer > form > output
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;
}

12
src/Controller/ModuleController.php

@ -120,13 +120,7 @@ class ModuleController extends AbstractController @@ -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 @@ -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 @@ -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
]
);
}

24
src/Controller/RoomController.php

@ -26,6 +26,7 @@ class RoomController extends AbstractController @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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')
]

2
templates/default/layout.html.twig

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

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
{% 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 %}
<output name="error" for="form-post-message">{{ error }}</output>
{% endif %}

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

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<form name="room" action="{{ path('room_add') }}" method="post">
{% if error %}
<output name="error" for="form-room-name">{{ error }}</output>
<form name="room" action="{{ path('room_add', { mode : request.get('mode') }) }}" method="post">
{% if request.get('error') %}
<output name="error" for="form-room-name">{{ request.get('error') }}</output>
{% 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>
</form>

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

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

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
{% macro recursive_post_tree(namespace, tree) %}
{% macro recursive_post_tree(mode, namespace, tree) %}
{% import _self as self %}
{% if tree | length %}
<ul>
@ -14,9 +14,9 @@ @@ -14,9 +14,9 @@
</strong>
{% endif %}
&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;
<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 %}
<span title="{{ 'pending in pool' | trans }}">
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 16 16">
@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
}}
</div>
{% if post.tree | length %}
{{ self.recursive_post_tree(namespace, post.tree) }}
{{ self.recursive_post_tree(mode, namespace, post.tree) }}
{% endif %}
</li>
{% endfor %}
@ -48,7 +48,7 @@ @@ -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) }}
<a name="latest"></a>
{% else %}
<ul>

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

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<li>
<div>
<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>
{{ 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">

Loading…
Cancel
Save