Skip to content

Commit 0008dd4

Browse files
committed
fix(feeds): 修复获取审核动态列表返回动态资源错误
zhiyicx/thinksns-plus-android#2365
1 parent 2629ce3 commit 0008dd4

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

packages/slimkit-plus-feed/src/API2/CommentPinnedController.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $
4848
$after = $request->query('after');
4949

5050
$grammar = $model->getConnection()->getQueryGrammar();
51-
$pinneds = $model->with('comment')
51+
$pinneds = $model->with('comment', 'user')
5252
->where('channel', 'comment')
5353
->where('target_user', $user->id)
5454
->when(boolval($after), function ($query) use ($after) {
@@ -65,8 +65,25 @@ public function index(Request $request, FeedPinnedModel $model, FeedRepository $
6565
->orderBy('created_at', 'desc')
6666
->limit($limit)
6767
->get();
68+
$pinneds = $pinneds->groupBy(function ($item) {
69+
return $item->channel;
70+
});
71+
$commentPinneds = $pinneds->get('comment', collect());
72+
$feedsPinneds = $pinneds->get('feed', collect());
73+
74+
if ($commentPinneds->isNotEmpty()) {
75+
$commentPinneds->load(['commentFeed']);
76+
$commentPinneds->map(function ($item) {
77+
$item->feed = $item->commentFeed;
78+
unset($item->commentFeed);
79+
});
80+
}
81+
if ($feedsPinneds->isNotEmpty()) {
82+
$feedsPinneds->load(['feed']);
83+
}
6884

69-
$pinneds = $pinneds->load(['feed', 'user'])->map(function ($pinned) use ($repository, $user) {
85+
$pinneds = $commentPinneds->merge($feedsPinneds->all());
86+
$pinneds = $pinneds->map(function ($pinned) use ($repository, $user) {
7087
if ($pinned->feed && $pinned->feed instanceof FeedModel) {
7188
$repository->setModel($pinned->feed);
7289
$repository->images();

packages/slimkit-plus-feed/src/Models/FeedPinned.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public function user()
4545
*/
4646
public function feed()
4747
{
48-
if ($this->channel === 'comment') {
49-
return $this->hasOne(Feed::class, 'id', 'raw');
50-
}
51-
5248
return $this->hasOne(Feed::class, 'id', 'target');
5349
}
5450

51+
public function commentFeed()
52+
{
53+
return $this->hasOne(Feed::class, 'id', 'raw');
54+
}
55+
5556
/**
5657
* Has feed comment.
5758
*

0 commit comments

Comments
 (0)