@@ -183,6 +183,9 @@ module.exports = baseVw.extend({
183183 //set view's userID from the userModel;
184184 this . userID = options . userModel . get ( 'guid' ) ;
185185 this . userProfileFetchParameters = { } ;
186+ this . followerFetchStart = 0 ;
187+ this . followersFetchPer = 30 ;
188+ this . followerFetchTotal = 0 ;
186189 this . itemFetchParameters = { } ;
187190 this . model = new Backbone . Model ( ) ;
188191 this . globalUserProfile = options . userProfile ;
@@ -663,6 +666,10 @@ module.exports = baseVw.extend({
663666 if ( self . options . ownPage === false && Boolean ( __ . findWhere ( followingArray , { guid : self . userID } ) ) ) {
664667 self . $ ( '.js-followsMe' ) . removeClass ( 'hide' )
665668 }
669+ //mark whether page is being followed
670+ if ( self . options . ownPage === false ) {
671+ self . toggleFollowButtons ( Boolean ( __ . findWhere ( followingArray , { guid : self . pageID } ) ) ) ;
672+ }
666673
667674 } ) . fail ( function ( jqXHR , status , errorThrown ) {
668675 if ( self . isRemoved ( ) ) return ;
@@ -685,21 +692,34 @@ module.exports = baseVw.extend({
685692 } ) ;
686693 } ,
687694
688- fetchFollowers : function ( ) {
689- var self = this ;
695+ fetchFollowers : function ( ignoreTotal ) {
696+ var self = this ,
697+ fetchFollowersParameters ;
690698
699+ if ( ! ignoreTotal && this . followerFetchStart > 0 && this . followerFetchStart >= this . followerFetchTotal ) {
700+ //don't fetch again if all of the followers have been fetched
701+ return ;
702+ }
703+
704+ if ( this . options . ownPage ) {
705+ fetchFollowersParameters = $ . param ( { 'start' : this . followerFetchStart } ) ;
706+ } else {
707+ fetchFollowersParameters = $ . param ( { 'guid' : this . pageID , 'start' : this . followerFetchStart } ) ;
708+ }
709+
691710 this . followers . fetch ( {
692- data : self . userProfileFetchParameters ,
693- //timeout: 5000,
694- success : function ( model ) {
695- var followerArray = model . get ( 'followers' ) ;
711+ data : fetchFollowersParameters ,
712+ success : ( model ) => {
713+ var followerArray = model . get ( 'followers' ) || [ ] ;
714+
715+ this . followerFetchTotal = model . get ( 'count' ) || followerArray . length ; //the length is for older servers
716+ this . $ ( '.js-userFollowerCount' ) . html ( this . followerFetchTotal ) ;
696717
697718 if ( self . isRemoved ( ) ) return ;
698719
699- self . renderFollowers ( followerArray ) ;
700- //if this is not their page, see if they are being followed
701- if ( self . options . ownPage === false ) {
702- self . toggleFollowButtons ( Boolean ( __ . findWhere ( followerArray , { guid : self . userID } ) ) ) ;
720+ if ( followerArray . length || this . followerFetchTotal == 0 ) {
721+ //always render the first time so the no followers message is shown for no followers
722+ this . renderFollowers ( followerArray , this . followerFetchTotal ) ;
703723 }
704724 } ,
705725 error : function ( model , response ) {
@@ -713,6 +733,7 @@ module.exports = baseVw.extend({
713733 }
714734 }
715735 } ) ;
736+ this . followerFetchStart += this . followersFetchPer ;
716737 } ,
717738
718739 getIsModerator : function ( ) {
@@ -783,25 +804,31 @@ module.exports = baseVw.extend({
783804 }
784805 } ,
785806
786- renderFollowers : function ( model ) {
807+ renderFollowers : function ( model , followerCount ) {
787808 "use strict" ;
788809
789810 model = model || [ ] ;
790- this . followerList = new personListView ( {
791- model : model ,
792- el : '.js-list1' ,
793- title : window . polyglot . t ( 'NoFollowers' ) ,
794- message : "" ,
795- ownFollowing : this . ownFollowing ,
796- hideFollow : true ,
797- serverUrl : this . options . userModel . get ( 'serverUrl' ) ,
798- reverse : true
799- } ) ;
800- this . registerChild ( this . followerList ) ;
801-
802- this . $ ( '.js-userFollowerCount' ) . html ( model . length ) ;
811+ //if view doesn't exist, create it
812+ if ( ! this . followerList ) {
813+ this . followerList = new personListView ( {
814+ model : model ,
815+ el : '.js-list1' ,
816+ title : window . polyglot . t ( 'NoFollowers' ) ,
817+ message : "" ,
818+ ownFollowing : this . ownFollowing ,
819+ hideFollow : true ,
820+ serverUrl : this . options . userModel . get ( 'serverUrl' ) ,
821+ reverse : true ,
822+ perFetch : 30 ,
823+ followerCount : followerCount
824+ } ) ;
825+ this . registerChild ( this . followerList ) ;
826+ } else if ( model . length ) {
827+ this . followerList . addUsers ( model ) ;
828+ }
803829
804830 if ( model . length ) {
831+ //refresh search
805832 this . followersSearch = new window . List ( 'searchFollowers' , {
806833 valueNames : [ 'js-searchName' , 'js-searchHandle' ] ,
807834 page : 1000
@@ -813,6 +840,10 @@ module.exports = baseVw.extend({
813840 this . followersSearch . reIndex ( ) ;
814841 searchTerms && this . followersSearch . search ( searchTerms ) ;
815842 } ) ;
843+
844+ this . listenTo ( this . followerList , 'fetchMoreUsers' , ( ) => {
845+ this . fetchFollowers ( ) ;
846+ } ) ;
816847 } ,
817848
818849 renderFollowing : function ( model ) {
0 commit comments