|
|
|
@ -2,48 +2,29 @@
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\{
|
|
|
|
|
AccountInterstitial,
|
|
|
|
|
Bookmark,
|
|
|
|
|
DirectMessage,
|
|
|
|
|
DiscoverCategory,
|
|
|
|
|
Hashtag,
|
|
|
|
|
Follower,
|
|
|
|
|
Like,
|
|
|
|
|
Media,
|
|
|
|
|
MediaTag,
|
|
|
|
|
Notification,
|
|
|
|
|
Profile,
|
|
|
|
|
StatusHashtag,
|
|
|
|
|
Status,
|
|
|
|
|
User,
|
|
|
|
|
UserFilter,
|
|
|
|
|
};
|
|
|
|
|
use Auth,Cache;
|
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
|
use League\Fractal;
|
|
|
|
|
use App\Transformer\Api\{
|
|
|
|
|
AccountTransformer,
|
|
|
|
|
StatusTransformer,
|
|
|
|
|
// StatusMediaContainerTransformer,
|
|
|
|
|
};
|
|
|
|
|
use App\Util\Media\Filter;
|
|
|
|
|
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
|
|
|
|
use App\AccountInterstitial;
|
|
|
|
|
use App\Bookmark;
|
|
|
|
|
use App\DirectMessage;
|
|
|
|
|
use App\DiscoverCategory;
|
|
|
|
|
use App\Follower;
|
|
|
|
|
use App\Jobs\ModPipeline\HandleSpammerPipeline;
|
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use App\Services\MediaTagService;
|
|
|
|
|
use App\Profile;
|
|
|
|
|
use App\Services\BookmarkService;
|
|
|
|
|
use App\Services\DiscoverService;
|
|
|
|
|
use App\Services\ModLogService;
|
|
|
|
|
use App\Services\PublicTimelineService;
|
|
|
|
|
use App\Services\SnowflakeService;
|
|
|
|
|
use App\Services\StatusService;
|
|
|
|
|
use App\Services\UserFilterService;
|
|
|
|
|
use App\Services\DiscoverService;
|
|
|
|
|
use App\Services\BookmarkService;
|
|
|
|
|
use App\Status; // StatusMediaContainerTransformer,
|
|
|
|
|
use App\Transformer\Api\StatusTransformer;
|
|
|
|
|
use App\User;
|
|
|
|
|
use Auth;
|
|
|
|
|
use Cache;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
|
|
|
|
use League\Fractal;
|
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
|
|
|
|
|
|
class InternalApiController extends Controller
|
|
|
|
|
{
|
|
|
|
@ -52,8 +33,8 @@ class InternalApiController extends Controller
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('auth');
|
|
|
|
|
$this->fractal = new Fractal\Manager();
|
|
|
|
|
$this->fractal->setSerializer(new ArraySerializer());
|
|
|
|
|
$this->fractal = new Fractal\Manager;
|
|
|
|
|
$this->fractal->setSerializer(new ArraySerializer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deprecated v2 compose api
|
|
|
|
@ -63,27 +44,25 @@ class InternalApiController extends Controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// deprecated
|
|
|
|
|
public function discover(Request $request)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
public function discover(Request $request) {}
|
|
|
|
|
|
|
|
|
|
public function discoverPosts(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
|
$filters = UserFilterService::filters($pid);
|
|
|
|
|
$forYou = DiscoverService::getForYou();
|
|
|
|
|
$posts = $forYou->take(50)->map(function($post) {
|
|
|
|
|
$posts = $forYou->take(50)->map(function ($post) {
|
|
|
|
|
return StatusService::get($post);
|
|
|
|
|
})
|
|
|
|
|
->filter(function($post) use($filters) {
|
|
|
|
|
->filter(function ($post) use ($filters) {
|
|
|
|
|
return $post &&
|
|
|
|
|
isset($post['account']) &&
|
|
|
|
|
isset($post['account']['id']) &&
|
|
|
|
|
!in_array($post['account']['id'], $filters);
|
|
|
|
|
! in_array($post['account']['id'], $filters);
|
|
|
|
|
})
|
|
|
|
|
->take(12)
|
|
|
|
|
->values();
|
|
|
|
|
|
|
|
|
|
return response()->json(compact('posts'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -91,16 +70,16 @@ class InternalApiController extends Controller
|
|
|
|
|
{
|
|
|
|
|
$profile = Auth::user()->profile;
|
|
|
|
|
|
|
|
|
|
if($profileId != $profile->id) {
|
|
|
|
|
if ($profileId != $profile->id) {
|
|
|
|
|
abort(403);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$msg = DirectMessage::whereToId($profile->id)
|
|
|
|
|
->orWhere('from_id',$profile->id)
|
|
|
|
|
->orWhere('from_id', $profile->id)
|
|
|
|
|
->findOrFail($threadId);
|
|
|
|
|
|
|
|
|
|
$thread = DirectMessage::with('status')->whereIn('to_id', [$profile->id, $msg->from_id])
|
|
|
|
|
->whereIn('from_id', [$profile->id,$msg->from_id])
|
|
|
|
|
->whereIn('from_id', [$profile->id, $msg->from_id])
|
|
|
|
|
->orderBy('created_at', 'asc')
|
|
|
|
|
->paginate(30);
|
|
|
|
|
|
|
|
|
@ -110,7 +89,7 @@ class InternalApiController extends Controller
|
|
|
|
|
public function statusReplies(Request $request, int $id)
|
|
|
|
|
{
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
'limit' => 'nullable|int|min:1|max:6'
|
|
|
|
|
'limit' => 'nullable|int|min:1|max:6',
|
|
|
|
|
]);
|
|
|
|
|
$parent = Status::whereScope('public')->findOrFail($id);
|
|
|
|
|
$limit = $request->input('limit') ?? 3;
|
|
|
|
@ -118,27 +97,25 @@ class InternalApiController extends Controller
|
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
|
->take($limit)
|
|
|
|
|
->get();
|
|
|
|
|
$resource = new Fractal\Resource\Collection($children, new StatusTransformer());
|
|
|
|
|
$resource = new Fractal\Resource\Collection($children, new StatusTransformer);
|
|
|
|
|
$res = $this->fractal->createData($resource)->toArray();
|
|
|
|
|
|
|
|
|
|
return response()->json($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function stories(Request $request)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public function stories(Request $request) {}
|
|
|
|
|
|
|
|
|
|
public function discoverCategories(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$categories = DiscoverCategory::whereActive(true)->orderBy('order')->take(10)->get();
|
|
|
|
|
$res = $categories->map(function($item) {
|
|
|
|
|
$res = $categories->map(function ($item) {
|
|
|
|
|
return [
|
|
|
|
|
'name' => $item->name,
|
|
|
|
|
'url' => $item->url(),
|
|
|
|
|
'thumb' => $item->thumb()
|
|
|
|
|
'thumb' => $item->thumb(),
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return response()->json($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -153,15 +130,15 @@ class InternalApiController extends Controller
|
|
|
|
|
'addcw',
|
|
|
|
|
'remcw',
|
|
|
|
|
'unlist',
|
|
|
|
|
'spammer'
|
|
|
|
|
])
|
|
|
|
|
'spammer',
|
|
|
|
|
]),
|
|
|
|
|
],
|
|
|
|
|
'item_id' => 'required|integer|min:1',
|
|
|
|
|
'item_type' => [
|
|
|
|
|
'required',
|
|
|
|
|
'string',
|
|
|
|
|
Rule::in(['profile', 'status'])
|
|
|
|
|
]
|
|
|
|
|
Rule::in(['profile', 'status']),
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$action = $request->input('action');
|
|
|
|
@ -172,7 +149,7 @@ class InternalApiController extends Controller
|
|
|
|
|
$author = User::whereProfileId($status->profile_id)->first();
|
|
|
|
|
abort_if($author && $author->is_admin, 422, 'Cannot moderate administrator accounts');
|
|
|
|
|
|
|
|
|
|
switch($action) {
|
|
|
|
|
switch ($action) {
|
|
|
|
|
case 'addcw':
|
|
|
|
|
$status->is_nsfw = true;
|
|
|
|
|
$status->save();
|
|
|
|
@ -184,12 +161,12 @@ class InternalApiController extends Controller
|
|
|
|
|
->action('admin.status.moderate')
|
|
|
|
|
->metadata([
|
|
|
|
|
'action' => 'cw',
|
|
|
|
|
'message' => 'Success!'
|
|
|
|
|
'message' => 'Success!',
|
|
|
|
|
])
|
|
|
|
|
->accessLevel('admin')
|
|
|
|
|
->save();
|
|
|
|
|
|
|
|
|
|
if($status->uri == null) {
|
|
|
|
|
if ($status->uri == null) {
|
|
|
|
|
$media = $status->media;
|
|
|
|
|
$ai = new AccountInterstitial;
|
|
|
|
|
$ai->user_id = $status->profile->user_id;
|
|
|
|
@ -229,11 +206,11 @@ class InternalApiController extends Controller
|
|
|
|
|
->action('admin.status.moderate')
|
|
|
|
|
->metadata([
|
|
|
|
|
'action' => 'remove_cw',
|
|
|
|
|
'message' => 'Success!'
|
|
|
|
|
'message' => 'Success!',
|
|
|
|
|
])
|
|
|
|
|
->accessLevel('admin')
|
|
|
|
|
->save();
|
|
|
|
|
if($status->uri == null) {
|
|
|
|
|
if ($status->uri == null) {
|
|
|
|
|
$ai = AccountInterstitial::whereUserId($status->profile->user_id)
|
|
|
|
|
->whereType('post.cw')
|
|
|
|
|
->whereItemId($status->id)
|
|
|
|
@ -255,12 +232,12 @@ class InternalApiController extends Controller
|
|
|
|
|
->action('admin.status.moderate')
|
|
|
|
|
->metadata([
|
|
|
|
|
'action' => 'unlist',
|
|
|
|
|
'message' => 'Success!'
|
|
|
|
|
'message' => 'Success!',
|
|
|
|
|
])
|
|
|
|
|
->accessLevel('admin')
|
|
|
|
|
->save();
|
|
|
|
|
|
|
|
|
|
if($status->uri == null) {
|
|
|
|
|
if ($status->uri == null) {
|
|
|
|
|
$media = $status->media;
|
|
|
|
|
$ai = new AccountInterstitial;
|
|
|
|
|
$ai->user_id = $status->profile->user_id;
|
|
|
|
@ -299,7 +276,7 @@ class InternalApiController extends Controller
|
|
|
|
|
->action('admin.status.moderate')
|
|
|
|
|
->metadata([
|
|
|
|
|
'action' => 'spammer',
|
|
|
|
|
'message' => 'Success!'
|
|
|
|
|
'message' => 'Success!',
|
|
|
|
|
])
|
|
|
|
|
->accessLevel('admin')
|
|
|
|
|
->save();
|
|
|
|
@ -307,6 +284,7 @@ class InternalApiController extends Controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusService::del($status->id, true);
|
|
|
|
|
|
|
|
|
|
return ['msg' => 200];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -321,19 +299,20 @@ class InternalApiController extends Controller
|
|
|
|
|
$res = Bookmark::whereProfileId($pid)
|
|
|
|
|
->orderByDesc('created_at')
|
|
|
|
|
->simplePaginate(10)
|
|
|
|
|
->map(function($bookmark) use($pid) {
|
|
|
|
|
->map(function ($bookmark) use ($pid) {
|
|
|
|
|
$status = StatusService::get($bookmark->status_id, false);
|
|
|
|
|
if(!$status) {
|
|
|
|
|
if (! $status) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$status['bookmarked_at'] = str_replace('+00:00', 'Z', $bookmark->created_at->format(DATE_RFC3339_EXTENDED));
|
|
|
|
|
|
|
|
|
|
if($status) {
|
|
|
|
|
if ($status) {
|
|
|
|
|
BookmarkService::add($pid, $status['id']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
|
})
|
|
|
|
|
->filter(function($bookmark) {
|
|
|
|
|
->filter(function ($bookmark) {
|
|
|
|
|
return $bookmark && isset($bookmark['id']);
|
|
|
|
|
})
|
|
|
|
|
->values();
|
|
|
|
@ -347,10 +326,10 @@ class InternalApiController extends Controller
|
|
|
|
|
'only_media' => 'nullable',
|
|
|
|
|
'pinned' => 'nullable',
|
|
|
|
|
'exclude_replies' => 'nullable',
|
|
|
|
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
|
|
|
|
'since_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
|
|
|
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
|
|
|
|
'limit' => 'nullable|integer|min:1|max:24'
|
|
|
|
|
'max_id' => 'nullable|integer|min:0|max:'.PHP_INT_MAX,
|
|
|
|
|
'since_id' => 'nullable|integer|min:0|max:'.PHP_INT_MAX,
|
|
|
|
|
'min_id' => 'nullable|integer|min:0|max:'.PHP_INT_MAX,
|
|
|
|
|
'limit' => 'nullable|integer|min:1|max:24',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$profile = Profile::whereNull('status')->findOrFail($id);
|
|
|
|
@ -362,24 +341,26 @@ class InternalApiController extends Controller
|
|
|
|
|
['photo', 'photo:album', 'video', 'video:album'] :
|
|
|
|
|
['photo', 'photo:album', 'video', 'video:album', 'share', 'reply'];
|
|
|
|
|
|
|
|
|
|
if($profile->is_private) {
|
|
|
|
|
if(!Auth::check()) {
|
|
|
|
|
if ($profile->is_private) {
|
|
|
|
|
if (! Auth::check()) {
|
|
|
|
|
return response()->json([]);
|
|
|
|
|
}
|
|
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
|
|
|
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function () use ($pid) {
|
|
|
|
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
|
|
|
|
|
|
|
|
|
return $following->push($pid)->toArray();
|
|
|
|
|
});
|
|
|
|
|
$visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : [];
|
|
|
|
|
$visibility = in_array($profile->id, $following) == true ? ['public', 'unlisted', 'private'] : [];
|
|
|
|
|
} else {
|
|
|
|
|
if(Auth::check()) {
|
|
|
|
|
if (Auth::check()) {
|
|
|
|
|
$pid = Auth::user()->profile->id;
|
|
|
|
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
|
|
|
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function () use ($pid) {
|
|
|
|
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
|
|
|
|
|
|
|
|
|
return $following->push($pid)->toArray();
|
|
|
|
|
});
|
|
|
|
|
$visibility = true == in_array($profile->id, $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
|
|
|
|
$visibility = in_array($profile->id, $following) == true ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
|
|
|
|
} else {
|
|
|
|
|
$visibility = ['public', 'unlisted'];
|
|
|
|
|
}
|
|
|
|
@ -391,7 +372,6 @@ class InternalApiController extends Controller
|
|
|
|
|
'id',
|
|
|
|
|
'uri',
|
|
|
|
|
'caption',
|
|
|
|
|
'rendered',
|
|
|
|
|
'profile_id',
|
|
|
|
|
'type',
|
|
|
|
|
'in_reply_to_id',
|
|
|
|
@ -411,7 +391,7 @@ class InternalApiController extends Controller
|
|
|
|
|
->limit($limit)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
$resource = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
|
|
|
|
$resource = new Fractal\Resource\Collection($timeline, new StatusTransformer);
|
|
|
|
|
$res = $this->fractal->createData($resource)->toArray();
|
|
|
|
|
|
|
|
|
|
return response()->json($res);
|
|
|
|
@ -419,18 +399,19 @@ class InternalApiController extends Controller
|
|
|
|
|
|
|
|
|
|
public function remoteProfile(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
return redirect('/i/web/profile/' . $id);
|
|
|
|
|
return redirect('/i/web/profile/'.$id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function remoteStatus(Request $request, $profileId, $statusId)
|
|
|
|
|
{
|
|
|
|
|
return redirect('/i/web/post/' . $statusId);
|
|
|
|
|
return redirect('/i/web/post/'.$statusId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function requestEmailVerification(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
|
$exists = Redis::sismember('email:manual', $pid);
|
|
|
|
|
|
|
|
|
|
return view('account.email.request_verification', compact('exists'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -438,6 +419,7 @@ class InternalApiController extends Controller
|
|
|
|
|
{
|
|
|
|
|
$pid = $request->user()->profile_id;
|
|
|
|
|
Redis::sadd('email:manual', $pid);
|
|
|
|
|
|
|
|
|
|
return redirect('/i/verify-email')->with(['status' => 'Successfully sent manual verification request!']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|