Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Is there a way to make discussion marked as favorite after a post?

edited May 2011 in Vanilla 2.0 - 2.8
Use case:
X starts a new discussion OR X comments a discussion
-> I'd like to make X following this topic automatically
Tagged:

Comments

  • If X starts a new discussion I don't see why X should follow the discussion since the X can see what he has posted.

    If X comments, there is a cool plugin that solves your problem --> http://vanillaforums.org/addon/participated-plugin
  • Thank you. That plugin seems interesting but that's not really what I'd like.

    I configured Vanilla to send an email when a new comment arrived in a favorite discussion. My main goal is that users receive an email as soon as they are replied to their message.
    That's the reason I'd like to automatically "subscribe" users to any thread they comment.

    Any other suggestion is appreciated. Thanks.

  • AoleeAolee ✭✭
    have a work around for that ill email it to you tomorrow :)
  • That email function is quite crucial for low activity forums. It shortens delay between answers drastically. In fact, right now, I'd really like to be notified by email if anyone answers that thread.
    I think it's a must have feature for small and medium forums.
    If it doesn't exist yet, we'll develop it.
  • AoleeAolee ✭✭
    this is a bit ugly but working

    change this code at

    applications/vanilla/views/post/comment.php
    //$ButtonOptions = array('class' => 'Button CommentButton'); $ButtonOptions = array('class' => 'Button CommentButton', 'onclick' =>"if($('a.Bookmark').attr('title') == 'Bookmark'){ $('a.Bookmark').trigger('click') }");

    this will trigger the click on * when user hit the post button
  • Thank you a lot Aolee.
  • Nice.

    I'm on 2.0.13, and the code change is slightly different:

    echo $this->Form->Button($Editing ? 'Save Comment' : 'Post Comment', array('class' => 'Button CommentButton', 'onclick' => "if($('a.Bookmark').attr('title') == 'Bookmark'){ $('a.Bookmark').trigger('click') }"));

    I also copied the view from applications/vanilla/views/post/comment.php to themes/{my-theme}/vanilla/views/post/comment.php, which makes upgrades a little more resilient.

    It should also be noted that this is language dependant since it replies on looking for the title text "Bookmark" on the bookmark link. In our case the link was labelled "Keep me posted" and so that needed to be put into the string instead of "Bookmark". Other languages would need something similar done. There ought to be a way to pick on the translated text so it will always work.
  • judgejjudgej
    edited May 2011
    In fact, this works multi-lingual (on 2.0.13):

    echo $this->Form->Button($Editing ? 'Save Comment' : 'Post Comment', array('class' => 'Button CommentButton', 'onclick' => "if($('a.Bookmark').attr('title') == '" . T('Bookmark') . "'){ $('a.Bookmark').trigger('click') }"));

    Just make sure "Bookmark" is translated on the server before it is passed to the page as a JavaScript string. The string probably needs escaping, but this is my lazy attempt that works for me.
  • this is a bit ugly but working

    change this code at

    applications/vanilla/views/post/comment.php
    //$ButtonOptions = array('class' => 'Button CommentButton'); $ButtonOptions = array('class' => 'Button CommentButton', 'onclick' =>"if($('a.Bookmark').attr('title') == 'Bookmark'){ $('a.Bookmark').trigger('click') }");

    this will trigger the click on * when user hit the post button
    I have a similar requirement and I used your code which works except while creating new threads. This works perfectly fine when a user replies to existing thread, but when creating a new thread, it doesn't work.
  • AoleeAolee ✭✭
    edited May 2011
    this is a bit ugly but working

    change this code at

    applications/vanilla/views/post/comment.php
    //$ButtonOptions = array('class' => 'Button CommentButton'); $ButtonOptions = array('class' => 'Button CommentButton', 'onclick' =>"if($('a.Bookmark').attr('title') == 'Bookmark'){ $('a.Bookmark').trigger('click') }");

    this will trigger the click on * when user hit the post button
    I have a similar requirement and I used your code which works except while creating new threads. This works perfectly fine when a user replies to existing thread, but when creating a new thread, it doesn't work.
    that's a different story. but then amend this one for your case
    application/vanilla/controller/class.postcontroller.php line 199

    $this->FireEvent('AfterDiscussionSave');
    $this->DiscussionModel->BookmarkDiscussion($DiscussionID, $Session->UserID, $Discussion);//add this line to autobookmark new thread
  • Thanks. This works like a charm.
  • @Aolee, there is a bug with your code snippet. When a user comments on an already bookmarked discussion, it removes the bookmark because of the click trigger. How do I add this only if the discussion is not already bookmarked by the user?
  • Thank you.

    BTW, I realized that this feature is a standard: FaceBook notifies you by email as soon as someone replies to a conversation you've participated in. Maybe Vanilla should consider to add it in regular options.

    Cheers
  • AoleeAolee ✭✭
    edited June 2011
    @Aolee, there is a bug with your code snippet. When a user comments on an already bookmarked discussion, it removes the bookmark because of the click trigger. How do I add this only if the discussion is not already bookmarked by the user?
    Hi Ronald, it shouldn't be, because if the discussion is bookmarked the star becomes yellow and the title tag name changes from "Bookmark" to "Unbookmark"

    so the code will only trigger the click if the Star is grey , meaning if the title attribute seen is "Bookmark"

    if($('a.Bookmark').attr('title') == 'Bookmark'){ $('a.Bookmark').trigger('click') }

    You should double chech in the firebug what the title tag gives you when the dicussion is bookmarked and unbookmarked

    you could be using a diff theme?



  • AoleeAolee ✭✭
    sorry wrong terminology... it's title "attribute" not title "tag"
  • There is another way to do this without patching the vanilla code : you can do a plugin which react to event AfterDiscussionSave and AfterCommentSave
    public function PostController_AfterDiscussionSave_Handler(&$Sender) { $Session = Gdn::Session(); $Discussion = $Sender->EventArguments['Discussion']; $Sender->DiscussionModel->BookmarkDiscussion($Discussion->DiscussionID, $Session->UserID, $Discussion); } public function PostController_AfterCommentSave_Handler(&$Sender) { $Session = Gdn::Session(); $Discussion = $Sender->EventArguments['Discussion']; $Sender->DiscussionModel->BookmarkDiscussion($Discussion->DiscussionID, $Session->UserID, $Discussion); }
  • AoleeAolee ✭✭
    There is another way to do this without patching the vanilla code : you can do a plugin which react to event AfterDiscussionSave and AfterCommentSave
    public function PostController_AfterDiscussionSave_Handler(&$Sender) { $Session = Gdn::Session(); $Discussion = $Sender->EventArguments['Discussion']; $Sender->DiscussionModel->BookmarkDiscussion($Discussion->DiscussionID, $Session->UserID, $Discussion); } public function PostController_AfterCommentSave_Handler(&$Sender) { $Session = Gdn::Session(); $Discussion = $Sender->EventArguments['Discussion']; $Sender->DiscussionModel->BookmarkDiscussion($Discussion->DiscussionID, $Session->UserID, $Discussion); }
    this is better! :)
Sign In or Register to comment.