]> source.dussan.org Git - nextcloud-server.git/commitdiff
Better comments pagination logic
authorVincent Petry <pvince81@owncloud.com>
Mon, 1 Feb 2016 15:54:18 +0000 (16:54 +0100)
committerVincent Petry <pvince81@owncloud.com>
Tue, 2 Feb 2016 17:01:15 +0000 (18:01 +0100)
apps/comments/js/commentcollection.js

index eaa7a1d53faed9745f6fda49589794b78b61071e..055752f327c61eb07d219d40d7c32cb45515bf67 100644 (file)
@@ -30,7 +30,7 @@
                _objectId: null,
 
                _endReached: false,
-               _limit : 5,
+               _limit : 20,
 
                initialize: function(models, options) {
                        options = options || {};
 
                        var body = '<?xml version="1.0" encoding="utf-8" ?>\n' +
                                '<D:report xmlns:D="DAV:" xmlns:oc="http://owncloud.org/ns">\n' +
-                               '   <oc:limit>' + this._limit + '</oc:limit>\n';
-
-                       if (this.length > 0) {
-                               body += '   <oc:datetime>' + this.last().get('creationDateTime') + '</oc:datetime>\n';
-                       }
-
-                       body += '</D:report>\n';
-
-                       var oldLength = this.length;
+                               // load one more so we know there is more
+                               '    <oc:limit>' + (this._limit + 1) + '</oc:limit>\n' +
+                               '    <oc:offset>' + this.length + '</oc:offset>\n' +
+                               '</D:report>\n';
 
                        options = options || {};
                        var success = options.success;
                                data: body,
                                davProperties: CommentsCollection.prototype.model.prototype.davProperties,
                                success: function(resp) {
-                                       if (resp.length === oldLength) {
+                                       if (resp.length <= self._limit) {
                                                // no new entries, end reached
                                                self._endReached = true;
+                                       } else {
+                                               // remove last entry, for next page load
+                                               resp = _.initial(resp);
                                        }
                                        if (!self.set(resp, options)) {
                                                return false;