aboutsummaryrefslogtreecommitdiffstats
path: root/view
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2017-11-18 22:16:06 +0100
committerMario Vavti <mario@mariovavti.com>2017-11-18 22:16:06 +0100
commitfbc57fa8e36e468abe81e4f3d72b3115cbdd794c (patch)
tree05e3924cfda2e18ae97f27304f1af1f0caff988d /view
parent6b6c2ccfa391d138db925b2c3f92a469c587c907 (diff)
downloadvolse-hubzilla-fbc57fa8e36e468abe81e4f3d72b3115cbdd794c.tar.gz
volse-hubzilla-fbc57fa8e36e468abe81e4f3d72b3115cbdd794c.tar.bz2
volse-hubzilla-fbc57fa8e36e468abe81e4f3d72b3115cbdd794c.zip
some more work on mod hq
Diffstat (limited to 'view')
-rw-r--r--view/js/main.js4
-rw-r--r--view/js/mod_hq.js145
-rw-r--r--view/tpl/notifications_widget.tpl16
3 files changed, 161 insertions, 4 deletions
diff --git a/view/js/main.js b/view/js/main.js
index e231dac60..026036300 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -959,9 +959,9 @@ function notify_popup_loader(notifyType) {
$("." + notifyType + "-update").html(data.notify.length);
$(data.notify).each(function() {
- html = navbar_notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid);
+ html = navbar_notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid,this.notify_id);
$("#navbar-" + notifyType + "-menu").append(html);
- html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid);
+ html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.message,this.when,this.hclass,this.b64mid,this.notify_id);
$("#nav-" + notifyType + "-menu").append(html);
});
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("<html>") != (-1)) && (data.indexOf("</html>") == (-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);
+
+ }
+ });
+}
diff --git a/view/tpl/notifications_widget.tpl b/view/tpl/notifications_widget.tpl
index ce64671d2..136b14abd 100644
--- a/view/tpl/notifications_widget.tpl
+++ b/view/tpl/notifications_widget.tpl
@@ -18,18 +18,30 @@
{{if $module == 'display' || $module == 'hq'}}
$(document).on('click', '.notification', function(e) {
var b64mid = $(this).data('b64mid');
+ var notify_id = $(this).data('notify_id');
var path = $(this)[0].pathname.substr(1,7);
+ {{if $module == 'hq'}}
+ if(b64mid !== 'undefined') {
+ {{else}}
if(path === 'display' && b64mid) {
+ {{/if}}
e.preventDefault();
e.stopPropagation();
$('.thread-wrapper').remove();
- $(this).fadeOut();
+
+ if(! page_load)
+ $(this).fadeOut();
+
bParam_mid = b64mid;
mode = 'replace';
page_load = true;
+ {{if $module == 'hq'}}
+ hqLiveUpdate(notify_id);
+ {{else}}
liveUpdate();
+ {{/if}}
if($('#notifications_wrapper').hasClass('fs'))
$('#notifications_wrapper').prependTo('#' + notifications_parent).removeClass('fs');
@@ -43,7 +55,7 @@
<div id="notifications_wrapper">
<div id="notifications" class="navbar-nav" data-children=".nav-item">
<div id="nav-notifications-template" rel="template">
- <a class="list-group-item clearfix notification {5}" href="{0}" title="{2} {3}" data-b64mid="{6}">
+ <a class="list-group-item clearfix notification {5}" href="{0}" title="{2} {3}" data-b64mid="{6}" data-notify_id="{7}">
<img class="menu-img-3" data-src="{1}">
<span class="contactname">{2}</span>
<span class="dropdown-sub-text">{3}<br>{4}</span>