From b55676d08914d58927b5503a1bfa283397cd6d44 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Jun 2021 07:33:45 +0000 Subject: New landing page HQ with separate views for direct messages, public/limited messages and starred messages if the feature is enabled --- Zotlabs/Widget/Messages.php | 181 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 Zotlabs/Widget/Messages.php (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php new file mode 100644 index 000000000..6117bfa73 --- /dev/null +++ b/Zotlabs/Widget/Messages.php @@ -0,0 +1,181 @@ + $page['entries'], + '$offset' => $page['offset'], + '$feature_star' => feature_enabled(local_channel(), 'star_posts'), + '$strings' => [ + 'messages_title' => t('Public and restricted messages'), + 'direct_messages_title' => t('Direct messages'), + 'starred_messages_title' => t('Starred messages'), + 'loading' => t('Loading') + ] + ]); + + return $o; + } + + public static function get_messages_page($options) { + if (!local_channel()) + return; + + if ($options['offset'] == -1) { + return; + } + + $channel = App::get_channel(); + $item_normal = item_normal(); + $entries = []; + $limit = 30; + + $offset = 0; + if ($options['offset']) { + $offset = intval($options['offset']); + } + + $loadtime = (($offset) ? $_SESSION['page_loadtime'] : datetime_convert()); + + switch($options['type']) { + case 'direct': + $type_sql = ' AND item_private = 2 '; + break; + case 'starred': + $type_sql = ' AND item_starred = 1 '; + break; + default: + $type_sql = ' AND item_private IN (0, 1) '; + } + + $items = q("SELECT * FROM item WHERE uid = %d + AND created <= '%s' + $type_sql + AND item_thread_top = 1 + $item_normal + ORDER BY created DESC + LIMIT $limit OFFSET $offset", + intval(local_channel()), + dbescdate($loadtime) + ); + + xchan_query($items, false); + + $i = 0; + + foreach($items as $item) { + + $info = ''; + if ($options['type'] == 'direct') { + $info .= self::get_dm_recipients($channel, $item); + } + + if($item['owner_xchan'] !== $item['author_xchan']) { + $info .= t('via') . ' ' . $item['owner']['xchan_name']; + } + + $summary = $item['title']; + if (!$summary) { + $summary = $item['summary']; + } + if (!$summary) { + $summary = htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_QUOTES, 'UTF-8', false); + } + if (!$summary) { + $summary = t('Sorry, there is no text preview available for this post'); + } + $summary = substr_words($summary, 68); + + switch(intval($item['item_private'])) { + case 1: + $icon = ''; + break; + case 2: + $icon = ''; + break; + default: + $icon = ''; + } + + $entries[$i]['author_name'] = $item['author']['xchan_name']; + $entries[$i]['author_addr'] = (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']); + $entries[$i]['info'] = $info; + $entries[$i]['created'] = datetime_convert('UTC', date_default_timezone_get(), $item['created']); + $entries[$i]['summary'] = $summary; + $entries[$i]['b64mid'] = gen_link_id($item['mid']); + $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); + $entries[$i]['icon'] = $icon; + + $i++; + } + + $result = [ + 'offset' => ((count($entries) < $limit) ? -1 : intval($offset + $limit)), + 'entries' => $entries + ]; + + return $result; + } + + public static function get_dm_recipients($channel, $item) { + + if($channel['channel_hash'] === $item['owner']['xchan_hash']) { + // we are the owner, get the recipients from the item + $recips = expand_acl($item['allow_cid']); + if (is_array($recips)) { + array_unshift($recips, $item['owner']['xchan_hash']); + $column = 'xchan_hash'; + } + } + else { + $recips = IConfig::Get($item, 'activitypub', 'recips'); + if (isset($recips['to']) && is_array($recips['to'])) { + $recips = $recips['to']; + array_unshift($recips, $item['owner']['xchan_url']); + $column = 'xchan_url'; + } + else { + $hookinfo = [ + 'item' => $item, + 'recips' => null, + 'column' => '' + ]; + + call_hooks('direct_message_recipients', $hookinfo); + + $recips = $hookinfo['recips']; + $column = $hookinfo['column']; + } + } + + if(is_array($recips)) { + stringify_array_elms($recips, true); + + $query_str = implode(',', $recips); + $xchans = dbq("SELECT DISTINCT xchan_name FROM xchan WHERE $column IN ($query_str)"); + + foreach($xchans as $xchan) { + $recipients .= $xchan['xchan_name'] . ', '; + } + } + + return trim($recipients, ', '); + } + +} -- cgit v1.2.3 From e79a27c654589ed2ab3b3f2c1a6b603e2e642ad9 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Jun 2021 08:08:14 +0000 Subject: just use ... as preview if we could not wind anything useful --- Zotlabs/Widget/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 6117bfa73..a03238c9a 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -98,7 +98,7 @@ class Messages { $summary = htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_QUOTES, 'UTF-8', false); } if (!$summary) { - $summary = t('Sorry, there is no text preview available for this post'); + $summary = '...'; } $summary = substr_words($summary, 68); -- cgit v1.2.3 From c42d8a81c729ff8441195371106e96d398210067 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 18 Jun 2021 09:51:20 +0000 Subject: bbcode: add option to drop media content --- Zotlabs/Widget/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index a03238c9a..95f3d4eb6 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -95,7 +95,7 @@ class Messages { $summary = $item['summary']; } if (!$summary) { - $summary = htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_QUOTES, 'UTF-8', false); + $summary = htmlentities(html2plain(bbcode($item['body'], ['drop_media' => true]), 75, true), ENT_QUOTES, 'UTF-8', false); } if (!$summary) { $summary = '...'; -- cgit v1.2.3 From 97d9764f015990b1df01463c45090c4cbc2192fa Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 23 Jun 2021 22:14:01 +0200 Subject: if there are no messages display that there are no messages --- Zotlabs/Widget/Messages.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 95f3d4eb6..9679631c6 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -11,14 +11,10 @@ class Messages { if (!local_channel()) return EMPTY_STR; - $o = ''; $page = self::get_messages_page($options); - if (!$page['entries']) - return $o; - $tpl = get_markup_template('messages_widget.tpl'); - $o .= replace_macros($tpl, [ + $o = replace_macros($tpl, [ '$entries' => $page['entries'], '$offset' => $page['offset'], '$feature_star' => feature_enabled(local_channel(), 'star_posts'), @@ -26,7 +22,8 @@ class Messages { 'messages_title' => t('Public and restricted messages'), 'direct_messages_title' => t('Direct messages'), 'starred_messages_title' => t('Starred messages'), - 'loading' => t('Loading') + 'loading' => t('Loading'), + 'empty' => t('No messages') ] ]); -- cgit v1.2.3 From bed81d785c50a1a056a409b8113eceb0c1d47bba Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 29 Jun 2021 09:22:38 +0000 Subject: an attempt to improve the query for direct messages on some systems with hopefully no bad side-effect for others --- Zotlabs/Widget/Messages.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 9679631c6..ed666bfaa 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -42,6 +42,7 @@ class Messages { $item_normal = item_normal(); $entries = []; $limit = 30; + $dummy_sql = ''; $offset = 0; if ($options['offset']) { @@ -53,6 +54,9 @@ class Messages { switch($options['type']) { case 'direct': $type_sql = ' AND item_private = 2 '; + // $dummy_order_sql has no other meaning but trick + // some mysql backends into using the right index. + $dummy_order_sql = ', received DESC '; break; case 'starred': $type_sql = ' AND item_starred = 1 '; @@ -66,7 +70,7 @@ class Messages { $type_sql AND item_thread_top = 1 $item_normal - ORDER BY created DESC + ORDER BY created DESC $dummy_order_sql LIMIT $limit OFFSET $offset", intval(local_channel()), dbescdate($loadtime) -- cgit v1.2.3 From e8c6121b4e40e16b291b38158dd3a1639641c56a Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 29 Jun 2021 09:24:13 +0000 Subject: version --- Zotlabs/Widget/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index ed666bfaa..9dda33d71 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -54,7 +54,7 @@ class Messages { switch($options['type']) { case 'direct': $type_sql = ' AND item_private = 2 '; - // $dummy_order_sql has no other meaning but trick + // $dummy_order_sql has no other meaning but to trick // some mysql backends into using the right index. $dummy_order_sql = ', received DESC '; break; -- cgit v1.2.3 From 6a4727e3eb8d00c5927644b43bd6ba69fcd3c247 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 29 Jun 2021 18:21:12 +0000 Subject: fix variable name --- Zotlabs/Widget/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 9dda33d71..269d669dc 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -42,7 +42,7 @@ class Messages { $item_normal = item_normal(); $entries = []; $limit = 30; - $dummy_sql = ''; + $dummy_order_sql = ''; $offset = 0; if ($options['offset']) { -- cgit v1.2.3 From 7b2f4b08145ec31f0150544891633db2f5061104 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 16 Jul 2021 12:56:57 +0200 Subject: fix a regression in regard to unified session page load times intoduced in 6.0 --- Zotlabs/Widget/Messages.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Widget/Messages.php') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 269d669dc..21375b08f 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -13,6 +13,8 @@ class Messages { $page = self::get_messages_page($options); + $_SESSION['messages_loadtime'] = datetime_convert(); + $tpl = get_markup_template('messages_widget.tpl'); $o = replace_macros($tpl, [ '$entries' => $page['entries'], @@ -49,7 +51,7 @@ class Messages { $offset = intval($options['offset']); } - $loadtime = (($offset) ? $_SESSION['page_loadtime'] : datetime_convert()); + $loadtime = (($offset) ? $_SESSION['messages_loadtime'] : datetime_convert()); switch($options['type']) { case 'direct': -- cgit v1.2.3