From eaf53f87c25f436e64b223cc5afde426ff0c822c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:13:53 +1300 Subject: [PATCH] no chats --- app/chat/routes.py | 22 ++++++++++++---------- app/templates/chat/empty.html | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 app/templates/chat/empty.html diff --git a/app/chat/routes.py b/app/chat/routes.py index 85346618..42d0ae16 100644 --- a/app/chat/routes.py +++ b/app/chat/routes.py @@ -25,7 +25,10 @@ def chat_home(conversation_id=None): conversation_member.c.conversation_id == Conversation.id). \ filter(conversation_member.c.user_id == current_user.id).order_by(desc(Conversation.updated_at)).limit(50).all() if conversation_id is None: - return redirect(url_for('chat.chat_home', conversation_id=conversations[0].id)) + if conversations: + return redirect(url_for('chat.chat_home', conversation_id=conversations[0].id)) + else: + return redirect(url_for('chat.empty')) else: conversation = Conversation.query.get_or_404(conversation_id) conversation.read = True @@ -33,16 +36,8 @@ def chat_home(conversation_id=None): abort(400) if conversations: messages = conversation.messages.order_by(ChatMessage.created_at).all() - if messages: - if messages[0].sender_id == current_user.id: - other_party = User.query.get(messages[0].recipient_id) - else: - other_party = User.query.get(messages[0].sender_id) - else: - other_party = None else: messages = [] - other_party = None sql = f"UPDATE notification SET read = true WHERE url = '/chat/{conversation_id}' AND user_id = {current_user.id}" db.session.execute(text(sql)) @@ -50,7 +45,8 @@ def chat_home(conversation_id=None): current_user.unread_notifications = Notification.query.filter_by(user_id=current_user.id, read=False).count() db.session.commit() - return render_template('chat/conversation.html', title=_('Chat with %(name)s', name=other_party.display_name()) if other_party else _('Chat'), + return render_template('chat/conversation.html', + title=_('Chat with %(name)s', name=conversation.member_names(current_user.id)), conversations=conversations, messages=messages, form=form, current_conversation=conversation_id, conversation=conversation, moderating_communities=moderating_communities(current_user.get_id()), @@ -99,6 +95,12 @@ def blocked(): return render_template('chat/blocked.html') +@bp.route('/chat/empty', methods=['GET']) +@login_required +def empty(): + return render_template('chat/empty.html') + + @bp.route('/chat//options', methods=['GET', 'POST']) @login_required def chat_options(conversation_id): diff --git a/app/templates/chat/empty.html b/app/templates/chat/empty.html new file mode 100644 index 00000000..70464750 --- /dev/null +++ b/app/templates/chat/empty.html @@ -0,0 +1,20 @@ +{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %} + {% extends 'themes/' + theme() + '/base.html' %} +{% else %} + {% extends "base.html" %} +{% endif %} %} + +{% block app_content %} +
+ +
+{% endblock %} \ No newline at end of file