From 696c2c03269135a6e3cf9d802da30e2152d2664c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 9 Nov 2021 22:58:16 +0100 Subject: Send new message notifications by mail. --- server.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 56f6de5..b61ca8c 100644 --- a/server.js +++ b/server.js @@ -1099,6 +1099,18 @@ function mail_password_reset_token(user, token) { mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); } +function mail_new_message(user, msg_id, msg_from, msg_subject, msg_body) { + if (!mailer) + return; + let subject = "You have a new message from " + msg_from + "."; + let body = "Subject: " + msg_subject + "\n\n" + + msg_body + "\n\n" + + "https://rally-the-troops.com/message/read/" + msg_id + "\n\n" + + MAIL_FOOTER; + console.log("SENT MAIL:", mail_addr(user), subject); + mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); +} + function mail_your_turn_notification(user, game_id, interval) { let too_soon = sql_notify_too_soon.get(interval, user.user_id, game_id); if (!too_soon) { @@ -1780,9 +1792,9 @@ app.post('/message/send', must_be_logged_in, function (req, res) { message: "Cannot find that user." }); } - MESSAGE_SEND.run(req.user.user_id, to_user.user_id, subject, body); + let info = MESSAGE_SEND.run(req.user.user_id, to_user.user_id, subject, body); if (to_user.notifications) { - console.log("MAIL USER NOTIFICATION"); + mail_new_message(to_user, info.lastInsertRowid, req.user.name, subject, body) } res.redirect('/inbox'); }); -- cgit v1.2.3