Browse Source

new option: "Switch to Promoted posts" (requires twister-core 0.9.15)

master
Miguel Freitas 11 years ago
parent
commit
af9699d645
  1. 3
      home.html
  2. 15
      interface_home.js
  3. 21
      twister_timeline.js

3
home.html

@ -48,7 +48,8 @@
<a class="dropdown-menu-item" href="following.html">Following users</a> <a class="dropdown-menu-item" href="following.html">Following users</a>
<a class="dropdown-menu-item" href="network.html">Network config</a> <a class="dropdown-menu-item" href="network.html">Network config</a>
<a class="dropdown-menu-item" href="login.html">Change user</a> <a class="dropdown-menu-item" href="login.html">Change user</a>
<a class="direct-messages" href="#">Direct Messages</a> <a class="dropdown-menu-item promoted-posts-only" href="#">Switch to Promoted posts</a>
<a class="direct-messages dropdown-menu-item" href="#">Direct Messages</a>
</div> </div>
</a> </a>
</li> </li>

15
interface_home.js

@ -3,6 +3,8 @@
// //
// Specific interface functions for home.html // Specific interface functions for home.html
var promotedPostsOnly = false;
//*********************************************** //***********************************************
//******************* DECLARATIONS ************** //******************* DECLARATIONS **************
//*********************************************** //***********************************************
@ -12,7 +14,14 @@ var InterfaceFunctions = function()
this.init = function() this.init = function()
{ {
$( ".wrapper .postboard-news").click(function() { $( ".wrapper .postboard-news").click(function() {
requestTimelineUpdate("latest",postsPerRefresh,followingUsers);}); requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);});
$( ".promoted-posts-only").click(function() {
promotedPostsOnly = !promotedPostsOnly;
$(this).text( promotedPostsOnly ? "Switch to Normal posts" : "Switch to Promoted posts" );
timelineChangedUser();
$.MAL.getStreamPostsParent().empty();
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers,promotedPostsOnly);
});
initInterfaceCommon(); initInterfaceCommon();
initUserSearch(); initUserSearch();
@ -45,13 +54,13 @@ var InterfaceFunctions = function()
setInterval("requestLastHave()", 1000); setInterval("requestLastHave()", 1000);
initMentionsCount(); initMentionsCount();
initDMsCount(); initDMsCount();
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers); requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers,promotedPostsOnly);
// install scrollbottom handler to load more posts as needed // install scrollbottom handler to load more posts as needed
$(window).scroll(function(){ $(window).scroll(function(){
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 20){ if ($(window).scrollTop() >= $(document).height() - $(window).height() - 20){
if( timelineLoaded ) { if( timelineLoaded ) {
requestTimelineUpdate("older", postsPerRefresh, followingUsers); requestTimelineUpdate("older", postsPerRefresh, followingUsers, promotedPostsOnly);
} }
} }
}); });

21
twister_timeline.js

@ -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;

Loading…
Cancel
Save