From 0b0309ce8f10e1f7f3a519d6d91408f8e9d35140 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 13 Feb 2020 23:40:00 -0500 Subject: [PATCH] Remove pager parameter from conversation() - Add getUrlParameter() Javascript function to determine current page --- include/conversation.php | 15 +++++++-------- mod/community.php | 2 +- mod/display.php | 2 +- mod/item.php | 2 +- mod/network.php | 2 +- mod/notes.php | 2 +- src/Model/Contact.php | 4 ++-- src/Module/Profile/Status.php | 2 +- src/Module/Search/Index.php | 2 +- src/Module/Update/Profile.php | 4 +--- view/js/main.js | 27 +++++++++++++++++++++++++-- 11 files changed, 42 insertions(+), 22 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 3707962576..d77e3b2f90 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -460,7 +460,6 @@ function conv_get_blocklist() * that are based on unique features of the calling module. * @param App $a * @param array $items - * @param Pager $pager * @param $mode * @param $update * @param bool $preview @@ -470,7 +469,7 @@ function conv_get_blocklist() * @throws ImagickException * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ -function conversation(App $a, array $items, Pager $pager, $mode, $update, $preview = false, $order = 'commented', $uid = 0) +function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) { $ssl_state = (local_user() ? true : false); @@ -506,7 +505,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ . (!empty($_GET['cmax']) ? '&cmax=' . rawurlencode($_GET['cmax']) : '') . (!empty($_GET['file']) ? '&file=' . rawurlencode($_GET['file']) : '') - . "'; var profile_page = " . $pager->getPage() . "; \r\n"; + . "'; \r\n"; } } elseif ($mode === 'profile') { $items = conversation_add_children($items, false, $order, $uid); @@ -525,7 +524,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ $live_update_div = '
' . "\r\n" . "\r\n"; + . "; var netargs = '?f='; \r\n"; } } } elseif ($mode === 'notes') { @@ -535,7 +534,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; + . "; var netargs = '/?f='; \r\n"; } } elseif ($mode === 'display') { $items = conversation_add_children($items, false, $order, $uid); @@ -544,7 +543,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
' . "\r\n" . ""; + . ""; } } elseif ($mode === 'community') { $items = conversation_add_children($items, true, $order, $uid); @@ -553,7 +552,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; + ."/?f='; \r\n"; } } elseif ($mode === 'contacts') { $items = conversation_add_children($items, false, $order, $uid); @@ -562,7 +561,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ if (!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; + ."/?f='; \r\n"; } } elseif ($mode === 'search') { $live_update_div = '' . "\r\n"; diff --git a/mod/community.php b/mod/community.php index 7aa00240b7..b95d13654c 100644 --- a/mod/community.php +++ b/mod/community.php @@ -200,7 +200,7 @@ function community_content(App $a, $update = 0) $s = $r; } - $o .= conversation($a, $s, $pager, 'community', $update, false, 'commented', local_user()); + $o .= conversation($a, $s, 'community', $update, false, 'commented', local_user()); if (!$update) { $o .= $pager->renderMinimal(count($r)); diff --git a/mod/display.php b/mod/display.php index ea52a994b0..dce8b25b9c 100644 --- a/mod/display.php +++ b/mod/display.php @@ -331,7 +331,7 @@ function display_content(App $a, $update = false, $update_uid = 0) $o .= ""; } - $o .= conversation($a, [$item], new Pager(DI::args()->getQueryString()), 'display', $update_uid, false, 'commented', $item_uid); + $o .= conversation($a, [$item], 'display', $update_uid, false, 'commented', $item_uid); // Preparing the meta header $description = trim(HTML::toPlaintext(BBCode::convert($item["body"], false), 0, true)); diff --git a/mod/item.php b/mod/item.php index 636bd8c319..2e5a082036 100644 --- a/mod/item.php +++ b/mod/item.php @@ -675,7 +675,7 @@ function item_post(App $a) { $datarray["item_id"] = -1; $datarray["author-network"] = Protocol::DFRN; - $o = conversation($a, [array_merge($contact_record, $datarray)], new Pager(DI::args()->getQueryString()), 'search', false, true); + $o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true); System::jsonExit(['preview' => $o]); } diff --git a/mod/network.php b/mod/network.php index 1f7afebf37..037a16ebfd 100644 --- a/mod/network.php +++ b/mod/network.php @@ -291,7 +291,7 @@ function networkConversation(App $a, $items, Pager $pager, $mode, $update, $orde $items = []; } - $o = conversation($a, $items, $pager, $mode, $update, false, $ordering, local_user()); + $o = conversation($a, $items, $mode, $update, false, $ordering, local_user()); if (!$update) { if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { diff --git a/mod/notes.php b/mod/notes.php index ccd30926c8..34cf404ca8 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -82,7 +82,7 @@ function notes_content(App $a, $update = false) $count = count($notes); - $o .= conversation($a, $notes, $pager, 'notes', $update); + $o .= conversation($a, $notes, 'notes', $update); } $o .= $pager->renderMinimal($count); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d3abc078ce..789062403b 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1815,13 +1815,13 @@ class Contact $items = Item::inArray($r); - $o = conversation($a, $items, $pager, 'contacts', $update, false, 'commented', local_user()); + $o = conversation($a, $items, 'contacts', $update, false, 'commented', local_user()); } else { $r = Item::selectForUser(local_user(), [], $condition, $params); $items = Item::inArray($r); - $o = conversation($a, $items, $pager, 'contact-posts', false); + $o = conversation($a, $items, 'contact-posts', false); } if (!$update) { diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 4cd14c021a..8da831405c 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -231,7 +231,7 @@ class Status extends BaseProfile $items = array_merge($items, $pinned); } - $o .= conversation($a, $items, $pager, 'profile', false, false, 'pinned_received', $a->profile['uid']); + $o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $a->profile['uid']); $o .= $pager->renderMinimal(count($items)); diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index a68086eccc..3e174c7905 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -200,7 +200,7 @@ class Index extends BaseSearch Logger::info('Start Conversation.', ['q' => $search]); - $o .= conversation(DI::app(), $r, $pager, 'search', false, false, 'commented', local_user()); + $o .= conversation(DI::app(), $r, 'search', false, false, 'commented', local_user()); $o .= $pager->renderMinimal(count($r)); diff --git a/src/Module/Update/Profile.php b/src/Module/Update/Profile.php index d23f766b57..79e53168b3 100644 --- a/src/Module/Update/Profile.php +++ b/src/Module/Update/Profile.php @@ -95,8 +95,6 @@ class Profile extends BaseModule return ''; } - $pager = new Pager(DI::args()->getQueryString()); - // Set a time stamp for this page. We will make use of it when we // search for new items (update routine) $last_updated_array[$last_updated_key] = time(); @@ -116,7 +114,7 @@ class Profile extends BaseModule $items = DBA::toArray($items_stmt); - $o .= conversation($a, $items, $pager, 'profile', $profile_uid, false, 'received', $a->profile['uid']); + $o .= conversation($a, $items, 'profile', $profile_uid, false, 'received', $a->profile['uid']); header("Content-type: text/html"); echo "\r\n"; diff --git a/view/js/main.js b/view/js/main.js index 41bae7cf23..560d9c4286 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -104,6 +104,20 @@ function decodeHtml(html) { return txt.value; } +/** + * Retrieves a single named query string parameter + * + * @param {string} name + * @returns {string} + * @see https://davidwalsh.name/query-string-javascript + */ +function getUrlParameter(name) { + name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); + var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); + var results = regex.exec(location.search); + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); +}; + var src = null; var prev = null; var livetime = null; @@ -511,7 +525,11 @@ function updateConvItems(data) { var ident = $(this).attr('id'); // Add new top-level item. - if ($('#' + ident).length == 0 && profile_page == 1) { + if ($('#' + ident).length === 0 + && (!getUrlParameter('page') + || getUrlParameter('page') === '1' + ) + ) { $('#' + prev).after($(this)); // Replace already existing thread. @@ -573,7 +591,12 @@ function liveUpdate(src) { var orgHeight = $("section").height(); var udargs = ((netargs.length) ? '/' + netargs : ''); - var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&page=' + profile_page + '&force=' + ((force_update) ? 1 : 0) + '&item=' + update_item; + + var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&force=' + ((force_update) ? 1 : 0) + '&item=' + update_item; + + if (getUrlParameter('page')) { + update_url += '&page=' + getUrlParameter('page'); + } $.get(update_url,function(data) { in_progress = false; -- 2.39.5