Author Topic: Coding a forum - Unread message tracking  (Read 1738 times)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Coding a forum - Unread message tracking
« on: May 09, 2011, 03:16:05 PM »
An in-game forum, for registered players only.
How to store notification of new posts (EDIT: I found out it's called "Unread message tracking", dunno why since it has nothing to do with messages :D)? I would love to avoid the horrors of "one table entry per each thread that was already read"...


Also, if you know any links related to this problem (I am unable to google anything).
« Last Edit: May 11, 2011, 02:07:55 AM by Chris »

Offline DV8

  • Level 10
  • *
  • Posts: 63
  • Reputation: +0/-0
    • View Profile
    • Shadowrun: Corrosion
Re: Coding a forum - new post notification
« Reply #1 on: May 10, 2011, 09:23:48 AM »
I remember when an online community I belong to switched from EzBoards to phpBB back in 2002. Both would highlight threads with new posts, but it was such a pain that phpBB didn't remember of individual threads whether you had seen them and marked them as old or not. phpBB kept record of which new threads you had seen, but probably did it through a session variable since all threads would be marked as old as soon as you closed your browser. If you want to persistently track it for individual threads, then I don't really see how you can get around keeping a record per user for every thread.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Coding a forum - new post notification
« Reply #2 on: May 10, 2011, 09:36:41 AM »
I only mind keeping each topic read status in separate database row (imagine there are 1000 topics on one board and someone click "MarkAllTopicsAsRead"...) Other solutions like cookies or maybe some single DB row entry for all topics are OK.

phpBB do not keep it in sessions, since these do not disappear after closing browser (but sometimes these disappear kind of randomly, sometimes when I refresh the page too much? I'm not sure what technique they used).

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Coding a forum - new post notification
« Reply #3 on: May 10, 2011, 01:44:24 PM »
It's been a while (so I may be mistaken) but I think Zeggy went though this some where in the forums :)
Creating online addictions, one game at a time:

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Coding a forum - Unread message tracking
« Reply #4 on: May 11, 2011, 02:09:58 AM »
Found it.
Topic: http://community.bbgamezone.net/code-help/custom-forum/
Wikipedia: http://en.wikipedia.org/wiki/Forum_software#Unread_message_tracking

Now that I know it's called "Unread message tracking" I can use the power of google :)

Quote
When a user creates an account, you create an array containing the id for each top-level posting. (It may help to have this array pre-built whenever a new topic is added and stored somewhere so it can just be selected and unserialized so you're only selecting 1 row not many thousands).

The array would store a value of true with a key matching the id of the top-level post.

Whenever a user visits a post, simply do:
unset ($unread [$top-levelId]);

When the user logs out (or is logged out by some method you perform: ie, cron), you serialize that array and datestamp it.

The next time the user logs in, that serialized array is called and unserialized and then you select only top-level postids for dates AFTER the date stamp on the array. Add those dates to the user's array and you've got a perpetual system.

When a user specifies 'mark a post as read' it's as easy as calling the same unset ($unread [$postId]).
Anyway, what you think about this solution?


Online Barrikor

  • Level 21
  • *
  • Posts: 248
  • Reputation: +3/-0
    • View Profile
Re: Coding a forum - Unread message tracking
« Reply #5 on: May 11, 2011, 02:19:28 PM »
Sounds pretty good...

If you've got a really active forum the $unread array might get a bit huge for users who log in but don't read much though.

Maybe this equates to the same thing, but what about saving postIDs for posts that are read after the date stamp instead of the unread ones?
« Last Edit: May 11, 2011, 02:22:51 PM by Barrikor »
Projects: Pith Framework (at 0.5), CactusGUI (at 0.3)

Offline toxin

  • Level 21
  • *
  • Posts: 231
  • Reputation: +4/-2
    • View Profile
    • Encore Montreal
Re: Coding a forum - Unread message tracking
« Reply #6 on: May 11, 2011, 07:44:14 PM »
I wonder how hard it would be to have an 'Op-out' feature working along with it. Say the board has a Spam section. Users could than choose to not have new post from it show up in their unread message section. This would be for user benefit not forums.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Coding a forum - Unread message tracking
« Reply #7 on: May 13, 2011, 05:20:31 AM »
Users could than choose to not have new post from it show up in their unread message section.
From experience, do not count on players setting such custom things. Sure, there will be big outcry of people who love that feature but when you check the DB and see who actually used the option it will be a really small portion of players. Most would be too lazy :D
Overall, design so it works ideal way without asking for user decisions.

I thought of a nice dirty trick. Include the timestamp in the topic URL. Then set different colours in CSS for link and visited... So each time there is a topic update it will be a new URL so the browser cache will see it as an unvisited link.

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Coding a forum - Unread message tracking
« Reply #8 on: May 13, 2011, 08:49:19 AM »
Here is a dirty trick....

Could you store the 'highest seen threadID' in a cookie and reference it?

That way, if a new thread is open, it will contain an ID higher than the value stored in the cookie, and will be displayed as new until you read it.

As you visit the thread and the highestIDSeen increases.... you'd drop items off your 'not viewed' log.

It wouldn't be 100% accurate.  But it also negates a new table in the db.

Offline Nox

  • Level 35
  • **
  • Posts: 767
  • Reputation: +12/-2
    • View Profile
Re: Coding a forum - Unread message tracking
« Reply #9 on: May 13, 2011, 12:59:49 PM »
@Chris: you could even do something like (not ccs3, should be css2.1)
Code: [Select]
.thread:link:before { content: url(./pcs/icon-unread.gif); /* ... */ }
.thread:visited:before { content: url(./pcs/icon-read.gif); /* ... */ }
it's pretty dirty but clever...important thing would be to redirect to a canonical url

@Cygnus this way if you read first one then all below would be marked as read...
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Coding a forum - Unread message tracking
« Reply #10 on: May 13, 2011, 01:03:59 PM »
@Cygnus this way if you read first one then all below would be marked as read...

This is true.  Hence, 'wouldn't' be 100% accurate.

This could be expanded on such that you group post together, and you store the highest read threadID per groupID in a cookie (ie, in an array).  

From here, if you read the most recent post in a group, all others in that group would be marked as read.  It wouldn't be perfect, but its low overhead for a fairly decent presentation.

Offline etentum

  • Level 1
  • *
  • Posts: 1
  • Reputation: +0/-0
    • View Profile
Re: Coding a forum - Unread message tracking
« Reply #11 on: May 31, 2011, 02:11:58 PM »
This topic is a couple weeks old but I thought I'd bring it up again because I'm working on the same problem right now. I'm going to implement the way phpBB does it, which is outlined in this text document I found http://ozguvenemlak.org/contrib/readme_files/technical_notes.txt

The benefits of this method allow unread topics to exist from session to session. It also wipes the database clean when users have read through all topics. The downside is you may get a lot of entries for users reading through an old forum, but I believe most users would probably go "mark forums read" at a certain point, which would wipe those entries out again.

Quote
1.   Summary of the database entries phpbb3 makes to track unread posts via the database

   a.   clicking "mark forums read" link on index page:

      -   sets user_lastmark for the user in the users table to the current time

      -   wipes out all entries for the user in the forums_track table

      -   wipes out all entries for the user in the topics_track table

   b.   clicking "mark topics read" link on viewforum page for a forum:

      -    sets mark_time for the user and that forum
         in the forums_track table to the current time

      -    wipes out all entries for the user and that forum
         in the topics_track table

   c.   opening up existing topic that is already read

      -    does nothing

   d.   opening up an existing topic that is unread:

      -   via the markread() function, sets mark_time for the user and that topic
         in the topics_track table to the post_time for the last post of the last page
         in the topic that the user read

      -   if there are no other unread topics in the relevant forum,
         then via the update_forum_tracking_info() function:

         -   sets mark_time for the user and that forum
            in the forums_track table to the post_time for the last post
            in the relevant forum

         -   wipes out all entries for the user and the relevant forum
            in the topics_track table

   e.   new topic or reply to existing topic:

      -   via the markread() function, sets mark_time for the user and that topic
         in the topics_track table to the post_time for the new topic or reply

      -   if there are no other unread topics in the relevant forum,
         then via the update_forum_tracking_info() function:
      
         -   sets mark_time for the user and the relevant forum
            in the forums_track table to the post_time for
            the last post in the relevant forum

         -   wipes out all entries for the user and the relevant forum
            in the topics_track table

Offline chrisjenkinson

  • Level 10
  • *
  • Posts: 61
  • Reputation: +0/-0
    • View Profile
    • Xiphos
Re: Coding a forum - Unread message tracking
« Reply #12 on: May 31, 2011, 03:48:20 PM »
That is a useful post etentum, thanks. I'm going to be working on this myself for the threaded forums I'm writing (https://github.com/chrisjenkinson/sfMaraePlugin).


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal