Skip to content

Commit

Permalink
fix(feeds): 修复获取审核动态列表返回动态资源错误
Browse files Browse the repository at this point in the history
zhiyicx/thinksns-plus-android#2365
  • Loading branch information
medz committed Sep 19, 2018
1 parent 2629ce3 commit 0008dd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
21 changes: 19 additions & 2 deletions packages/slimkit-plus-feed/src/API2/CommentPinnedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $
$after = $request->query('after');

$grammar = $model->getConnection()->getQueryGrammar();
$pinneds = $model->with('comment')
$pinneds = $model->with('comment', 'user')
->where('channel', 'comment')
->where('target_user', $user->id)
->when(boolval($after), function ($query) use ($after) {
Expand All @@ -65,8 +65,25 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $
->orderBy('created_at', 'desc')
->limit($limit)
->get();
$pinneds = $pinneds->groupBy(function ($item) {
return $item->channel;
});
$commentPinneds = $pinneds->get('comment', collect());
$feedsPinneds = $pinneds->get('feed', collect());

if ($commentPinneds->isNotEmpty()) {
$commentPinneds->load(['commentFeed']);
$commentPinneds->map(function ($item) {
$item->feed = $item->commentFeed;
unset($item->commentFeed);
});
}
if ($feedsPinneds->isNotEmpty()) {
$feedsPinneds->load(['feed']);
}

$pinneds = $pinneds->load(['feed', 'user'])->map(function ($pinned) use ($repository, $user) {
$pinneds = $commentPinneds->merge($feedsPinneds->all());
$pinneds = $pinneds->map(function ($pinned) use ($repository, $user) {
if ($pinned->feed && $pinned->feed instanceof FeedModel) {
$repository->setModel($pinned->feed);
$repository->images();
Expand Down
9 changes: 5 additions & 4 deletions packages/slimkit-plus-feed/src/Models/FeedPinned.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function user()
*/
public function feed()
{
if ($this->channel === 'comment') {
return $this->hasOne(Feed::class, 'id', 'raw');
}

return $this->hasOne(Feed::class, 'id', 'target');
}

public function commentFeed()
{
return $this->hasOne(Feed::class, 'id', 'raw');
}

/**
* Has feed comment.
*
Expand Down

0 comments on commit 0008dd4

Please sign in to comment.