|
|
@ -9,6 +9,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _idTrackerMap = {}; |
|
|
|
var _idTrackerMap = {}; |
|
|
|
|
|
|
|
var _idTrackerSpam = new idTrackerObj(); |
|
|
|
var _lastHaveMap = {}; |
|
|
|
var _lastHaveMap = {}; |
|
|
|
var _refreshInProgress = false; |
|
|
|
var _refreshInProgress = false; |
|
|
|
var _newPostsPending = 0; |
|
|
|
var _newPostsPending = 0; |
|
|
@ -72,17 +73,21 @@ function idTrackerObj() |
|
|
|
/* object to maintain a request state for several users. |
|
|
|
/* object to maintain a request state for several users. |
|
|
|
* each user is tracked by idTrackerObj in global _idTrackerMap. |
|
|
|
* each user is tracked by idTrackerObj in global _idTrackerMap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function requestObj(users, mode, count) |
|
|
|
function requestObj(users, mode, count, getspam) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this.users = users; |
|
|
|
this.users = users; |
|
|
|
this.mode = mode; // 'latest', 'latestFirstTime' or 'older'
|
|
|
|
this.mode = mode; // 'latest', 'latestFirstTime' or 'older'
|
|
|
|
this.count = count; |
|
|
|
this.count = count; |
|
|
|
|
|
|
|
this.getspam = getspam; |
|
|
|
|
|
|
|
|
|
|
|
// 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() { |
|
|
|
var req = []; |
|
|
|
var req = []; |
|
|
|
if( this.mode == 'done') |
|
|
|
if( this.mode == 'done') |
|
|
|
return req; |
|
|
|
return req; |
|
|
|
|
|
|
|
if( this.getspam ) { |
|
|
|
|
|
|
|
return _idTrackerSpam.getRequest(this.mode); |
|
|
|
|
|
|
|
} |
|
|
|
for( var i = 0; i < this.users.length; i++ ) { |
|
|
|
for( var i = 0; i < this.users.length; i++ ) { |
|
|
|
var user = this.users[i]; |
|
|
|
var user = this.users[i]; |
|
|
|
if( !(user in _idTrackerMap) ) |
|
|
|
if( !(user in _idTrackerMap) ) |
|
|
@ -96,6 +101,9 @@ function requestObj(users, mode, count) |
|
|
|
|
|
|
|
|
|
|
|
// receiveId method notifies that a post was received (and possibly shown)
|
|
|
|
// receiveId method notifies that a post was received (and possibly shown)
|
|
|
|
this.reportProcessedPost = function(user, id, shown) { |
|
|
|
this.reportProcessedPost = function(user, id, shown) { |
|
|
|
|
|
|
|
if( this.getspam ) { |
|
|
|
|
|
|
|
_idTrackerSpam.receivedId(this.mode, id, shown); |
|
|
|
|
|
|
|
} |
|
|
|
if( this.users.indexOf(user) >= 0 ) { |
|
|
|
if( this.users.indexOf(user) >= 0 ) { |
|
|
|
_idTrackerMap[user].receivedId(this.mode, id, shown); |
|
|
|
_idTrackerMap[user].receivedId(this.mode, id, shown); |
|
|
|
} |
|
|
|
} |
|
|
@ -115,11 +123,17 @@ function requestObj(users, mode, count) |
|
|
|
function requestGetposts(req) |
|
|
|
function requestGetposts(req) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var r = req.getRequest(); |
|
|
|
var r = req.getRequest(); |
|
|
|
|
|
|
|
if( !req.getspam ) { |
|
|
|
if( r.length ) { |
|
|
|
if( r.length ) { |
|
|
|
twisterRpc("getposts", [req.count,r], |
|
|
|
twisterRpc("getposts", [req.count,r], |
|
|
|
function(req, posts) {processReceivedPosts(req, posts);}, req, |
|
|
|
function(req, posts) {processReceivedPosts(req, posts);}, req, |
|
|
|
function(req, ret) {console.log("ajax error:" + ret);}, req); |
|
|
|
function(req, ret) {console.log("ajax error:" + ret);}, req); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
twisterRpc("getspamposts", [req.count,r.max_id?r.max_id:-1,r.since_id?r.since_id:-1], |
|
|
|
|
|
|
|
function(req, posts) {processReceivedPosts(req, posts);}, req, |
|
|
|
|
|
|
|
function(req, ret) {console.log("ajax error:" + ret);}, req); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// callback to getposts rpc when updating the timeline
|
|
|
|
// callback to getposts rpc when updating the timeline
|
|
|
@ -189,14 +203,14 @@ function processReceivedPosts(req, posts) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// request timeline update for a given list of users
|
|
|
|
// request timeline update for a given list of users
|
|
|
|
function requestTimelineUpdate(mode, count, timelineUsers) |
|
|
|
function requestTimelineUpdate(mode, count, timelineUsers, getspam) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( _refreshInProgress ) |
|
|
|
if( _refreshInProgress ) |
|
|
|
return; |
|
|
|
return; |
|
|
|
$.MAL.postboardLoading(); |
|
|
|
$.MAL.postboardLoading(); |
|
|
|
_refreshInProgress = true; |
|
|
|
_refreshInProgress = true; |
|
|
|
if( timelineUsers.length ) { |
|
|
|
if( timelineUsers.length ) { |
|
|
|
var req = new requestObj(timelineUsers, mode, count); |
|
|
|
var req = new requestObj(timelineUsers, mode, count, getspam); |
|
|
|
requestGetposts(req); |
|
|
|
requestGetposts(req); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log("requestTimelineUpdate: not following any users"); |
|
|
|
console.log("requestTimelineUpdate: not following any users"); |
|
|
@ -269,6 +283,7 @@ function processNewPostsConfirmation(expected, posts) |
|
|
|
function timelineChangedUser() |
|
|
|
function timelineChangedUser() |
|
|
|
{ |
|
|
|
{ |
|
|
|
_idTrackerMap = {}; |
|
|
|
_idTrackerMap = {}; |
|
|
|
|
|
|
|
_idTrackerSpam = new idTrackerObj(); |
|
|
|
_lastHaveMap = {}; |
|
|
|
_lastHaveMap = {}; |
|
|
|
_refreshInProgress = false; |
|
|
|
_refreshInProgress = false; |
|
|
|
_newPostsPending = 0; |
|
|
|
_newPostsPending = 0; |
|
|
|