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. 43
      js/twister_timeline.js

6
js/interface_common.js

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

12
js/interface_home.js

@ -14,11 +14,19 @@ var InterfaceFunctions = function()
this.init = function() this.init = function()
{ {
$( ".wrapper .postboard-news").click(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 // Add refresh posts for home link in menu
$( ".userMenu-home.current a").click(function() { $( ".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() { $( ".promoted-posts-only").click(function() {
promotedPostsOnly = !promotedPostsOnly; promotedPostsOnly = !promotedPostsOnly;

6
js/mobile_abstract.js

@ -104,9 +104,9 @@ var MAL = function()
newTweetsBarMenu.addClass("show"); newTweetsBarMenu.addClass("show");
if ($.Options.getShowDesktopNotifPostsOpt() === 'enable') { 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() { 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); requestTimelineUpdate('latest',this,followingUsers,promotedPostsOnly);
}, false) }).bind(newPosts), false)
} }
} else { } else {
newTweetsBar.hide(); newTweetsBar.hide();

4
js/twister_actions.js

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

5
js/twister_following.js

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

43
js/twister_timeline.js

@ -79,6 +79,7 @@ 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() {
@ -111,10 +112,17 @@ function requestObj(users, mode, count, getspam)
// doneReportProcessing is called after an getposts response is processed // doneReportProcessing is called after an getposts response is processed
// mode changing may require a new request (to fill gaps) // mode changing may require a new request (to fill gaps)
this.doneReportProcessing = function(receivedCount) { this.doneReportProcessing = function(receivedCount) {
if( this.mode == 'latest') this.mode = 'fillgap'; if (receivedCount === this.count) {
if( this.mode == 'latestFirstTime') this.mode = 'done'; this.mode = 'done';
if( this.mode == 'older') this.mode = 'done'; } else {
if( receivedCount < this.count ) this.mode = 'done'; 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)
} }
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended); 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 the count of recieved posts less then or equals to requested...
if( req.mode == "done" && p2a > 5) { if (req.mode === 'done') {
timelineLoaded = true; timelineLoaded = true;
$.MAL.postboardLoaded(); $.MAL.postboardLoaded();
_refreshInProgress = false; _refreshInProgress = false;
$(window).scroll();
} else { } else {
//we will request more older post... //we will request more older post...
req.count += postsPerRefresh; req.count -= p2a;
req.mode = 'older'; if (req.count > 0) {
//console.log('we are requesting '+req.count+' more posts...');
requestGetposts(req); requestGetposts(req);
} else {
timelineLoaded = true;
$.MAL.postboardLoaded();
_refreshInProgress = false;
}
} }
} }
// 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)
{ {
//console.log(mode+' timeline update request: '+count+' posts for following users - '+timelineUsers);
if( _refreshInProgress || !defaultScreenName) if( _refreshInProgress || !defaultScreenName)
return; return;
$.MAL.postboardLoading(); $.MAL.postboardLoading();
@ -226,10 +245,6 @@ function requestTimelineUpdate(mode, count, timelineUsers, getspam)
} else { } else {
console.log("requestTimelineUpdate: not following any users"); 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 // getlasthave is called every second to check if followed users have posted anything new

Loading…
Cancel
Save