update the stream states in localstorage more often, and some messing with setting new streams
This commit is contained in:
parent
cff9c53f78
commit
ae24576fe7
|
@ -628,9 +628,7 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
|
||||||
$('.error-message').remove();
|
$('.error-message').remove();
|
||||||
|
|
||||||
// remember state of old stream (including profile card)
|
// remember state of old stream (including profile card)
|
||||||
if(typeof window.currentStreamObject != 'undefined') {
|
rememberStreamStateInLocalStorage();
|
||||||
localStorageObjectCache_STORE('streamState',window.currentStreamObject.path, $('#feed').siblings('.profile-card').outerHTML() + $('#feed').outerHTML());
|
|
||||||
}
|
|
||||||
|
|
||||||
// halt interval that checks for new queets
|
// halt interval that checks for new queets
|
||||||
window.clearInterval(checkForNewQueetsInterval);
|
window.clearInterval(checkForNewQueetsInterval);
|
||||||
|
@ -644,36 +642,57 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
|
||||||
// blur any selected links
|
// blur any selected links
|
||||||
$('a').blur();
|
$('a').blur();
|
||||||
|
|
||||||
// null any pagings
|
// unset metadata for the old stream saved in attributes
|
||||||
$('#feed-body').removeAttr('data-search-page-number');
|
$('#feed-body').removeAttr('data-search-page-number');
|
||||||
|
$('#feed-body').removeAttr('data-end-reached');
|
||||||
|
|
||||||
|
// are we just reloading?
|
||||||
|
var weAreReloading = false;
|
||||||
|
if(typeof window.currentStreamObject != 'undefined' && window.currentStreamObject.name == streamObject.name) {
|
||||||
|
weAreReloading = true;
|
||||||
|
}
|
||||||
|
|
||||||
// remember the most recent stream
|
// remember the most recent stream
|
||||||
window.currentStream = streamObject.stream;
|
window.currentStream = streamObject.stream;
|
||||||
window.currentStreamObject = streamObject;
|
window.currentStreamObject = streamObject;
|
||||||
|
|
||||||
|
// set the new streams header
|
||||||
if(streamObject.streamSubHeader) {
|
if(streamObject.streamSubHeader) {
|
||||||
var h2FeedHeader = streamObject.streamSubHeader;
|
$('#feed-header-inner h2').html(streamObject.streamSubHeader);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var h2FeedHeader = streamObject.streamHeader;
|
$('#feed-header-inner h2').html(streamObject.streamHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a saved copy of this stream, show it immediately (but it is replaced when stream finishes to load later)
|
// add menu cog if this stream has a menu
|
||||||
var haveOldStreamState = localStorageObjectCache_GET('streamState',window.currentStreamObject.path);
|
|
||||||
if(haveOldStreamState) {
|
|
||||||
$('.profile-card,.hover-card,.hover-card-caret').remove();
|
|
||||||
$('#feed').remove();
|
|
||||||
$('#user-container').after(haveOldStreamState);
|
|
||||||
$('.profile-card').css('display','none');
|
|
||||||
$('#feed').css('display','none');
|
|
||||||
$('.profile-card').show();
|
|
||||||
$('#feed').show();
|
|
||||||
$('#feed-body').removeAttr('data-end-reached');
|
|
||||||
$('#feed-header-inner h2').css('opacity','0.2');
|
|
||||||
$('#feed-header-inner h2').html(h2FeedHeader); // update header (could be wrong in cache)
|
|
||||||
if(streamObject.menu && window.loggedIn) {
|
if(streamObject.menu && window.loggedIn) {
|
||||||
$('#feed-header-inner h2').append('<div id="stream-menu-cog" data-tooltip="' + window.sL.timelineOptions + '"></div>');
|
$('#feed-header-inner h2').append('<div id="stream-menu-cog" data-tooltip="' + window.sL.timelineOptions + '"></div>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we're just reloading, we dont need to:
|
||||||
|
// (1) check if we have a cached version of this stream
|
||||||
|
// (2) remove the stream if we don't
|
||||||
|
// (3) change design
|
||||||
|
if(weAreReloading === false) {
|
||||||
|
|
||||||
|
// (1) check if we have a cached version of the stream
|
||||||
|
var haveOldStreamState = localStorageObjectCache_GET('streamState',window.currentStreamObject.path);
|
||||||
|
|
||||||
|
// discard and remove any cached data that is not in this (new) format
|
||||||
|
if(typeof haveOldStreamState.card == 'undefined'
|
||||||
|
|| typeof haveOldStreamState.feed == 'undefined') {
|
||||||
|
localStorageObjectCache_STORE('streamState',window.currentStreamObject.path, false);
|
||||||
|
haveOldStreamState = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show cached version immediately (it is replaced when stream finishes to load later)
|
||||||
|
if(haveOldStreamState) {
|
||||||
|
$('.profile-card,.hover-card,.hover-card-caret').remove();
|
||||||
|
$('#feed').before(haveOldStreamState.card);
|
||||||
|
$('#feed-body').html(haveOldStreamState.feed);
|
||||||
|
|
||||||
|
// subtle animation to show somethings happening
|
||||||
|
$('#feed-header-inner h2').css('opacity','0.2');
|
||||||
$('#feed-header-inner h2').animate({opacity:'1'},1000);
|
$('#feed-header-inner h2').animate({opacity:'1'},1000);
|
||||||
|
|
||||||
// set location bar from stream
|
// set location bar from stream
|
||||||
|
@ -693,27 +712,21 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
|
||||||
actionOnSuccess = false;
|
actionOnSuccess = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// otherwise we fade out and wait for stream to load
|
// (2) if we don't have a cached version we remove and hide the old stream and wait for the new one to load
|
||||||
else {
|
else {
|
||||||
// fade out
|
|
||||||
$('#feed,.profile-card').animate({opacity:'0'},150,function(){
|
|
||||||
// when fade out finishes, remove any profile cards and set new header
|
|
||||||
$('.profile-card,.hover-card,.hover-card-caret').remove();
|
$('.profile-card,.hover-card,.hover-card-caret').remove();
|
||||||
|
$('#feed').css('opacity',0);
|
||||||
$('#feed-body').html('');
|
$('#feed-body').html('');
|
||||||
$('#feed-header-inner h2').html(h2FeedHeader);
|
|
||||||
if(streamObject.menu && window.loggedIn) {
|
|
||||||
$('#feed-header-inner h2').append('<div id="stream-menu-cog" data-tooltip="' + window.sL.timelineOptions + '"></div>');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// change design immediately to either cached design or logged in user's
|
// (3) change design immediately to either cached design or logged in user's
|
||||||
if(typeof window.oldStreamsDesigns[theUserOrGroupThisStreamBelongsTo(window.currentStream)] != 'undefined') {
|
if(typeof window.oldStreamsDesigns[theUserOrGroupThisStreamBelongsTo(window.currentStream)] != 'undefined') {
|
||||||
changeDesign(window.oldStreamsDesigns[theUserOrGroupThisStreamBelongsTo(window.currentStream)]);
|
changeDesign(window.oldStreamsDesigns[theUserOrGroupThisStreamBelongsTo(window.currentStream)]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
changeDesign({backgroundimage:window.loggedIn.background_image, backgroundcolor:window.loggedIn.backgroundcolor, linkcolor:window.loggedIn.linkcolor});
|
changeDesign({backgroundimage:window.loggedIn.background_image, backgroundcolor:window.loggedIn.backgroundcolor, linkcolor:window.loggedIn.linkcolor});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get stream
|
// get stream
|
||||||
getFromAPI(streamObject.stream, function(queet_data, userArray, error, url){
|
getFromAPI(streamObject.stream, function(queet_data, userArray, error, url){
|
||||||
|
@ -758,7 +771,7 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
|
||||||
// getting stream failed, and we don't have a fallback id
|
// getting stream failed, and we don't have a fallback id
|
||||||
else if(queet_data === false) {
|
else if(queet_data === false) {
|
||||||
|
|
||||||
// maybe fade in user-container here, ("success" was a badly chosen name...)
|
// e.g. maybe fade in user-container here, ("success" was a badly chosen name...)
|
||||||
if(typeof actionOnSuccess == 'function') {
|
if(typeof actionOnSuccess == 'function') {
|
||||||
actionOnSuccess();
|
actionOnSuccess();
|
||||||
}
|
}
|
||||||
|
@ -843,8 +856,6 @@ function setNewCurrentStream(streamObject,setLocation,fallbackId,actionOnSuccess
|
||||||
addToFeed(queet_data, false,'visible'); // add stream items to feed element
|
addToFeed(queet_data, false,'visible'); // add stream items to feed element
|
||||||
$('#feed').animate({opacity:'1'},150); // fade in
|
$('#feed').animate({opacity:'1'},150); // fade in
|
||||||
$('.reload-stream').show();
|
$('.reload-stream').show();
|
||||||
$('#feed-body').removeAttr('data-end-reached');
|
|
||||||
$('#feed-body').removeAttr('data-search-page-number');
|
|
||||||
$('body').removeClass('loading-older');$('body').removeClass('loading-newer');
|
$('body').removeClass('loading-older');$('body').removeClass('loading-newer');
|
||||||
$('html,body').scrollTop(0); // scroll to top
|
$('html,body').scrollTop(0); // scroll to top
|
||||||
|
|
||||||
|
@ -1135,10 +1146,8 @@ function expand_queet(q,doScrolling) {
|
||||||
// show conversation and reply form (but not if already in conversation)
|
// show conversation and reply form (but not if already in conversation)
|
||||||
if(!q.hasClass('conversation')) {
|
if(!q.hasClass('conversation')) {
|
||||||
|
|
||||||
// show conversation (wait for css to animate the margin 50ms)
|
// show conversation
|
||||||
setTimeout(function(){
|
|
||||||
getConversation(q, qid);
|
getConversation(q, qid);
|
||||||
},50);
|
|
||||||
|
|
||||||
// show inline reply form if logged in
|
// show inline reply form if logged in
|
||||||
if(typeof window.loggedIn.screen_name != 'undefined') {
|
if(typeof window.loggedIn.screen_name != 'undefined') {
|
||||||
|
@ -1302,7 +1311,7 @@ function getConversation(q, qid) {
|
||||||
// check if we have a conversation for this notice cached in localstorage
|
// check if we have a conversation for this notice cached in localstorage
|
||||||
var cacheData = localStorageObjectCache_GET('conversation',q.attr('data-conversation-id'));
|
var cacheData = localStorageObjectCache_GET('conversation',q.attr('data-conversation-id'));
|
||||||
if(cacheData) {
|
if(cacheData) {
|
||||||
showConversation(q, qid, cacheData);
|
showConversation(q, qid, cacheData, 8);
|
||||||
}
|
}
|
||||||
// always get most recent conversation from server
|
// always get most recent conversation from server
|
||||||
getFromAPI('statusnet/conversation/' + q.attr('data-conversation-id') + '.json?count=100', function(data){ if(data) {
|
getFromAPI('statusnet/conversation/' + q.attr('data-conversation-id') + '.json?count=100', function(data){ if(data) {
|
||||||
|
@ -1310,14 +1319,12 @@ function getConversation(q, qid) {
|
||||||
// cache in localstorage
|
// cache in localstorage
|
||||||
localStorageObjectCache_STORE('conversation',q.attr('data-conversation-id'), data);
|
localStorageObjectCache_STORE('conversation',q.attr('data-conversation-id'), data);
|
||||||
|
|
||||||
showConversation(q, qid,data);
|
showConversation(q, qid,data, 0);
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showConversation(q, qid, data) {
|
function showConversation(q, qid, data, offsetScroll) {
|
||||||
|
|
||||||
rememberMyScrollPos(q.children('.queet'),qid,0);
|
|
||||||
|
|
||||||
if(data && !q.hasClass('collapsing')){
|
if(data && !q.hasClass('collapsing')){
|
||||||
|
|
||||||
|
@ -1379,6 +1386,7 @@ function showConversation(q, qid, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop trough this stream items conversation and show the "strict" line of replies
|
// loop trough this stream items conversation and show the "strict" line of replies
|
||||||
|
rememberMyScrollPos(q.children('.queet'),qid,offsetScroll);
|
||||||
findInReplyToStatusAndShow(q,qid,q.attr('data-in-reply-to-status-id'),true,false);
|
findInReplyToStatusAndShow(q,qid,q.attr('data-in-reply-to-status-id'),true,false);
|
||||||
backToMyScrollPos(q.children('.queet'),qid,false);
|
backToMyScrollPos(q.children('.queet'),qid,false);
|
||||||
findAndMarkLastVisibleInConversation(q);
|
findAndMarkLastVisibleInConversation(q);
|
||||||
|
@ -1466,12 +1474,6 @@ function checkForHiddenConversationQueets(q, qid) {
|
||||||
if(q.find('.hidden-conversation').length>0) {
|
if(q.find('.hidden-conversation').length>0) {
|
||||||
if(q.children('.queet').find('.show-full-conversation').length == 0) {
|
if(q.children('.queet').find('.show-full-conversation').length == 0) {
|
||||||
q.children('.queet').find('.stream-item-footer').append('<span class="show-full-conversation" data-stream-item-id="' + qid + '">' + window.sL.expandFullConversation + '</span>');
|
q.children('.queet').find('.stream-item-footer').append('<span class="show-full-conversation" data-stream-item-id="' + qid + '">' + window.sL.expandFullConversation + '</span>');
|
||||||
|
|
||||||
// if this is a single notice, we show conversation
|
|
||||||
if(window.currentStream.substring(0,14) == 'statuses/show/') {
|
|
||||||
q.children('.queet').find('.show-full-conversation').trigger('click');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -569,6 +569,40 @@ function searchForUserDataToCache(obj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ·
|
||||||
|
·
|
||||||
|
· Store the current stream's state (html) in localStorage
|
||||||
|
·
|
||||||
|
· · · · · · · · · */
|
||||||
|
|
||||||
|
|
||||||
|
function rememberStreamStateInLocalStorage() {
|
||||||
|
if(typeof window.currentStreamObject != 'undefined') {
|
||||||
|
|
||||||
|
// dont store open conversations, and only store profile card and the top 20 stream-items
|
||||||
|
var firstTwentyHTML = '';
|
||||||
|
$.each($('#feed-body').children('.stream-item').slice(0,20),function(){
|
||||||
|
firstTwentyHTML += $(this).outerHTML();
|
||||||
|
});
|
||||||
|
var feed = $('<div/>').append(firstTwentyHTML);
|
||||||
|
feed.find('.view-more-container-top').remove();
|
||||||
|
feed.find('.view-more-container-bottom').remove();
|
||||||
|
feed.find('.stream-item.conversation').remove();
|
||||||
|
feed.find('.expanded-content').remove();
|
||||||
|
feed.find('.inline-reply-queetbox').remove();
|
||||||
|
feed.find('.stream-item').removeClass('expanded').removeClass('next-expanded');
|
||||||
|
var feedHtml = feed.html();
|
||||||
|
var profileCardHtml = $('#feed').siblings('.profile-card').outerHTML();
|
||||||
|
var streamData = {
|
||||||
|
card: profileCardHtml,
|
||||||
|
feed: feedHtml
|
||||||
|
};
|
||||||
|
|
||||||
|
localStorageObjectCache_STORE('streamState',window.currentStreamObject.path, streamData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ·
|
/* ·
|
||||||
·
|
·
|
||||||
· Appends a user to the array containing the mentions suggestions to show when typing a notice
|
· Appends a user to the array containing the mentions suggestions to show when typing a notice
|
||||||
|
|
|
@ -1729,6 +1729,9 @@ function checkForNewQueets() {
|
||||||
if(window.currentStreamObject.name == 'notifications') {
|
if(window.currentStreamObject.name == 'notifications') {
|
||||||
helloAPI();
|
helloAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cache the now updated stream
|
||||||
|
rememberStreamStateInLocalStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user