[PATCH v2] Add "Enable notifications" checkbox in "Add Comment" form

Vladimir Panteleev archlinux at thecybershadow.net
Tue Oct 16 05:22:29 UTC 2018


Currently, it is a little to easy to forget to enable notifications
for a package after leaving a comment, thus never being notified of a
reply. Even though the "Enable notifications" link is on the same
page, it is not part of the flow for posting a new comment, and so,
easy to miss.

Most web forums and comment systems include a checkbox to enable
notifications when posting for the first time in a thread. This patch
implements this in aurweb, as well.
---

Following Eli's comment, this version only allows enabling
notifications - the checkbox is simply not displayed when they are
already enabled. The corresponding server-side code is also
simplified.

 web/html/css/aurweb.css           | 5 +++++
 web/html/pkgbase.php              | 3 +++
 web/template/pkg_comment_form.php | 6 ++++++
 3 files changed, 14 insertions(+)

diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css
index 593c9ae..ef37bf5 100644
--- a/web/html/css/aurweb.css
+++ b/web/html/css/aurweb.css
@@ -104,6 +104,11 @@
 	top: 1px;
 }
 
+.comment-enable-notifications {
+	display: inline-block;
+	margin-left: 1em;
+}
+
 .rss-icon, .delete-comment, .undelete-comment, .edit-comment, .pin-comment {
 	-webkit-filter: grayscale(100%);
 	filter: grayscale(100%);
diff --git a/web/html/pkgbase.php b/web/html/pkgbase.php
index 46ad77e..b716644 100644
--- a/web/html/pkgbase.php
+++ b/web/html/pkgbase.php
@@ -120,6 +120,9 @@ if (check_token()) {
 	} elseif (current_action("do_AddComment")) {
 		$uid = uid_from_sid($_COOKIE["AURSID"]);
 		list($ret, $output) = pkgbase_add_comment($base_id, $uid, $_REQUEST['comment']);
+		if ($ret && isset($_REQUEST['enable_notifications'])) {
+			list($ret, $output) = pkgbase_notify(array($base_id));
+		}
 		$fragment = '#news';
 	} elseif (current_action("do_EditComment")) {
 		list($ret, $output) = pkgbase_edit_comment($_REQUEST['comment']);
diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php
index c450c4b..3feee8f 100644
--- a/web/template/pkg_comment_form.php
+++ b/web/template/pkg_comment_form.php
@@ -13,6 +13,12 @@
 			</p>
 			<p>
 				<input type="submit" value="<?= (isset($comment_id)) ? __("Save") : __("Add Comment") ?>" />
+				<?php if (!isset($comment_id) && !pkgbase_user_notify($uid, $base_id)): ?>
+					<span class="comment-enable-notifications">
+						<input type="checkbox" name="enable_notifications" id="id_enable_notifications" />
+						<label for="id_enable_notifications"><?= __("Enable notifications") ?></label>
+					</span>
+				<?php endif; ?>
 			</p>
 		</fieldset>
 	</form>
-- 
2.19.0


More information about the aur-dev mailing list