|
|
@ -12,7 +12,8 @@ var _idTrackerMap = {}; |
|
|
|
var _idTrackerSpam = new idTrackerObj(); |
|
|
|
var _idTrackerSpam = new idTrackerObj(); |
|
|
|
var _lastHaveMap = {}; |
|
|
|
var _lastHaveMap = {}; |
|
|
|
var _refreshInProgress = false; |
|
|
|
var _refreshInProgress = false; |
|
|
|
var _newPostsPending = 0; |
|
|
|
var _newPostsPending = []; |
|
|
|
|
|
|
|
var _sendedPostIDs = []; |
|
|
|
var timelineLoaded = false; |
|
|
|
var timelineLoaded = false; |
|
|
|
|
|
|
|
|
|
|
|
/* object to keep tracking of post ids for a given user, that is, which |
|
|
|
/* object to keep tracking of post ids for a given user, that is, which |
|
|
@ -79,7 +80,6 @@ function requestObj(users, mode, count, getspam) |
|
|
|
this.mode = mode; // 'latest', 'latestFirstTime' or 'older'
|
|
|
|
this.mode = mode; // 'latest', 'latestFirstTime' or 'older'
|
|
|
|
this.count = count; |
|
|
|
this.count = count; |
|
|
|
this.getspam = getspam; |
|
|
|
this.getspam = getspam; |
|
|
|
this.updateReportNewPosts = (users.toString() === defaultScreenName || mode === 'older') ? false : true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// getRequest method returns the list parameter expected by getposts rpc
|
|
|
|
// getRequest method returns the list parameter expected by getposts rpc
|
|
|
|
this.getRequest = function() { |
|
|
|
this.getRequest = function() { |
|
|
@ -149,77 +149,23 @@ function requestGetposts(req) |
|
|
|
function processReceivedPosts(req, posts) |
|
|
|
function processReceivedPosts(req, posts) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//hiding posts can cause empty postboard, so we have to track the count...
|
|
|
|
//hiding posts can cause empty postboard, so we have to track the count...
|
|
|
|
var p2a = posts.length; |
|
|
|
|
|
|
|
for( var i = 0; i < posts.length; i++ ) { |
|
|
|
for( var i = 0; i < posts.length; i++ ) { |
|
|
|
var post = posts[i]; |
|
|
|
if (willBeHidden(posts[i])) { |
|
|
|
if (willBeHidden(post)) { |
|
|
|
posts.splice(i, 1); |
|
|
|
p2a--; |
|
|
|
i--; |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var streamPost = postToElem(post, "original", req.getspam); |
|
|
|
|
|
|
|
var timePost = post["userpost"]["time"]; |
|
|
|
|
|
|
|
streamPost.attr("data-time",timePost); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// post will only be shown if appended to the stream list
|
|
|
|
|
|
|
|
var streamPostAppended = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// insert the post in timeline ordered by (you guessed) time
|
|
|
|
|
|
|
|
// FIXME: lame! searching everything everytime. please optimize!
|
|
|
|
|
|
|
|
var streamItemsParent = $.MAL.getStreamPostsParent(); |
|
|
|
|
|
|
|
var streamItems = streamItemsParent.children(); |
|
|
|
|
|
|
|
if( streamItems.length == 0) { |
|
|
|
|
|
|
|
// timeline is empty
|
|
|
|
|
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var j = 0; |
|
|
|
|
|
|
|
for( j = 0; j < streamItems.length; j++) { |
|
|
|
|
|
|
|
var streamItem = streamItems.eq(j); |
|
|
|
|
|
|
|
var timeItem = streamItem.attr("data-time"); |
|
|
|
|
|
|
|
if( timeItem == undefined || |
|
|
|
|
|
|
|
timePost > parseInt(timeItem) ) { |
|
|
|
|
|
|
|
// this post in stream is older, so post must be inserted above
|
|
|
|
|
|
|
|
streamItem.before(streamPost); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if( j == streamItems.length ) { |
|
|
|
|
|
|
|
// no older posts in stream, so post is to be inserted below
|
|
|
|
|
|
|
|
if( req.mode == "older" || req.mode == "latestFirstTime" ) { |
|
|
|
|
|
|
|
// note: when filling gaps, the post must be discarded (not
|
|
|
|
|
|
|
|
// shown) since it can never be older than what we already
|
|
|
|
|
|
|
|
// have on timeline. this is a problem due to requesting from
|
|
|
|
|
|
|
|
// several users at the same time, as some older posts might
|
|
|
|
|
|
|
|
// be included to complete the <count> in getposts because
|
|
|
|
|
|
|
|
// other users may have already been excluded by since_id.
|
|
|
|
|
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( streamPostAppended ) { |
|
|
|
|
|
|
|
streamPost.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
req.doneReportProcessing(p2a); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (req.updateReportNewPosts) { |
|
|
|
|
|
|
|
_newPostsPending = 0; // FIXME maybe we need updating here instead this zeroing
|
|
|
|
|
|
|
|
$.MAL.reportNewPosts(_newPostsPending); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
showPosts(req, posts); |
|
|
|
|
|
|
|
req.doneReportProcessing(posts.length); |
|
|
|
|
|
|
|
|
|
|
|
//if the count of recieved posts less then or equals to requested...
|
|
|
|
//if the count of recieved posts less or equals to requested then...
|
|
|
|
if (req.mode === 'done') { |
|
|
|
if (req.mode === 'done') { |
|
|
|
timelineLoaded = true; |
|
|
|
timelineLoaded = true; |
|
|
|
$.MAL.postboardLoaded(); |
|
|
|
$.MAL.postboardLoaded(); |
|
|
|
_refreshInProgress = false; |
|
|
|
_refreshInProgress = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//we will request more older post...
|
|
|
|
//we will request more older post...
|
|
|
|
req.count -= p2a; |
|
|
|
req.count -= posts.length; |
|
|
|
if (req.count > 0) { |
|
|
|
if (req.count > 0) { |
|
|
|
//console.log('we are requesting '+req.count+' more posts...');
|
|
|
|
//console.log('we are requesting '+req.count+' more posts...');
|
|
|
|
requestGetposts(req); |
|
|
|
requestGetposts(req); |
|
|
@ -231,6 +177,64 @@ function processReceivedPosts(req, posts) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function showPosts(req, posts) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var streamItemsParent = $.MAL.getStreamPostsParent(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for( var i = 0; i < posts.length; i++ ) { |
|
|
|
|
|
|
|
if ( req.users.indexOf(posts[i]['userpost']['n']) > -1 ) { |
|
|
|
|
|
|
|
var post = posts[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var streamPost = postToElem(post, "original", req.getspam); |
|
|
|
|
|
|
|
var timePost = post["userpost"]["time"]; |
|
|
|
|
|
|
|
streamPost.attr("data-time",timePost); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// post will only be shown if appended to the stream list
|
|
|
|
|
|
|
|
var streamPostAppended = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// insert the post in timeline ordered by (you guessed) time
|
|
|
|
|
|
|
|
// FIXME: lame! searching everything everytime. please optimize!
|
|
|
|
|
|
|
|
var streamItems = streamItemsParent.children(); |
|
|
|
|
|
|
|
if( streamItems.length == 0) { |
|
|
|
|
|
|
|
// timeline is empty
|
|
|
|
|
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var j = 0; |
|
|
|
|
|
|
|
for( j = 0; j < streamItems.length; j++) { |
|
|
|
|
|
|
|
var streamItem = streamItems.eq(j); |
|
|
|
|
|
|
|
var timeItem = streamItem.attr("data-time"); |
|
|
|
|
|
|
|
if( timeItem == undefined || |
|
|
|
|
|
|
|
timePost > parseInt(timeItem) ) { |
|
|
|
|
|
|
|
// this post in stream is older, so post must be inserted above
|
|
|
|
|
|
|
|
streamItem.before(streamPost); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if( j == streamItems.length ) { |
|
|
|
|
|
|
|
// no older posts in stream, so post is to be inserted below
|
|
|
|
|
|
|
|
if( req.mode == "older" || req.mode == "latestFirstTime" ) { |
|
|
|
|
|
|
|
// note: when filling gaps, the post must be discarded (not
|
|
|
|
|
|
|
|
// shown) since it can never be older than what we already
|
|
|
|
|
|
|
|
// have on timeline. this is a problem due to requesting from
|
|
|
|
|
|
|
|
// several users at the same time, as some older posts might
|
|
|
|
|
|
|
|
// be included to complete the <count> in getposts because
|
|
|
|
|
|
|
|
// other users may have already been excluded by since_id.
|
|
|
|
|
|
|
|
streamItemsParent.append( streamPost ); |
|
|
|
|
|
|
|
streamPostAppended = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( streamPostAppended ) { |
|
|
|
|
|
|
|
streamPost.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// request timeline update for a given list of users
|
|
|
|
// request timeline update for a given list of users
|
|
|
|
function requestTimelineUpdate(mode, count, timelineUsers, getspam) |
|
|
|
function requestTimelineUpdate(mode, count, timelineUsers, getspam) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -241,7 +245,16 @@ function requestTimelineUpdate(mode, count, timelineUsers, getspam) |
|
|
|
_refreshInProgress = true; |
|
|
|
_refreshInProgress = true; |
|
|
|
if( timelineUsers.length ) { |
|
|
|
if( timelineUsers.length ) { |
|
|
|
var req = new requestObj(timelineUsers, mode, count, getspam); |
|
|
|
var req = new requestObj(timelineUsers, mode, count, getspam); |
|
|
|
requestGetposts(req); |
|
|
|
if (mode === 'pending') { |
|
|
|
|
|
|
|
req.mode = 'latest'; |
|
|
|
|
|
|
|
showPosts(req, _newPostsPending); |
|
|
|
|
|
|
|
_newPostsPending = []; |
|
|
|
|
|
|
|
$.MAL.reportNewPosts(_newPostsPending.length); |
|
|
|
|
|
|
|
$.MAL.postboardLoaded(); |
|
|
|
|
|
|
|
_refreshInProgress = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
requestGetposts(req); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log("requestTimelineUpdate: not following any users"); |
|
|
|
console.log("requestTimelineUpdate: not following any users"); |
|
|
|
} |
|
|
|
} |
|
|
@ -293,24 +306,35 @@ function processLastHave(userHaves) |
|
|
|
// callback for getposts to update the number of new pending posts not shown in timeline
|
|
|
|
// callback for getposts to update the number of new pending posts not shown in timeline
|
|
|
|
function processNewPostsConfirmation(expected, posts) |
|
|
|
function processNewPostsConfirmation(expected, posts) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//we don't want to produce alert for the posts that won't be displayed
|
|
|
|
//console.log('we got '+posts.length+' posts from expected '+expected+' for confirmation');
|
|
|
|
var pnp = 0; |
|
|
|
//console.log(posts);
|
|
|
|
|
|
|
|
// we want to report about new posts that would be displayed
|
|
|
|
|
|
|
|
var rnp = 0; |
|
|
|
|
|
|
|
// we want to display sended posts immediately
|
|
|
|
|
|
|
|
var sendedPostsPending = []; |
|
|
|
for( var i = posts.length-1; i >= 0; i-- ) { |
|
|
|
for( var i = posts.length-1; i >= 0; i-- ) { |
|
|
|
if (willBeHidden(posts[i]) || posts[i]['userpost']['n'] === defaultScreenName) { |
|
|
|
if ( !willBeHidden(posts[i]) ) { |
|
|
|
pnp++; |
|
|
|
if ( _sendedPostIDs.indexOf(posts[i]['userpost']['k']) > -1 ) { |
|
|
|
|
|
|
|
sendedPostsPending.push(posts[i]); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
_newPostsPending.push(posts[i]); |
|
|
|
|
|
|
|
rnp++; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_newPostsPending += posts.length - pnp; |
|
|
|
if ( rnp > 0 ) { |
|
|
|
if( _newPostsPending ) { |
|
|
|
$.MAL.reportNewPosts(_newPostsPending.length); |
|
|
|
$.MAL.reportNewPosts(_newPostsPending); |
|
|
|
} |
|
|
|
|
|
|
|
if ( sendedPostsPending.length > 0 ) { |
|
|
|
|
|
|
|
var req = new requestObj([defaultScreenName],'latest',sendedPostsPending.length,promotedPostsOnly); |
|
|
|
|
|
|
|
showPosts(req, sendedPostsPending); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if( posts.length < expected ) { |
|
|
|
if( posts.length < expected ) { |
|
|
|
// new DMs have probably been produced by users we follow.
|
|
|
|
// new DMs have probably been produced by users we follow.
|
|
|
|
// check with getdirectmsgs
|
|
|
|
// check with getdirectmsgs
|
|
|
|
requestDMsCount(); |
|
|
|
requestDMsCount(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: possibly cache this response
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function timelineChangedUser() |
|
|
|
function timelineChangedUser() |
|
|
@ -319,7 +343,8 @@ function timelineChangedUser() |
|
|
|
_idTrackerSpam = new idTrackerObj(); |
|
|
|
_idTrackerSpam = new idTrackerObj(); |
|
|
|
_lastHaveMap = {}; |
|
|
|
_lastHaveMap = {}; |
|
|
|
_refreshInProgress = false; |
|
|
|
_refreshInProgress = false; |
|
|
|
_newPostsPending = 0; |
|
|
|
_newPostsPending = []; |
|
|
|
|
|
|
|
_sendedPostIDs = []; |
|
|
|
timelineLoaded = false; |
|
|
|
timelineLoaded = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|