From 68d6efff4ef666dc5262a9d0d0302ea81e98f6cf Mon Sep 17 00:00:00 2001 From: n9k Date: Wed, 10 Aug 2022 00:08:18 +0000 Subject: [PATCH 1/4] Chat: show dates in chat when time is ambiguous (nojs) --- anonstream/routes/nojs.py | 7 +++-- anonstream/templates/nojs_chat_messages.html | 30 ++++++++++++++++++++ anonstream/utils/chat.py | 13 +++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/anonstream/routes/nojs.py b/anonstream/routes/nojs.py index e34c52e..fb5aaf2 100644 --- a/anonstream/routes/nojs.py +++ b/anonstream/routes/nojs.py @@ -10,11 +10,12 @@ from anonstream.user import add_state, pop_state, try_change_appearance, update_ from anonstream.routes.wrappers import with_user_from, render_template_with_etag from anonstream.helpers.chat import get_scrollback from anonstream.helpers.user import get_default_name -from anonstream.utils.chat import generate_nonce +from anonstream.utils.chat import generate_nonce, should_show_initial_date from anonstream.utils.security import generate_csp from anonstream.utils.user import concatenate_for_notice CONFIG = current_app.config +MESSAGES = current_app.messages USERS_BY_TOKEN = current_app.users_by_token @current_app.route('/stream.html') @@ -47,15 +48,17 @@ async def nojs_info(timestamp, user): @with_user_from(request) async def nojs_chat_messages(timestamp, user): reading(user) + messages = get_scrollback(MESSAGES) return await render_template_with_etag( 'nojs_chat_messages.html', {'csp': generate_csp()}, refresh=CONFIG['NOJS_REFRESH_MESSAGES'], user=user, users_by_token=USERS_BY_TOKEN, - messages=get_scrollback(current_app.messages), + messages=messages, timeout=CONFIG['NOJS_TIMEOUT_CHAT'], get_default_name=get_default_name, + show_initial_date=should_show_initial_date(timestamp, messages), ) @current_app.route('/chat/messages') diff --git a/anonstream/templates/nojs_chat_messages.html b/anonstream/templates/nojs_chat_messages.html index 91999cd..1af249d 100644 --- a/anonstream/templates/nojs_chat_messages.html +++ b/anonstream/templates/nojs_chat_messages.html @@ -144,6 +144,27 @@ font-size: 9pt; cursor: default; } + .chat-date { + transform: rotate(-180deg); + text-align: center; + position: relative; + display: grid; + align-items: center; + margin: 8px 0; + color: #b2b2b3; + cursor: default; + } + .chat-date > hr { + margin: 0; + position: absolute; + width: 100%; + box-sizing: border-box; + } + .chat-date > :not(hr) > time { + padding: 0 1ch; + background-color: #232327; + position: relative; + } {% for token in messages | map(attribute='token') | list | unique %} {% with this_user = users_by_token[token] %} @@ -180,6 +201,15 @@ {{ message.markup }} {% endwith %} + {% + if loop.nextitem is defined and loop.nextitem.date != message.date + or loop.nextitem is not defined and show_initial_date + %} +
  • +
    +
    +
  • + {% endif %} {% endfor %}