Browse Source

Fix Posts suggestions, groups by Communities and Blog

pull/647/head
Timothée Jaussoin 8 years ago
parent
commit
986e82d844
  1. 23
      app/Post.php
  2. 3
      app/widgets/Communities/Communities.php
  3. 3
      app/widgets/ContactDiscoPosts/ContactDiscoPosts.php
  4. 8
      app/widgets/NewsNav/NewsNav.php

23
app/Post.php

@ -8,6 +8,7 @@ use Movim\Picture;
use Movim\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;
class Post extends Model
{
@ -66,17 +67,17 @@ class Post extends Model
public function scopeRestrictToMicroblog($query)
{
return $query->where('node', 'urn:xmpp:microblog:0');
return $query->where('posts.node', 'urn:xmpp:microblog:0');
}
public function scopeRestrictToCommunities($query)
{
return $query->where('node', '!=', 'urn:xmpp:microblog:0');
return $query->where('posts.node', '!=', 'urn:xmpp:microblog:0');
}
public function scopeWithoutComments($query)
{
return $query->whereNull('parent_id');
return $query->whereNull('posts.parent_id');
}
public function scopeRestrictUserHost($query)
@ -103,9 +104,23 @@ class Post extends Model
}
}
public function scopeRecents($query)
{
$query->join(DB::raw('(
select max(published) as published, server, node
from posts
group by server, node) as recents
'), function($join)
{
$join->on('posts.node', '=', 'recents.node');
$join->on('posts.published', '=', 'recents.published');
}
);
}
protected function withContactsScope($query)
{
return $query->orWhereIn('server', function($query) {
return $query->orWhereIn('posts.server', function($query) {
$query->from('rosters')
->select('jid')
->where('session_id', SESSION_ID)

3
app/widgets/Communities/Communities.php

@ -25,7 +25,8 @@ class Communities extends \Movim\Widget\Base
$posts = \App\Post::withoutComments()
->restrictToCommunities()
->restrictNSFW()
->orderBy('published', 'desc')
->recents()
->orderBy('posts.published', 'desc')
->where('open', true)
->take(40)
->get();

3
app/widgets/ContactDiscoPosts/ContactDiscoPosts.php

@ -24,8 +24,9 @@ class ContactDiscoPosts extends \Movim\Widget\Base
$blogs = \App\Post::restrictToMicroblog()
->restrictUserHost()
->restrictNSFW()
->recents()
->where('open', true)
->orderBy('published', 'desc')
->orderBy('posts.published', 'desc')
->get();
$view->assign('blogs', $blogs);

8
app/widgets/NewsNav/NewsNav.php

@ -10,10 +10,11 @@ class NewsNav extends Base
public function display()
{
$blogs = \App\Post::where('open', true)
->orderBy('published', 'desc')
->orderBy('posts.published', 'desc')
->restrictToMicroblog()
->restrictUserHost()
->restrictNSFW()
->recents()
->take(6)
->get()
->shuffle();
@ -21,14 +22,15 @@ class NewsNav extends Base
$this->view->assign('blogs', $blogs);
$posts = \App\Post::where('open', true)
->orderBy('published', 'desc')
->orderBy('posts.published', 'desc')
->restrictToCommunities()
->restrictUserHost()
->restrictNSFW()
->recents()
->take(6);
if ($this->get('s') && $this->get('s') != 'subscriptions') {
$posts->where('server', $this->get('s'));
$posts->where('posts.server', $this->get('s'));
}
$this->view->assign('posts', $posts->get()->shuffle());

Loading…
Cancel
Save