]> git.mxchange.org Git - friendica.git/commitdiff
Endless scroll now avoids showing the same items
authorMichael <heluecht@pirati.ca>
Mon, 31 Jul 2017 06:04:37 +0000 (06:04 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 31 Jul 2017 06:04:37 +0000 (06:04 +0000)
include/conversation.php
js/main.js
mod/network.php
object/Item.php
view/templates/wall_thread.tpl
view/theme/frio/templates/wall_thread.tpl
view/theme/quattro/templates/wall_thread.tpl
view/theme/vier/templates/wall_thread.tpl

index e58df19f16cc03908d0c71174fc569750b4530ff..bd6e714654cca2fdf6512afcfbb04665ee7d4f31 100644 (file)
@@ -424,7 +424,6 @@ function item_fieldlists() {
 These Fields are not added below (yet). They are here to for bug search.
 `item`.`type`,
 `item`.`extid`,
-`item`.`received`,
 `item`.`changed`,
 `item`.`moderated`,
 `item`.`target-type`,
@@ -451,7 +450,7 @@ These Fields are not added below (yet). They are here to for bug search.
                `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
                `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
                `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`,
-               `item`.`commented`, `item`.`created`, `item`.`edited`,
+               `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
                `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
                `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`,
                `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
index 5df33ed590c8f0000286cf86144c3c10697b89a7..fff4078ae82626a88a43a8fa51bba8d00f162509 100644 (file)
                // page number
                infinite_scroll.pageno+=1;
 
+               match = $("span.received").last();
+               if (match.length > 0) {
+                       received = match[0].innerHTML;
+               } else {
+                       received = "0000-00-00 00:00:00";
+               }
+
+               match = $("span.created").last();
+               if (match.length > 0) {
+                       created = match[0].innerHTML;
+               } else {
+                       created = "0000-00-00 00:00:00";
+               }
+
+               match = $("span.commented").last();
+               if (match.length > 0) {
+                       commented = match[0].innerHTML;
+               } else {
+                       commented = "0000-00-00 00:00:00";
+               }
+
+               match = $("span.id").last();
+               if (match.length > 0) {
+                       id = match[0].innerHTML;
+               } else {
+                       id = "0";
+               }
+               // console.log("Received: " + received + " - Commented: " + commented+ " - Created: " + created + " - ID: " + id);
+
                // get the raw content from the next page and insert this content
                // right before "#conversation-end"
-               $.get('network?mode=raw' + infinite_scroll.reload_uri + '&page=' + infinite_scroll.pageno, function(data) {
+               $.get('network?mode=raw' + infinite_scroll.reload_uri + '&last_received=' + received + '&last_commented=' + commented + '&last_created=' + created + '&last_id=' + id + '&page=' + infinite_scroll.pageno, function(data) {
                        $("#scroll-loader").hide();
                        if ($(data).length > 0) {
+
                                $(data).insertBefore('#conversation-end');
                                lockLoadContent = false;
                        } else {
index 61db199d554a068703b28124e6aa42aefec3b782..aad56bfd67e9dd2f3470fcc1572cdc74c216c82f 100644 (file)
@@ -325,6 +325,18 @@ function network_content(App $a, $update = 0) {
        // Rawmode is used for fetching new content at the end of the page
        $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
 
+       if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
+               $last_received = dbm::date($_GET["last_received"]);
+               $last_commented = dbm::date($_GET["last_commented"]);
+               $last_created = dbm::date($_GET["last_created"]);
+               $last_id = intval($_GET["last_id"]);
+       } else {
+               $last_received = '';
+               $last_commented = '';
+               $last_created = '';
+               $last_id = 0;
+       }
+
        /// @TODO Is this really necessary? $a is already available to hooks
        $arr = array('query' => $a->query_string);
        call_hooks('network_content_init', $arr);
@@ -596,14 +608,12 @@ function network_content(App $a, $update = 0) {
                $order_mode = "id";
        }
 
-       if($conv)
+       if ($conv) {
                $sql_extra3 .= " AND $sql_table.`mention`";
-
-       if($update) {
-
+       }
+       if ($update) {
                // only setup pagination on initial page view
                $pager_sql = '';
-
        } else {
                //  check if we serve a mobile device and get the user settings
                //  accordingly
@@ -624,7 +634,7 @@ function network_content(App $a, $update = 0) {
                $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
        }
 
-       if($nouveau) {
+       if ($nouveau) {
                $simple_update = (($update) ? " AND `item`.`unseen` " : '');
 
                if ($sql_order == "")
@@ -644,8 +654,6 @@ function network_content(App $a, $update = 0) {
        } else {
 
                // Normal conversation view
-
-
                if($order === 'post') {
                        $ordering = "`created`";
                        if ($sql_order == "")
@@ -662,8 +670,39 @@ function network_content(App $a, $update = 0) {
                if (($_GET["offset"] != ""))
                        $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
 
+               switch ($order_mode) {
+                       case 'received':
+                               if ($last_received != '') {
+                                       $sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
+                                       $a->set_pager_page(1);
+                                       $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
+                               }
+                               break;
+                       case 'commented':
+                               if ($last_commented != '') {
+                                       $sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
+                                       $a->set_pager_page(1);
+                                       $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
+                               }
+                               break;
+                       case 'created':
+                               if ($last_created != '') {
+                                       $sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
+                                       $a->set_pager_page(1);
+                                       $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
+                               }
+                               break;
+                       case 'id':
+                               if (($last_id > 0) && ($sql_table == "`thread`")) {
+                                       $sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
+                                       $a->set_pager_page(1);
+                                       $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
+                               }
+                               break;
+               }
+
                // Fetch a page full of parent items for this page
-               if($update) {
+               if ($update) {
                        if (get_config("system", "like_no_comment"))
                                $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'";
                        else
index 95c01a073e1fe2fb2b7a209edb508347130daa3b..e8110f5ffaa2a478831cc6779a10cc375771dafe 100644 (file)
@@ -394,6 +394,9 @@ class Item extends BaseObject {
                        'edited'          => $edited,
                        'network'         => $item["item_network"],
                        'network_name'    => network_to_name($item['item_network'], $profile_link),
+                       'received'        => $item['received'],
+                       'commented'       => $item['commented'],
+                       'created_date'    => $item['created'],
                );
 
                $arr = array('item' => $item, 'output' => $tmp_item);
index f020d68df1256700fabd0a695519e6295cfeca12..37f034586af9a98360001b943fc8fa9d12e34698 100644 (file)
@@ -5,6 +5,12 @@
        </div>
        <div id="collapsed-comments-{{$item.id}}" class="collapsed-comments" style="display: none;">
 {{/if}}
+{{if $item.thread_level==1}}
+<span class="commented" style="display: none;">{{$item.commented}}</span>
+<span class="received" style="display: none;">{{$item.received}}</span>
+<span class="created" style="display: none;">{{$item.created_date}}</span>
+<span class="id" style="display: none;">{{$item.id}}</span>
+{{/if}}
 <div id="tread-wrapper-{{$item.id}}" class="tread-wrapper {{$item.toplevel}} {{if $item.toplevel}} h-entry {{else}} u-comment h-cite {{/if}}">
 <a name="{{$item.id}}" ></a>
 <div class="wall-item-outside-wrapper {{$item.indent}}{{$item.previewing}}{{if $item.owner_url}} wallwall{{/if}}" id="wall-item-outside-wrapper-{{$item.id}}" >
index f2429a78b73f4abd90795fad9f39059f4599b470..89b58b2ccb85f0b814efb01756e323707f73d23c 100644 (file)
@@ -71,7 +71,13 @@ as the value of $top_child_total (this is done at the end of this file)
 <div class="item-{{$item.id}} wall-item-container {{$item.indent}} {{$item.shiny}} {{$item.network}} thread_level_{{$item.thread_level}} {{if $item.thread_level==1}}panel-body h-entry{{else}}u-comment h-cite{{/if}}" id="item-{{$item.guid}}"><!-- wall-item-container -->
 {{else}}
 <div class="item-{{$item.id}} wall-item-container {{$item.indent}} {{$item.shiny}} {{$item.network}} thread_level_7 u-comment h-cite" id="item-{{$item.guid}}">
- {{/if}}
+{{/if}}
+{{if $item.thread_level==1}}
+<span class="commented" style="display: none;">{{$item.commented}}</span>
+<span class="received" style="display: none;">{{$item.received}}</span>
+<span class="created" style="display: none;">{{$item.created_date}}</span>
+<span class="id" style="display: none;">{{$item.id}}</span>
+{{/if}}
        <div class="media">
                {{* Put addional actions in a top-right dropdown menu *}}
 
index 2ec43c0ce51587733a46958980f0c3c5a7eb17a4..c6085e9b1610233462a27b01962817e68362796b 100644 (file)
 {{/if}}
 {{/if}}
 
-{{if $item.thread_level!=1}}<div class="children u-comment h-cite">{{/if}}
+{{if $item.thread_level!=1}}
+<div class="children u-comment h-cite">
+{{else}}
+<span class="commented" style="display: none;">{{$item.commented}}</span>
+<span class="received" style="display: none;">{{$item.received}}</span>
+<span class="created" style="display: none;">{{$item.created_date}}</span>
+<span class="id" style="display: none;">{{$item.id}}</span>
+{{/if}}
 
 <div class="wall-item-decor">
        {{if $item.star}}<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
index 23adef340478f47a7036434178bbb0cc3157d129..c46c83ef5b1b2ccb87d1aec381902c247b2b36db 100644 (file)
        <div class="wall-item-container {{$item.indent}} {{$item.shiny}} {{$item.network}} thread_level_{{$item.thread_level}}" id="item-{{$item.guid}}">
 {{else}}
        <div class="wall-item-container {{$item.indent}} {{$item.shiny}} {{$item.network}} thread_level_7" id="item-{{$item.guid}}">
+{{/if}}
+{{if $item.thread_level==1}}
+<span class="commented" style="display: none;">{{$item.commented}}</span>
+<span class="received" style="display: none;">{{$item.received}}</span>
+<span class="created" style="display: none;">{{$item.created_date}}</span>
+<span class="id" style="display: none;">{{$item.id}}</span>
 {{/if}}
        <div class="wall-item-item">
                <div class="wall-item-info">