Posted by starkos on February 12, 2009 at 7:36pm
| Project: | Watcher |
| Version: | 6.x-1.0-beta3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (works as designed) |
Issue Summary
I added a checkbox to the node and comment authoring forms: "Notify me of replies or changes to this post". This saves a step when creating new content, enabling a subscribe (or unsubscribe) at the same time as the content is posted. It also helps people who are using to another system (like Wordpress, phpBB, or every system that isn't drupal) that uses similar checkboxes.
It didn't take much code (for D6):
<?php
function _watcher_node_form_submit($form, &$form_state) {
global $user;
$form_id = $form['form_id']['#value'];
if (preg_match('/_node_form$/', $form_id) || $form_id == 'comment_form') {
$nid = $form_state['values']['nid'];
if ($form_state['values']['watcher_enable']) {
_watcher_user_set_watching_node($nid, $user);
} else {
_watcher_user_unset_watching_nodes(array($nid), $user);
}
}
}
function watcher_form_alter(&$form, $form_state, $form_id) {
global $user;
if (preg_match('/_node_form$/', $form_id) || $form_id == 'comment_form') {
$nid = $form['nid']['#value'];
if ($user->uid && user_access('use watcher') && (!$nid ||_watcher_node_type_enabled($nid))) {
// See if the user is already watching this node
$watching = _watcher_user_is_watching_node($user, $nid);
// Add "Notify me..." checkbox to the form
$form['watcher_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Notify me of replies or changes to this post'),
'#default_value' => $watching,
);
// Add a submit hook to process the checkbox
$form['#submit'][] = '_watcher_node_form_submit';
}
}
}
?>
Comments
#1
There are already settings for this in the user settings, it makes the user automatically watch any node he or she creates or comments on. You can set them as defaults for all users if you like.
Thanks for sharing but I won't implement this as with it, Watcher will be just more or less a clone of all existing notification modules. I will however consider adding some text to comment forms informing users if autowatching is enabled, providing a link to their settings page.
#2
This isn't autowatching. This is giving the user the *option* to watch a node at the time they author it, or add a comment to it. Otherwise a user has to author a node/comment, submit it, and then find and click the "watch" link.
Or, turn on autowatching, and then find and click "Stop watching" for every post they don't intend to follow.
Not a big deal if you don't want to integrate it; it is easy enough to tack on after the fact. Sure seems like an easy win to me, especially for visitors accustomed to other systems where this presentation is the norm.
#3
You make a good point. I'll find a way to implement this that rhymes well with the overall design. I want to keep Watcher as lean as possible and with all feature requests popping up, I try my best to be strict about what I add.
Thanks for your input!
#4
Upon further testing, I discovered that the code above has a number of glaring holes (d'oh - I should have slept on it before I posted). There is a new, improved version attached which addresses the obvious flaws and seems to work under all submit combinations I could think up.
I appreciate you considering it for inclusion into your module, and I understand what you mean about keeping it lightweight. To that end, I've packaged it up as a separate module "watcher_checkboxes", in addition to the other fixes I mentioned.
#5
WOuld this work for D5?
#6
@starkos: would the Comment Notify module work for what you need? http://drupal.org/project/comment_notify
#7
I'll look into implementing this. Stay tuned.
#8
I'm tuning in :-) Is this feature coming in a dev version?
#9
If you really want this feature, seek me out here at Drupalcon Paris and buy me a beer and we'll do some coding. :) You'll find me, or someone who knows how to find me, at the NodeOne table in the sponsors room.
#10
I guess there was no beer? ;)
I also think this would be a great addition.
From fitst-hand experience on a site with watcher and a lot of comments everyday:
According to the many comments versus the amount of people who are actually watching posts, my guess is many people who post a comment overlook the watcher-link, don't understand it, or don't complete the form (anonymous users).
And extra checkbox below the comment-form would solve this, because anonymous users wouldn't have to leave their contact info twice.
#11
@askibinski, @yngvewb - I've been using the module in #4 for months now with no trouble. It isn't part of the official release, of course, but it has been working well nevertheless.
@scottrigby - I looked at Comment Notify, but discarded it. Off the top of my head, I think it required a comment before your could follow, and I liked the Watcher presentation better. It has been a long time since I looked at it though, and I could be remembering incorrectly.
#12
@starkos allright, but will Solipsist welcome a patch which implements the functionality of #4 so this could be a part of the official release ?
#13
Sure, go ahead. A patch would be most welcome. Please diff against CVS. I'll try and get some time to spend on Watcher and my other modules so this gets in.
#14
I kind of like the fact that it is a separate module, and can be turned on or off. Could it be kept as-is, and included in the watcher package (like the way CCK includes separate modules for all the different field types)?
#15
One of the best features of Watcher is the ability for anonymous users to subscribe for notifications.
In this case, this (Great) feature\module will not only not help, but will confuse.
It would be great if :
a. when anonymous user publish comment\node she will be prompt with the watcher form to submit her E-mail address.
or
b. if the user submitted her E-mail address in the comment form she will only have to enable the checkbox to be notified (this will be a problem with anonymous node creation that doesn't offer E-mail submission)
#16
FWIW, until anonymous watches verify the email address (the same way drupal does for new user accounts) they are just asking to be spammed. As an anonymous user I can plug in any email address--or hundreds of them using a script--then submit my spam as a comment on that article. It gets emailed to everyone. Script and repeat, easy spam gateway using your site. Just something to keep in mind before turning on that particular feature.
Still love this module for everything else it does, though.
#17
This is true... BUT we have other tools to prevent spam like mollom and captcha.
Saying this feature shouldn't be enabled for anonymous just to prevent spam is like not giving them access to the registration page just to prevent spam.
I'm afraid a lot of users will prefer passing captcha 30 times but not registering once, go figure...
this is why on my last project I put a lot of effort in allowing but not forcing users to register and this module is just perfect for this.
This feature will make it easier for users to opt-in for watching during the node creation or commenting process, witch makes a lot of sense IMHO - I believe the average user expects to be registered for watching after commenting to a node and will not think about clicking the toggle link, so making this an OPTIONAL part of the commenting or node creation process is absolutely right.
#18
Thanks starkos for the module; I patched it so the default state of the checkboxes reflect the users "Watch Automatically" settings.