From fbc57fa8e36e468abe81e4f3d72b3115cbdd794c Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 18 Nov 2017 22:16:06 +0100 Subject: some more work on mod hq --- view/js/mod_hq.js | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 view/js/mod_hq.js (limited to 'view/js/mod_hq.js') diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js new file mode 100644 index 000000000..cf7ec941c --- /dev/null +++ b/view/js/mod_hq.js @@ -0,0 +1,145 @@ +function hqLiveUpdate(notify_id, b64mid) { + + if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ + if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } + if(($('.comment-edit-text.expanded').length) || (in_progress)) { + if(livetime) { + clearTimeout(livetime); + } + livetime = setTimeout(liveUpdate, 10000); + return; + } + if(livetime !== null) + livetime = null; + + prev = 'live-' + src; + + in_progress = true; + + var update_url; + var update_mode; + + if(scroll_next) { + bParam_page = next_page; + page_load = true; + } + else { + bParam_page = 1; + } + + update_url = buildCmd(); + + if(page_load) { + $("#page-spinner").show(); + if(bParam_page == 1) + update_mode = 'replace'; + else + update_mode = 'append'; + } + else { + update_mode = 'update'; + var orgHeight = $("#region_2").height(); + } + + var dstart = new Date(); + console.log('LOADING data...'); + $.get(update_url, function(data) { + + // on shared hosts occasionally the live update process will be killed + // leaving an incomplete HTML structure, which leads to conversations getting + // truncated and the page messed up if all the divs aren't closed. We will try + // again and give up if we can't get a valid HTML response after 10 tries. + + if((data.indexOf("") != (-1)) && (data.indexOf("") == (-1))) { + console.log('Incomplete data. Reloading'); + in_progress = false; + liveRecurse ++; + if(liveRecurse < 10) { + liveUpdate(); + } + else { + console.log('Incomplete data. Too many attempts. Giving up.'); + } + } + + // else data was valid - reset the recursion counter + liveRecurse = 0; + + if(notify_id !== 'undefined') { + $.post( + "hq", + { + "notify_id" : notify_id + }, + function(data) { + if(timer) clearTimeout(timer); + timer = setTimeout(NavUpdate,10); + } + ); + } + + var dready = new Date(); + console.log('DATA ready in: ' + (dready - dstart)/1000 + ' seconds.'); + + if(update_mode === 'update' || preloadImages) { + console.log('LOADING images...'); + + $('.wall-item-body, .wall-photo-item',data).imagesLoaded( function() { + var iready = new Date(); + console.log('IMAGES ready in: ' + (iready - dready)/1000 + ' seconds.'); + + page_load = false; + scroll_next = false; + updateConvItems(update_mode,data); + $("#page-spinner").hide(); + $("#profile-jot-text-loading").hide(); + + // adjust scroll position if new content was added above viewport + if(update_mode === 'update') { + $(window).scrollTop($(window).scrollTop() + $("#region_2").height() - orgHeight + contentHeightDiff); + } + + in_progress = false; + + // FIXME - the following lines were added so that almost + // immediately after we update the posts on the page, we + // re-check and update the notification counts. + // As it turns out this causes a bit of an inefficiency + // as we're pinging twice for every update, once before + // and once after. A btter way to do this is to rewrite + // NavUpdate and perhaps LiveUpdate so that we check for + // post updates first and only call the notification ping + // once. + + updateCountsOnly = true; + if(timer) clearTimeout(timer); + timer = setTimeout(NavUpdate,10); + + }); + } + else { + page_load = false; + scroll_next = false; + updateConvItems(update_mode,data); + $("#page-spinner").hide(); + $("#profile-jot-text-loading").hide(); + + in_progress = false; + + // FIXME - the following lines were added so that almost + // immediately after we update the posts on the page, we + // re-check and update the notification counts. + // As it turns out this causes a bit of an inefficiency + // as we're pinging twice for every update, once before + // and once after. A btter way to do this is to rewrite + // NavUpdate and perhaps LiveUpdate so that we check for + // post updates first and only call the notification ping + // once. + + updateCountsOnly = true; + if(timer) clearTimeout(timer); + timer = setTimeout(NavUpdate,10); + + } + }); +} -- cgit v1.2.3 From d942818bd9d9e90db7a3083bfe33a54732f6184d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 21 Nov 2017 22:10:09 +0100 Subject: use item_thread_top = 1 instead of mid = parent_mid and make sure local_channel is intval --- view/js/mod_hq.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'view/js/mod_hq.js') diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index cf7ec941c..8bbd5e3ad 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -1,4 +1,4 @@ -function hqLiveUpdate(notify_id, b64mid) { +function hqLiveUpdate(notify_id) { if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } @@ -65,7 +65,7 @@ function hqLiveUpdate(notify_id, b64mid) { // else data was valid - reset the recursion counter liveRecurse = 0; - if(notify_id !== 'undefined') { + if(notify_id !== 'undefined') { $.post( "hq", { -- cgit v1.2.3 From 87eaa6d8e5a5fece531a8ce191f8e89e90f673c2 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 24 Nov 2017 15:01:34 +0100 Subject: some more work on mod hq --- view/js/mod_hq.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'view/js/mod_hq.js') diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index 8bbd5e3ad..3ce5f1ca6 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -1,3 +1,15 @@ +$(document).on('click', '#jot-toggle', function(e) { + e.preventDefault(); + e.stopPropagation(); + + $(this).toggleClass('active'); + $(window).scrollTop(0); + $('#jot-popup').toggle(); + $('#profile-jot-text').focus(); + +}); + + function hqLiveUpdate(notify_id) { if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ -- cgit v1.2.3 From bf1ec44186ac87827ed7fc9b21e96101b6c4fad2 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 29 Nov 2017 08:34:47 +0100 Subject: rework liveUpdate() and notificationsUpdate() (aka ping) to first do the liveUpdate and when this is done only do the ping once. rename initLiveUpdate() to initUpdate() and more main.js cleanup. --- view/js/mod_hq.js | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) (limited to 'view/js/mod_hq.js') diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index 3ce5f1ca6..d61a4ff3b 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -9,18 +9,20 @@ $(document).on('click', '#jot-toggle', function(e) { }); - function hqLiveUpdate(notify_id) { if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ + if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } - if(($('.comment-edit-text.expanded').length) || (in_progress)) { + + if(($('.comment-edit-text.expanded').length) || (in_progress) || (mediaPlaying)) { if(livetime) { clearTimeout(livetime); } livetime = setTimeout(liveUpdate, 10000); return; } + if(livetime !== null) livetime = null; @@ -113,20 +115,6 @@ function hqLiveUpdate(notify_id) { in_progress = false; - // FIXME - the following lines were added so that almost - // immediately after we update the posts on the page, we - // re-check and update the notification counts. - // As it turns out this causes a bit of an inefficiency - // as we're pinging twice for every update, once before - // and once after. A btter way to do this is to rewrite - // NavUpdate and perhaps LiveUpdate so that we check for - // post updates first and only call the notification ping - // once. - - updateCountsOnly = true; - if(timer) clearTimeout(timer); - timer = setTimeout(NavUpdate,10); - }); } else { @@ -138,20 +126,11 @@ function hqLiveUpdate(notify_id) { in_progress = false; - // FIXME - the following lines were added so that almost - // immediately after we update the posts on the page, we - // re-check and update the notification counts. - // As it turns out this causes a bit of an inefficiency - // as we're pinging twice for every update, once before - // and once after. A btter way to do this is to rewrite - // NavUpdate and perhaps LiveUpdate so that we check for - // post updates first and only call the notification ping - // once. - - updateCountsOnly = true; - if(timer) clearTimeout(timer); - timer = setTimeout(NavUpdate,10); - } + + }) + .done(function() { + notificationsUpdate(); }); } + -- cgit v1.2.3 From e6a59ad36fcdbe4dcb534ff700663d9588b5d734 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 29 Nov 2017 11:22:59 +0100 Subject: allow an optional notify_id arg for liveUpdate() --- view/js/mod_hq.js | 126 ------------------------------------------------------ 1 file changed, 126 deletions(-) (limited to 'view/js/mod_hq.js') diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index d61a4ff3b..b321382bd 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -8,129 +8,3 @@ $(document).on('click', '#jot-toggle', function(e) { $('#profile-jot-text').focus(); }); - -function hqLiveUpdate(notify_id) { - - if(typeof profile_uid === 'undefined') profile_uid = false; /* Should probably be unified with channelId defined in head.tpl */ - - if((src === null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } - - if(($('.comment-edit-text.expanded').length) || (in_progress) || (mediaPlaying)) { - if(livetime) { - clearTimeout(livetime); - } - livetime = setTimeout(liveUpdate, 10000); - return; - } - - if(livetime !== null) - livetime = null; - - prev = 'live-' + src; - - in_progress = true; - - var update_url; - var update_mode; - - if(scroll_next) { - bParam_page = next_page; - page_load = true; - } - else { - bParam_page = 1; - } - - update_url = buildCmd(); - - if(page_load) { - $("#page-spinner").show(); - if(bParam_page == 1) - update_mode = 'replace'; - else - update_mode = 'append'; - } - else { - update_mode = 'update'; - var orgHeight = $("#region_2").height(); - } - - var dstart = new Date(); - console.log('LOADING data...'); - $.get(update_url, function(data) { - - // on shared hosts occasionally the live update process will be killed - // leaving an incomplete HTML structure, which leads to conversations getting - // truncated and the page messed up if all the divs aren't closed. We will try - // again and give up if we can't get a valid HTML response after 10 tries. - - if((data.indexOf("") != (-1)) && (data.indexOf("") == (-1))) { - console.log('Incomplete data. Reloading'); - in_progress = false; - liveRecurse ++; - if(liveRecurse < 10) { - liveUpdate(); - } - else { - console.log('Incomplete data. Too many attempts. Giving up.'); - } - } - - // else data was valid - reset the recursion counter - liveRecurse = 0; - - if(notify_id !== 'undefined') { - $.post( - "hq", - { - "notify_id" : notify_id - }, - function(data) { - if(timer) clearTimeout(timer); - timer = setTimeout(NavUpdate,10); - } - ); - } - - var dready = new Date(); - console.log('DATA ready in: ' + (dready - dstart)/1000 + ' seconds.'); - - if(update_mode === 'update' || preloadImages) { - console.log('LOADING images...'); - - $('.wall-item-body, .wall-photo-item',data).imagesLoaded( function() { - var iready = new Date(); - console.log('IMAGES ready in: ' + (iready - dready)/1000 + ' seconds.'); - - page_load = false; - scroll_next = false; - updateConvItems(update_mode,data); - $("#page-spinner").hide(); - $("#profile-jot-text-loading").hide(); - - // adjust scroll position if new content was added above viewport - if(update_mode === 'update') { - $(window).scrollTop($(window).scrollTop() + $("#region_2").height() - orgHeight + contentHeightDiff); - } - - in_progress = false; - - }); - } - else { - page_load = false; - scroll_next = false; - updateConvItems(update_mode,data); - $("#page-spinner").hide(); - $("#profile-jot-text-loading").hide(); - - in_progress = false; - - } - - }) - .done(function() { - notificationsUpdate(); - }); -} - -- cgit v1.2.3