views:

186

answers:

7

I've wondered about this for some time now. I'm wondering webforums implement the option to highlight something you haven't read. How the forum knows.

Since most webforums have a function to show you all posts since your last visit, they must save the last time you visited one of their pages in your userdata in the database.

But that doesn't explain how individual topics are still highlighted after you've read just one.

+3  A: 

A many to many table connecting a user to a topic/post with flags for read/favorite etc.

Vasil
Which works but isn't very scalable
John Sheehan
+2  A: 

Many web forums store a huge list of the last time you looked at each topic you've looked at.

This gets out of hand quickly, but there are mitigations. See http://stackoverflow.com/questions/514232/determining-unread-items-in-a-forum/514302#514302

bobince
+1  A: 

Usually, this list of "unread" items only shows changes that have been made since the last time you logged out.

Use the user's last activity date/time to mark items as "unread" (any activity in a topic after that time is marked "unread"). Then store in a Session variable, a list of topic IDs that the user viewed since last login. Combining these two would give you a relatively accurate list of unread topics.

Of course this data would then be lost on log-out or session expire and the cycle would start again without sacrificing an unnecessary amount of SQL queries.

St. John Johnson
+1  A: 

On the custom forum I used to work with, we used a combination of your last visit time (updated every time you viewed another page - usually cookied), and a "mark read" button on each topic that added a date/time value to a SQL table containing your UserID, the TopicID and the Date/Time.

Thus to view new topics we would look at your last visit date and anything created after that point in time was a new topic.

Once you entered a topic any topic you had clicked "mark read" on would only show the initial topic and then any replies with a date/time added after you clicked the mark read button. If you have fewer viewers and performance to spare you could basically set it up to add an entry to the table for every topic the user clicks on, when they click on it.

TJ
+1  A: 

Keeping track of what posts a visitor has read is of course not that much of a big deal. Since it's highly likely that the number of posts a visitor read will be much less than the posts not read. So, if you know what posts a visitor has read, you also know what posts this visitor didn't read. To make this less computational intensive you'd normally do this only over a certain period of time, say the last two weeks. Everything before that time will be considered read.

Luke
A: 

Another option you have, and I have actually seen this done before in a vBulletin installation, is to store a comma separated list of viewed topic ids client-side in a cookie.

Server-side, the only thing stored was the time of the user's previous visit. The forum system used this in conjunction with the information in the user's cookie to show 'as read' for any topic where either

  • Last modified date (ie last post) older than the user's previous visit
  • Topic ID found in the user's cookie as a topic the user has visited this session.

I'm not saying it's a good idea, but I thought I'd mention it as an alternative - the obvious way to do it has already been stated in other answers, ie store it server-side as a relation table (many to many table).

I guess it does have the advantage of putting less burden on the server of keeping that information.

The downsides are that it ties it to the session, so once a new session is started everything that occurred before the last session is considered 'already read'. Another downside is that a cookie can only hold so much information, and a user may view hundreds of topics in a session, so it approaches the storage limit of the cookie.

thomasrutter
A: 

One more approach:

  • Make sure your stylesheet shows a clear difference between visited and non-visited links, taking advantage of the fact that browsers remember visited pages persistently.

For this to work, however, you'd need to have consistent URLs for topics, and most forum systems don't tend to do this. Another downside to this is that users may clear their history, or use more than one browser. This therefore puts this measure into the 'not highly reliable category'; you would probably just do this to augment whatever other measure you are using to track viewed topics.

thomasrutter