|
|
@ -188,6 +188,7 @@ function showPosts(req, posts) |
|
|
|
//console.log(req);
|
|
|
|
//console.log(req);
|
|
|
|
//console.log(posts);
|
|
|
|
//console.log(posts);
|
|
|
|
var streamItemsParent = $.MAL.getStreamPostsParent(); |
|
|
|
var streamItemsParent = $.MAL.getStreamPostsParent(); |
|
|
|
|
|
|
|
var streamItems = streamItemsParent.children(); |
|
|
|
|
|
|
|
|
|
|
|
for( var i = 0; i < posts.length; i++ ) { |
|
|
|
for( var i = 0; i < posts.length; i++ ) { |
|
|
|
var post = posts[i]; |
|
|
|
var post = posts[i]; |
|
|
@ -200,31 +201,44 @@ function showPosts(req, posts) |
|
|
|
var streamPostAppended = false; |
|
|
|
var streamPostAppended = false; |
|
|
|
|
|
|
|
|
|
|
|
// insert the post in timeline ordered by (you guessed) time
|
|
|
|
// insert the post in timeline ordered by (you guessed) time
|
|
|
|
// FIXME: lame! searching everything everytime. please optimize!
|
|
|
|
if (streamItems.length) { |
|
|
|
var streamItems = streamItemsParent.children(); |
|
|
|
// check for duplicate twists
|
|
|
|
if( streamItems.length == 0) { |
|
|
|
var streamItemsSameTime = streamItemsParent.children('[data-time='+timePost+']'); |
|
|
|
// timeline is empty
|
|
|
|
if (streamItemsSameTime.length) { |
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
var streamPostInnerHTML = streamPost[0].innerHTML; |
|
|
|
|
|
|
|
for (var j = 0; j < streamItemsSameTime.length; j++) { |
|
|
|
|
|
|
|
var streamItem = streamItemsSameTime.eq(j); |
|
|
|
|
|
|
|
if (streamItem[0].innerHTML === streamPostInnerHTML) { |
|
|
|
streamPostAppended = true; |
|
|
|
streamPostAppended = true; |
|
|
|
} else { |
|
|
|
console.log('appending of duplicate twist prevented'); |
|
|
|
var j = 0; |
|
|
|
break; |
|
|
|
for( j = 0; j < streamItems.length; j++) { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!streamPostAppended) { |
|
|
|
|
|
|
|
for (var j = 0; j < streamItems.length; j++) { |
|
|
|
var streamItem = streamItems.eq(j); |
|
|
|
var streamItem = streamItems.eq(j); |
|
|
|
var timeItem = streamItem.attr("data-time"); |
|
|
|
var timeItem = streamItem.attr("data-time"); |
|
|
|
if( timeItem == undefined || |
|
|
|
if( timeItem == undefined || |
|
|
|
timePost > parseInt(timeItem) ) { |
|
|
|
timePost > parseInt(timeItem) ) { |
|
|
|
// this post in stream is older, so post must be inserted above
|
|
|
|
// this post in stream is older, so post must be inserted above
|
|
|
|
streamItem.before(streamPost); |
|
|
|
streamItem.before(streamPost); |
|
|
|
|
|
|
|
streamItems[streamItems.length] = streamPost[0]; |
|
|
|
|
|
|
|
streamItems.length += 1; |
|
|
|
streamPostAppended = true; |
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
streamPost.show(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!streamPostAppended) |
|
|
|
} |
|
|
|
|
|
|
|
if (!streamPostAppended) { |
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
|
|
|
|
streamItems[streamItems.length] = streamPost[0]; |
|
|
|
|
|
|
|
streamItems.length += 1; |
|
|
|
streamPostAppended = true; |
|
|
|
streamPostAppended = true; |
|
|
|
streamPost.show(); |
|
|
|
streamPost.show(); |
|
|
|
|
|
|
|
} |
|
|
|
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended); |
|
|
|
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|