Procházet zdrojové kódy

Ticket #4479 - Timeline: Improve infinite scroll.

AntonLV před 3 roky
rodič
revize
febc089569

+ 4 - 4
modules/boonex/russian/data/langs/bx_timeline/ru.xml

@@ -17,11 +17,11 @@
     <string name="_bx_timeline_option_enable_count_all_views"><![CDATA[Считать просмотры для всех событий в хронике]]></string>
     <string name="_bx_timeline_option_enable_repost_own_actions"><![CDATA[Репост использует собственные действия (просмотры, голосование и тп.)]]></string>
     <string name="_bx_timeline_option_enable_hide_upon_delete"><![CDATA[Деактивировать сообщения при скрывании вместо удаления]]></string>
-    <string name="_bx_timeline_option_events_per_page_profile"><![CDATA[Количество элементов на странице профайла]]></string>
-    <string name="_bx_timeline_option_events_per_page_account"><![CDATA[Количество элементов на странице "панель аккаунта"]]></string>
-    <string name="_bx_timeline_option_events_per_page_home"><![CDATA[Количество элементов на главной странице сайта]]></string>
+    <string name="_bx_timeline_option_events_per_page_profile"><![CDATA[Количество элементов в ленте контекста (профиля)]]></string>
+    <string name="_bx_timeline_option_events_per_page_account"><![CDATA[Количество элементов в ленте контекст (профиль) + подписки]]></string>
+    <string name="_bx_timeline_option_events_per_page_home"><![CDATA[Количество элементов в публичной ленте]]></string>
     <string name="_bx_timeline_option_events_per_page"><![CDATA[Количество элементов на странице]]></string>
-    <string name="_bx_timeline_option_enable_infinite_scroll"><![CDATA[Включить 'Бесконечную прокрутку' (экспериментально)]]></string>
+    <string name="_bx_timeline_option_enable_infinite_scroll"><![CDATA[Включить 'Бесконечную прокрутку']]></string>
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Бесконечная прокрутка: Количество элементов, получаемых при авто-подгрузке]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Бесконечная прокрутка: Количество авто-подгрузок]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[Количество элементов в RSS-ленте]]></string>

+ 20 - 15
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -30,6 +30,7 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
     protected $_aCacheTableCheckFields;
 
     protected $_bInfScroll;
+    protected $_iInfScrollPerPreload;
     protected $_iInfScrollAutoPreloads;
 
     protected $_iRssLength;
@@ -417,16 +418,25 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
             'sticked' => 'flag'
         ];
 
-        $this->_aPerPage = array(
+        $iPerPagePublic = (int)getParam($sOptionPrefix . 'events_per_page_home');
+        $iPerPageContext = (int)getParam($sOptionPrefix . 'events_per_page_profile');
+        $iPerPageFeed = (int)getParam($sOptionPrefix . 'events_per_page_account');
+
+        $this->_aPerPage = [
             'default' => (int)getParam($sOptionPrefix . 'events_per_page'),
-            'profile' => (int)getParam($sOptionPrefix . 'events_per_page_profile'),
-            'account' => (int)getParam($sOptionPrefix . 'events_per_page_account'),
-            'home' => (int)getParam($sOptionPrefix . 'events_per_page_home'),
-            'preload' => (int)getParam($sOptionPrefix . 'events_per_preload')
-    	);
+            BX_BASE_MOD_NTFS_TYPE_PUBLIC => $iPerPagePublic,
+            BX_TIMELINE_TYPE_HOT => $iPerPagePublic,
+            BX_BASE_MOD_NTFS_TYPE_OWNER => $iPerPageContext,
+            BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS => $iPerPageFeed,
+            BX_TIMELINE_TYPE_FEED => $iPerPageFeed,
+            BX_TIMELINE_TYPE_FEED_AND_HOT => $iPerPageFeed,
+            BX_TIMELINE_TYPE_CHANNELS => $iPerPageFeed,
+    	];
 
         $this->_bInfScroll = getParam($sOptionPrefix . 'enable_infinite_scroll') == 'on';
+        $this->_iInfScrollPerPreload = (int)getParam($sOptionPrefix . 'events_per_preload');
         $this->_iInfScrollAutoPreloads = (int)getParam($sOptionPrefix . 'auto_preloads');
+        
 
         $this->_iRssLength = (int)getParam($sOptionPrefix . 'rss_length');
         $this->_iLiveUpdateLength = (int)getParam($sOptionPrefix . 'live_updates_length');
@@ -712,14 +722,6 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
         return $this->_aItemToUploader[$sMenuItem];
     }
 
-    public function getPerPage($sType = 'default')
-    {
-        if($this->isInfiniteScroll())
-            $sType = 'preload';
-
-        return parent::getPerPage($sType);
-    }
-
     public function getExtenalsEvery($sType = 'default')
     {
         if($this->isInfiniteScroll())
@@ -738,7 +740,10 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
 
         return $iExtenalsEvery;
     }
-
+    public function getPerPreload()
+    {
+        return $this->_iInfScrollPerPreload;
+    }
     public function getAutoPreloads()
     {
         return $this->_iInfScrollAutoPreloads;

+ 36 - 21
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -1661,7 +1661,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'type' => BX_BASE_MOD_NTFS_TYPE_OWNER, 
             'start' => -1, 
             'per_page' => -1, 
-            'per_page_default' => $this->_oConfig->getPerPage('profile'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER), 
             'timeline' => -1, 
             'filter' => '', 
             'modules' => array()
@@ -1693,7 +1693,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'type' => BX_BASE_MOD_NTFS_TYPE_OWNER, 
             'start' => -1, 
             'per_page' => -1, 
-            'per_page_default' => $this->_oConfig->getPerPage('profile'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER), 
             'timeline' => -1, 
             'filter' => '', 
             'modules' => array()
@@ -1731,7 +1731,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'type' => BX_BASE_MOD_NTFS_TYPE_OWNER, 
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('profile'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1769,7 +1769,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'type' => BX_BASE_MOD_NTFS_TYPE_OWNER, 
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('profile'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_OWNER), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1795,7 +1795,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId,
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage(), 
+            'per_page_default' => $this->_oConfig->getPerPage($sType), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1810,7 +1810,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId,
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage(), 
+            'per_page_default' => $this->_oConfig->getPerPage($sType), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1848,7 +1848,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId,
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('home'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_PUBLIC), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1886,7 +1886,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId,
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('home'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_BASE_MOD_NTFS_TYPE_PUBLIC), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1924,7 +1924,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId,
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('home'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_HOT), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -1962,7 +1962,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId, 
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('home'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_HOT), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -2003,7 +2003,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId, 
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('account'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_FEED), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -2044,7 +2044,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             'owner_id' => $iProfileId, 
             'start' => $iStart, 
             'per_page' => $iPerPage, 
-            'per_page_default' => $this->_oConfig->getPerPage('account'), 
+            'per_page_default' => $this->_oConfig->getPerPage(BX_TIMELINE_TYPE_FEED), 
             'timeline' => $iTimeline, 
             'filter' => $sFilter, 
             'modules' => $aModules
@@ -2075,12 +2075,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     /** 
      * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
      */
-    public function serviceGetBlockViewCustom($aParams = array())
+    public function serviceGetBlockViewCustom($aParams = [])
     {
     	return $this->_serviceGetBlockViewByType($aParams);
     }
 
-    public function serviceGetBlockMenuDb($aParams = array())
+    public function serviceGetBlockMenuDb($aParams = [])
     {
         $aParams = $this->_prepareParams(array_merge([
             'name' => BX_TIMELINE_NAME_VIEWS_DB,
@@ -2090,7 +2090,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         ], $aParams));
 
         if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
-            $aParams['type'] = $sType;
+            $this->_setParamsType($sType, $aParams);
 
         $sMenu = $this->_oConfig->getObject('menu_feeds');
         if(isset($aParams['menu_feeds'])) {
@@ -2122,7 +2122,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             $aParams['owner_id'] = $this->getUserId();
 
         if(!isset($aParams['type']) && ($sType = $this->_oConfig->getUserChoice('type', $aParams['viewer_id'])) !== false)
-            $aParams['type'] = $sType;
+            $this->_setParamsType($sType, $aParams);
 
         $aParams = $this->_prepareParams(array_merge([
             'name' => BX_TIMELINE_NAME_VIEWS_DB,
@@ -5129,12 +5129,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return $this->_getBlockView($aBrowseParams);
     }
 
-    protected function _serviceGetBlockViews($aBrowseParams = array())
+    protected function _serviceGetBlockViews($aBrowseParams = [])
     {
         $aParams = $this->_prepareParams($aBrowseParams);
 
         if(($sType = $this->_oConfig->getUserChoice('type')) !== false)
-            $aParams['type'] = $sType;
+            $this->_setParamsType($sType, $aParams);
 
         $this->_iOwnerId = $aParams['owner_id'];
 
@@ -5503,6 +5503,20 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         $this->_oDb->deleteMedia($sType, $iContentId);
     }
 
+    protected function _setParamsType($sType, &$aParams)
+    {
+        if($aParams['type'] == $sType)
+            return;
+
+        $iPerPage = $this->_oConfig->getPerPage($sType);
+
+        $aParams = array_merge($aParams, [
+            'type' => $sType,
+            'per_page' => $iPerPage,
+            'per_page_default' => $iPerPage
+        ]);
+    }
+
     protected function _prepareParams($aParams)
     {
         if(empty($aParams['name']))
@@ -5521,7 +5535,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
             $aParams['start'] = 0;
 
         if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
-            $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
+            $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage($aParams['type']);
 
         if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
             $aParams['timeline'] = 0;
@@ -5557,7 +5571,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
     protected function _prepareParamsGet($mParams = false)
     {
-        $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id'];
+        $aKeys = ['name', 'view', 'type', 'owner_id', 'start', 'per_page', 'per_page_default', 'timeline', 'filter', 'modules', 'media', 'context', 'blink', 'viewer_id'];
 
         $aParams = [];
         if(!empty($mParams) && is_array($mParams))
@@ -5572,7 +5586,8 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         $aParams['type'] = $this->_oConfig->processParamWithDefault($aParams['type'], BX_TIMELINE_TYPE_DEFAULT);
         $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
         $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
-        $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
+        $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
+        $aParams['per_page_default'] = $aParams['per_page_default'] !== false ? bx_process_input($aParams['per_page_default'], BX_DATA_INT) : $this->_oConfig->getPerPage($aParams['type']);
         $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
         $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
         $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : [];

+ 14 - 7
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -114,11 +114,15 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
             return $mixedResult; 
     }
 
-    public function getJsCodeView($aParams = array(), $bWrap = true, $bDynamic = false)
+    public function getJsCodeView($aParams = [], $bWrap = true, $bDynamic = false)
     {
+        $bInfiniteScroll = $this->_oConfig->isInfiniteScroll();
+        if($bInfiniteScroll && isset($aParams['oRequestParams']['per_page']))
+            $aParams['oRequestParams']['per_page'] = $this->_oConfig->getPerPreload();
+
         $aParams = array_merge([
             'sObjNameMenuFeeds' => $this->_oConfig->getObject('menu_feeds'),
-            'bInfScroll' => $this->_oConfig->isInfiniteScroll(),
+            'bInfScroll' => $bInfiniteScroll,
             'iInfScrollAutoPreloads' => $this->_oConfig->getAutoPreloads(),
             'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
             'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
@@ -868,12 +872,15 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
         $sBack = $this->getBack($aParams);
 
-        $iPerPage = $this->_oConfig->getPerPage();
-        $iPreloads = $this->_oConfig->getAutoPreloads();
-        if(!$this->_oConfig->isInfiniteScroll() || (($aParams['start'] - $iPerPage * ($iPreloads - 1)) % ($iPerPage * $iPreloads) == 0))
-            $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0 && $bEvents);
+        if($this->_oConfig->isInfiniteScroll()) {
+            $aParams['per_page'] = $this->_oConfig->getPerPreload();
+            $iAutoPreloads = $this->_oConfig->getAutoPreloads();
+
+            $bAuto = ($aParams['start'] - $aParams['per_page_default'] - $aParams['per_page'] * ($iAutoPreloads - 2)) % ($aParams['per_page'] * $iAutoPreloads) != 0;
+            $sLoadMore = $this->{'getLoadMore' . ($bAuto ? 'Auto' : '')}($aParams, $bNext, $iEvents > 0 && $bEvents);
+        }
         else
-            $sLoadMore = $this->getLoadMoreAuto($aParams, $bNext, $iEvents > 0 && $bEvents);
+            $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0 && $bEvents);
 
         $sEmpty = $this->getEmpty($iEvents <= 0 || !$bEvents);
 

+ 4 - 4
modules/boonex/timeline/install/langs/en.xml

@@ -17,11 +17,11 @@
     <string name="_bx_timeline_option_enable_count_all_views"><![CDATA[Count views for all items in the Feed]]></string>
     <string name="_bx_timeline_option_enable_repost_own_actions"><![CDATA[Repost uses its own actions (views, likes, etc)]]></string>
     <string name="_bx_timeline_option_enable_hide_upon_delete"><![CDATA[Inactivate items upon hiding instead of deletion]]></string>
-    <string name="_bx_timeline_option_events_per_page_profile"><![CDATA[Number of items on profile page]]></string>
-    <string name="_bx_timeline_option_events_per_page_account"><![CDATA[Number of items on dashboard page]]></string>
-    <string name="_bx_timeline_option_events_per_page_home"><![CDATA[Number of items on site home page]]></string>
+    <string name="_bx_timeline_option_events_per_page_profile"><![CDATA[Number of items in context (profile) timeline]]></string>
+    <string name="_bx_timeline_option_events_per_page_account"><![CDATA[Number of items in context (profile) + subscriptions timeline]]></string>
+    <string name="_bx_timeline_option_events_per_page_home"><![CDATA[Number of items in public timeline]]></string>
     <string name="_bx_timeline_option_events_per_page"><![CDATA[Number of items per page]]></string>
-    <string name="_bx_timeline_option_enable_infinite_scroll"><![CDATA[Enable Infinite Scroll (experimental)]]></string>
+    <string name="_bx_timeline_option_enable_infinite_scroll"><![CDATA[Enable Infinite Scroll]]></string>
     <string name="_bx_timeline_option_events_per_preload"><![CDATA[Infinite Scroll: Number of items per preload]]></string>
     <string name="_bx_timeline_option_auto_preloads"><![CDATA[Infinite Scroll: Number of auto preloads]]></string>
     <string name="_bx_timeline_option_rss_length"><![CDATA[The length of RSS feed]]></string>

+ 5 - 1
modules/boonex/timeline/js/view.js

@@ -266,8 +266,10 @@ BxTimelineView.prototype.initInfiniteScroll = function(oParent)
                 return;
         }
 
+        var iStart = $this._oRequestParams.start + ($this._oRequestParams.start == 0 ? $this._oRequestParams.per_page_default : $this._oRequestParams.per_page);
+
         $this._bInfScrollBusy = true;
-        $this._getPage(undefined, $this._oRequestParams.start + $this._oRequestParams.per_page, $this._oRequestParams.per_page, function(oData) {
+        $this._getPage(undefined, iStart, $this._oRequestParams.per_page, function(oData) {
             $this._bEventsToLoad = oData.events_to_load;
             $this._iInfScrollPreloads += 1;
             $this._bInfScrollBusy = false;
@@ -545,6 +547,8 @@ BxTimelineView.prototype.changeView = function(oLink, sType, oRequestParams)
         this.pauseVideos(oViewBefore);
 
     this._oRequestParams.start = 0;
+    this._oRequestParams.per_page = undefined;
+    this._oRequestParams.per_page_default = undefined;
     this._oRequestParams.type = sType;
 
     var oTab = $(oLink);