Skip to content

Commit

Permalink
Merge pull request #45 from TheRomanVolkov/messages
Browse files Browse the repository at this point in the history
Add route('/send_message/<recipient>', methods=['GET', 'POST'])
  • Loading branch information
JustRomanVolkov committed Feb 15, 2024
2 parents 4ab5f70 + d1209fc commit 535defd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,24 @@ def search():
next_url=next_url, prev_url=prev_url)


@bp.route('/send_message/<recipient>', 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():
Expand Down

0 comments on commit 535defd

Please sign in to comment.