Post Numbers

Reply view: Most recent post is numbered #1 - Post Numbers

Reply view: Most recent post is numbered #1

by holg3r » Wed Aug 02, 2017 8:29 am

Relevant version of extension: 1.1.1

In the reply view, the 15 most recent posts of the current topic are displayed.
The most recent one is displayed on top and erroneously is numbered #1 while all subsequent ones carry the correct number (in descending order).

This is not a duplicate of issue "Post appeared as #1 when it should have been #13".

Instead, it has to do with the "First Post On Every Page" extension by rxu which is installed in my board but not activated for the affected topic.

The following code snippet (lines 252-263 in file "event/listener.php") sets the first post to 1 on purpose, even when the sort order is chronologically descending:

Code: Select all

		// Compatibility with the First Post On Every Page extension by rxu
		if ($this->firstPostOnEveryPage !== null)
		{
			$this->firstPostOnEveryPage = null;

			// If posts are sorted ascending, we display #1 on all except the first page.
			// If posts are sorted descending, we always display #1.
			if (!$is_ascending || $start != 0)
			{
				return 1;
			}
		}
This works well for viewtopic and MCP topic review. But it seems to me that the reply view was not taken into account here -- for in that view, the "First Post On Every Page" extension does not repeat the topic's opening post. Instead, the post shown on top is the one posted most recently.


For my installation, I modified the above code snippet by extending line 259 from

Code: Select all

if (!$is_ascending || $start != 0)
to

Code: Select all

if ((!$is_reply_review && !$is_ascending) || $start != 0)

@kasimi: Is this the proper way how you would fix it?

Cheers
holg3r
holg3r
Registered User
Posts: 6
Joined: Thu Feb 09, 2017 9:23 am
Contact:

Re: Reply view: Most recent post is numbered #1

by kasimi » Wed Aug 02, 2017 4:06 pm

Yes, looks good. Thanks for bringing it to my attention. I'll add the fix to the next release.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Reply view: Most recent post is numbered #1

by holg3r » Thu Aug 03, 2017 10:27 am

Hi again

I just noticed that in addition to the reply view, the "First Post On Every Page" extension does not repeat the first page for the MCP topic review either (in contrast to what I wrote yesterday).
So it seems that extension only applies to the normal viewtopic views.

To take this into account, instead of the change I proposed in my previous post, I suggest these changes, all in the file "event/listener.php" of your extension:

Extend line 157 from:

Code: Select all

if ($post_num = $this->get_post_number($this->user->data['user_post_sortby_type'], $this->user->data['user_post_sortby_dir'], $this->user->data['user_post_show_days'], $event['row'], $event['topic_data']['topic_posts_approved'], $event['total_posts'], $event['start'], false))
to:

Code: Select all

if ($post_num = $this->get_post_number($this->user->data['user_post_sortby_type'], $this->user->data['user_post_sortby_dir'], $this->user->data['user_post_show_days'], $event['row'], $event['topic_data']['topic_posts_approved'], $event['total_posts'], $event['start'], false, true))
Extend line 183 from:

Code: Select all

if ($post_num = $this->get_post_number('t', 'd', 0, $event['row'], $event['total_posts'], $event['total_posts'], $event['start'], true))
to:

Code: Select all

if ($post_num = $this->get_post_number('t', 'd', 0, $event['row'], $event['total_posts'], $event['total_posts'], $event['start'], true, false))
Extend line 209 from:

Code: Select all

if ($post_num = $this->get_post_number('t', 'a', 0, $event['row'], $event['topic_info']['topic_posts_approved'], $event['total'], $event['start'], false))
to:

Code: Select all

if ($post_num = $this->get_post_number('t', 'a', 0, $event['row'], $event['topic_info']['topic_posts_approved'], $event['total'], $event['start'], false, false))
Extend line 229 from:

Code: Select all

protected function get_post_number($default_sort_by, $default_sort_dir, $default_days, $row, $approved_posts, $total_posts, $start, $is_reply_review)
to:

Code: Select all

protected function get_post_number($default_sort_by, $default_sort_dir, $default_days, $row, $approved_posts, $total_posts, $start, $is_reply_review, $is_viewtopic)
Extend line 259 from:

Code: Select all

if (!$is_ascending || $start != 0)
to:

Code: Select all

if ($is_viewtopic && (!$is_ascending || $start != 0))
For code consistency, insert a new line after line 226:

Code: Select all

	 * @param bool $is_viewtopic
Changing the signature of function get_post_number() like this is probably not the most elegant way. But it works.


I attach the file resulting from these changes.
Attachments
kasimi.zip
Fixed event/listener.php
(3.41 KiB) Downloaded 34 times
holg3r
Registered User
Posts: 6
Joined: Thu Feb 09, 2017 9:23 am
Contact:

Re: Reply view: Most recent post is numbered #1

by kasimi » Thu Aug 03, 2017 11:56 am

Thanks for the follow-up. Please test these changes: https://github.com/kasimi/phpbb-ext-pos ... ace682c477
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Reply view: Most recent post is numbered #1

by holg3r » Fri Aug 04, 2017 8:25 am

kasimi wrote:Thanks for the follow-up. Please test these changes: https://github.com/kasimi/phpbb-ext-pos ... ace682c477

I tested these changes.
Unfortunately, at least in my installation the results look wrong for two out of the three views:

(1) viewtopic:
In combination with "First Post On Every Page" extension, the repeated first post should be #1 -- but with your fix, it instead receives the consecutive number as if it were a normal post.

(2) review_reply:
The top post in this view (which is the one posted most recently in this topic) carries no number at all any more. The subsequent ones carry negative numbers -1, -2, -3.
Looks like the top post carries a null value as $post_num.
It probably only needs to be initialized with its correct number, then the subsequent posts will be numbered properly.

(3) review_mcp:
This view looks correct now.
holg3r
Registered User
Posts: 6
Joined: Thu Feb 09, 2017 9:23 am
Contact:

Re: Reply view: Most recent post is numbered #1

by kasimi » Fri Aug 04, 2017 10:00 am

My bad, forgot to set the property. With this fix added, it should work correctly.
https://github.com/kasimi/phpbb-ext-pos ... 7310f5498f

Thanks for testing.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Reply view: Most recent post is numbered #1

by holg3r » Fri Aug 04, 2017 10:14 am

Yes, numbering looks correct now for all three views.
And your fix is cleaner and more elegant than the solution I proposed, of course.
Thanx.
holg3r
Registered User
Posts: 6
Joined: Thu Feb 09, 2017 9:23 am
Contact: