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. 17
      interface_home.js
  3. 29
      twister_timeline.js

3
home.html

@ -48,7 +48,8 @@ @@ -48,7 +48,8 @@
<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="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>
</a>
</li>

17
interface_home.js

@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
//
// Specific interface functions for home.html
var promotedPostsOnly = false;
//***********************************************
//******************* DECLARATIONS **************
//***********************************************
@ -12,8 +14,15 @@ var InterfaceFunctions = function() @@ -12,8 +14,15 @@ var InterfaceFunctions = function()
this.init = 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();
initUserSearch();
initInterfaceDirectMsg();
@ -45,13 +54,13 @@ var InterfaceFunctions = function() @@ -45,13 +54,13 @@ var InterfaceFunctions = function()
setInterval("requestLastHave()", 1000);
initMentionsCount();
initDMsCount();
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers);
requestTimelineUpdate("latestFirstTime",postsPerRefresh,followingUsers,promotedPostsOnly);
// install scrollbottom handler to load more posts as needed
$(window).scroll(function(){
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 20){
if( timelineLoaded ) {
requestTimelineUpdate("older", postsPerRefresh, followingUsers);
requestTimelineUpdate("older", postsPerRefresh, followingUsers, promotedPostsOnly);
}
}
});

29
twister_timeline.js

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

Loading…
Cancel
Save