From 843946fdd8f066eebbccf15e7f2a598d0a31f6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 13 Aug 2017 22:19:12 +0200 Subject: [PATCH] WIP update/document settings and start to add notification support. --- source/diskuto/settings.d | 36 ++++++++++++++++++++++++++++++++++-- source/diskuto/web.d | 18 ++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/source/diskuto/settings.d b/source/diskuto/settings.d index b6b4120..20739c8 100644 --- a/source/diskuto/settings.d +++ b/source/diskuto/settings.d @@ -6,13 +6,45 @@ import vibe.data.json : Json; import core.time : Duration, minutes; +/** Contains all available properties to configure a Diskuto instance. +*/ class DiskutoSettings { - string resourcePath = "public/"; // Path to Diskutp's "public" folder + /// Path to Diskuto's "public" folder + NativePath resourcePath = "public/"; + + /// Used for permanent storage of all comments DiskutoCommentStore commentStore; - deprecated("Use commentStore instead.") alias backend = commentStore; + + deprecated("Use .commentStore instead.") alias backend = commentStore; + + /// Used to query information about registered or unregistered users DiskutoUserStore userStore; + + /// Settings to use for AntiSpam Json antispam; + + /// Maximum editing time as presented to the user Duration softEditTimeLimit = 5.minutes; + + /** Maximum editing time as enforced by the server + + Note that synchronization to external services will be + delayed by this amount of time. However, there should + be some slack room, so that there is still some time + to author changes when someone begins to edit a + message after almost `softEditTimeLimit`. + */ Duration hardEditTimeLimit = 15.minutes; + + /// Allow voting only for registered users bool onlyRegisteredMayVote = false; + + /// Settings to use for sending e-mails + SMTPClientSettings smtpSettings; + + /// E-Mail addresses to be notified of new messages + string[] notificationEmails; + + /// E-Mail address to use as the "from" field + string notificationSender; } diff --git a/source/diskuto/web.d b/source/diskuto/web.d index 3e455bb..aaaa68d 100644 --- a/source/diskuto/web.d +++ b/source/diskuto/web.d @@ -431,9 +431,27 @@ private final class DiskutoWebInterface { if (is_spam_async) m_settings.commentStore.setCommentStatus(comment.id, StoredComment.Status.spam); + else + sendNotifications(comment); return comment; } + private void sendNotifications(ref StoredComment comment) + { + if (!m_settings.smtpSettings) return; + EmailMessage msg; + msg.headers["Subject"] = format("Diskuto: New reply for %s", comment.topic); + msg.from = m_settings.notificationSender; + msg.body_ = render!("notification-email.dt", comment); + + foreach (mail; m_settings.notificationEmails) { + msg.headers["To"] = mail; + sendMail(settings, mail); + } + + // TODO: send to any posters in the reply chain that have entered an e-mail + } + private void redirectBack(HTTPServerRequest req, string field = null, string value = null) { import vibe.textfilter.urlencode : urlEncode;