From d1209fc3a649469e3103dcb8ef0ff1f83c6815a2 Mon Sep 17 00:00:00 2001 From: R2 Date: Thu, 15 Feb 2024 15:36:13 +0700 Subject: [PATCH] Add route('/send_message/', methods=['GET', 'POST']) --- app/main/routes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/main/routes.py b/app/main/routes.py index d24a38a..a1287f1 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -283,6 +283,24 @@ def search(): next_url=next_url, prev_url=prev_url) +@bp.route('/send_message/', methods=['GET', 'POST']) +@login_required +def send_message(recipient): + user = db.first_or_404(sa.select(User).where(User.username == recipient)) + form = MessageForm() + if form.validate_on_submit(): + msg = Message(author=current_user, recipient=user, + body=form.message.data) + db.session.add(msg) + user.add_notification('unread_message_count', + user.unread_message_count()) + db.session.commit() + flash(_('Your message has been sent.')) + return redirect(url_for('main.user', username=recipient)) + return render_template('send_message.html', title=_('Send Message'), + form=form, recipient=recipient) + + @bp.route('/messages') @login_required def messages():