keep unread flags

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in here. No new MODs will be accepted into the MOD Database for phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.

Rating:

Excellent!
72
75%
Very Good
16
17%
Good
4
4%
Fair
0
No votes
Poor
4
4%
 
Total votes: 96

zeber
Registered User
Posts: 55
Joined: Thu Apr 03, 2003 8:17 pm

Post by zeber »

Merlin Sythove wrote: Another refresh *would* show it as unread

No-no, i just did some 20 refreshes during the post submission & finally achieved wholly read post, as it was before the fix. I'll try moving the block to some place in posting.php...
Zeber
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

I'm currently looking into solving the problem in another way, we may be barking up the wrong tree here. Please remember that the fix was a first attempt. There is another possible problem that may happen from time to time and that is that someone else posts a small message just before yours, and since your post will be set as the last read post, you will not have the previous post marked as unread. I always check that anyway, you know "see if someone posted together with me". Also, if THAT post is marked unread, then so will be yours, which is illogical. Anyway, when you get to the edges of the system, anomalies creep in (they do in any system... :D)

Summary so far for whoever is reading: the mod works fine, but if you do weird things like loads of refreshes, or posting at the same time as someone else, you may occasionally end up with a post that is marked read, even when you haven't seen it.
Need custom work done? Pimp My Forum!
FaKeOnE-rSe
Registered User
Posts: 31
Joined: Wed Jul 27, 2005 7:49 am
Location: Greece, Thessaloniki
Contact:

Post by FaKeOnE-rSe »

Hello there.Grats for this great mod.
A little help needed here.

OK. I installed this mod and it works fine, but the problem is that I also have installed simple subforums mod mod which doesn't works with the keep unread flags.

Here's what I mean: This mod is designed to create subforums. It uses 2 new images for the forum icons (the red and the unread, grey and orange). With the new icons that simple subforums mod uses, the forum icon with subforums in it, (this with the "+") is always shown as you have red it (with grey colour and not orange), even if it has new posts in it.

Help me :?
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

FaKeOnE-rSe wrote: ...I also have installed simple subforums mod mod which doesn't works with the keep unread flags...

I don't have access to my files here but isn't there an author's note in the mod about this?
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

asinshesq wrote:
FaKeOnE-rSe wrote:...I also have installed simple subforums mod mod which doesn't works with the keep unread flags...

I don't have access to my files here but isn't there an author's note in the mod about this?


Here's the author's code from keep unread:

Code: Select all

##			Similarly, if you want to run this with simple subforums, you need to make some additional modifications figured out by Wicher; go to
##			this post for a solution: http://www.phpbb.com/phpBB/viewtopic.php?p=2033623#2033623 (you may also want to check
##			here in case there is a new version of that mod: http://www.phpbb.com/phpBB/viewtopic.php?p=2090189#2090189 or directly at:
##			http://www.detecties.com/phpbb2018/viewtopic.php?t=15 )
FaKeOnE-rSe
Registered User
Posts: 31
Joined: Wed Jul 27, 2005 7:49 am
Location: Greece, Thessaloniki
Contact:

Post by FaKeOnE-rSe »

Thx wichie for your addition mod (keep unread). Works great!
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

OK, some theory. The main problem is that a refresh will set the tracking_time, which is the time when the user has collected all new posts for the purposes of displaying read/unread post icons.

It is possible that this tracking_time lands BETWEEN the beginning of saving a post, and the point where the post is actually available for retrieval in the database. This would later show this post as READ since its time is earlier than the new tracking_time. Both processes work independently from each other so a mismatch is possible.

One solution is to set the tracking_time not to 'now', but to the time of the last post in the database. The assumption is that if the post that is currently being made was not yet ready to retrieve for display, even though the time was set, then it won't be ready to retrieve its time either.

Zeber, if you're up to it, would you mind running a test?

1. Remove the block of code at the end of submit_post in functions_post.php, just before the return, the block that we added that sets the post time once more. Just put // in front of all lines there and save the file.

2. In includes/functions.php find

Code: Select all

$board_config['tracking_time'] = time();
and after it, add

Code: Select all

	//MOD Keep_unread: solving refresh bypassing new posts
 	$sql = "SELECT MAX(post_time) AS maxtime
	     FROM "  . POSTS_TABLE;
  if ( !($result = $db->sql_query($sql)) )
  {
     message_die(GENERAL_ERROR, 'Could not query latest post information', '', __LINE__, __FILE__, $sql);
  }
  $row = $db->sql_fetchrow($result);
  $board_config['tracking_time'] = $row['maxtime'];
This will set the tracking_time to the last / highest post in the database that can be retrieved at that point in time. Any post that is being processed / saved but not yet ready, whichever type of database is being used, should stay out of this at this point.

See if this solves the issue.
Need custom work done? Pimp My Forum!
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

And the second problem that someone pointed out to me: if a user posts a short message during the time that you are posting your long message. It doesn't really matter if this happens whilst you are writing, or whilst your long message is being processed into the database. The time up to when the topic is read, was set to 'now', to just after your own post, and that would cause you to miss the new but earlier post.

This is how to solve it. Note that this is experimental, I would appreciate feedback!

In posting.php find

Code: Select all

$board_config['tracking_unreads'][$topic_id]
and replace by

Code: Select all

     	 	$sql = "SELECT post_id, post_time
		    	FROM "  . POSTS_TABLE . "
				  WHERE post_time > " . $board_config['tracking_unreads'][$topic_id] . "
				  AND topic_id = $topic_id
					ORDER BY post_time
					LIMIT 1";
			  if ( !($result = $db->sql_query($sql)) )
			  {
			     message_die(GENERAL_ERROR, 'Could not query latest post information', '', __LINE__, __FILE__, $sql);
			  }
			  $row = $db->sql_fetchrow($result);
				if ($row['post_id'] == $post_id)
				{
          $board_config['tracking_unreads'][$topic_id] = $row['post_time'];
				}
And what it does is simple, it gets the next post after your current unread-time for that topic. If that post is your own, you have read the topic until that point. If not, do not alter the unread-time of this topic, which will leave the next post unread.

Feedback welcome!
Need custom work done? Pimp My Forum!
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Clever.

But merlin, I was thinking some more about the original problem and suddenly realized that perhaps the fix (artificially updating the timestamp for a post when the post is complete) does more harm than good.

A while back, I discovered that if the post with the largest post_id in a topic (last_post_id) has a timestamp that is not as great as a post with a lower post_id, that triggers the sync() function whenever any user happens to be looking at the last page of that topic. And if you have anything other than a tiny board, that causes the board to hang a fairly long time. And the sync actually fixes nothing, so for as long as it remains true that the post with the highest post_id has a timestamp less than some other post in the topic, users will continue to experience hangs (it's quite annoying). (Coincidentally, I discovered this using m2f, but that has nothing to do with the underlying problem.)

Notice that your fix for the refresh problem creates a real possibility that a post with a lower post_id has a higher timestamp and so your fix may run into the hang problem.

I suppose you might be able to work around the problem by changing the last_post_id for the topic to be whichever post has the latest timestamp after your fix is done (update the last_post_id in for the topic at the time you update the posttime for the post), but that seems pretty kludgie and I haven't thought about whether it might have other unintended consequences.

What do you think?
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

asinshesq wrote: Clever.

But merlin, I was thinking some more about the original problem and suddenly realized that perhaps the fix (artificially updating the timestamp for a post when the post is complete) does more harm than good.


Well, it should not be the end solution for the simple reason that the real problem is the user who is refreshing all the time, not the user who is posting. The user who is refreshing, is updating HIS timer for all the posts he has seen, and this sometimes happens in the middle of someone posting so the "refresher" has a problem. That is where the solution must be found.
A while back, I discovered that if the post with the largest post_id in a topic (last_post_id) has a timestamp that is not as great as a post with a lower post_id, that triggers the sync() function whenever any user happens to be looking at the last page of that topic.


Hmm, I can't find sync being called in any unusual way in viewtopic. Please explain.
Need custom work done? Pimp My Forum!
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Merlin Sythove wrote: Hmm, I can't find sync being called in any unusual way in viewtopic. Please explain.


I didn't say it was called in an 'unusal' way. I just said it was called. Viewtopic executes a sync when the last_post_id is no longer the last post by timestamp. I explain where in viewtopic that code appears in this post: http://www.mail2forum.com/forums/viewto ... 2288#12288
Aquillar
Registered User
Posts: 17
Joined: Tue Nov 08, 2005 3:59 am
Location: Canada
Contact:

Post by Aquillar »

I've searched around this topic but can't find an answer:

Is there a way to add a link to the bototm left of the topic (in the area under "watch this topic for replies") for marking the whole topic unread? It would say "mark topic unread" and would apply to the first post (and each underneath as your code already does).

Basically another way of clicking the mark unread button on the first post, but at the bottom as a link.
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

asinshesq wrote: Viewtopic executes a sync when the last_post_id is no longer the last post by timestamp.


Not quite: in viewtopic a sync is executed if the actual last post on the last page of a topic, is not the same one as listed as the last post in the database. So the ID's must be identical, but there is nothing to indicate that it has anything to do with the time.

This is the code you refer to:

Code: Select all

if ($postrow[$row_id]['post_id'] != $forum_topic_data['topic_last_post_id']...
So yes, if we in this mod alter the time of a post, making it the last one in a topic, and there has been a post in between that is listed as the last post of the topic, then there is a mismatch. The first user opening that topic page will trigger the sync, after that everything is fine, no further problems.

Unless sync() enters the highest post ID instead of taking the latest time as the last post, then sync needs correcting.
Need custom work done? Pimp My Forum!
Merlin Sythove
Registered User
Posts: 2339
Joined: Tue Mar 16, 2004 7:42 am

Post by Merlin Sythove »

Hmmm, sync has a problem, it does indeed seem to use the post_id as the order, exactly the problem that I encountered earlier. In my own forum I have apparently corrected that mistake but the 2.0.20 source code I have does this:

Code: Select all

$sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
FROM " . POSTS_TABLE . "
WHERE topic_id = $id";
and that is indeed wrong if you change the post time in any way, either manually or because of server post time errors or via code as above.

This is my code for the sync function, the case 'topic'.

Code: Select all

		case 'topic':
			$sql = "SELECT COUNT(post_id) AS total_posts
				FROM " . POSTS_TABLE . "
				WHERE topic_id = $id";
			if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
      $row = $db->sql_fetchrow($result);      
			$sql = "SELECT *
				FROM " . POSTS_TABLE . "
				WHERE topic_id = $id
        ORDER BY post_time ASC
        LIMIT 1";
			if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
			$row_first = $db->sql_fetchrow($result);
			$sql = "SELECT *
				FROM " . POSTS_TABLE . "
				WHERE topic_id = $id
        ORDER BY post_time DESC
        LIMIT 1";
			if ( !($result = $db->sql_query($sql)) ) message_die(GENERAL_ERROR, 'Could not get post ID', '', __LINE__, __FILE__, $sql);
			$row_last = $db->sql_fetchrow($result);
      			
		  if ($row_first && $row_last)
			 {
           if ($row['total_posts'])
				{
					// Correct the details of this topic
					//2.0.18: Added topic_poster and topic_time, adjusted id's 
					$sql = 'UPDATE ' . TOPICS_TABLE . ' 
						SET topic_replies = ' . ($row['total_posts'] - 1) . ', 
              topic_first_post_id = ' . $row_first['post_id'] . ', 
              topic_poster = ' . $row_first['poster_id'] . ', 
              topic_time = ' . $row_first['post_time'] . ', 
              topic_last_post_id = ' . $row_last['post_id'] . '
						WHERE topic_id = ' . $id;

					if (!$db->sql_query($sql))
					{
						message_die(GENERAL_ERROR, 'Could not update topic', '', __LINE__, __FILE__, $sql);
					}
				}
				else
				{
					// There are no replies to this topic
					// Check if it is a move stub
					$sql = 'SELECT topic_moved_id 
						FROM ' . TOPICS_TABLE . " 
						WHERE topic_id = $id";

					if (!($result = $db->sql_query($sql)))
					{
						message_die(GENERAL_ERROR, 'Could not get topic ID', '', __LINE__, __FILE__, $sql);
					}

					if ($row = $db->sql_fetchrow($result))
					{
						if (!$row['topic_moved_id'])
						{
							$sql = 'DELETE FROM ' . TOPICS_TABLE . " WHERE topic_id = $id";
			
							if (!$db->sql_query($sql))
							{
								message_die(GENERAL_ERROR, 'Could not remove topic', '', __LINE__, __FILE__, $sql);
							}
						}
					}

					$db->sql_freeresult($result);
				}
        //End of 2.0.18 update
        				
			}
			break; 
This is just for information only at this point, please do not copy this code into your forum, we're just discussing a possible problem with the sync function that may result from a temporary solution to a possible bug in Keep_unread!!!
Need custom work done? Pimp My Forum!
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Post by asinshesq »

Merlin Sythove wrote:
asinshesq wrote:Viewtopic executes a sync when the last_post_id is no longer the last post by timestamp.


Not quite: in viewtopic a sync is executed if the actual last post on the last page of a topic, is not the same one as listed as the last post in the database. So the ID's must be identical, but there is nothing to indicate that it has anything to do with the time.

You're not looking high enough up in viewtopic. The sql that creates $postrow[] is sorted by time. That means that the last element in $postrow[] ['post_id'] is the post_id of the post with the highest post_time.

If statement I quoted in my last post above compares the post_id of the last elelment in $postrow[]['post_id'] to the last_post_id of the topic. If the post_id of the last element in $postrow[]['post_id'] (i.e. that post_id of the latest post in the topic as measured by post_time) is not the same as last+_post_id of the topic, viewtopic calls sync (which is where the trouble comes from).

So I think I am correct that viewtopic does what I describe. Am I missing something?
Post Reply

Return to “[2.0.x] MOD Database Releases”