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.
Options

Update Comments on Preview

R_JR_J Ex-FanboyMunich Admin

I'm really annoyed by not knowing if anybody had posted in the time that it takes to write an answer. I open up a discussion, start writing an answer and if I send my answer, I do not know if the comment I'm seeing is the most current one. Even after posting my comment, I might not see the complete discussion.

I would like to have a plugin that a) updates the discussion when I press preview and/or b) updates a discussion after I have sent my comment.
When I say "update" I just think of fetching comments from LastCommentID at the time I've opened the discussion to GDN_Discussion.LastCommentID and displaying them using the same functionality that is used to insert my comment. Maybe something like a MaxInbetweenComments settings so that if there are more than x comments in the meantime, the complete page get's refreshed, but if it is only say max 10 comments, then they will be fetched via an AJAX request and inserted.

I do not want anybody of you to write such a plugin for me (although I would not complain if anybody wants to), but I would welcome if anybody could help me.

In theory, I think that I will have to do the following:

  1. php: hook into some discussion event to insert a javascript file
  2. js: get the LastCommentID from current form and store it somehow
  3. js: "hook" (attach an event in js-speak?) to the preview button
  4. js: if preview is pressed, call a php function "GetNewComments(DiscussionID, LastCommentID)" (request /plugin/pluginname/getnewcommentids/DiscussionID/LastCommentID).
  5. php: GetNewComments(LastCommentID): NewComments = select CommentID from Discussion where DiscussionID = $DiscussionID and LastCommentID > $LastCommentID. Return CommentModel::Get(NewComments) and max(NewComments)
  6. js: LastCommentID = max(NewComments)
  7. js: insert html for new comments

Easier said than done...

  1. Easy! I could do that all by myself B-)
  2. Yeah, harder for me but I will manage that. I will have to read something about variable scope in js so that I will treat that variable right. Any help about that is welcome
  3. Should be no bigger problem with some research. Any warnings about probable pitfalls?
  4. Best way to store the results would be json, right?
  5. Again something that I'm nearly happy to do because I know how to do it!
  6. If I know how to store that var the way I can access it anytime with the correct value, that should be one easy step
  7. Hmm... I've found some code in discussion.js which is a starting point for my but by now I do not understand too much of it...
      // Post the form, and append the results to #Discussion, and erase the textbox
      var postValues = $(frm).serialize();
      postValues += '&DeliveryType=VIEW&DeliveryMethod=JSON'; // DELIVERY_TYPE_VIEW
      postValues += '&Type='+type;
      var discussionID = $(frm).find('[name$=DiscussionID]');
      discussionID = discussionID.length > 0 ? discussionID.val() : 0;
      var tKey = $(frm).find('[name$=TransientKey]');
      var prefix = tKey.attr('name').replace('TransientKey', '');
      // Get the last comment id on the page
      ...

There are 150 lines of code following and by now I cannot judge if they all are important/necessary for displaying a comment on the page.
So here's my most important question: does anybody now of a plugin that uses js to display a comment on the page so that I can steallearn from there? Or can draft the needed steps so that I can identify them in discussion.js?

Comments

  • Options
    hgtonighthgtonight ∞ · New Moderator

    This would be a great addition!

    There was a discussion about adding this to the core in the future, but I can't find the discussion ATM. I think it would be better/simpler/faster to just get that pages comments for the discussion and sort out any additions via JS. Definitely streamlines the db queries (so the could be cached).

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.