From 5abbfd3f19b6b77ea8d6dd418afcb84775716f21 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 29 Apr 2019 23:21:17 +0200 Subject: [PATCH 01/14] Add initial threaded comment support --- include/items.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/items.php b/include/items.php index c08deb3a0..7a5c2c3c3 100755 --- a/include/items.php +++ b/include/items.php @@ -1875,9 +1875,12 @@ function item_store($arr, $allow_exec = false, $deliver = true) { // is the new message multi-level threaded? // even though we don't support it now, preserve the info // and re-attach to the conversation parent. + + // @FIXME when we'll start threaded comments support, + // now this respected on mid / parent_mid level (MK) if($r[0]['mid'] != $r[0]['parent_mid']) { - $arr['parent_mid'] = $r[0]['parent_mid']; + //$arr['parent_mid'] = $r[0]['parent_mid']; $z = q("SELECT * FROM item WHERE mid = '%s' AND parent_mid = '%s' AND uid = %d ORDER BY id ASC LIMIT 1", dbesc($r[0]['parent_mid']), @@ -4278,7 +4281,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C if($arr['mid']) $sql_options .= " and parent_mid = '" . dbesc($arr['mid']) . "' "; - $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options $item_normal ) "; + $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE $item_uids and item_thread_top = 1 $sql_options $item_normal ) "; if($arr['since_id']) $sql_extra .= " and item.id > " . $since_id . " "; From 6db323b15e6e9b5429d8d786959fcd60af4a30b2 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 29 Apr 2019 23:24:48 +0200 Subject: [PATCH 02/14] Add variables for threaded comments support --- Zotlabs/Lib/ThreadItem.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 40c0fca4b..22f4724a0 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -305,6 +305,7 @@ class ThreadItem { if($this->is_commentable() && $observer) { $like = array( t("I like this \x28toggle\x29"), t("like")); $dislike = array( t("I don't like this \x28toggle\x29"), t("dislike")); + $reply_to = array( t("Reply on this comment"), t("reply")); } if ($shareable) { @@ -348,9 +349,6 @@ class ThreadItem { $list_unseen_txt = (($unseen_comments) ? sprintf('%d unseen',$unseen_comments) : ''); - - - $children = $this->get_children(); $has_tags = (($body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders']) ? true : false); @@ -373,6 +371,8 @@ class ThreadItem { 'text' => strip_tags($body['html']), 'id' => $this->get_id(), 'mid' => $item['mid'], + 'parent' => $item['parent'], + 'author_id' => $item['author']['xchan_addr'], 'isevent' => $isevent, 'attend' => $attend, 'consensus' => $consensus, @@ -425,9 +425,10 @@ class ThreadItem { 'has_tags' => $has_tags, 'reactions' => $this->reactions, // Item toolbar buttons - 'emojis' => (($this->is_toplevel() && $this->is_commentable() && $observer && feature_enabled($conv->get_profile_owner(),'emojis')) ? '1' : ''), + 'emojis' => (($this->is_toplevel() && $this->is_commentable() && $observer && feature_enabled($conv->get_profile_owner(),'emojis')) ? '1' : ''), 'like' => $like, 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? $dislike : ''), + 'reply_to' => (((! $this->is_toplevel()) && feature_enabled($conv->get_profile_owner(),'reply_to')) ? $reply_to : ''), 'share' => $share, 'embed' => $embed, 'rawmid' => $item['mid'], @@ -869,4 +870,3 @@ class ThreadItem { } - From d9be443e53e7a8ef624f5e997bfc544ac567ee4b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 29 Apr 2019 23:26:20 +0200 Subject: [PATCH 03/14] Add initial threaded comments support --- Zotlabs/Module/Item.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 6bc8c645f..11ce1d268 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -216,7 +216,7 @@ class Item extends Controller { $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0); $parent_mid = ((x($_REQUEST,'parent_mid')) ? trim($_REQUEST['parent_mid']) : ''); - + $remote_xchan = ((x($_REQUEST,'remote_xchan')) ? trim($_REQUEST['remote_xchan']) : false); $r = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($remote_xchan) @@ -329,9 +329,14 @@ class Item extends Controller { $obj_type = ACTIVITY_OBJ_COMMENT; if($parent) { - $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", + // Get commented post data + $rr = q("SELECT parent, mid FROM item WHERE id = %d LIMIT 1", intval($parent) ); + // and its parent + $r = q("SELECT * FROM item WHERE id = %d LIMIT 1", + intval($rr[0]['parent']) + ); } elseif($parent_mid && $uid) { // This is coming from an API source, and we are logged in @@ -910,8 +915,7 @@ class Item extends Controller { } if($parent_item) - $parent_mid = $parent_item['mid']; - + $parent_mid = $rr[0]['mid']; // Fallback so that we alway have a thr_parent @@ -1014,7 +1018,7 @@ class Item extends Controller { $datarray['term'] = $post_tags; $datarray['plink'] = $plink; $datarray['route'] = $route; - + // A specific ACL over-rides public_policy completely @@ -1160,7 +1164,7 @@ class Item extends Controller { 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $parent, - 'parent_mid' => $parent_item['mid'] + 'parent_mid' => $rr[0]['mid'] )); } From e80c99ad744f675ff193802fa2fe91d1c1207d01 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 29 Apr 2019 23:29:16 +0200 Subject: [PATCH 04/14] Add 'reply to comment' button --- view/tpl/conv_item.tpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/view/tpl/conv_item.tpl b/view/tpl/conv_item.tpl index 428529de2..29401a35c 100755 --- a/view/tpl/conv_item.tpl +++ b/view/tpl/conv_item.tpl @@ -102,6 +102,11 @@ {{/if}} + {{if $item.reply_to}} + + {{/if}} {{if $item.isevent}}
{{/if}} {{if $item.reply_to}} - {{/if}} From c340416c9424c285de4701158714541f24d66e85 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 1 May 2019 06:24:58 +0200 Subject: [PATCH 14/14] Add 'reply on comment' code --- view/js/main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/view/js/main.js b/view/js/main.js index 8f644dc8e..325ad9a51 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1148,6 +1148,16 @@ function doprofilelike(ident, verb) { $.get('like/' + ident + '?verb=' + verb, function() { window.location.href=window.location.href; }); } +function doreply(parent, ident, owner, hint) { + var form = $('#comment-edit-form-' + parent.toString()); + form.find('input[name=parent]').val(ident); + var i = form.find('button[type=submit]'); + var btn = i.html().replace(/<[^>]*>/g, '').trim(); + i.html(' ' + btn); + i.prop('title', hint); + form.find('textarea').val("@{" + owner + "}\n"); + $('#comment-edit-text-' + parent.toString()).focus(); +} function dropItem(url, object) {