Check if a user has ever read a topic?

Started by samborabora, May 27, 2015, 08:17:35 AM

Previous topic - Next topic

samborabora

Quote from: Kindred on May 27, 2015, 02:09:30 PM
well, for one...   the system already performs part of what you are asking.... in your description, you are essentially doing exactly what the <NEW> icon already DOES...

When you start adding things to it is when it beomces more expensive...   you ONLY want to show the "read unread" link when a user HAS unread posts?   
That query alone is one of THE MOST EXPENSIVE queries in the entire system....   and you want to do that query on EVERY page?

I only want to show the "read unread" link when a user HAS unread posts AND they have already visited the topic.

Quote from: Burke ♞ Knight on May 27, 2015, 02:15:21 PM
Really? Sure looks like you said earlier, that you were.

Sorry, mark as read is available, but I also only want that avilable on messageindex if the user has visited the topic. If they want to fiddle urls, okay, I don't care.

Quote from: margarett on May 27, 2015, 02:20:22 PM
It's not that simple...
If $context['topics'][topic_id_here]['new'] then the topic *has unseen messages*. But the user might have visited the topic already, yet new replies were posted after his last visit.

So I guess that you do need to perform a new check, yes. Potentially an expensive one, as it requires a COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

So, id_topic keeps track of if a topic has ever been seen or not? What sql query would be needed for this?

samborabora

For instance, if the user has never clicked the topic, I won't show a marked as read or a "there are unread posts" link/text. However, if the topic has three pages, and the user clicks on page one of the topics or even page one and two, or just page two, since they never saw page three, NOW when they return to message index, they would now see "mark as read" and "there are unread posts" since they saw the topic, but didn't see the last page of the topic.

Pipke

you should use the mod i posted earlier, then tweak it on the logging page, you can check if the users last view topic time is lower then the last post on that certain topic inside that list, if so then the topic can (still) have the flag 'unread posts' in the topic.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Kindred

yup...   you are attempting to duplicate one of the most expensive queries in the system anf then add additional logic processing on top of that on every page load...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: Pipke on May 27, 2015, 02:41:50 PM
you should use the mod i posted earlier, then tweak it on the logging page, you can check if the users last view topic time is lower then the last post on that certain topic inside that list, if so then the topic can (still) have the flag 'unread posts' in the topic.

Definitely going to use it, just checking there wasn't already a function built-in to save me adding a package.

Quote from: Kindred on May 27, 2015, 02:45:15 PM
yup...   you are attempting to duplicate one of the most expensive queries in the system anf then add additional logic processing on top of that on every page load...

I mean, are queries THAT much of a problem in 2015? I could understand back in the message board golden days, but aren't processors and servers just a little bit more up to spec now for this kind of work?

samborabora

Quote from: margarett on May 27, 2015, 02:20:22 PM
It's not that simple...
If $context['topics'][topic_id_here]['new'] then the topic *has unseen messages*. But the user might have visited the topic already, yet new replies were posted after his last visit.

So I guess that you do need to perform a new check, yes. Potentially an expensive one, as it requires a COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

Would customising something to do it this way be better than using the suggested mod?

margarett

Which suggested mod? Sorry, I probably missed something...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair


samborabora

Quote from: margarett on May 27, 2015, 07:42:30 PM
Which suggested mod? Sorry, I probably missed something...

I can give this a go, I just want to make sure I'm not wasting time installing a package that's overdoing it for my purposes, on the other hand, if there ISN'T a way of doing this with existing functions or accessing the database, this mod should be perfect.

samborabora

margarett, what would be the easiest way of implementing your idea? It it a query that needs to go in Load and called as a variable?

margarett

It depends. I would say that it should go at Sources/MessageIndex.php. You get the list of topics per page (already exists), then perform the query to load the "seen/not seen" thing from all topics at once, then stuff the result in $context['topics'] again. That gives you that information in the list of topics (MessageIndex).
If you also want it in topic view, then you need to do it again in Display.php.

I still don't fully understand what you want to do with this information, though :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

samborabora

Quote from: margarett on May 28, 2015, 05:53:59 PM
It depends. I would say that it should go at Sources/MessageIndex.php. You get the list of topics per page (already exists), then perform the query to load the "seen/not seen" thing from all topics at once, then stuff the result in $context['topics'] again. That gives you that information in the list of topics (MessageIndex).
If you also want it in topic view, then you need to do it again in Display.php.

I still don't fully understand what you want to do with this information, though :P

:D Ahh, I think my modded theme is making it hard to convey what part I'm using. Okay. You know that "New" image that appears on topic titles in MessageIndex that have new posts? Okay, I'm basically not having that appear unless the user has read the topic. Only then, will it appear if there are new posts.

Kindred

I really don't mean to offend you... (which as always is a prelude to a comment which could be construed as offensive)

but that is a stupid piece of logic, IMO   Since someone has never read a topic, the entire topic is new - which means that the NEW icon is completely appropriate on a topic which you are now attempting to exclude it from...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

Quote from: Kindred on May 28, 2015, 06:26:23 PM
I really don't mean to offend you... (which as always is a prelude to a comment which could be construed as offensive)

but that is a stupid piece of logic, IMO   Since someone has never read a topic, the entire topic is new - which means that the NEW icon is completely appropriate on a topic which you are now attempting to exclude it from...

Or completely irrelevant since it's painfully obvious if they haven't read the topic that every post would be new. Being told it is new is a waste of time since everything to do with it is new to someone who hasn't seen it.

Kindred

and yet....   how do they KNOW that they haven't read the topic in the first place, if there is no indicator?


Seriously...     
200 topics in a board --
I read the top 3 and come back later...   
there are 3 NEW topics (which won't be marked, based on your logic)
ONE of the topics that I read has a new response and gets marked
the other two topics are not updated... but they are now 4 down in the list...

or even worse...
20 new topics when I come back
all three of the ones that I read before have responses...
but they are the only ones marked as new


if it's been 3 days since I visited -- there is a very good chance that I have NO IDEA which topics I have read and which ones I have not...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

samborabora

If all pages of the topic are read, the topic will be un-bolded, if there are unread pages, the topic will be bold. So the user will still know what topics are new, it just won't have a "New" image next to it since the new posts are as new to the user as the entire topic is, it will already be <strong>.

margarett

OK, I don't necessarily agree with that :P but that's your call and I'll respect that much.

So you only need it in MessageIndex.php. Eventually (because you just want to hide the "new" icon) you don't even need to touch MessageIndex.template.php
The logics that I outlined above should work. That will add you a (potentially expensive) query per page load and only when someone (not guest) is viewing MessageIndex.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Burke ♞ Knight

And this is where I state my mind finally, and step out.

1. This idea would be a major server strain issue.

2. The ideas behind this, is really not making a lick of sense.

3. The idea behind this, IMO is pointless, and not worth the time and resources to make happen.

4. I really think the OP needs to figure out what exactly they want, then post it more clearly, without contradicting one post with another.

Saying that, peace out all those involved in this topic. :)

samborabora

Quote from: margarett on May 28, 2015, 07:36:41 PM
OK, I don't necessarily agree with that :P but that's your call and I'll respect that much.

So you only need it in MessageIndex.php. Eventually (because you just want to hide the "new" icon) you don't even need to touch MessageIndex.template.php
The logics that I outlined above should work. That will add you a (potentially expensive) query per page load and only when someone (not guest) is viewing MessageIndex.

I appreciate what you are saying,  my "new" image is basically an image that says unread with a X mark next to it, when you click the X it marks unread posts as read, and I only want this to show for folks who have clicked on the topic. I've already got some pretty expensive calls but I'm trying some ideas out to see how we go. Since I'm so useless with neat SQL can you suggest what I should put into sources/messageindex? What should I use in Messageindextemplate as some sort of variable to wrap around the "new" image?

samborabora

Quote from: Burke ♞ Knight on May 28, 2015, 07:45:35 PM
And this is where I state my mind finally, and step out.

1. This idea would be a major server strain issue.

2. The ideas behind this, is really not making a lick of sense.

3. The idea behind this, IMO is pointless, and not worth the time and resources to make happen.

4. I really think the OP needs to figure out what exactly they want, then post it more clearly, without contradicting one post with another.

Saying that, peace out all those involved in this topic. :)

1. Noted.
2. Noted, I disagree.
3.Noted, though I doubt time and resource is an issue if it is a simple bit of code.
4. I used the wrong wording, I didn't contradict my own posts, necessarily.

Let's try again. I'd like a variable, say $context[user][seenpost] that
Quoteif (empty$context[user][seenpost])
echo 'there are new posts'

And the seenpost variable is sorted via, presumably, as margarett suggested
Quotea COUNT of id_topic WHERE id_topic = xxx AND id_member = your_member
If count is 0, then the topic as a whole was never seen by said user.

Does that look doable? If so, what SQL would be needed to pull this off?

Advertisement: