Browse Source

improve of timeline updates, fix of follow button event handler

master
Simon Grim 10 years ago
parent
commit
33bea37ae0
  1. 6
      js/interface_common.js
  2. 12
      js/interface_home.js
  3. 6
      js/mobile_abstract.js
  4. 4
      js/twister_actions.js
  5. 5
      js/twister_following.js
  6. 45
      js/twister_timeline.js

6
js/interface_common.js

@ -590,7 +590,7 @@ function toggleFollowButton(username, toggleUnfollow, bindFunc) { @@ -590,7 +590,7 @@ function toggleFollowButton(username, toggleUnfollow, bindFunc) {
.unbind("click")
.bind("click",
(function(e) {
userClickFollow;
userClickFollow(e);
if (this.bindFunc)
this.bindFunc;
@ -855,9 +855,8 @@ function replyTextKeypress(e) { @@ -855,9 +855,8 @@ function replyTextKeypress(e) {
tweetAction.click();
}
}
}else if( !$.Options.keyEnterToSend() ){
} else if( !$.Options.keyEnterToSend() ){
if (e.keyCode === 13 && (e.metaKey || e.ctrlKey)) {
$this.val($this.val().trim());
if( !tweetAction.hasClass("disabled") ) {
tweetAction.click();
@ -1367,7 +1366,6 @@ var postSubmit = function(e, oldLastPostId) @@ -1367,7 +1366,6 @@ var postSubmit = function(e, oldLastPostId)
if($this.closest('.post-area,.post-reply-content')){
$('.post-area-new').removeClass('open').find('textarea').blur();
};
setTimeout('requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly)', 1000);
$replyText.data("unicodeConversionStack", []);
$replyText.data("disabledUnicodeRules", []);
}

12
js/interface_home.js

@ -14,11 +14,19 @@ var InterfaceFunctions = function() @@ -14,11 +14,19 @@ var InterfaceFunctions = function()
this.init = function()
{
$( ".wrapper .postboard-news").click(function() {
requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);});
var newPosts = parseInt($(".userMenu .menu-news").text());
if (!newPosts)
newPosts = postsPerRefresh;
requestTimelineUpdate("latest",newPosts,followingUsers,promotedPostsOnly);
});
// Add refresh posts for home link in menu
$( ".userMenu-home.current a").click(function() {
requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);});
var newPosts = parseInt($(".userMenu .menu-news").text());
if (!newPosts)
newPosts = postsPerRefresh;
requestTimelineUpdate("latest",newPosts,followingUsers,promotedPostsOnly);
});
$( ".promoted-posts-only").click(function() {
promotedPostsOnly = !promotedPostsOnly;

6
js/mobile_abstract.js

@ -104,9 +104,9 @@ var MAL = function() @@ -104,9 +104,9 @@ var MAL = function()
newTweetsBarMenu.addClass("show");
if ($.Options.getShowDesktopNotifPostsOpt() === 'enable') {
this.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t("new_posts", newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', $.Options.getShowDesktopNotifPostsTimerOpt(), function() {
requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly);
}, false)
this.showDesktopNotif(false, polyglot.t('You got')+' '+polyglot.t('new_posts', newPosts)+' '+polyglot.t('in postboard')+'.', false,'twister_notification_new_posts', $.Options.getShowDesktopNotifPostsTimerOpt(), (function() {
requestTimelineUpdate('latest',this,followingUsers,promotedPostsOnly);
}).bind(newPosts), false)
}
} else {
newTweetsBar.hide();

4
js/twister_actions.js

@ -224,7 +224,6 @@ function requestPostRecursively(containerToAppend,username,resource,count,useGet @@ -224,7 +224,6 @@ function requestPostRecursively(containerToAppend,username,resource,count,useGet
}
}
function newPostMsg(msg, $postOrig) {
if( lastPostId != undefined ) {
var params = [defaultScreenName, lastPostId + 1, msg]
@ -236,6 +235,7 @@ function newPostMsg(msg, $postOrig) { @@ -236,6 +235,7 @@ function newPostMsg(msg, $postOrig) {
function(arg, ret) { incLastPostId(); }, null,
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert(polyglot.t("ajax_error", { error: msg })); }, null);
setTimeout('requestTimelineUpdate("latest",1,["'+defaultScreenName+'"],promotedPostsOnly)', 1000);
} else {
alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
}
@ -256,7 +256,7 @@ function newRtMsg($postOrig) { @@ -256,7 +256,7 @@ function newRtMsg($postOrig) {
function(arg, ret) { incLastPostId(); }, null,
function(arg, ret) { var msg = ("message" in ret) ? ret.message : ret;
alert(polyglot.t("ajax_error", { error: msg })); }, null);
setTimeout('requestTimelineUpdate("latest",postsPerRefresh,followingUsers,promotedPostsOnly)', 1000);
setTimeout('requestTimelineUpdate("latest",1,["'+defaultScreenName+'"],promotedPostsOnly)', 1000);
} else {
alert(polyglot.t("Internal error: lastPostId unknown (following yourself may fix!)"));
}

5
js/twister_following.js

@ -366,6 +366,7 @@ function updateFollowing(cbFunc, cbArg) { @@ -366,6 +366,7 @@ function updateFollowing(cbFunc, cbArg) {
// it is safe to call this even if username is already in followingUsers.
// may also be used to set/clear publicFollow.
function follow(user, publicFollow, cbFunc, cbArg) {
//console.log('we are following @'+user);
if( followingUsers.indexOf(user) < 0 ) {
followingUsers.push(user);
twisterFollowingO.update(user);
@ -380,6 +381,7 @@ function follow(user, publicFollow, cbFunc, cbArg) { @@ -380,6 +381,7 @@ function follow(user, publicFollow, cbFunc, cbArg) {
// unfollow a single user
function unfollow(user, cbFunc, cbArg) {
//console.log('we are not following @'+user+' anymore');
var i = followingUsers.indexOf(user);
if( i >= 0 ) {
followingUsers.splice(i,1);
@ -696,8 +698,7 @@ function userClickFollow(e) { @@ -696,8 +698,7 @@ function userClickFollow(e) {
e.stopPropagation();
e.preventDefault();
var $this = $(this);
var $userInfo = $this.closest("[data-screen-name]");
var $userInfo = $(e.target).closest("[data-screen-name]");
var username = $userInfo.attr("data-screen-name");
if(!defaultScreenName)

45
js/twister_timeline.js

@ -79,6 +79,7 @@ function requestObj(users, mode, count, getspam) @@ -79,6 +79,7 @@ function requestObj(users, mode, count, getspam)
this.mode = mode; // 'latest', 'latestFirstTime' or 'older'
this.count = count;
this.getspam = getspam;
this.updateReportNewPosts = (users.toString() === defaultScreenName || mode === 'older') ? false : true;
// getRequest method returns the list parameter expected by getposts rpc
this.getRequest = function() {
@ -111,10 +112,17 @@ function requestObj(users, mode, count, getspam) @@ -111,10 +112,17 @@ function requestObj(users, mode, count, getspam)
// doneReportProcessing is called after an getposts response is processed
// mode changing may require a new request (to fill gaps)
this.doneReportProcessing = function(receivedCount) {
if( this.mode == 'latest') this.mode = 'fillgap';
if( this.mode == 'latestFirstTime') this.mode = 'done';
if( this.mode == 'older') this.mode = 'done';
if( receivedCount < this.count ) this.mode = 'done';
if (receivedCount === this.count) {
this.mode = 'done';
} else {
if (this.mode === 'latest' || this.mode === 'latestFirstTime') {
this.mode = 'fillgap';
} else if (this.mode === 'fillgap') {
this.mode = 'older';
} else if (this.mode === 'older')
this.mode = 'done';
}
//console.log('we got '+receivedCount+' posts from requested '+this.count+', status of processing is "'+this.mode+'"');
}
}
@ -197,25 +205,36 @@ function processReceivedPosts(req, posts) @@ -197,25 +205,36 @@ function processReceivedPosts(req, posts)
}
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended);
}
req.doneReportProcessing(posts.length);
req.doneReportProcessing(p2a);
if (req.updateReportNewPosts) {
_newPostsPending = 0; // FIXME maybe we need updating here instead this zeroing
$.MAL.reportNewPosts(_newPostsPending);
}
//if the count of posts less then 5....
if( req.mode == "done" && p2a > 5) {
//if the count of recieved posts less then or equals to requested...
if (req.mode === 'done') {
timelineLoaded = true;
$.MAL.postboardLoaded();
_refreshInProgress = false;
$(window).scroll();
} else {
//we will request more older post...
req.count += postsPerRefresh;
req.mode = 'older';
requestGetposts(req);
req.count -= p2a;
if (req.count > 0) {
//console.log('we are requesting '+req.count+' more posts...');
requestGetposts(req);
} else {
timelineLoaded = true;
$.MAL.postboardLoaded();
_refreshInProgress = false;
}
}
}
// request timeline update for a given list of users
function requestTimelineUpdate(mode, count, timelineUsers, getspam)
{
//console.log(mode+' timeline update request: '+count+' posts for following users - '+timelineUsers);
if( _refreshInProgress || !defaultScreenName)
return;
$.MAL.postboardLoading();
@ -226,10 +245,6 @@ function requestTimelineUpdate(mode, count, timelineUsers, getspam) @@ -226,10 +245,6 @@ function requestTimelineUpdate(mode, count, timelineUsers, getspam)
} else {
console.log("requestTimelineUpdate: not following any users");
}
if( mode == "latest" || mode == "latestFirstTime" ) {
_newPostsPending = 0;
$.MAL.reportNewPosts(0);
}
}
// getlasthave is called every second to check if followed users have posted anything new

Loading…
Cancel
Save