mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
commit
abe8298999
20 changed files with 795 additions and 848 deletions
|
@ -1,10 +1,14 @@
|
|||
# Release Notes
|
||||
|
||||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev)
|
||||
|
||||
### Updates
|
||||
- Update AP helpers, reject statuses with invalid dates ([960f3849](https://github.com/pixelfed/pixelfed/commit/960f3849))
|
||||
- Update DirectMessage API, fix broken threading ([044d410c](https://github.com/pixelfed/pixelfed/commit/044d410c))
|
||||
- Update Status caption render logic ([fb8dbb95](https://github.com/pixelfed/pixelfed/commit/fb8dbb95))
|
||||
- Update ApiV1Controller, fix bookmark bug. Closes #5216 ([9f7cc52c](https://github.com/pixelfed/pixelfed/commit/9f7cc52c))
|
||||
- Update Status caption logic, stop storing duplicate html caption in db and defer to cached StatusService rendering ([9eeb7b67](https://github.com/pixelfed/pixelfed/commit/9eeb7b67))
|
||||
- Update AutolinkService, optimize lookups ([eac2c196](https://github.com/pixelfed/pixelfed/commit/eac2c196))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||
|
||||
## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)
|
||||
|
|
|
@ -2,17 +2,16 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\ImportPost;
|
||||
use App\Services\ImportService;
|
||||
use App\Media;
|
||||
use App\Models\ImportPost;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use Storage;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\ImportService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Status;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Storage;
|
||||
|
||||
class TransformImports extends Command
|
||||
{
|
||||
|
@ -35,23 +34,24 @@ class TransformImports extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
if(!config('import.instagram.enabled')) {
|
||||
if (! config('import.instagram.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ips = ImportPost::whereNull('status_id')->where('skip_missing_media', '!=', true)->take(500)->get();
|
||||
|
||||
if(!$ips->count()) {
|
||||
if (! $ips->count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($ips as $ip) {
|
||||
foreach ($ips as $ip) {
|
||||
$id = $ip->user_id;
|
||||
$pid = $ip->profile_id;
|
||||
$profile = Profile::find($pid);
|
||||
if(!$profile) {
|
||||
if (! $profile) {
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -63,39 +63,43 @@ class TransformImports extends Command
|
|||
->where('creation_day', $ip->creation_day)
|
||||
->exists();
|
||||
|
||||
if($exists == true) {
|
||||
if ($exists == true) {
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$idk = ImportService::getId($ip->user_id, $ip->creation_year, $ip->creation_month, $ip->creation_day);
|
||||
if(!$idk) {
|
||||
if (! $idk) {
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(Storage::exists('imports/' . $id . '/' . $ip->filename) === false) {
|
||||
if (Storage::exists('imports/'.$id.'/'.$ip->filename) === false) {
|
||||
ImportService::clearAttempts($profile->id);
|
||||
ImportService::getPostCount($profile->id, true);
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$missingMedia = false;
|
||||
foreach($ip->media as $ipm) {
|
||||
foreach ($ip->media as $ipm) {
|
||||
$fileName = last(explode('/', $ipm['uri']));
|
||||
$og = 'imports/' . $id . '/' . $fileName;
|
||||
if(!Storage::exists($og)) {
|
||||
$og = 'imports/'.$id.'/'.$fileName;
|
||||
if (! Storage::exists($og)) {
|
||||
$missingMedia = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($missingMedia === true) {
|
||||
if ($missingMedia === true) {
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -103,7 +107,6 @@ class TransformImports extends Command
|
|||
$status = new Status;
|
||||
$status->profile_id = $pid;
|
||||
$status->caption = $caption;
|
||||
$status->rendered = strlen(trim($caption)) ? Autolink::create()->autolink($ip->caption) : null;
|
||||
$status->type = $ip->post_type;
|
||||
|
||||
$status->scope = 'unlisted';
|
||||
|
@ -112,20 +115,21 @@ class TransformImports extends Command
|
|||
$status->created_at = now()->parse($ip->creation_date);
|
||||
$status->save();
|
||||
|
||||
foreach($ip->media as $ipm) {
|
||||
foreach ($ip->media as $ipm) {
|
||||
$fileName = last(explode('/', $ipm['uri']));
|
||||
$ext = last(explode('.', $fileName));
|
||||
$basePath = MediaPathService::get($profile);
|
||||
$og = 'imports/' . $id . '/' . $fileName;
|
||||
if(!Storage::exists($og)) {
|
||||
$og = 'imports/'.$id.'/'.$fileName;
|
||||
if (! Storage::exists($og)) {
|
||||
$ip->skip_missing_media = true;
|
||||
$ip->save();
|
||||
|
||||
continue;
|
||||
}
|
||||
$size = Storage::size($og);
|
||||
$mime = Storage::mimeType($og);
|
||||
$newFile = Str::random(40) . '.' . $ext;
|
||||
$np = $basePath . '/' . $newFile;
|
||||
$newFile = Str::random(40).'.'.$ext;
|
||||
$np = $basePath.'/'.$newFile;
|
||||
Storage::move($og, $np);
|
||||
$media = new Media;
|
||||
$media->profile_id = $pid;
|
||||
|
|
|
@ -3490,8 +3490,7 @@ class ApiV1Controller extends Controller
|
|||
return [];
|
||||
}
|
||||
|
||||
$content = strip_tags($request->input('status'));
|
||||
$rendered = Autolink::create()->autolink($content);
|
||||
$content = $request->filled('status') ? strip_tags(Purify::clean($request->input('status'))) : null;
|
||||
$cw = $user->profile->cw == true ? true : $request->boolean('sensitive', false);
|
||||
$spoilerText = $cw && $request->filled('spoiler_text') ? $request->input('spoiler_text') : null;
|
||||
|
||||
|
@ -3505,7 +3504,6 @@ class ApiV1Controller extends Controller
|
|||
|
||||
$status = new Status;
|
||||
$status->caption = $content;
|
||||
$status->rendered = $rendered;
|
||||
$status->scope = $visibility;
|
||||
$status->visibility = $visibility;
|
||||
$status->profile_id = $user->profile_id;
|
||||
|
@ -3530,7 +3528,6 @@ class ApiV1Controller extends Controller
|
|||
if (! $in_reply_to_id) {
|
||||
$status = new Status;
|
||||
$status->caption = $content;
|
||||
$status->rendered = $rendered;
|
||||
$status->profile_id = $user->profile_id;
|
||||
$status->is_nsfw = $cw;
|
||||
$status->cw_summary = $spoilerText;
|
||||
|
|
|
@ -37,7 +37,6 @@ use App\Status;
|
|||
use App\StatusArchived;
|
||||
use App\User;
|
||||
use App\UserSetting;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\RestrictedNames;
|
||||
use Cache;
|
||||
use DB;
|
||||
|
@ -49,6 +48,7 @@ use Jenssegers\Agent\Agent;
|
|||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use Mail;
|
||||
use Purify;
|
||||
|
||||
class ApiV1Dot1Controller extends Controller
|
||||
{
|
||||
|
@ -1293,14 +1293,12 @@ class ApiV1Dot1Controller extends Controller
|
|||
return [];
|
||||
}
|
||||
|
||||
$content = strip_tags($request->input('status'));
|
||||
$rendered = Autolink::create()->autolink($content);
|
||||
$content = $request->filled('status') ? strip_tags(Purify::clean($request->input('status'))) : null;
|
||||
$cw = $user->profile->cw == true ? true : $request->boolean('sensitive', false);
|
||||
$spoilerText = $cw && $request->filled('spoiler_text') ? $request->input('spoiler_text') : null;
|
||||
|
||||
$status = new Status;
|
||||
$status->caption = $content;
|
||||
$status->rendered = $rendered;
|
||||
$status->profile_id = $user->profile_id;
|
||||
$status->is_nsfw = $cw;
|
||||
$status->cw_summary = $spoilerText;
|
||||
|
|
|
@ -8,12 +8,12 @@ use App\Services\StatusService;
|
|||
use App\Status;
|
||||
use App\Transformer\Api\StatusTransformer;
|
||||
use App\UserFilter;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use Purify;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
|
@ -56,12 +56,10 @@ class CommentController extends Controller
|
|||
|
||||
$reply = DB::transaction(function () use ($comment, $status, $profile, $nsfw) {
|
||||
$scope = $profile->is_private == true ? 'private' : 'public';
|
||||
$autolink = Autolink::create()->autolink($comment);
|
||||
$reply = new Status();
|
||||
$reply = new Status;
|
||||
$reply->profile_id = $profile->id;
|
||||
$reply->is_nsfw = $nsfw;
|
||||
$reply->caption = e($comment);
|
||||
$reply->rendered = $autolink;
|
||||
$reply->caption = Purify::clean($comment);
|
||||
$reply->in_reply_to_id = $status->id;
|
||||
$reply->in_reply_to_profile_id = $status->profile_id;
|
||||
$reply->scope = $scope;
|
||||
|
@ -76,9 +74,9 @@ class CommentController extends Controller
|
|||
CommentPipeline::dispatch($status, $reply);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$entity = new Fractal\Resource\Item($reply, new StatusTransformer());
|
||||
$fractal = new Fractal\Manager;
|
||||
$fractal->setSerializer(new ArraySerializer);
|
||||
$entity = new Fractal\Resource\Item($reply, new StatusTransformer);
|
||||
$entity = $fractal->createData($entity)->toArray();
|
||||
$response = [
|
||||
'code' => 200,
|
||||
|
|
|
@ -25,7 +25,6 @@ use App\Services\UserStorageService;
|
|||
use App\Status;
|
||||
use App\Transformer\Api\MediaTransformer;
|
||||
use App\UserFilter;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Media\Filter;
|
||||
use App\Util\Media\License;
|
||||
use Auth;
|
||||
|
@ -43,8 +42,8 @@ class ComposeController 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);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
|
@ -112,14 +111,14 @@ class ComposeController extends Controller
|
|||
|
||||
abort_if(MediaBlocklistService::exists($hash) == true, 451);
|
||||
|
||||
$media = new Media();
|
||||
$media = new Media;
|
||||
$media->status_id = null;
|
||||
$media->profile_id = $profile->id;
|
||||
$media->user_id = $user->id;
|
||||
$media->media_path = $path;
|
||||
$media->original_sha256 = $hash;
|
||||
$media->size = $photo->getSize();
|
||||
$media->caption = "";
|
||||
$media->caption = '';
|
||||
$media->mime = $mime;
|
||||
$media->filter_class = $filterClass;
|
||||
$media->filter_name = $filterName;
|
||||
|
@ -151,7 +150,7 @@ class ComposeController extends Controller
|
|||
$user->save();
|
||||
|
||||
Cache::forget($limitKey);
|
||||
$resource = new Fractal\Resource\Item($media, new MediaTransformer());
|
||||
$resource = new Fractal\Resource\Item($media, new MediaTransformer);
|
||||
$res = $this->fractal->createData($resource)->toArray();
|
||||
$res['preview_url'] = $preview_url;
|
||||
$res['url'] = $url;
|
||||
|
@ -571,7 +570,6 @@ class ComposeController extends Controller
|
|||
}
|
||||
|
||||
$status->caption = strip_tags($request->caption);
|
||||
$status->rendered = Autolink::create()->autolink($status->caption);
|
||||
$status->scope = 'draft';
|
||||
$status->visibility = 'draft';
|
||||
$status->profile_id = $profile->id;
|
||||
|
@ -693,7 +691,6 @@ class ComposeController extends Controller
|
|||
$status->visibility = $visibility;
|
||||
$status->scope = $visibility;
|
||||
$status->type = 'text';
|
||||
$status->rendered = Autolink::create()->autolink($status->caption);
|
||||
$status->entities = json_encode(array_merge([
|
||||
'timg' => [
|
||||
'version' => 0,
|
||||
|
@ -806,7 +803,6 @@ class ComposeController extends Controller
|
|||
$status = new Status;
|
||||
$status->profile_id = $request->user()->profile_id;
|
||||
$status->caption = $request->input('caption');
|
||||
$status->rendered = Autolink::create()->autolink($status->caption);
|
||||
$status->visibility = 'draft';
|
||||
$status->scope = 'draft';
|
||||
$status->type = 'poll';
|
||||
|
|
|
@ -22,6 +22,7 @@ use App\Services\WebfingerService;
|
|||
use App\Status;
|
||||
use App\UserFilter;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
@ -326,7 +327,6 @@ class DirectMessageController extends Controller
|
|||
$status = new Status;
|
||||
$status->profile_id = $profile->id;
|
||||
$status->caption = $msg;
|
||||
$status->rendered = $msg;
|
||||
$status->visibility = 'direct';
|
||||
$status->scope = 'direct';
|
||||
$status->in_reply_to_profile_id = $recipient->id;
|
||||
|
@ -636,7 +636,6 @@ class DirectMessageController extends Controller
|
|||
$status = new Status;
|
||||
$status->profile_id = $profile->id;
|
||||
$status->caption = null;
|
||||
$status->rendered = null;
|
||||
$status->visibility = 'direct';
|
||||
$status->scope = 'direct';
|
||||
$status->in_reply_to_profile_id = $recipient->id;
|
||||
|
@ -830,6 +829,11 @@ class DirectMessageController extends Controller
|
|||
{
|
||||
$profile = $dm->author;
|
||||
$url = $dm->recipient->sharedInbox ?? $dm->recipient->inbox_url;
|
||||
$status = $dm->status;
|
||||
|
||||
if (! $status) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = [
|
||||
[
|
||||
|
@ -839,6 +843,8 @@ class DirectMessageController extends Controller
|
|||
],
|
||||
];
|
||||
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
|
||||
$body = [
|
||||
'@context' => [
|
||||
'https://w3id.org/security/v1',
|
||||
|
@ -854,7 +860,7 @@ class DirectMessageController extends Controller
|
|||
'id' => $dm->status->url(),
|
||||
'type' => 'Note',
|
||||
'summary' => null,
|
||||
'content' => $dm->status->rendered ?? $dm->status->caption,
|
||||
'content' => $content,
|
||||
'inReplyTo' => null,
|
||||
'published' => $dm->status->created_at->toAtomString(),
|
||||
'url' => $dm->status->url(),
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupPost;
|
||||
use App\Status;
|
||||
use App\Models\InstanceActor;
|
||||
use App\Services\MediaService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class GroupFederationController extends Controller
|
||||
{
|
||||
|
@ -16,12 +17,13 @@ class GroupFederationController extends Controller
|
|||
{
|
||||
$group = Group::whereLocal(true)->whereActivitypub(true)->findOrFail($id);
|
||||
$res = $this->showGroupObject($group);
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function showGroupObject($group)
|
||||
{
|
||||
return Cache::remember('ap:groups:object:' . $group->id, 3600, function() use($group) {
|
||||
return Cache::remember('ap:groups:object:'.$group->id, 3600, function () use ($group) {
|
||||
return [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $group->url(),
|
||||
|
@ -32,34 +34,35 @@ class GroupFederationController extends Controller
|
|||
'type' => 'Group',
|
||||
'attributedTo' => [
|
||||
'type' => 'Person',
|
||||
'id' => $group->admin->permalink()
|
||||
'id' => $group->admin->permalink(),
|
||||
],
|
||||
// 'endpoints' => [
|
||||
// 'sharedInbox' => config('app.url') . '/f/inbox'
|
||||
// ],
|
||||
'preferredUsername' => 'gid_' . $group->id,
|
||||
'preferredUsername' => 'gid_'.$group->id,
|
||||
'publicKey' => [
|
||||
'id' => $group->permalink('#main-key'),
|
||||
'owner' => $group->permalink(),
|
||||
'publicKeyPem' => InstanceActor::first()->public_key,
|
||||
],
|
||||
'url' => $group->permalink()
|
||||
'url' => $group->permalink(),
|
||||
];
|
||||
|
||||
if($group->metadata && isset($group->metadata['avatar'])) {
|
||||
if ($group->metadata && isset($group->metadata['avatar'])) {
|
||||
$res['icon'] = [
|
||||
'type' => 'Image',
|
||||
'url' => $group->metadata['avatar']['url']
|
||||
'url' => $group->metadata['avatar']['url'],
|
||||
];
|
||||
}
|
||||
|
||||
if($group->metadata && isset($group->metadata['header'])) {
|
||||
if ($group->metadata && isset($group->metadata['header'])) {
|
||||
$res['image'] = [
|
||||
'type' => 'Image',
|
||||
'url' => $group->metadata['header']['url']
|
||||
'url' => $group->metadata['header']['url'],
|
||||
];
|
||||
}
|
||||
ksort($res);
|
||||
|
||||
return $res;
|
||||
});
|
||||
}
|
||||
|
@ -70,7 +73,7 @@ class GroupFederationController extends Controller
|
|||
$gp = GroupPost::whereGroupId($gid)->findOrFail($sid);
|
||||
$status = Status::findOrFail($gp->status_id);
|
||||
// permission check
|
||||
|
||||
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
|
||||
$res = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $gp->url(),
|
||||
|
@ -78,7 +81,7 @@ class GroupFederationController extends Controller
|
|||
'type' => 'Note',
|
||||
|
||||
'summary' => null,
|
||||
'content' => $status->rendered ?? $status->caption,
|
||||
'content' => $content,
|
||||
'inReplyTo' => null,
|
||||
|
||||
'published' => $status->created_at->toAtomString(),
|
||||
|
@ -94,10 +97,11 @@ class GroupFederationController extends Controller
|
|||
'target' => [
|
||||
'type' => 'Collection',
|
||||
'id' => $group->permalink('/wall'),
|
||||
'attributedTo' => $group->permalink()
|
||||
]
|
||||
'attributedTo' => $group->permalink(),
|
||||
],
|
||||
];
|
||||
|
||||
// ksort($res);
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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!']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Status;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use App\{
|
||||
Profile,
|
||||
Status,
|
||||
};
|
||||
use Auth, DB, Purify;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MicroController extends Controller
|
||||
|
@ -23,7 +21,7 @@ class MicroController extends Controller
|
|||
'type' => [
|
||||
'required',
|
||||
'string',
|
||||
Rule::in(['text'])
|
||||
Rule::in(['text']),
|
||||
],
|
||||
'title' => 'nullable|string|max:140',
|
||||
'content' => 'required|string|max:500',
|
||||
|
@ -34,34 +32,35 @@ class MicroController extends Controller
|
|||
'public',
|
||||
'unlisted',
|
||||
'private',
|
||||
'draft'
|
||||
])
|
||||
]
|
||||
'draft',
|
||||
]),
|
||||
],
|
||||
]);
|
||||
$profile = Auth::user()->profile;
|
||||
$title = $request->input('title');
|
||||
$content = $request->input('content');
|
||||
$visibility = $request->input('visibility');
|
||||
|
||||
$status = DB::transaction(function() use($profile, $content, $visibility, $title) {
|
||||
$status = DB::transaction(function () use ($profile, $content, $visibility, $title) {
|
||||
$status = new Status;
|
||||
$status->type = 'text';
|
||||
$status->profile_id = $profile->id;
|
||||
$status->caption = strip_tags($content);
|
||||
$status->rendered = Purify::clean($content);
|
||||
$status->is_nsfw = false;
|
||||
|
||||
// TODO: remove deprecated visibility in favor of scope
|
||||
$status->visibility = $visibility;
|
||||
$status->scope = $visibility;
|
||||
$status->entities = json_encode(['title'=>$title]);
|
||||
$status->entities = json_encode(['title' => $title]);
|
||||
$status->save();
|
||||
|
||||
return $status;
|
||||
});
|
||||
|
||||
$fractal = new \League\Fractal\Manager();
|
||||
$fractal->setSerializer(new \League\Fractal\Serializer\ArraySerializer());
|
||||
$s = new \League\Fractal\Resource\Item($status, new \App\Transformer\Api\StatusTransformer());
|
||||
$fractal = new \League\Fractal\Manager;
|
||||
$fractal->setSerializer(new \League\Fractal\Serializer\ArraySerializer);
|
||||
$s = new \League\Fractal\Resource\Item($status, new \App\Transformer\Api\StatusTransformer);
|
||||
|
||||
return $fractal->createData($s)->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Profile;
|
|||
use App\Services\WebfingerService;
|
||||
use App\Status;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
@ -320,17 +321,21 @@ class SearchController extends Controller
|
|||
|
||||
if (Status::whereUri($tag)->whereLocal(false)->exists()) {
|
||||
$item = Status::whereUri($tag)->first();
|
||||
if (! $item) {
|
||||
return;
|
||||
}
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if ($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$content = $item->caption ? Autolink::create()->autolink($item->caption) : null;
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'caption' => $content,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans(),
|
||||
]];
|
||||
|
@ -340,17 +345,21 @@ class SearchController extends Controller
|
|||
|
||||
if (isset($remote['type']) && $remote['type'] == 'Note') {
|
||||
$item = Helpers::statusFetch($tag);
|
||||
if (! $item) {
|
||||
return;
|
||||
}
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if ($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$content = $item->caption ? Autolink::create()->autolink($item->caption) : null;
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'caption' => $content,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans(),
|
||||
]];
|
||||
|
|
|
@ -281,7 +281,7 @@ class StoryApiV1Controller extends Controller
|
|||
$photo = $request->file('file');
|
||||
$path = $this->storeMedia($photo, $user);
|
||||
|
||||
$story = new Story();
|
||||
$story = new Story;
|
||||
$story->duration = $request->input('duration', 3);
|
||||
$story->profile_id = $user->profile_id;
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' : 'photo';
|
||||
|
@ -418,7 +418,6 @@ class StoryApiV1Controller extends Controller
|
|||
$status->type = 'story:reply';
|
||||
$status->profile_id = $pid;
|
||||
$status->caption = $text;
|
||||
$status->rendered = $text;
|
||||
$status->scope = 'direct';
|
||||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
|
|
|
@ -54,7 +54,7 @@ class StoryComposeController extends Controller
|
|||
$photo = $request->file('file');
|
||||
$path = $this->storePhoto($photo, $user);
|
||||
|
||||
$story = new Story();
|
||||
$story = new Story;
|
||||
$story->duration = 3;
|
||||
$story->profile_id = $user->profile_id;
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' : 'photo';
|
||||
|
@ -403,7 +403,6 @@ class StoryComposeController extends Controller
|
|||
$status->profile_id = $pid;
|
||||
$status->type = 'story:reaction';
|
||||
$status->caption = $text;
|
||||
$status->rendered = $text;
|
||||
$status->scope = 'direct';
|
||||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
|
@ -477,7 +476,6 @@ class StoryComposeController extends Controller
|
|||
$status->type = 'story:reply';
|
||||
$status->profile_id = $pid;
|
||||
$status->caption = $text;
|
||||
$status->rendered = $text;
|
||||
$status->scope = 'direct';
|
||||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
|
|
|
@ -2,35 +2,32 @@
|
|||
|
||||
namespace App\Jobs\GroupPipeline;
|
||||
|
||||
use App\Notification;
|
||||
use App\Hashtag;
|
||||
use App\Mention;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use App\StatusHashtag;
|
||||
use App\Models\GroupPostHashtag;
|
||||
use App\Models\GroupPost;
|
||||
use Cache;
|
||||
use App\Models\GroupPostHashtag;
|
||||
use App\Profile;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\Extractor;
|
||||
use DB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\NotificationService;
|
||||
use App\Services\StatusService;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\Extractor;
|
||||
|
||||
class NewStatusPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
|
||||
protected $gp;
|
||||
|
||||
protected $tags;
|
||||
|
||||
protected $mentions;
|
||||
|
||||
public function __construct(Status $status, GroupPost $gp)
|
||||
|
@ -50,21 +47,17 @@ class NewStatusPipeline implements ShouldQueue
|
|||
->autolink($status->caption);
|
||||
|
||||
$entities = Extractor::create()->extract($status->caption);
|
||||
|
||||
$autolink = str_replace('/discover/tags/', '/groups/' . $status->group_id . '/topics/', $autolink);
|
||||
|
||||
$status->rendered = nl2br($autolink);
|
||||
$status->entities = null;
|
||||
$status->save();
|
||||
|
||||
$this->tags = array_unique($entities['hashtags']);
|
||||
$this->mentions = array_unique($entities['mentions']);
|
||||
|
||||
if(count($this->tags)) {
|
||||
if (count($this->tags)) {
|
||||
$this->storeHashtags();
|
||||
}
|
||||
|
||||
if(count($this->mentions)) {
|
||||
if (count($this->mentions)) {
|
||||
$this->storeMentions($this->mentions);
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +69,7 @@ class NewStatusPipeline implements ShouldQueue
|
|||
$gp = $this->gp;
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if(mb_strlen($tag) > 124) {
|
||||
if (mb_strlen($tag) > 124) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -98,7 +91,7 @@ class NewStatusPipeline implements ShouldQueue
|
|||
});
|
||||
}
|
||||
|
||||
if(count($this->mentions)) {
|
||||
if (count($this->mentions)) {
|
||||
$this->storeMentions();
|
||||
}
|
||||
StatusService::del($status->id);
|
||||
|
@ -112,12 +105,12 @@ class NewStatusPipeline implements ShouldQueue
|
|||
foreach ($mentions as $mention) {
|
||||
$mentioned = Profile::whereUsername($mention)->first();
|
||||
|
||||
if (empty($mentioned) || !isset($mentioned->id)) {
|
||||
if (empty($mentioned) || ! isset($mentioned->id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($status, $mentioned) {
|
||||
$m = new Mention();
|
||||
$m = new Mention;
|
||||
$m->status_id = $status->id;
|
||||
$m->profile_id = $mentioned->id;
|
||||
$m->save();
|
||||
|
|
|
@ -91,11 +91,6 @@ class StatusEntityLexer implements ShouldQueue
|
|||
public function storeEntities()
|
||||
{
|
||||
$this->storeHashtags();
|
||||
DB::transaction(function () {
|
||||
$status = $this->status;
|
||||
$status->rendered = nl2br($this->autolink);
|
||||
$status->save();
|
||||
});
|
||||
}
|
||||
|
||||
public function storeHashtags()
|
||||
|
@ -146,7 +141,7 @@ class StatusEntityLexer implements ShouldQueue
|
|||
}
|
||||
|
||||
DB::transaction(function () use ($status, $mentioned) {
|
||||
$m = new Mention();
|
||||
$m = new Mention;
|
||||
$m->status_id = $status->id;
|
||||
$m->profile_id = $mentioned->id;
|
||||
$m->save();
|
||||
|
|
|
@ -120,8 +120,7 @@ class StatusRemoteUpdatePipeline implements ShouldQueue
|
|||
protected function updateImmediateAttributes($status, $activity)
|
||||
{
|
||||
if (isset($activity['content'])) {
|
||||
$status->caption = strip_tags($activity['content']);
|
||||
$status->rendered = Purify::clean($activity['content']);
|
||||
$status->caption = strip_tags(Purify::clean($activity['content']));
|
||||
}
|
||||
|
||||
if (isset($activity['sensitive'])) {
|
||||
|
|
|
@ -2,53 +2,25 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use Cache;
|
||||
use App\Profile;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Util\Webfinger\WebfingerUrl;
|
||||
use Cache;
|
||||
use Purify;
|
||||
|
||||
class AutolinkService
|
||||
{
|
||||
const CACHE_KEY = 'pf:services:autolink:';
|
||||
const CACHE_KEY = 'pf:services:autolink:mue:';
|
||||
|
||||
public static function mentionedUsernameExists($username)
|
||||
{
|
||||
$key = 'pf:services:autolink:userexists:' . hash('sha256', $username);
|
||||
if (str_starts_with($username, '@')) {
|
||||
if (substr_count($username, '@') === 1) {
|
||||
$username = substr($username, 1);
|
||||
}
|
||||
}
|
||||
$name = Purify::clean(strtolower($username));
|
||||
|
||||
return Cache::remember($key, 3600, function() use($username) {
|
||||
$remote = Str::of($username)->contains('@');
|
||||
$profile = Profile::whereUsername($username)->first();
|
||||
if($profile) {
|
||||
if($profile->domain != null) {
|
||||
$instance = InstanceService::getByDomain($profile->domain);
|
||||
if($instance && $instance->banned == true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if($remote) {
|
||||
$parts = explode('@', $username);
|
||||
$domain = last($parts);
|
||||
$instance = InstanceService::getByDomain($domain);
|
||||
|
||||
if($instance) {
|
||||
if($instance->banned == true) {
|
||||
return false;
|
||||
} else {
|
||||
$wf = WebfingerUrl::generateWebfingerUrl($username);
|
||||
$res = Http::head($wf);
|
||||
return $res->ok();
|
||||
}
|
||||
} else {
|
||||
$wf = WebfingerUrl::generateWebfingerUrl($username);
|
||||
$res = Http::head($wf);
|
||||
return $res->ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Cache::remember(self::CACHE_KEY.base64_encode($name), 7200, function () use ($name) {
|
||||
return Profile::where('username', $name)->exists();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
namespace App\Services\Status;
|
||||
|
||||
use App\Media;
|
||||
use App\ModLog;
|
||||
use App\Status;
|
||||
use App\Models\StatusEdit;
|
||||
use Purify;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\ModLog;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use Purify;
|
||||
|
||||
class UpdateStatusService
|
||||
{
|
||||
|
@ -27,20 +26,22 @@ class UpdateStatusService
|
|||
public static function updateMediaAttachements(Status $status, $attributes)
|
||||
{
|
||||
$count = $status->media()->count();
|
||||
if($count === 0 || $count === 1) {
|
||||
if ($count === 0 || $count === 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$oids = $status->media()->orderBy('order')->pluck('id')->map(function($m) { return (string) $m; });
|
||||
$oids = $status->media()->orderBy('order')->pluck('id')->map(function ($m) {
|
||||
return (string) $m;
|
||||
});
|
||||
$nids = collect($attributes['media_ids']);
|
||||
|
||||
if($oids->toArray() === $nids->toArray()) {
|
||||
if ($oids->toArray() === $nids->toArray()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($oids->diff($nids)->values()->toArray() as $mid) {
|
||||
foreach ($oids->diff($nids)->values()->toArray() as $mid) {
|
||||
$media = Media::find($mid);
|
||||
if(!$media) {
|
||||
if (! $media) {
|
||||
continue;
|
||||
}
|
||||
$media->status_id = null;
|
||||
|
@ -48,9 +49,9 @@ class UpdateStatusService
|
|||
MediaStorageService::delete($media, true);
|
||||
}
|
||||
|
||||
$nids->each(function($nid, $idx) {
|
||||
$nids->each(function ($nid, $idx) {
|
||||
$media = Media::find($nid);
|
||||
if(!$media) {
|
||||
if (! $media) {
|
||||
return;
|
||||
}
|
||||
$media->order = $idx;
|
||||
|
@ -61,42 +62,39 @@ class UpdateStatusService
|
|||
|
||||
public static function handleImmediateAttributes(Status $status, $attributes)
|
||||
{
|
||||
if(isset($attributes['status'])) {
|
||||
if (isset($attributes['status'])) {
|
||||
$cleaned = Purify::clean($attributes['status']);
|
||||
$status->caption = $cleaned;
|
||||
$status->rendered = nl2br(Autolink::create()->autolink($cleaned));
|
||||
} else {
|
||||
$status->caption = null;
|
||||
$status->rendered = null;
|
||||
}
|
||||
if(isset($attributes['sensitive'])) {
|
||||
if($status->is_nsfw != (bool) $attributes['sensitive'] &&
|
||||
(bool) $attributes['sensitive'] == false)
|
||||
{
|
||||
if (isset($attributes['sensitive'])) {
|
||||
if ($status->is_nsfw != (bool) $attributes['sensitive'] &&
|
||||
(bool) $attributes['sensitive'] == false) {
|
||||
$exists = ModLog::whereObjectType('App\Status::class')
|
||||
->whereObjectId($status->id)
|
||||
->whereAction('admin.status.moderate')
|
||||
->exists();
|
||||
if(!$exists) {
|
||||
if (! $exists) {
|
||||
$status->is_nsfw = (bool) $attributes['sensitive'];
|
||||
}
|
||||
} else {
|
||||
$status->is_nsfw = (bool) $attributes['sensitive'];
|
||||
}
|
||||
}
|
||||
if(isset($attributes['spoiler_text'])) {
|
||||
if (isset($attributes['spoiler_text'])) {
|
||||
$status->cw_summary = Purify::clean($attributes['spoiler_text']);
|
||||
} else {
|
||||
$status->cw_summary = null;
|
||||
}
|
||||
if(isset($attributes['location'])) {
|
||||
if (isset($attributes['location'])) {
|
||||
if (isset($attributes['location']['id'])) {
|
||||
$status->place_id = $attributes['location']['id'];
|
||||
} else {
|
||||
$status->place_id = null;
|
||||
}
|
||||
}
|
||||
if($status->cw_summary && !$status->is_nsfw) {
|
||||
if ($status->cw_summary && ! $status->is_nsfw) {
|
||||
$status->cw_summary = null;
|
||||
}
|
||||
$status->edited_at = now();
|
||||
|
@ -106,7 +104,7 @@ class UpdateStatusService
|
|||
|
||||
public static function createPreviousEdit(Status $status)
|
||||
{
|
||||
if(!$status->edits()->count()) {
|
||||
if (! $status->edits()->count()) {
|
||||
StatusEdit::create([
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
|
@ -114,7 +112,7 @@ class UpdateStatusService
|
|||
'spoiler_text' => $status->cw_summary,
|
||||
'is_nsfw' => $status->is_nsfw,
|
||||
'ordered_media_attachment_ids' => $status->media()->orderBy('order')->pluck('id')->toArray(),
|
||||
'created_at' => $status->created_at
|
||||
'created_at' => $status->created_at,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +129,7 @@ class UpdateStatusService
|
|||
'caption' => $cleaned,
|
||||
'spoiler_text' => $spoiler_text,
|
||||
'is_nsfw' => $sensitive,
|
||||
'ordered_media_attachment_ids' => $mids
|
||||
'ordered_media_attachment_ids' => $mids,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -694,8 +694,7 @@ class Helpers
|
|||
$status->url = isset($res['url']) ? $res['url'] : $url;
|
||||
$status->uri = isset($res['url']) ? $res['url'] : $url;
|
||||
$status->object_url = $id;
|
||||
$status->caption = strip_tags($res['content']);
|
||||
$status->rendered = Purify::clean($res['content']);
|
||||
$status->caption = strip_tags(Purify::clean($res['content']));
|
||||
$status->created_at = Carbon::parse($ts)->tz('UTC');
|
||||
$status->in_reply_to_id = null;
|
||||
$status->local = false;
|
||||
|
|
|
@ -438,7 +438,6 @@ class Inbox
|
|||
$status = new Status;
|
||||
$status->profile_id = $actor->id;
|
||||
$status->caption = $msgText;
|
||||
$status->rendered = $msg;
|
||||
$status->visibility = 'direct';
|
||||
$status->scope = 'direct';
|
||||
$status->url = $activity['id'];
|
||||
|
@ -1081,7 +1080,6 @@ class Inbox
|
|||
$status->uri = $url;
|
||||
$status->object_url = $url;
|
||||
$status->caption = $text;
|
||||
$status->rendered = $text;
|
||||
$status->scope = 'direct';
|
||||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
|
@ -1199,7 +1197,6 @@ class Inbox
|
|||
$status->profile_id = $actorProfile->id;
|
||||
$status->type = 'story:reply';
|
||||
$status->caption = $text;
|
||||
$status->rendered = $text;
|
||||
$status->url = $url;
|
||||
$status->uri = $url;
|
||||
$status->object_url = $url;
|
||||
|
|
Loading…
Reference in a new issue