Site Notes

About Bloody Time: RTH Gets Threaded Comments

By Ryan McGreal
Published January 27, 2011

this blog entry has been updated

Back in April, 2008, I optimistically wrote that we would update the commenting system to allow threaded comments "in the near future". (Not surprisingly, I wrote this in response to a nasty troll.)

Today I'm happy to announce that, almost three years later, RTH finally has the threaded comments I've been promising all this time.

The way it works is pretty simple:

Try it out and let me know if you run into any problems.


Update: Some people have reported that they need to refresh their browser a couple of times before the reply buttons and comment thread collapse work properly. This is because browsers often store local copies of frequently-used web page files (like javascript files and stylesheets) so they don't need download those files every time.


Update 2: According to RTH reader seancb, you may need to hold down the shift button while refreshing to force the browser to fetch new copies of the javascript and stylesheet files from the server.


Update 3: I have implemented the ability to switch between nested comment threads and the original flat comments. At the top and the bottom of the comment list are links to View Comments in Nested or Flat format.

The site saves your selection as a cookie so that subsequent pages will be served in your preferred format. This should work for both registered users and for anonymous visitors, as long as you have cookies enabled.


Update 4: I just realized that a child comment of a comment that gets deleted would be orphaned. I've updated the code so that child comments of a comment about to be deleted are attached to the parent comment (or to the OP root if there is no parent comment).


Update 5: I updated the code so that even if you're viewing comments in Flat view, you still get a link to the parent comment of a reply.

Ryan McGreal, the editor of Raise the Hammer, lives in Hamilton with his family and works as a programmer, writer and consultant. Ryan volunteers with Hamilton Light Rail, a citizen group dedicated to bringing light rail transit to Hamilton. Ryan writes a city affairs column in Hamilton Magazine, and several of his articles have been published in the Hamilton Spectator. He also maintains a personal website and has been known to post passing thoughts on Twitter @RyanMcGreal. Recently, he took the plunge and finally joined Facebook.

59 Comments

View Comments: Nested | Flat

Read Comments

[ - ]

By Ryan (registered) - website | Posted January 27, 2011 at 21:24:10

This is a comment.

Permalink | Context

By Ryan (registered) - website | Posted January 27, 2011 at 21:24:22 in reply to Comment 58452

This is another comment in reply to my previous comment.

Permalink | Context

By IE6 / Win XP (anonymous) | Posted January 28, 2011 at 11:30:11 in reply to Comment 58453

This is a reply from Internet Explorer 6 on Windows XP.

Anonymous screen name and math question input fields are tiny, but it seems to work.

Permalink | Context

By IE6 / Win XP (anonymous) | Posted January 28, 2011 at 11:30:26 in reply to Comment 58551

Yes, it works.

Permalink | Context

By MattM (registered) | Posted January 27, 2011 at 21:31:14 in reply to Comment 58453

This is a reply to your reply to a comment.

Permalink | Context

By UrbanRenaissance (registered) | Posted January 28, 2011 at 10:01:28 in reply to Comment 58456

This is a reply to your reply to his reply to a comment.

Permalink | Context

By Mogadon Megalodon (anonymous) | Posted January 27, 2011 at 21:30:19 in reply to Comment 58453

Eureka!

Permalink | Context

[ - ]

By GrapeApe (registered) | Posted January 27, 2011 at 21:30:11

How do we track replies now? Edit - reply did not work for me. Is this browser specific?

Comment edited by GrapeApe on 2011-01-27 21:31:09

Permalink | Context

By GrapeApe (registered) | Posted January 27, 2011 at 21:32:38 in reply to Comment 58454

Oddly, it works now. Cool

Permalink | Context

By Ryan (registered) - website | Posted January 27, 2011 at 21:39:38 in reply to Comment 58457

Your browser may have been caching the older javascript file for a bit.

Permalink | Context

[ - ]

By Ryan (registered) - website | Posted January 27, 2011 at 21:42:33

I'll have to watch page load performance for pages with very large numbers of comments. The threading does require more processing than a flat list, and I may need to optimize it at some point.

Permalink | Context

[ - ]

By jason (registered) | Posted January 27, 2011 at 21:55:40

nothing happens when I hit 'reply'. I'm on Safari for Mac

Permalink | Context

By jason (registered) | Posted January 27, 2011 at 21:55:57 in reply to Comment 58462

ok, I can reply to my own comment, but not another comment.

Permalink | Context

By Ryan (registered) - website | Posted January 27, 2011 at 22:16:03 in reply to Comment 58464

It might not work right away due to caching in your browser. Try it again. I've got it working in Firefox 3.6.13 and Chromium 8.0.552.237 (70801), both running on Ubuntu 10.04. Chromium is based on the same rendering engine as Safari, so it should work the same.

Comment edited by administrator Ryan on 2011-01-27 22:17:30

Permalink | Context

By jason (registered) | Posted January 27, 2011 at 22:40:17 in reply to Comment 58474

there we go. Thx

Permalink | Context

By grapusapus (anonymous) | Posted January 27, 2011 at 22:07:52 in reply to Comment 58464

works for me

Permalink | Context

By moylek (registered) - website | Posted January 28, 2011 at 08:24:47 in reply to Comment 58470

And for me?

Edit: Yes.

Comment edited by moylek on 2011-01-28 08:25:01

Permalink | Context

[ - ]

By mrgrande (registered) | Posted January 27, 2011 at 21:55:43

Hey Ryan, sorry I wasn't of (any) help with this. I got an implementation working in C# and was trying to port it to Python, but was having troubles getting Python working on my compy.

Looks great! Did you opt to do most of your ordering/arranging in the DB, or is it mostly in the code?

Permalink | Context

By Ryan (registered) - website | Posted January 27, 2011 at 22:14:26 in reply to Comment 58463

No worries - I appreciate you taking a look at it. It actually ended up being quite simple to implement, once I sat down and took a good look at it.

  • The comments table has a parent_id column which either has the comment_id of the parent or 0 for an OP.

  • The query just pulls the comments in ascending order by comment_id. I didn't end up using self-joins or any of that.

  • The Python code:

    • Dumps the comments recordset into a list.
    • Pulls all the OPs into a second list and assigns them an indent of 0.
    • Takes a second pass through the remaining comments (all replies) and inserts them in the second list after the parent, incrementing the indent value by 1 over the parent's indent.
    • When the code renders the comments into HTML, it gives each comment a left-indent of 20 * indent pixels.

The rest is done in the client using a bit of javascript (based on jQuery).

You can see a demo of the code here.

Comment edited by administrator Ryan on 2011-01-27 22:15:34

Permalink | Context

[ - ]

By hammy (anonymous) | Posted January 27, 2011 at 22:51:16

Comments with a score below -5 are hidden by default.

You can change or disable this comment score threshold by registering an RTH user account.

Permalink | Context

By mbeacon (anonymous) | Posted January 28, 2011 at 10:25:08 in reply to Comment 58491

And whom can afford to waiste thyme like that?

(Gratuitous comment not intended to feed troll. Just a way to try out new system.)

Permalink | Context

By Undustrial (registered) - website | Posted January 27, 2011 at 23:33:44 in reply to Comment 58491

Didn't work, then I refreshed and it did. Strange. Older Ubuntu with firefox.

What's a "waiste"?

Permalink | Context

By drb (registered) - website | Posted January 27, 2011 at 23:57:36 in reply to Comment 58506

Damn, can get the reply to work. I've tried refresh, and shut down and re-started.

Any way Undustrial, your waiste is the indentation above your hipes. A waiste of time is the narrow part of an hour glasse.

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 06:10:07 in reply to Comment 58507

What operating system and which browser and version are you using?

Also, did you try refreshing a couple of times? It may be that your browser is using a locally cached version of the javascript and stylesheet files for the site.

Permalink | Context

By drb (registered) - website | Posted January 28, 2011 at 11:15:01 in reply to Comment 58513

Hi Ryan, trying it in firefox.

Permalink | Context

[ - ]

By mrjanitor (registered) | Posted January 28, 2011 at 01:09:32

Can't reply. I use Flock as my browser, is that the issue?

Permalink | Context

By rednic (registered) | Posted January 28, 2011 at 07:45:57 in reply to Comment 58509

one of the .1% ! Flock ( on the mac) uses webkit to trender the pages which is the same engine as safari.. so it should work since im posting reply with safari

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 06:06:17 in reply to Comment 58509

What operating system and which version of Flock are you using?

I just installed and tested Flock 3.5 on Windows XP and it's working for me.

Try refreshing a couple of times - it may be that your browser is using a locally cached version of the javascript and stylesheet files for the site.

Permalink | Context

By browser_test (anonymous) | Posted January 28, 2011 at 06:04:24 in reply to Comment 58509

Testing reply with Flock 3.5 on Windows XP.

Permalink | Context

By mrjanitor (registered) | Posted January 28, 2011 at 12:15:22 in reply to Comment 58510

Thanks everybody! Updated from 1.1 to 3.5... yeah, I know! Works great, have to get used to the new features now.

Permalink | Context

[ - ]

By adrian (registered) | Posted January 28, 2011 at 09:15:44

Nice feature!

Suggestion: drop the [ - ], it's distracting and it's not obvious what it's supposed to represent.

Also, there are too many boxes going on. This design needs to be de-boxified!

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 09:22:42 in reply to Comment 58531

Thanks for the feedback - agreed. Next item on my list is finally to implement the new RTH layout. I promise it won't take three years this time, but I am embarrassed that it's not already done. :(

Permalink | Context

[ - ]

By highwater (registered) | Posted January 28, 2011 at 10:28:03

No! I hate change!

Permalink | Context

[ - ]

By highwater (registered) | Posted January 28, 2011 at 10:28:47

Ok. that was actually a test. clearly reply not working for me either.

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 10:34:45 in reply to Comment 58540

Did you try refreshing the page a couple of times?

If so, what operating system and browser / version are you using?

Permalink | Context

By highwater (registered) | Posted January 28, 2011 at 12:03:36 in reply to Comment 58542

Well whaddaya know. Working now.

Mere thanks cannot convey my appreciation for everything you do, especially given the 'defamation' shitstorm you just had to deal with. I don't know how you do it, but I think the next feature you add should be a tip jar.

Permalink | Context

By Michelle Martin (registered) - website | Posted January 28, 2011 at 13:17:58 in reply to Comment 58561

I second the tip jar

Permalink | Context

[ - ]

By mrjanitor (registered) | Posted January 28, 2011 at 12:31:19

OK, this is how I was using RTH, especially when there was a hot topic getting lots of rapid posting. I'd surf other sites for a while, refresh RTH and see if the comment count on the hot topic went up. If comment count went up then I'd scroll to the bottom of the article and read the new content. Now I don't really know where that new content is. It could be anywhere. Imagine one of those 230 comment stories, where are the new comments using the new system? I guess I'm going to have to re-read the whole comment thread to look for anything new. I'm not sure if this is going to be the way to go, I'll give it a fair chance for sure... but I'm a little worried about it.

Permalink | Context

By seancb (registered) - website | Posted January 28, 2011 at 12:52:56 in reply to Comment 58572

I was just thinking the same thing... how do you find the unread comments? Maybe there needs to be a n option to display in non-threaded mode that just lists comments chronologically. or the threads should be listed in order of "most recently received a comment" so the threads with the most recent activity are floated to the top?

Permalink | Context

By Pxtl (registered) - website | Posted January 28, 2011 at 13:32:44 in reply to Comment 58578

This is the problem. Sites that have threaded comments end up with a myriad of tools to manage tracking replies and re-sorting and re-jiggering the commentary.

As a programmer, I can totally see the appeal of wanting a formalized solution to the @suchandsuch convention that most flat commentary systems use, but threaded, imho, creates more problems than it solves unless you're willing to put in the terriffic amount of work it takes to put it all together.

Even old hands at nested commentary like Reddit and Slashdot have a lot of warts in their systems.

Perhaps a flat view that includes a brief header over replies that includes the name and a truncated expandable version of the parent post would work, duct-taping the posts together without the header if the child is chronologically adjascent to the parent... but that would be a fair bit of UI work.

Permalink | Context

By mrjanitor (registered) | Posted January 28, 2011 at 14:26:38 in reply to Comment 58592

Pxtl,

Would a 'mark as read' button that would change the header colour on each comment be a difficult patch to put in. Also, do you think it would really do any good for the usability of the comment section? Just some ideas to make things work.

Permalink | Context

By Pxtl (registered) - website | Posted January 28, 2011 at 14:29:59 in reply to Comment 58616

To clarify, I'm not a contributor here - my previous comment must've suggested that I am. I have no idea what Juju Ryan uses to keep this site running.

I'm just spitballing ideas same as you, from my own knowledge of software development.

But a mark-as-read button would probably be simple to implement, but might be too crude to be useful in a substantial thread, so then you need a mark-all-as-read... and if you forget to use it and come back, and wish to read new commentary, you're still hosed. Either way, like I said - websites with nested commentary need a myriad of tools to make it sensible.

Permalink | Context

By mrjanitor (registered) | Posted January 28, 2011 at 14:43:12 in reply to Comment 58618

Pxtl,

Yes, I know, I was just looking for an experts general opinion. I know Ryan and Adrian work all of the voodoo that make this site such an enriching experience.

If I haven't said this in a while I'll say it now... thank you for creating and opening up this citizen's playground. Hamilton is so much better off due to the amazing efforts put into making RTH work the way it does!

Comment edited by mrjanitor on 2011-01-28 14:43:51

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 14:32:46 in reply to Comment 58618

Some great suggestions here. Certainly it wouldn't be hard to implement the ability to switch between flat and nested views.

Pxtl, what do you think about the reddit model? I'm thinking particularly of the exciting orange envelope.

Permalink | Context

By Pxtl (registered) - website | Posted January 28, 2011 at 15:12:31 in reply to Comment 58619

I am, of course, a big fan of the orangered. Except for the long load times it has exhibited since the Digg exodus.

It just seems that there are so very many little things you have to implement to make nested commenting work, that's why I'm not a fan. Orangereds and context-buttons and expanding comments that are too-deeply-nested and all that jazz. I suppose I really shouldn't worry about all that stuff for a site the size of RTH - it's not like you get five-figure-comment threads like Fark does.

Permalink | Context

By Ryan (registered) - website | Posted January 31, 2011 at 07:04:28 in reply to Comment 58631

I'm also working on implementing a Replies page so you can see a list of recent comments posted in reply to your comments.

I have a couple of queries that work (one uses a subquery and the other uses a self-join), but neither are optimized. I'm still trying to figure out how best to index the comments table to reduce the number of reads for each query.

Any MySQL optimization wizards out there? I'd appreciate any pointers.

Comment edited by administrator Ryan on 2011-01-31 07:38:37

Permalink | Context

By Ryan (registered) - website | Posted January 28, 2011 at 20:30:12 in reply to Comment 58631

FYI I just added functionality to switch between nested and flat comment view. The site saves your choice in a cookie so that subsequent pages are served according to your most recent selection. This should work for anonymous visitors as well as logged-in registered users, as long as you have cookies enabled in your browser.

Permalink | Context

[ - ]

By Pxtl (registered) - website | Posted January 28, 2011 at 13:14:52

sigh.

Well, different strokes for different folks. I've always preferred pure-chronological, but that's just me. I spent too much time on Fark in a past life.

Permalink | Context

[ - ]

By bobinnes (registered) - website | Posted January 28, 2011 at 20:03:46

kudos Ryan. PDC - pretty darn cool. Having a new appreciation for the coding involved, i'm curious as to the development/ history - any dimension you care to share. Way too ambitious for me!!! Cheers. Bob.

Permalink | Context

[ - ]

By mrjanitor (registered) | Posted January 30, 2011 at 13:22:11

Here is an example of the issues I am having with the comment system. I re-freshed and found the comments on this article Raise the Hammer Response to Mayor's Accusation went from 159 to 173. Great. I looked at the bottom and saw about 3 comments I had not read, the other 11 comments are god knows where in the stream and I have no intention of looking for them anymore. Others may be happy with this change, I am finding it is a huge hindrance to the usability of RTH.

Permalink | Context

By Ryan (registered) - website | Posted January 30, 2011 at 21:44:54 in reply to Comment 58773

You can now switch to flat view if you want the comments in their original layout.

Permalink | Context

By drb (registered) - website | Posted January 30, 2011 at 13:53:50 in reply to Comment 58773

I use the "latest comments" button in "site tools" to keep in touch with new comments and threaded replies. I dunno, it may help.

Permalink | Context

By goin'downtown (registered) | Posted February 01, 2011 at 14:01:25 in reply to Comment 58775

@drb, sorry to ask probably a stupid question, but where are the "site tools"?

Permalink | Context

By drb (registered) - website | Posted February 01, 2011 at 14:12:07 in reply to Comment 59029

No problem, on the right-hand side of the page beneath recent articles and and blogs.

Permalink | Context

By goin'downtown (registered) | Posted February 01, 2011 at 14:55:19 in reply to Comment 59031

Doh! Bifocals on the horizon. Bloody awesome, and thank you!

Permalink | Context

[ - ]

By goin'downtown (registered) | Posted January 30, 2011 at 22:51:40

Sorry to clog up the site with my little tech problems, but I can't "reply"- I have an error message at the bottom (left) of the screen:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; .NET CLR 2.0.50727; .NET CLR 3.5.30729) Timestamp: Mon, 31 Jan 2011 02:12:57 UTC

Message: 'attr(...)' is null or not an object Line: 98 Char: 5 Code: 0 URI: http://www.raisethehammer.org/static/scr...

I've refreshed, shift refreshed (that sounds vulgar), and deleted my browsing history. I'm on IE8 with Windows XP.

Permalink | Context

By Ryan (registered) - website | Posted January 30, 2011 at 23:32:02 in reply to Comment 58827

Test reply using IE8 / Windows XP.

Edit - Try refreshing again. It should work properly in IE8 now. (I upgraded to the newest version of jQuery and changed the queries so they play nicer with IE8.)

Comment edited by administrator Ryan on 2011-01-30 23:34:14

Permalink | Context

By goin'downtown (registered) | Posted January 31, 2011 at 12:49:09 in reply to Comment 58829

Eureka! Merci beaucoup.

Permalink | Context

[ - ]

By seancb (registered) - website | Posted June 14, 2011 at 09:36:40

Hey Ryan,

The threads are great but we REALLY need the most recent replied-to thread floated to the top.. threaded replies are easily lost otherwise!

There could be an option to turn that off if some people want... but I'd say that the default view should either be flat and chronological OR threaded with most recent threads floated up. threaded chronological is a tough one to follow...

Permalink | Context

View Comments: Nested | Flat

Post a Comment

You must be logged in to comment.

Events Calendar

Recent Articles

Article Archives

Blog Archives

Site Tools

Feeds