Repository: isso-comments/isso (language: python)

Issue:
[client] Option to enable email notifications by default
I would like to make the checkbox to get email notifications enabled by default instead of needing to manually click it.


Discussion / hints:
That would probably necessitate the introduction of a client-side preference via `data-isso-*` attributes, since not everyone would want that by default.
I can probably do this one as well with a pull request, I think it should be easy
Tracked in #846

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index a7b7f77ec..bca86a23d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -12,6 +12,8 @@ Changelog for Isso
 - Fix avatar sizing, limit default gravatar images to 55px (#831, l33tname)
   In case of a custom gravatar URL, the ``&s=55`` size parameter will have
   to be added, see `Gravatar: Image requests`_.
+- Add ``data-isso-reply-notifications-default-enabled`` option to configure
+  whether or not the subscribe to replies checkbox should be checked by default.
 
 .. _Gravatar: Image requests: http://en.gravatar.com/site/implement/images/
 
diff --git a/docs/docs/reference/client-config.rst b/docs/docs/reference/client-config.rst
index 6079fdfd7..1f89f8e86 100644
--- a/docs/docs/reference/client-config.rst
+++ b/docs/docs/reference/client-config.rst
@@ -20,6 +20,7 @@ preferably in the script tag which embeds the JS:
             data-isso-vote="true"
             data-isso-vote-levels=""
             data-isso-feed="false"
+            data-isso-reply-notifications-default-enabled="false"
             src="/prefix/js/embed.js"></script>
 
 Furthermore you can override the automatic title detection inside
@@ -142,6 +143,18 @@ data-isso-feed
     thread. The link will only be valid if the appropriate setting, in
     ``[rss]`` section, is also enabled server-side.
 
+data-isso-reply-notifications-default-enabled
+    Set to ``true`` to make the reply notifications checkbox on the postbox be
+    checked by default. Otherwise, the user will have to manually opt-in to
+    reply notifications.
+
+    This setting will have no effect if ``reply-notifications`` are not enabled
+    on the server.
+
+    Default: ``false``
+
+    .. versionadded:: 0.13
+
 
 Deprecated Client Settings
 --------------------------
diff --git a/isso/js/app/config.js b/isso/js/app/config.js
index 140ef3ce1..9e059c8a5 100644
--- a/isso/js/app/config.js
+++ b/isso/js/app/config.js
@@ -11,6 +11,7 @@ var config = {
     "require-email": false,
     "require-author": false,
     "reply-notifications": false,
+    "reply-notifications-default-enabled": false,
     "max-comments-top": "inf",
     "max-comments-nested": 5,
     "reveal-on-click": 5,
diff --git a/isso/js/app/templates/postbox.js b/isso/js/app/templates/postbox.js
index a59d6a1a2..99bfef9cb 100644
--- a/isso/js/app/templates/postbox.js
+++ b/isso/js/app/templates/postbox.js
@@ -1,8 +1,10 @@
 var html = function (globals) {
   var i18n = globals.i18n;
+  var conf = globals.conf;
   var author = globals.author;
   var email = globals.email;
   var website = globals.website;
+  var notify = conf["reply-notifications-default-enabled"] ? " checked" : '';
 
   return "" +
 "<div class='isso-postbox'>"
@@ -39,7 +41,7 @@ var html = function (globals) {
   + "</section>"
   + "<section class='isso-notification-section'>"
     + "<label>"
-      + "<input type='checkbox' name='notification' />" + i18n('postbox-notification')
+      + "<input type='checkbox'" + notify + " name='notification' />" + i18n('postbox-notification')
     + "</label>"
   + "</section>"
 + "</div>"


Test patch:
diff --git a/isso/js/tests/unit/postbox-reply-notif.test.js b/isso/js/tests/unit/postbox-reply-notif.test.js
new file mode 100644
index 000000000..918063900
--- /dev/null
+++ b/isso/js/tests/unit/postbox-reply-notif.test.js
@@ -0,0 +1,47 @@
+/**
+ * @jest-environment jsdom
+ */
+
+/* Keep the above exactly as-is!
+ * https://jestjs.io/docs/configuration#testenvironment-string
+ * https://jestjs.io/docs/configuration#testenvironmentoptions-object
+ */
+
+"use strict";
+
+// Set up our document body
+document.body.innerHTML =
+  '<div id=isso-thread></div>' +
+  '<script ' +
+    'src="http://isso.api/js/embed.min.js" ' +
+    'data-isso="/" ' +
+    '></script>';
+
+const isso = require("app/isso");
+const $ = require("app/dom");
+const config = require("app/config");
+const i18n = require("app/i18n");
+const template = require("app/template");
+template.set("conf", config);
+template.set("i18n", i18n.translate);
+
+test('Create Postbox with reply notifications disabled by default', () => {
+  var isso_thread = $('#isso-thread');
+  isso_thread.append('<div id="isso-root"></div>');
+  isso_thread.append(new isso.Postbox(null));
+
+  expect($('.isso-notification-section input[type="checkbox"]',
+           isso_thread).checked).toBeFalse;
+});
+
+test('Create Postbox with reply notifications enabled by default', () => {
+  var script_tag = document.getElementsByTagName('script')[0];
+  script_tag.setAttribute('data-isso-reply-notifications-default-enabled', 'true');
+
+  var isso_thread = $('#isso-thread');
+  isso_thread.append('<div id="isso-root"></div>');
+  isso_thread.append(new isso.Postbox(null));
+
+  expect($('.isso-notification-section input[type="checkbox"]',
+           isso_thread).checked).toBeTrue;
+});