From ded234bed7f6a66ec690178632433b311a4481da Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Wed, 26 Mar 2014 01:27:16 +0400 Subject: [PATCH] auto load old posts in profile view --- js/twister_actions.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/js/twister_actions.js b/js/twister_actions.js index 03fd659..9634626 100644 --- a/js/twister_actions.js +++ b/js/twister_actions.js @@ -95,8 +95,12 @@ function requestRTs(postLi) } } +var lastk, + profilePostsLoading = false; + function requestPostRecursively(containerToAppend,username,resource,count) { + profilePostsLoading = true; dhtget( username, resource, "s", function(args, postFromJson) { if( postFromJson ) { @@ -106,14 +110,16 @@ function requestPostRecursively(containerToAppend,username,resource,count) newStreamPost.slideDown("fast"); $.MAL.postboardLoaded(); - if( args.count > 1 ) { - var userpost = postFromJson["userpost"]; - var n = userpost["n"]; - var lastk = userpost["lastk"]; - if( lastk == undefined ) - lastk = userpost["k"] - 1; // not true with directmsgs in stream + var userpost = postFromJson["userpost"]; + var n = userpost["n"]; + lastk = userpost["lastk"]; + if( lastk == undefined ) + lastk = userpost["k"] - 1; // not true with directmsgs in stream + if( args.count > 1 ) { requestPostRecursively(args.containerToAppend, n, "post"+lastk, count-1); + } else { + profilePostsLoading = false; } } }, {containerToAppend:containerToAppend, count:count} ); @@ -179,7 +185,16 @@ function updateProfileData(profileModalContent, username) { profileModalContent.find(".following-count").parent().attr("href", $.MAL.followingUrl(username)); - requestPostRecursively(profileModalContent.find(".postboard-posts"),username,"status",20); + var postsView = profileModalContent.find(".postboard-posts"); + requestPostRecursively(postsView,username,"status",20); + postsView.scroll(function(){ + if (!profilePostsLoading) { + var $this = $(this); + if ($this.scrollTop() >= this.scrollHeight - $this.height() - 20) { + requestPostRecursively($this,username,"post"+lastk,20); + } + } + }); } function updateFollowingData(followingModalContent, username) {