Browse Source

Merge pull request #31 from dryabov/master

auto load old posts in profile view
master
iHedgehog 11 years ago
parent
commit
0cbad0e0a7
  1. 21
      js/twister_actions.js

21
js/twister_actions.js

@ -95,8 +95,12 @@ function requestRTs(postLi)
} }
} }
var lastk,
profilePostsLoading = false;
function requestPostRecursively(containerToAppend,username,resource,count) function requestPostRecursively(containerToAppend,username,resource,count)
{ {
profilePostsLoading = true;
dhtget( username, resource, "s", dhtget( username, resource, "s",
function(args, postFromJson) { function(args, postFromJson) {
if( postFromJson ) { if( postFromJson ) {
@ -106,14 +110,16 @@ function requestPostRecursively(containerToAppend,username,resource,count)
newStreamPost.slideDown("fast"); newStreamPost.slideDown("fast");
$.MAL.postboardLoaded(); $.MAL.postboardLoaded();
if( args.count > 1 ) {
var userpost = postFromJson["userpost"]; var userpost = postFromJson["userpost"];
var n = userpost["n"]; var n = userpost["n"];
var lastk = userpost["lastk"]; lastk = userpost["lastk"];
if( lastk == undefined ) if( lastk == undefined )
lastk = userpost["k"] - 1; // not true with directmsgs in stream lastk = userpost["k"] - 1; // not true with directmsgs in stream
if( args.count > 1 ) {
requestPostRecursively(args.containerToAppend, n, "post"+lastk, count-1); requestPostRecursively(args.containerToAppend, n, "post"+lastk, count-1);
} else {
profilePostsLoading = false;
} }
} }
}, {containerToAppend:containerToAppend, count:count} ); }, {containerToAppend:containerToAppend, count:count} );
@ -179,7 +185,16 @@ function updateProfileData(profileModalContent, username) {
profileModalContent.find(".following-count").parent().attr("href", $.MAL.followingUrl(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) { function updateFollowingData(followingModalContent, username) {

Loading…
Cancel
Save