Refactor Matrix chat widget implementation and enhance CSS styles for improved UI

This commit is contained in:
ryan
2026-06-19 17:45:21 +02:00
parent e04aeccee4
commit aaa738d3cd
3 changed files with 362 additions and 259 deletions
+13 -16
View File
@@ -1,4 +1,4 @@
from flask import Blueprint, render_template, current_app, redirect, url_for, request
from flask import Blueprint, current_app, redirect, url_for, request
blueprint = Blueprint(
'matrix_iframe',
@@ -8,29 +8,35 @@ blueprint = Blueprint(
static_url_path='/static/matrix_iframe',
)
def init_app(app, server_url='', room_alias='', base_template='layout.html', login_endpoint=None):
def init_app(app, server_url='', room_alias='', login_endpoint=None):
"""
Register the Matrix chat blueprint with a Flask app.
The blueprint serves static assets (JS + CSS) and injects
matrix_chat_available, matrix_server_url, and matrix_room_alias
into every template context so the host app's layout can mount
the chat overlay widget.
Args:
server_url: Matrix homeserver base URL, e.g. "https://matrix.sticknife.com"
room_alias: Matrix room alias, e.g. "#sticknife-library:matrix.sticknife.com"
base_template: Jinja2 base template to extend, default "layout.html"
login_endpoint: Flask endpoint to redirect unauthenticated users to,
e.g. "web.login". If None, no auth guard is applied.
"""
app.config.setdefault('MATRIX_SERVER_URL', server_url)
app.config.setdefault('MATRIX_ROOM_ALIAS', room_alias)
app.config.setdefault('MATRIX_CHAT_BASE', base_template)
app.config.setdefault('MATRIX_CHAT_LOGIN_ENDPOINT', login_endpoint)
app.register_blueprint(blueprint)
@blueprint.app_context_processor
def _inject_matrix_chat():
"""Makes matrix_chat_available=True visible to all templates when the blueprint is registered."""
return {'matrix_chat_available': True}
"""Injects matrix chat config into every template when the blueprint is registered."""
return {
'matrix_chat_available': True,
'matrix_server_url': current_app.config.get('MATRIX_SERVER_URL', ''),
'matrix_room_alias': current_app.config.get('MATRIX_ROOM_ALIAS', ''),
}
@blueprint.before_request
@@ -46,12 +52,3 @@ def _auth_guard():
pass
@blueprint.route('/chat')
def chat():
return render_template(
'matrix_iframe/chat.html',
matrix_server=current_app.config.get('MATRIX_SERVER_URL', ''),
matrix_room_alias=current_app.config.get('MATRIX_ROOM_ALIAS', ''),
base_template=current_app.config.get('MATRIX_CHAT_BASE', 'layout.html'),
page='chat',
)