some more work on mod hq
This commit is contained in:
parent
6b6c2ccfa3
commit
fbc57fa8e3
@ -10,21 +10,28 @@ require_once('include/items.php');
|
||||
|
||||
class Hq extends \Zotlabs\Web\Controller {
|
||||
|
||||
function post() {
|
||||
|
||||
if(!local_channel())
|
||||
return;
|
||||
|
||||
if($_REQUEST['notify_id']) {
|
||||
q("update notify set seen = 1 where id = %d and uid = %d",
|
||||
intval($_REQUEST['notify_id']),
|
||||
intval(local_channel())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function get($update = 0, $load = false) {
|
||||
|
||||
if(!local_channel())
|
||||
return;
|
||||
|
||||
$checkjs = new \Zotlabs\Web\CheckJS(1);
|
||||
|
||||
if($load)
|
||||
$_SESSION['loadtime'] = datetime_convert();
|
||||
|
||||
if(observer_prohibited()) {
|
||||
notice( t('Public access denied.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
if(argc() > 1 && argv(1) !== 'load') {
|
||||
$item_hash = argv(1);
|
||||
}
|
||||
@ -32,10 +39,6 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
if($_REQUEST['mid'])
|
||||
$item_hash = $_REQUEST['mid'];
|
||||
|
||||
require_once('include/channel.php');
|
||||
$sys = get_sys_channel();
|
||||
$sysid = $sys['channel_id'];
|
||||
|
||||
if(! $item_hash) {
|
||||
|
||||
$r = q("SELECT mid FROM item
|
||||
@ -44,7 +47,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
$item_normal
|
||||
ORDER BY id DESC
|
||||
limit 1",
|
||||
local_channel() ? intval(local_channel()) : intval($sysid)
|
||||
local_channel()
|
||||
);
|
||||
$item_hash = 'b64.' . base64url_encode($r[0]['mid']);
|
||||
|
||||
@ -57,7 +60,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
|
||||
$updateable = false;
|
||||
|
||||
if(local_channel() && (! $update)) {
|
||||
if(! $update) {
|
||||
|
||||
$channel = \App::get_channel();
|
||||
|
||||
@ -113,29 +116,8 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
goaway(z_root() . '/moderate/' . $target_item['id']);
|
||||
}
|
||||
|
||||
$r = null;
|
||||
|
||||
if($target_item['item_type'] == ITEM_TYPE_WEBPAGE) {
|
||||
$x = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($target_item['uid'])
|
||||
);
|
||||
$y = q("select * from iconfig left join item on iconfig.iid = item.id
|
||||
where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item.id = %d limit 1",
|
||||
intval($target_item['uid']),
|
||||
intval($target_item['id'])
|
||||
);
|
||||
if($x && $y) {
|
||||
goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['v']);
|
||||
}
|
||||
else {
|
||||
notice( t('Page not found.') . EOL);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
$static = ((array_key_exists('static',$_REQUEST)) ? intval($_REQUEST['static']) : 0);
|
||||
|
||||
|
||||
$simple_update = (($update) ? " AND item_unseen = 1 " : '');
|
||||
|
||||
if($update && $_SESSION['loadtime'])
|
||||
@ -146,7 +128,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
if($static && $simple_update)
|
||||
$simple_update .= " and item_thread_top = 0 and author_xchan = '" . protect_sprintf(get_observer_hash()) . "' ";
|
||||
|
||||
if((! $update) && (! $load)) {
|
||||
if(! $update && ! $load) {
|
||||
|
||||
$static = ((local_channel()) ? channel_manual_conv_update(local_channel()) : 1);
|
||||
|
||||
@ -159,7 +141,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
$mid = 'b64.' . base64url_encode($mid);
|
||||
|
||||
$o .= '<div id="live-display"></div>' . "\r\n";
|
||||
$o .= "<script> var profile_uid = " . ((intval(local_channel())) ? local_channel() : (-1))
|
||||
$o .= "<script> var profile_uid = " . local_channel()
|
||||
. "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] . "; </script>\r\n";
|
||||
|
||||
\App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),[
|
||||
@ -178,7 +160,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
'$nouveau' => '0',
|
||||
'$wall' => '0',
|
||||
'$static' => $static,
|
||||
'$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1),
|
||||
'$page' => 1,
|
||||
'$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0),
|
||||
'$search' => '',
|
||||
'$xchan' => '',
|
||||
@ -193,47 +175,30 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
'$mid' => $mid
|
||||
]);
|
||||
|
||||
head_add_link([
|
||||
'rel' => 'alternate',
|
||||
'type' => 'application/json+oembed',
|
||||
'href' => z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string),
|
||||
'title' => 'oembed'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
$item_normal = item_normal();
|
||||
$item_normal_update = item_normal_update();
|
||||
|
||||
$sql_extra = ''; //public_permissions_sql($observer_hash);
|
||||
|
||||
if(($update && $load) || ($checkjs->disabled())) {
|
||||
|
||||
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']),intval(\App::$pager['start']));
|
||||
|
||||
if($load || ($checkjs->disabled())) {
|
||||
$r = null;
|
||||
|
||||
$r = q("SELECT item.id as item_id from item
|
||||
WHERE uid = %d
|
||||
and mid = '%s'
|
||||
$item_normal
|
||||
limit 1",
|
||||
intval(local_channel()),
|
||||
dbesc($target_item['parent_mid'])
|
||||
);
|
||||
if($r) {
|
||||
$updateable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
elseif($update && !$load) {
|
||||
if($load) {
|
||||
$r = null;
|
||||
|
||||
require_once('include/channel.php');
|
||||
$sys = get_sys_channel();
|
||||
$sysid = $sys['channel_id'];
|
||||
$r = q("SELECT item.id as item_id from item
|
||||
WHERE uid = %d
|
||||
and mid = '%s'
|
||||
$item_normal
|
||||
limit 1",
|
||||
intval(local_channel()),
|
||||
dbesc($target_item['parent_mid'])
|
||||
);
|
||||
if($r) {
|
||||
$updateable = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
elseif($update) {
|
||||
$r = null;
|
||||
|
||||
$r = q("SELECT item.parent AS item_id from item
|
||||
WHERE uid = %d
|
||||
@ -273,15 +238,7 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
$items = [];
|
||||
}
|
||||
|
||||
|
||||
if ($checkjs->disabled()) {
|
||||
$o .= conversation($items, 'display', $update, 'traditional');
|
||||
if ($items[0]['title'])
|
||||
\App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title'];
|
||||
}
|
||||
else {
|
||||
$o .= conversation($items, 'display', $update, 'client');
|
||||
}
|
||||
$o .= conversation($items, 'display', $update, 'client');
|
||||
|
||||
if($updateable) {
|
||||
$x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ",
|
||||
@ -292,6 +249,10 @@ class Hq extends \Zotlabs\Web\Controller {
|
||||
|
||||
$o .= '<div id="content-complete"></div>';
|
||||
|
||||
if(($update && $load) && (! $items)) {
|
||||
notice( t('Something went wrong.') . EOL );
|
||||
}
|
||||
|
||||
return $o;
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Notify extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
|
||||
|
||||
function get() {
|
||||
function get() {
|
||||
if(! local_channel())
|
||||
return login();
|
||||
|
||||
|
@ -274,6 +274,8 @@ class Ping extends \Zotlabs\Web\Controller {
|
||||
'photo' => $tt['photo'],
|
||||
'when' => relative_date($tt['created']),
|
||||
'hclass' => (($tt['seen']) ? 'notify-seen' : 'notify-unseen'),
|
||||
'b64mid' => 'b64.' . base64url_encode(basename($tt['link'])),
|
||||
'notify_id' => $tt['id'],
|
||||
'message' => $message
|
||||
);
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
145
view/js/mod_hq.js
Normal file
145
view/js/mod_hq.js
Normal file
@ -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);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
@ -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>
|
||||
|
Reference in New Issue
Block a user