Browse Source

Fix Search (again) and bring back a simple Discover tab for communities

pull/617/head
Timothée Jaussoin 8 years ago
parent
commit
a7d6972bb4
  1. 58
      app/Post.php
  2. 29
      app/widgets/Communities/Communities.php
  3. 2
      app/widgets/Communities/_communities.tpl
  4. 3
      app/widgets/Communities/communities.tpl
  5. 47
      app/widgets/Menu/Menu.php
  6. 4
      app/widgets/Post/Post.php
  7. 52
      app/widgets/Search/Search.php
  8. 10
      app/widgets/Search/_search_results.tpl

58
app/Post.php

@ -55,6 +55,64 @@ class Post extends Model
$this->tags()->sync($this->tags);
}
public function scopeWithoutComments($query)
{
return $query->whereNull('parent_id');
}
protected function withContactsScope($query)
{
return $query->orWhereIn('server', function($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID)
->where('subscription', 'both');
});
}
public function scopeWithContacts($query)
{
return $this->withContactsScope($query);
}
protected function withMineScope($query)
{
return $query->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->where('node', 'urn:xmpp:microblog:0')
->where('server', \App\User::me()->id);
});
}
public function scopeWithMine($query)
{
return $this->withMineScope($query);
}
protected function withSubscriptionsScope($query)
{
return $query->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->whereIn('server', function($query) {
$query->select('server')
->from('subscriptions')
->where('jid', \App\User::me()->id);
})
->whereIn('node', function($query) {
$query->select('node')
->from('subscriptions')
->where('jid', \App\User::me()->id);
});
});
}
public function scopeWithSubscriptions($query)
{
return $this->withSubscriptionsScope($query);
}
public function getOpenlinkAttribute()
{
if (!$this->open) return;

29
app/widgets/Communities/Communities.php

@ -3,6 +3,8 @@
use Respect\Validation\Validator;
use App\Configuration;
include_once WIDGETS_PATH . 'Post/Post.php';
class Communities extends \Movim\Widget\Base
{
public function load()
@ -19,30 +21,15 @@ class Communities extends \Movim\Widget\Base
function prepareCommunities()
{
$view = $this->tpl();
/*$view->assign('communities', $id->getItems(
false,
0,
40,
true, (Configuration::findOrNew(1)->restrictsuggestions)
? $this->user->getServer()
: false
));*/
$communities = \App\Post::select('server', 'node', 'published')
->groupBy('server', 'node', 'published')
$posts = \App\Post::withoutComments()
->orderBy('published', 'desc')
->orderBy('server', 'desc')
->orderBy('node', 'desc')
->where('open', true)
->take(40)
->get();
$posts = [];
foreach ($communities as $community) {
array_push($posts, \App\Post::where('server', $community->server)
->where('node', $community->node)
->where('open', true)
->orderBy('published', 'desc')
->first());
}
$view->assign('posts', $posts);
return $view->draw('_communities', true);
@ -50,6 +37,6 @@ class Communities extends \Movim\Widget\Base
public function prepareTicket(\App\Post $post)
{
return (new Post)->prepareTicket($post);
return (new \Post)->prepareTicket($post);
}
}

2
app/widgets/Communities/_communities.tpl

@ -1,4 +1,4 @@
<ul class="list column third active card">
<ul class="list column third middle active card">
{loop="$posts"}
{$c->prepareTicket($value)}
{/loop}

3
app/widgets/Communities/communities.tpl

@ -1,2 +1 @@
<div id="communities" class="tabelem spin" title="{$c->__('button.discover')}">
</div>
<div id="communities" class="tabelem spin" title="{$c->__('button.discover')}"></div>

47
app/widgets/Menu/Menu.php

@ -143,39 +143,21 @@ class Menu extends \Movim\Widget\Base
\App\Cache::c('since', date(DATE_ISO8601, strtotime($pd->getLastDate())));
}
$items = \App\Post::skip($page * $this->_paging + $count);
if (in_array($type, ['all', 'feed'])) {
$items = $items->whereIn('server', function($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID)
->where('subscription', 'both');
})
->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->where('node', 'urn:xmpp:microblog:0')
->where('server', $this->user->id);
});
}
$items = \App\Post::skip($page * $this->_paging + $count)->withoutComments();
if (in_array($type, ['all', 'news'])) {
$items = $items->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->whereIn('server', function($query) {
$query->select('server')
->from('subscriptions')
->where('jid', $this->user->id);
})
->whereIn('node', function($query) {
$query->select('node')
->from('subscriptions')
->where('jid', $this->user->id);
});
});
}
$items->whereIn('id', function ($query) use ($type) {
$query = $query->select('id')->from('posts');
if (in_array($type, ['all', 'feed'])) {
$query = \App\Post::withContactsScope($query);
$query = \App\Post::withMineScope($query);
}
if (in_array($type, ['all', 'news'])) {
$query = \App\Post::withSubscriptionsScope($query);
}
});
$next = $page + 1;
@ -188,7 +170,6 @@ class Menu extends \Movim\Widget\Base
}
$view->assign('items', $items
->where('parent_id', null)
->orderBy('published', 'desc')
->take($this->_paging)->get());
$view->assign('type', $type);

4
app/widgets/Post/Post.php

@ -5,8 +5,6 @@ use Moxl\Xec\Action\Pubsub\GetItem;
use Moxl\Xec\Action\Microblog\CommentsGet;
use Moxl\Xec\Action\Microblog\CommentPublish;
use App\User;
use Respect\Validation\Validator;
class Post extends \Movim\Widget\Base
@ -212,7 +210,7 @@ class Post extends \Movim\Widget\Base
$view->assign('repost', \App\Contact::find($p->server));
}
$view->assign('nsfw', User::me()->nsfw);
$view->assign('nsfw', \App\User::me()->nsfw);
$view->assign('post', $p);
return ($card)

52
app/widgets/Search/Search.php

@ -45,59 +45,37 @@ class Search extends \Movim\Widget\Base
});
})
->whereIn('id', function($query) {
$query->select('id')
->from('posts')
->whereIn('server', function($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID)
->where('subscription', 'both');
})
->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->where('node', 'urn:xmpp:microblog:0')
->where('server', $this->user->id);
})
->orWhereIn('id', function($query) {
$query->select('id')
->from('posts')
->whereIn('server', function($query) {
$query->select('server')
->from('subscriptions')
{$c->prepareTicket($value)} ->where('jid', $this->user->id);
})
->whereIn('node', function($query) {
$query->select('node')
->from('subscriptions')
->where('jid', $this->user->id);
});
});
$query = $query->select('id')->from('posts');
$query = \App\Post::withContactsScope($query);
$query = \App\Post::withMineScope($query);
$query = \App\Post::withSubscriptionsScope($query);
})
->orderBy('published', 'desc')
->take(10)
->take(6)
->get();
}
$view->assign('posts', $posts);
$view->assign('posts', $posts);
}
if (!$posts) $view->assign('empty', true);
if ($posts == false) $view->assign('empty', true);
}
if (!empty($key)) {
$contacts = \App\Contact::where('id', function ($query) {
$contacts = \App\Contact::where('id', function ($query) use ($key) {
$query->select('id')
->from('users')
->where('public', true);
->where('public', true)
->where('id', 'like', '%'. $key . '%');
})->limit(5)->get();
$view->assign('contacts', $contacts);
if (Validator::email()->validate($key)) {
$contact = new \App\Contact;
$contact->jid = $key;
$view->assign('contacts', [$contact]);
$contacts->push();
}
$view->assign('contacts', $contacts);
} else {
$view->assign('contacts', null);
}

10
app/widgets/Search/_search_results.tpl

@ -3,16 +3,16 @@
<h4>{$c->__('search.subtitle')}</h4>
</div>
{else}
{if="$posts->isNotEmpty()"}
<ul class="list active divided middle">
{if="$posts"}
<li class="subheader"><p>{$c->__('page.news')}</p></li>
{/if}
<li class="subheader"><p>{$c->__('page.news')}</p></li>
{loop="$posts"}
{$c->prepareTicket($value)}
{/loop}
</ul>
{/if}
{if="$contacts != null"}
{if="$contacts->isNotEmpty()"}
<ul class="list">
<li class="subheader">
<p>{$c->__('explore.explore')}</p>
@ -38,7 +38,7 @@
<span class="control icon active gray" onclick="Search_ajaxChat('{$value->jid}')">
<i class="zmdi zmdi-comment-text-alt"></i>
</span>
<p class="normal line">{$value->getTrueName()}</p>
<p class="normal line">{$value->truename}</p>
{if="$value->isEmpty()"}
<p>{$value->jid}</p>
{/if}

Loading…
Cancel
Save