Gossamer Forum
Quote Reply
Marking as read
I added a tweak on my board to display all the posts below a thread, rather than just the subject list. It all works fine except none of the replies are marked read-- could you tell me which call in the flat view marks all replies read instead of just the root post, or is there some other way I can take care of it? Thanks :)


Realiiity.com Forums
Quote Reply
Re: [ellipsiiis] Marking as read In reply to
Alright, well I've played around with it and here's what I've come up with. Unfortunately, it's not a simple one-liner global, but actually 3 of them, due to speed issues and the complexity of keeping track of what's new and what's not.

The first global variable you'll need will be an initialization subroutine; make a global called 'mark_as_read_init' with the following as a value:

Code:
sub { @GForum::mark_as_read::inserts = (); return }


This basically initializes a global variable, in case you are running under mod_perl. You should put the appropriate template tag at the beginning of the page: <%mark_as_read_init%>

Next, you need a global subroutine to actually set posts as new. Call this one 'mark_as_read', with the following for the value:

Code:


sub {
return unless $SESSION and $USER;
my ($post_id, $forum_id, $root_id) = @_;
$root_id = $post_id if not $root_id;

my $data = $SESSION->data();
$data->{posts}->{$forum_id}->{$post_id} = time;
$data->{roots}->{$forum_id}->{$root_id} = time;

push @GForum::mark_as_read::inserts, [$USER->{user_id}, $post_id, $forum_id, $root_id];
return;
}


That basically sets the post to new for the current user, but doesn't save it because saving it would two queries per new post (which is the reason for using three globals). To call this one, you'll do this on the page, somewhere inside the post loop:

Code:
<%if post_new%><%mark_as_read($post_id, $forum_id, $post_root_id)%><%endif%>


Then the last thing you need to do is create a global subroutine to save the information, so create the following as global 'mark_as_read_save':


Code:
sub {
return unless @GForum::mark_as_read::inserts;
$DB->table('PostNew')->insert_multiple(['user_id_fk', 'post_id_fk', 'forum_id_fk', 'root_id_fk'], @GForum::mark_as_read::inserts);
$SESSION->save();
return;
}



To call this, put a tag <%mark_as_read_save%> at the end of the page.

Note that <%mark_as_read_init%> and <%mark_as_read_save%> should be each called only once, but <%mark_as_read_save(...)%> should be called for each new post.



Let me know if this works for you, or if you encounter any problems.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [ellipsiiis] Marking as read In reply to
Just a though - in GForum 1.1.1, you can put that in the globals for the 'common' template set and the global will be available for all template sets (assuming, when creating a new template set, you copy over the .tplinfo file - which you must do or the advanced editor won't work).

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [jagerman] Marking as read In reply to
Seems to work, thanks so much!


Realiiity.com Forums
Quote Reply
Re: [ellipsiiis] Marking as read In reply to
*Whew* Good to hear - I didn't test it before posting Wink

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com