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