From 559776140b0eba7ca282dc7559eba29316d72456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 28 Dec 2021 22:41:58 +0100 Subject: [PATCH] First raw implementation of Pubsub galleries in Movim Add a small "dumb" galleries detector --- app/helpers/UtilsHelper.php | 3 +- app/widgets/CommunityPosts/CommunityPosts.php | 68 +++++++++++++++---- .../CommunityPosts/_communityposts.tpl | 36 ++++++---- app/widgets/CommunityPosts/communityposts.js | 2 +- app/widgets/Post/_post_comments_error.tpl | 2 +- app/widgets/Post/_post_ticket.tpl | 3 +- lib/moxl/src/Stanza/Pubsub.php | 26 ++++++- lib/moxl/src/Xec/Action/Pubsub/GetItem.php | 5 ++ lib/moxl/src/Xec/Action/Pubsub/GetItems.php | 21 ++++-- public/theme/css/block.css | 35 ++++++++++ src/Movim/Route.php | 2 +- 11 files changed, 168 insertions(+), 35 deletions(-) diff --git a/app/helpers/UtilsHelper.php b/app/helpers/UtilsHelper.php index 35c6cfc88..61185d5e2 100644 --- a/app/helpers/UtilsHelper.php +++ b/app/helpers/UtilsHelper.php @@ -639,7 +639,8 @@ function generateKey($size) return $hash; } -define('DEFAULT_HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://google.com/bot.html)'); +//define('DEFAULT_HTTP_USER_AGENT', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://google.com/bot.html)'); +define('DEFAULT_HTTP_USER_AGENT', 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'); /** * @desc Request a url async diff --git a/app/widgets/CommunityPosts/CommunityPosts.php b/app/widgets/CommunityPosts/CommunityPosts.php index 05cc975e1..74f54ee09 100644 --- a/app/widgets/CommunityPosts/CommunityPosts.php +++ b/app/widgets/CommunityPosts/CommunityPosts.php @@ -11,7 +11,8 @@ include_once WIDGETS_PATH.'Post/Post.php'; class CommunityPosts extends Base { - private $_paging = 10; + private $_paging = 12; + private $_beforeAfter = 'b='; public function load() { @@ -25,10 +26,10 @@ class CommunityPosts extends Base public function onItemsId($packet) { - list($origin, $node, $ids, $first, $last, $count, $paginated, $before) + list($origin, $node, $ids, $first, $last, $count, $paginated, $before, $after, $query) = array_values($packet->content); - $this->displayItems($origin, $node, $ids, $first, $last, $count, $paginated, $before); + $this->displayItems($origin, $node, $ids, $first, $last, $count, $paginated, $before, $after, $query); } public function onItemsError($packet) @@ -59,13 +60,15 @@ class CommunityPosts extends Base $last = false, $count = false, $paginated = false, - $before = null + $before = null, + $after = null, + $query = null ) { if (!$this->validateServerNode($origin, $node)) { return; } - $html = $this->prepareCommunity($origin, $node, 0, $ids, $first, $last, $count, $before); + $html = $this->prepareCommunity($origin, $node, 0, $ids, $first, $last, $count, $before, $after, $query); $slugify = new Slugify; $this->rpc( @@ -82,7 +85,7 @@ class CommunityPosts extends Base $c->ajaxGetDrawer($jid); } - public function ajaxGetItems($origin, $node, $before = 'empty') + public function ajaxGetItems($origin, $node, $before = 'empty', $query = null) { if (!$this->validateServerNode($origin, $node)) { return; @@ -91,9 +94,17 @@ class CommunityPosts extends Base $r = new GetItems; $r->setTo($origin) ->setNode($node) - ->setPaging($this->_paging) - ->setBefore($before) - ->request(); + ->setPaging($this->_paging); + + $r = (strpos($before, $this->_beforeAfter) === 0) + ? $r->setAfter(substr($before, strlen($this->_beforeAfter))) + : $r->setBefore($before); + + if ($query) { + $r->setQuery($query); + } + + $r->request(); } public function ajaxClear() @@ -113,6 +124,11 @@ class CommunityPosts extends Base return (new \Post)->preparePost($p, false, true); } + public function prepareTicket($p) + { + return (new \Post)->prepareTicket($p); + } + private function prepareCommunity( $origin, $node, @@ -121,7 +137,9 @@ class CommunityPosts extends Base $first = false, $last = false, $count = false, - $before = null + $before = null, + $after = null, + $query = null ) { $ids = is_array($ids) ? $ids : []; foreach ($ids as $key => $id) { @@ -130,6 +148,10 @@ class CommunityPosts extends Base } } + if (empty($ids)) { + return $this->prepareEmpty(); + } + $posts = \App\Post::where('server', $origin)->where('node', $node) ->whereIn('nodeid', $ids)->get(); $postsWithKeys = []; @@ -150,6 +172,7 @@ class CommunityPosts extends Base $view->assign('ids', $ids); $view->assign('posts', $postsWithKeys); $view->assign('before', $before); + $view->assign('after', $after); $view->assign('info', \App\Info::where('server', $origin) ->where('node', $node) ->first()); @@ -159,6 +182,19 @@ class CommunityPosts extends Base ->first()); $view->assign('paging', $this->_paging); + // For now we detect if a node is a gallery if all the publications have an attached picture + // and if the post contents are short. + $shortCount = 0; + + $gallery = $posts->every(function ($post) use (&$shortCount) { + if ($post->isShort()) $shortCount++; + return $post->picture != null; + }); + + if ($gallery && $shortCount < $posts->count()/2) $gallery = false; + + $view->assign('gallery', $gallery); + $view->assign('publicposts', ($ids == false) ? \App\Post::where('server', $origin) ->where('node', $node) @@ -173,9 +209,17 @@ class CommunityPosts extends Base $view->assign('last', $last); $view->assign('count', $count); - $view->assign('goback', $this->route( + + if ($first) { + $view->assign('previouspage', $this->route( + $node == 'urn:xmpp:microblog:0' ? 'contact' : 'community', + [$origin, $node, $this->_beforeAfter.$first, $query] + )); + } + + $view->assign('nextpage', $this->route( $node == 'urn:xmpp:microblog:0' ? 'contact' : 'community', - [$origin, $node, $last] + [$origin, $node, $last, $query] )); $html = $view->draw('_communityposts'); diff --git a/app/widgets/CommunityPosts/_communityposts.tpl b/app/widgets/CommunityPosts/_communityposts.tpl index 482fa6752..fa825845a 100644 --- a/app/widgets/CommunityPosts/_communityposts.tpl +++ b/app/widgets/CommunityPosts/_communityposts.tpl @@ -1,23 +1,35 @@ {if="!empty($ids)"} -