@@ -37,6 +37,7 @@ public function show(string $username)
3737 'facebook ' => $ user ->facebook ,
3838 'instagram ' => $ user ->instagram ,
3939 'github ' => $ user ->github ,
40+ 'website ' => $ user ->website ,
4041 'created_at ' => $ user ->created_at ?->format('M Y ' ) ?? '2026 ' ,
4142 'is_verified ' => $ user ->is_verified ,
4243 'is_online ' => $ user ->isOnline (),
@@ -85,18 +86,39 @@ public function show(string $username)
8586 }
8687 }
8788
88- $ appreciators = $ user ->appreciators ()
89+ $ authId = auth ()->id ();
90+
91+ $ rawAppreciators = $ user ->appreciators ()
8992 ->select (['users.id ' , 'users.name ' , 'users.username ' , 'users.image_path ' , 'users.institution ' , 'users.is_verified ' ])
9093 ->latest ('user_appreciations.id ' )
9194 ->take (15 )
9295 ->get ();
9396
94- $ appreciating = $ user ->appreciatingUsers ()
97+ $ rawAppreciating = $ user ->appreciatingUsers ()
9598 ->select (['users.id ' , 'users.name ' , 'users.username ' , 'users.image_path ' , 'users.institution ' , 'users.is_verified ' ])
9699 ->latest ('user_appreciations.id ' )
97100 ->take (15 )
98101 ->get ();
99102
103+ $ allModalUserIds = $ rawAppreciators ->pluck ('id ' )->concat ($ rawAppreciating ->pluck ('id ' ))->unique ();
104+ $ myAppreciatingIds = $ authId && $ allModalUserIds ->isNotEmpty ()
105+ ? UserAppreciation ::where ('appreciator_id ' , $ authId )->whereIn ('user_id ' , $ allModalUserIds )->pluck ('user_id ' )->flip ()->toArray ()
106+ : [];
107+
108+ $ appreciators = $ rawAppreciators ->map (function ($ u ) use ($ myAppreciatingIds ) {
109+ $ data = $ u ->toArray ();
110+ $ data ['is_appreciated ' ] = isset ($ myAppreciatingIds [$ u ->id ]);
111+
112+ return $ data ;
113+ });
114+
115+ $ appreciating = $ rawAppreciating ->map (function ($ u ) use ($ myAppreciatingIds ) {
116+ $ data = $ u ->toArray ();
117+ $ data ['is_appreciated ' ] = isset ($ myAppreciatingIds [$ u ->id ]);
118+
119+ return $ data ;
120+ });
121+
100122 $ pokeEnabled = (bool ) AppSetting ::get ('peer_poke_enabled ' , true );
101123 $ canPoke = $ pokeEnabled && ! $ isOwner && ($ user ->allow_pokes ?? true );
102124 $ isPokeOnCooldown = $ canPoke && auth ()->check () && Cache ::has ('study_poke: ' .auth ()->id ().": {$ user ->id }" );
@@ -281,9 +303,8 @@ private function getSyllabusProgress(User $user): array
281303 $ trackableSubjects = $ subjectsQuery
282304 ->with (['nodes ' => function ($ query ) {
283305 $ query ->where ('is_trackable ' , true )
284- ->with ('parent:id,name,sort_order ' )
285306 ->orderBy ('sort_order ' , 'asc ' )
286- ->select ('id ' , 'subject_id ' , 'parent_id ' , ' name ' , 'slug ' , 'sort_order ' , 'weight ' );
307+ ->select ('id ' , 'subject_id ' , 'name ' , 'slug ' , 'sort_order ' , 'weight ' );
287308 }])
288309 ->get (['id ' , 'name ' , 'slug ' , 'course ' , 'tailwind_format ' , 'icon ' , 'sort_order ' ]);
289310
@@ -322,12 +343,6 @@ private function getSyllabusProgress(User $user): array
322343 'name ' => $ node ->name ,
323344 'weight ' => $ nodeWeight ,
324345 'is_completed ' => $ isDone ,
325- 'parent_id ' => $ node ->parent_id ,
326- 'parent ' => $ node ->parent ? [
327- 'id ' => $ node ->parent ->id ,
328- 'name ' => $ node ->parent ->name ,
329- 'sort_order ' => $ node ->parent ->sort_order ,
330- ] : null ,
331346 ];
332347 }
333348
@@ -376,8 +391,20 @@ public function appreciators(Request $request, User $user): JsonResponse
376391 ->latest ('user_appreciations.id ' )
377392 ->simplePaginate (15 );
378393
394+ $ authId = auth ()->id ();
395+ $ myAppreciatingIds = $ authId
396+ ? UserAppreciation ::where ('appreciator_id ' , $ authId )->whereIn ('user_id ' , $ paginator ->pluck ('id ' ))->pluck ('user_id ' )->flip ()->toArray ()
397+ : [];
398+
399+ $ items = collect ($ paginator ->items ())->map (function ($ u ) use ($ myAppreciatingIds ) {
400+ $ data = $ u ->toArray ();
401+ $ data ['is_appreciated ' ] = isset ($ myAppreciatingIds [$ u ->id ]);
402+
403+ return $ data ;
404+ })->all ();
405+
379406 return response ()->json ([
380- 'users ' => $ paginator -> items () ,
407+ 'users ' => $ items ,
381408 'has_more ' => $ paginator ->hasMorePages (),
382409 'current_page ' => $ paginator ->currentPage (),
383410 ]);
@@ -393,8 +420,20 @@ public function appreciating(Request $request, User $user): JsonResponse
393420 ->latest ('user_appreciations.id ' )
394421 ->simplePaginate (15 );
395422
423+ $ authId = auth ()->id ();
424+ $ myAppreciatingIds = $ authId
425+ ? UserAppreciation ::where ('appreciator_id ' , $ authId )->whereIn ('user_id ' , $ paginator ->pluck ('id ' ))->pluck ('user_id ' )->flip ()->toArray ()
426+ : [];
427+
428+ $ items = collect ($ paginator ->items ())->map (function ($ u ) use ($ myAppreciatingIds ) {
429+ $ data = $ u ->toArray ();
430+ $ data ['is_appreciated ' ] = isset ($ myAppreciatingIds [$ u ->id ]);
431+
432+ return $ data ;
433+ })->all ();
434+
396435 return response ()->json ([
397- 'users ' => $ paginator -> items () ,
436+ 'users ' => $ items ,
398437 'has_more ' => $ paginator ->hasMorePages (),
399438 'current_page ' => $ paginator ->currentPage (),
400439 ]);
0 commit comments