From dc06b851f558b62f05edb8ac11ae8145203b0d05 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 Nov 2017 00:55:37 -0500 Subject: [PATCH 1/5] Update Composer autoload files --- vendor/composer/autoload_classmap.php | 23 +++++++++++++++++++++++ vendor/composer/autoload_static.php | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 35482a8ff1..10e576ad03 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -10,17 +10,40 @@ return array( 'Console_Getopt' => $vendorDir . '/pear-pear.php.net/Console_Getopt/Console/Getopt.php', 'Detection\\MobileDetect' => $vendorDir . '/mobiledetect/mobiledetectlib/namespaced/Detection/MobileDetect.php', 'Friendica\\App' => $baseDir . '/src/App.php', + 'Friendica\\Content\\Smilies' => $baseDir . '/src/Content/Smilies.php', + 'Friendica\\Core\\BaseObject' => $baseDir . '/src/Core/BaseObject.php', + 'Friendica\\Core\\Cache' => $baseDir . '/src/Core/Cache.php', 'Friendica\\Core\\Config' => $baseDir . '/src/Core/Config.php', + 'Friendica\\Core\\Conversation' => $baseDir . '/src/Core/Conversation.php', + 'Friendica\\Core\\Item' => $baseDir . '/src/Core/Item.php', 'Friendica\\Core\\NotificationsManager' => $baseDir . '/src/Core/NotificationsManager.php', 'Friendica\\Core\\PConfig' => $baseDir . '/src/Core/PConfig.php', 'Friendica\\Core\\System' => $baseDir . '/src/Core/System.php', 'Friendica\\Core\\Worker' => $baseDir . '/src/Core/Worker.php', 'Friendica\\Database\\DBM' => $baseDir . '/src/Database/DBM.php', + 'Friendica\\Model\\GlobalContact' => $baseDir . '/src/Model/GlobalContact.php', 'Friendica\\Network\\Probe' => $baseDir . '/src/Network/Probe.php', 'Friendica\\ParseUrl' => $baseDir . '/src/ParseUrl.php', 'Friendica\\Protocol\\DFRN' => $baseDir . '/src/Protocol/DFRN.php', 'Friendica\\Protocol\\Diaspora' => $baseDir . '/src/Protocol/Diaspora.php', + 'Friendica\\Protocol\\OStatus' => $baseDir . '/src/Protocol/OStatus.php', + 'Friendica\\Protocol\\PortableContact' => $baseDir . '/src/Protocol/PortableContact.php', 'Friendica\\Util\\Lock' => $baseDir . '/src/Util/Lock.php', + 'Friendica\\Util\\XML' => $baseDir . '/src/Util/XML.php', + 'Friendica\\Worker\\CheckVersion' => $baseDir . '/src/Worker/CheckVersion.php', + 'Friendica\\Worker\\Cron' => $baseDir . '/src/Worker/Cron.php', + 'Friendica\\Worker\\CronHooks' => $baseDir . '/src/Worker/CronHooks.php', + 'Friendica\\Worker\\CronJobs' => $baseDir . '/src/Worker/CronJobs.php', + 'Friendica\\Worker\\DBClean' => $baseDir . '/src/Worker/DBClean.php', + 'Friendica\\Worker\\DBUpdate' => $baseDir . '/src/Worker/DBUpdate.php', + 'Friendica\\Worker\\Directory' => $baseDir . '/src/Worker/Directory.php', + 'Friendica\\Worker\\DiscoverPoCo' => $baseDir . '/src/Worker/DiscoverPoCo.php', + 'Friendica\\Worker\\OnePoll' => $baseDir . '/src/Worker/OnePoll.php', + 'Friendica\\Worker\\RemoveContact' => $baseDir . '/src/Worker/RemoveContact.php', + 'Friendica\\Worker\\SpoolPost' => $baseDir . '/src/Worker/SpoolPost.php', + 'Friendica\\Worker\\TagUpdate' => $baseDir . '/src/Worker/TagUpdate.php', + 'Friendica\\Worker\\ThreadUpdate' => $baseDir . '/src/Worker/ThreadUpdate.php', + 'Friendica\\Worker\\UpdateGContact' => $baseDir . '/src/Worker/UpdateGContact.php', 'HTMLPurifier' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.php', 'HTMLPurifier_Arborize' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php', 'HTMLPurifier_AttrCollections' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 9c40e66c6f..8a188c2fa9 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -62,17 +62,40 @@ class ComposerStaticInitFriendica 'Console_Getopt' => __DIR__ . '/..' . '/pear-pear.php.net/Console_Getopt/Console/Getopt.php', 'Detection\\MobileDetect' => __DIR__ . '/..' . '/mobiledetect/mobiledetectlib/namespaced/Detection/MobileDetect.php', 'Friendica\\App' => __DIR__ . '/../..' . '/src/App.php', + 'Friendica\\Content\\Smilies' => __DIR__ . '/../..' . '/src/Content/Smilies.php', + 'Friendica\\Core\\BaseObject' => __DIR__ . '/../..' . '/src/Core/BaseObject.php', + 'Friendica\\Core\\Cache' => __DIR__ . '/../..' . '/src/Core/Cache.php', 'Friendica\\Core\\Config' => __DIR__ . '/../..' . '/src/Core/Config.php', + 'Friendica\\Core\\Conversation' => __DIR__ . '/../..' . '/src/Core/Conversation.php', + 'Friendica\\Core\\Item' => __DIR__ . '/../..' . '/src/Core/Item.php', 'Friendica\\Core\\NotificationsManager' => __DIR__ . '/../..' . '/src/Core/NotificationsManager.php', 'Friendica\\Core\\PConfig' => __DIR__ . '/../..' . '/src/Core/PConfig.php', 'Friendica\\Core\\System' => __DIR__ . '/../..' . '/src/Core/System.php', 'Friendica\\Core\\Worker' => __DIR__ . '/../..' . '/src/Core/Worker.php', 'Friendica\\Database\\DBM' => __DIR__ . '/../..' . '/src/Database/DBM.php', + 'Friendica\\Model\\GlobalContact' => __DIR__ . '/../..' . '/src/Model/GlobalContact.php', 'Friendica\\Network\\Probe' => __DIR__ . '/../..' . '/src/Network/Probe.php', 'Friendica\\ParseUrl' => __DIR__ . '/../..' . '/src/ParseUrl.php', 'Friendica\\Protocol\\DFRN' => __DIR__ . '/../..' . '/src/Protocol/DFRN.php', 'Friendica\\Protocol\\Diaspora' => __DIR__ . '/../..' . '/src/Protocol/Diaspora.php', + 'Friendica\\Protocol\\OStatus' => __DIR__ . '/../..' . '/src/Protocol/OStatus.php', + 'Friendica\\Protocol\\PortableContact' => __DIR__ . '/../..' . '/src/Protocol/PortableContact.php', 'Friendica\\Util\\Lock' => __DIR__ . '/../..' . '/src/Util/Lock.php', + 'Friendica\\Util\\XML' => __DIR__ . '/../..' . '/src/Util/XML.php', + 'Friendica\\Worker\\CheckVersion' => __DIR__ . '/../..' . '/src/Worker/CheckVersion.php', + 'Friendica\\Worker\\Cron' => __DIR__ . '/../..' . '/src/Worker/Cron.php', + 'Friendica\\Worker\\CronHooks' => __DIR__ . '/../..' . '/src/Worker/CronHooks.php', + 'Friendica\\Worker\\CronJobs' => __DIR__ . '/../..' . '/src/Worker/CronJobs.php', + 'Friendica\\Worker\\DBClean' => __DIR__ . '/../..' . '/src/Worker/DBClean.php', + 'Friendica\\Worker\\DBUpdate' => __DIR__ . '/../..' . '/src/Worker/DBUpdate.php', + 'Friendica\\Worker\\Directory' => __DIR__ . '/../..' . '/src/Worker/Directory.php', + 'Friendica\\Worker\\DiscoverPoCo' => __DIR__ . '/../..' . '/src/Worker/DiscoverPoCo.php', + 'Friendica\\Worker\\OnePoll' => __DIR__ . '/../..' . '/src/Worker/OnePoll.php', + 'Friendica\\Worker\\RemoveContact' => __DIR__ . '/../..' . '/src/Worker/RemoveContact.php', + 'Friendica\\Worker\\SpoolPost' => __DIR__ . '/../..' . '/src/Worker/SpoolPost.php', + 'Friendica\\Worker\\TagUpdate' => __DIR__ . '/../..' . '/src/Worker/TagUpdate.php', + 'Friendica\\Worker\\ThreadUpdate' => __DIR__ . '/../..' . '/src/Worker/ThreadUpdate.php', + 'Friendica\\Worker\\UpdateGContact' => __DIR__ . '/../..' . '/src/Worker/UpdateGContact.php', 'HTMLPurifier' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.php', 'HTMLPurifier_Arborize' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier/Arborize.php', 'HTMLPurifier_AttrCollections' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier/AttrCollections.php', From 81c3ddd1fbcae84a471c232062dbfecf740049ce Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 Nov 2017 00:57:06 -0500 Subject: [PATCH 2/5] Add smart_flatten_conversation function - Fix doc - Fix formatting - Update conv_sort with smart threading --- include/conversation.php | 243 +++++++++++++++++++++++++-------------- 1 file changed, 158 insertions(+), 85 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 7abe97e063..196fb6389c 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1361,13 +1361,20 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { return $o; } - -function get_item_children($arr, $parent) { - $children = array(); - $a = get_app(); - foreach ($arr as $item) { +/** + * Returns all the children in the given item list of the given parent. If threading + * is allowed, does it recursively. + * + * @param array $item_list + * @param array $parent + * @return type + */ +function get_item_children(array $item_list, array $parent, $recursive = true) +{ + $children = []; + foreach ($item_list as $item) { if ($item['id'] != $item['parent']) { - if (Config::get('system', 'thread_allow') && $a->theme_thread_allow) { + if ($recursive) { // Fallback to parent-uri if thr-parent is not set $thr_parent = $item['thr-parent']; if ($thr_parent == '') { @@ -1375,7 +1382,7 @@ function get_item_children($arr, $parent) { } if ($thr_parent == $parent['uri']) { - $item['children'] = get_item_children($arr, $item); + $item['children'] = get_item_children($item_list, $item); $children[] = $item; } } elseif ($item['parent'] == $parent['id']) { @@ -1386,54 +1393,124 @@ function get_item_children($arr, $parent) { return $children; } -/// @TODO Add type-hint -function sort_item_children($items) { +/** + * Recursively sorts a tree-like item array + * + * @param array $items + * @return array + */ +function sort_item_children(array $items) +{ $result = $items; usort($result, 'sort_thr_created_rev'); foreach ($result as $k => $i) { - if (count($result[$k]['children'])) { + if (isset($result[$k]['children'])) { $result[$k]['children'] = sort_item_children($result[$k]['children']); } } return $result; } -/// @TODO Add type-hint -function add_children_to_list($children, &$arr) { - foreach ($children as $y) { - $arr[] = $y; - if (count($y['children'])) { - add_children_to_list($y['children'], $arr); +/** + * Recursively add all children items at the top level of a list + * + * @param array $children List of items to append + * @param array $item_list + */ +function add_children_to_list(array $children, array &$item_list) +{ + foreach ($children as $child) { + $item_list[] = $child; + if (isset($child['children'])) { + add_children_to_list($child['children'], $item_list); } } } -/// @TODO Add type-hint -function conv_sort($arr, $order) { - - if ((!(is_array($arr) && count($arr)))) { - return array(); +/** + * This recursive function takes the item tree structure created by conv_sort() and + * flatten the extraneous depth levels when people reply sequentially, removing the + * stairs effect in threaded conversations limiting the available content width. + * + * The basic principle is the following: if a post item has only one reply and is + * the last reply of its parent, then the reply is moved to the parent. + * + * This process is rendered somewhat more complicated because items can be either + * replies or likes, and these don't factor at all in the reply count/last reply. + * + * @param array $parent A tree-like array of items + * @return array + */ +function smart_flatten_conversation(array $parent) +{ + if (! isset($parent['children']) || count($parent['children']) == 0) { + return $parent; } - $parents = array(); - $children = array(); - $newarr = array(); + // We use a for loop to ensure we process the newly-moved items + for ($i = 0; $i < count($parent['children']); $i++) { + $child = $parent['children'][$i]; - /* - * This is a preparation for having two different items with the same uri in one thread - * This will otherwise lead to an endless loop. - */ - foreach ($arr as $x) { - if (!isset($newarr[$x['uri']])) { - $newarr[$x['uri']] = $x; + if (isset($child['children']) && count($child['children'])) { + // This helps counting only the regular posts + $count_post_closure = function($var) { + return $var['verb'] === 'http://activitystrea.ms/schema/1.0/post'; + }; + + $child_post_count = count(array_filter($child['children'], $count_post_closure)); + + $remaining_post_count = count(array_filter(array_slice($parent['children'], $i), $count_post_closure)); + + // If there's only one child's children post and this is the last child post + if ($child_post_count == 1 && $remaining_post_count == 1) { + + // Searches the post item in the children + $j = 0; + while($child['children'][$j]['verb'] !== 'http://activitystrea.ms/schema/1.0/post' && $j < count($child['children'])) { + $j ++; + } + + $moved_item = $child['children'][$j]; + unset($parent['children'][$i]['children'][$j]); + $parent['children'][] = $moved_item; + } else { + $parent['children'][$i] = smart_flatten_conversation($child); + } } } - $arr = $newarr; + return $parent; +} - foreach ($arr as $x) { - if ($x['id'] == $x['parent']) { - $parents[] = $x; + +/** + * Expands a flat list of items into corresponding tree-like conversation structures, + * sort the top-level posts either on "created" or "commented", and finally + * append all the items at the top level (???) + * + * @param array $item_list A list of items belonging to one or more conversations + * @param string $order Either on "created" or "commented" + * @return array + */ +function conv_sort(array $item_list, $order) +{ + $parents = []; + + if (!(is_array($item_list) && count($item_list))) { + return $parents; + } + + $item_array = []; + + // Dedupes the item list on the uri to prevent infinite loops + foreach ($item_list as $item) { + $item_array[$item['uri']] = $item; + } + + // Extract the top level items + foreach ($item_array as $item) { + if ($item['id'] == $item['parent']) { + $parents[] = $item; } } @@ -1443,73 +1520,69 @@ function conv_sort($arr, $order) { usort($parents, 'sort_thr_commented'); } - if (count($parents)) { - foreach ($parents as $i => $_x) { - $parents[$i]['children'] = get_item_children($arr, $_x); + $thread_allowed = Config::get('system', 'thread_allow') && get_app()->theme_thread_allow; + + foreach ($parents as $i => $parent) { + $parents[$i]['children'] = get_item_children($item_array, $parent, $thread_allowed); + } + + foreach ($parents as $i => $parent) { + $parents[$i]['children'] = sort_item_children($parents[$i]['children']); + } + + if ($thread_allowed && PConfig::get(local_user(), 'system', 'smart_threading', 0)) { + foreach ($parents as $i => $parent) { + $parents[$i] = smart_flatten_conversation($parent); } } - /// @TODO Old-lost code? - /*foreach ($arr as $x) { - if ($x['id'] != $x['parent']) { - $p = find_thread_parent_index($parents,$x); - if ($p !== false) - $parents[$p]['children'][] = $x; - } - }*/ - if (count($parents)) { - foreach ($parents as $k => $v) { - if (count($parents[$k]['children'])) { - $parents[$k]['children'] = sort_item_children($parents[$k]['children']); - /// @TODO Old-lost code? - /*$y = $parents[$k]['children']; - usort($y,'sort_thr_created_rev'); - $parents[$k]['children'] = $y;*/ - } + /// @TODO: Stop recusrsively adding all children back to the top level (!!!) + /// However, this apparently ensures responses (likes, attendance) display (?!) + foreach ($parents as $parent) { + if (count($parent['children'])) { + add_children_to_list($parent['children'], $parents); } } - $ret = array(); - if (count($parents)) { - foreach ($parents as $x) { - $ret[] = $x; - if (count($x['children'])) { - add_children_to_list($x['children'], $ret); - /// @TODO Old-lost code? - /*foreach ($x['children'] as $y) - $ret[] = $y;*/ - } - } - } - - return $ret; + return $parents; } -/// @TODO Add type-hint -function sort_thr_created($a, $b) { +/** + * usort() callback to sort item arrays by the created key + * + * @param array $a + * @param array $b + * @return int + */ +function sort_thr_created(array $a, array $b) +{ return strcmp($b['created'], $a['created']); } -/// @TODO Add type-hint -function sort_thr_created_rev($a, $b) { +/** + * usort() callback to reverse sort item arrays by the created key + * + * @param array $a + * @param array $b + * @return int + */ +function sort_thr_created_rev(array $a, array $b) +{ return strcmp($a['created'], $b['created']); } -/// @TODO Add type-hint -function sort_thr_commented($a, $b) { +/** + * usort() callback to sort item arrays by the commented key + * + * @param array $a + * @param array $b + * @return type + */ +function sort_thr_commented(array $a, array $b) +{ return strcmp($b['commented'], $a['commented']); } -/// @TODO Add type-hint -function find_thread_parent_index($arr, $x) { - foreach ($arr as $k => $v) { - if ($v['id'] == $x['parent']) { - return $k; - } - } - return false; -} - /// @TODO Add type-hint function render_location_dummy($item) { if ($item['location'] != "") { From 2336fa9d74ff395439066e9ffcf77a83fb0a35c1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 Nov 2017 00:57:31 -0500 Subject: [PATCH 3/5] Add smart_threading user setting --- mod/settings.php | 4 ++++ view/templates/settings_display.tpl | 1 + view/theme/frio/templates/settings_display.tpl | 1 + 3 files changed, 6 insertions(+) diff --git a/mod/settings.php b/mod/settings.php index c0b3d2cc16..bc6425171c 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -303,6 +303,7 @@ function settings_post(App $a) { $infinite_scroll = x($_POST, 'infinite_scroll') ? intval($_POST['infinite_scroll']) : 0; $no_auto_update = x($_POST, 'no_auto_update') ? intval($_POST['no_auto_update']) : 0; $bandwidth_saver = x($_POST, 'bandwidth_saver') ? intval($_POST['bandwidth_saver']) : 0; + $smart_threading = x($_POST, 'smart_threading') ? intval($_POST['smart_threading']) : 0; $nowarn_insecure = x($_POST, 'nowarn_insecure') ? intval($_POST['nowarn_insecure']) : 0; $browser_update = x($_POST, 'browser_update') ? intval($_POST['browser_update']) : 0; if ($browser_update != -1) { @@ -335,6 +336,7 @@ function settings_post(App $a) { PConfig::set(local_user(), 'system', 'infinite_scroll' , $infinite_scroll); PConfig::set(local_user(), 'system', 'no_auto_update' , $no_auto_update); PConfig::set(local_user(), 'system', 'bandwidth_saver' , $bandwidth_saver); + PConfig::set(local_user(), 'system', 'smart_threading' , $smart_threading); if ($theme == $a->user['theme']) { // call theme_post only if theme has not been changed @@ -989,6 +991,7 @@ function settings_content(App $a) { $infinite_scroll = PConfig::get(local_user(), 'system', 'infinite_scroll', 0); $no_auto_update = PConfig::get(local_user(), 'system', 'no_auto_update', 0); $bandwidth_saver = PConfig::get(local_user(), 'system', 'bandwidth_saver', 0); + $smart_threading = PConfig::get(local_user(), 'system', 'smart_threading', 0); $theme_config = ""; if (($themeconfigfile = get_theme_config_file($theme_selected)) != null) { @@ -1017,6 +1020,7 @@ function settings_content(App $a) { '$infinite_scroll' => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''), '$no_auto_update' => array('no_auto_update', t("Automatic updates only at the top of the network page"), $no_auto_update, t('When disabled, the network page is updated all the time, which could be confusing while reading.')), '$bandwidth_saver' => array('bandwidth_saver', t('Bandwith Saver Mode'), $bandwidth_saver, t('When enabled, embedded content is not displayed on automatic updates, they only show on page reload.')), + '$smart_threading' => array('smart_threading', t('Smart Threading'), $smart_threading, t('When enabled, suppress extraneous thread indentation while keeping it where it matters. Only works if threading is available and enabled.')), '$d_tset' => t('General Theme Settings'), '$d_ctset' => t('Custom Theme Settings'), diff --git a/view/templates/settings_display.tpl b/view/templates/settings_display.tpl index ef2091035f..ff3e4fba6e 100644 --- a/view/templates/settings_display.tpl +++ b/view/templates/settings_display.tpl @@ -20,6 +20,7 @@ {{include file="field_checkbox.tpl" field=$noinfo}} {{include file="field_checkbox.tpl" field=$infinite_scroll}} {{include file="field_checkbox.tpl" field=$bandwidth_saver}} +{{include file="field_checkbox.tpl" field=$smart_threading}}

{{$calendar_title}}

{{include file="field_select.tpl" field=$first_day_of_week}} diff --git a/view/theme/frio/templates/settings_display.tpl b/view/theme/frio/templates/settings_display.tpl index 177fa63117..cc36762dc9 100644 --- a/view/theme/frio/templates/settings_display.tpl +++ b/view/theme/frio/templates/settings_display.tpl @@ -75,6 +75,7 @@ {{include file="field_checkbox.tpl" field=$noinfo}} {{include file="field_checkbox.tpl" field=$infinite_scroll}} {{include file="field_checkbox.tpl" field=$bandwidth_saver}} + {{include file="field_checkbox.tpl" field=$smart_threading}}
From 0fe42335695c210024733bdc1ea0b0491d9d593a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 Nov 2017 08:41:16 -0500 Subject: [PATCH 4/5] Improve documentation with brief key --- include/conversation.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 196fb6389c..31ab4eadec 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1362,11 +1362,14 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { } /** - * Returns all the children in the given item list of the given parent. If threading - * is allowed, does it recursively. + * Returns all the children in the given item list of the given parent, recusrsively + * or not. + * + * @brief Returns all the children in the given item list of the given parent * * @param array $item_list * @param array $parent + * @param bool $recursive * @return type */ function get_item_children(array $item_list, array $parent, $recursive = true) @@ -1394,7 +1397,7 @@ function get_item_children(array $item_list, array $parent, $recursive = true) } /** - * Recursively sorts a tree-like item array + * @brief Recursively sorts a tree-like item array * * @param array $items * @return array @@ -1412,7 +1415,7 @@ function sort_item_children(array $items) } /** - * Recursively add all children items at the top level of a list + * @brief Recursively add all children items at the top level of a list * * @param array $children List of items to append * @param array $item_list @@ -1438,6 +1441,8 @@ function add_children_to_list(array $children, array &$item_list) * This process is rendered somewhat more complicated because items can be either * replies or likes, and these don't factor at all in the reply count/last reply. * + * @brief Selectively flattens a tree-like item structure to prevent threading stairs + * * @param array $parent A tree-like array of items * @return array */ @@ -1488,6 +1493,8 @@ function smart_flatten_conversation(array $parent) * sort the top-level posts either on "created" or "commented", and finally * append all the items at the top level (???) * + * @brief Expands a flat item list into a conversation array for display + * * @param array $item_list A list of items belonging to one or more conversations * @param string $order Either on "created" or "commented" * @return array @@ -1548,7 +1555,7 @@ function conv_sort(array $item_list, $order) } /** - * usort() callback to sort item arrays by the created key + * @brief usort() callback to sort item arrays by the created key * * @param array $a * @param array $b @@ -1560,7 +1567,7 @@ function sort_thr_created(array $a, array $b) } /** - * usort() callback to reverse sort item arrays by the created key + * @brief usort() callback to reverse sort item arrays by the created key * * @param array $a * @param array $b @@ -1572,7 +1579,7 @@ function sort_thr_created_rev(array $a, array $b) } /** - * usort() callback to sort item arrays by the commented key + * @brief usort() callback to sort item arrays by the commented key * * @param array $a * @param array $b From 4aa003f43fb18184de25d85e21c6146e51ac3e80 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 19 Nov 2017 08:41:33 -0500 Subject: [PATCH 5/5] Use constant instead of hardcoded string for ACTIVITY_POST --- include/conversation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 31ab4eadec..2e6da4ce90 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1459,7 +1459,7 @@ function smart_flatten_conversation(array $parent) if (isset($child['children']) && count($child['children'])) { // This helps counting only the regular posts $count_post_closure = function($var) { - return $var['verb'] === 'http://activitystrea.ms/schema/1.0/post'; + return $var['verb'] === ACTIVITY_POST; }; $child_post_count = count(array_filter($child['children'], $count_post_closure)); @@ -1471,7 +1471,7 @@ function smart_flatten_conversation(array $parent) // Searches the post item in the children $j = 0; - while($child['children'][$j]['verb'] !== 'http://activitystrea.ms/schema/1.0/post' && $j < count($child['children'])) { + while($child['children'][$j]['verb'] !== ACTIVITY_POST && $j < count($child['children'])) { $j ++; }