mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-24 07:21:27 +00:00
Update GroupController.php
This commit is contained in:
parent
c0b2f5efa1
commit
58b8a385bd
1 changed files with 553 additions and 580 deletions
|
@ -2,82 +2,45 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Instance;
|
||||
use App\Models\Group;
|
||||
use App\Models\GroupActivityGraph;
|
||||
use App\Models\GroupBlock;
|
||||
use App\Models\GroupCategory;
|
||||
use App\Models\GroupComment;
|
||||
use App\Models\GroupEvent;
|
||||
use App\Models\GroupInteraction;
|
||||
use App\Models\GroupInvitation;
|
||||
use App\Models\GroupLimit;
|
||||
use App\Models\GroupLike;
|
||||
use App\Models\GroupLimit;
|
||||
use App\Models\GroupMember;
|
||||
use App\Models\GroupPost;
|
||||
use App\Models\GroupPostHashtag;
|
||||
use App\Models\GroupReport;
|
||||
use App\Models\GroupRole;
|
||||
use App\Models\GroupStore;
|
||||
use App\Models\Poll;
|
||||
use App\Follower;
|
||||
use App\Instance;
|
||||
use App\Hashtag;
|
||||
use App\StatusHashtag;
|
||||
use App\Like;
|
||||
use App\Media;
|
||||
use App\Notification;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\GroupService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\LikeService;
|
||||
use App\Services\Groups\GroupCommentService;
|
||||
use App\Services\Groups\GroupsLikeService;
|
||||
use App\Services\HashtagService;
|
||||
use App\Services\GroupService;
|
||||
use App\Services\GroupFeedService;
|
||||
use App\Services\GroupPostService;
|
||||
use App\Services\PollService;
|
||||
use App\Services\RelationshipService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\UserFilterService;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use Storage;
|
||||
use Purify;
|
||||
use App\Jobs\GroupPipeline\LikePipeline;
|
||||
use App\Jobs\GroupPipeline\UnlikePipeline;
|
||||
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||
use App\Jobs\VideoPipeline\VideoThumbnail;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\GroupPipeline\GroupCommentPipeline;
|
||||
use App\Jobs\GroupPipeline\GroupMemberInvite;
|
||||
use App\Jobs\GroupPipeline\NewStatusPipeline;
|
||||
use App\Jobs\GroupPipeline\JoinApproved;
|
||||
use App\Jobs\GroupPipeline\JoinRejected;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
||||
class GroupController extends GroupFederationController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth');
|
||||
$this->middleware('auth');
|
||||
abort_unless(config('groups.enabled'), 404);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
|
||||
return view('layouts.spa');
|
||||
}
|
||||
|
||||
public function home(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
|
||||
return view('layouts.spa');
|
||||
}
|
||||
|
||||
|
@ -92,6 +55,7 @@ class GroupController extends GroupFederationController
|
|||
if ($request->wantsJson()) {
|
||||
return $this->showGroupObject($group);
|
||||
}
|
||||
|
||||
return view('layouts.spa', compact('id', 'path'));
|
||||
}
|
||||
|
||||
|
@ -111,6 +75,7 @@ class GroupController extends GroupFederationController
|
|||
|
||||
$gp = GroupPost::whereGroupId($gid)
|
||||
->findOrFail($sid);
|
||||
|
||||
return view('layouts.spa', compact('group', 'gp'));
|
||||
}
|
||||
|
||||
|
@ -124,7 +89,6 @@ class GroupController extends GroupFederationController
|
|||
return response()->json($group, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
|
||||
public function showStatusLikes(Request $request, $id, $sid)
|
||||
{
|
||||
$group = Group::findOrFail($id);
|
||||
|
@ -137,12 +101,14 @@ class GroupController extends GroupFederationController
|
|||
->map(function ($l) use ($group) {
|
||||
$account = AccountService::get($l->profile_id);
|
||||
$account['url'] = "/groups/{$group->id}/user/{$account['id']}";
|
||||
|
||||
return $account;
|
||||
})
|
||||
->filter(function ($l) {
|
||||
return $l && isset($l['id']);
|
||||
})
|
||||
->values();
|
||||
|
||||
return $likes;
|
||||
}
|
||||
|
||||
|
@ -201,7 +167,7 @@ class GroupController extends GroupFederationController
|
|||
'discoverable' => 'required',
|
||||
'activitypub' => 'required',
|
||||
'is_nsfw' => 'required',
|
||||
'category' => 'required|string|in:' . implode(',',GroupService::categories())
|
||||
'category' => 'required|string|in:'.implode(',', GroupService::categories()),
|
||||
]);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
|
@ -230,7 +196,7 @@ class GroupController extends GroupFederationController
|
|||
$metadata['avatar'] = [
|
||||
'path' => $path,
|
||||
'url' => $url,
|
||||
'updated_at' => now()
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +218,7 @@ class GroupController extends GroupFederationController
|
|||
$metadata['header'] = [
|
||||
'path' => $path,
|
||||
'url' => $url,
|
||||
'updated_at' => now()
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -266,9 +232,9 @@ class GroupController extends GroupFederationController
|
|||
$group->description = e($request->input('description', null));
|
||||
$group->is_private = $request->input('membership') == 'private';
|
||||
$group->local_only = $request->input('membership') == 'local';
|
||||
$group->activitypub = $request->input('activitypub') == "true";
|
||||
$group->discoverable = $request->input('discoverable') == "true";
|
||||
$group->is_nsfw = $request->input('is_nsfw') == "true";
|
||||
$group->activitypub = $request->input('activitypub') == 'true';
|
||||
$group->discoverable = $request->input('discoverable') == 'true';
|
||||
$group->is_nsfw = $request->input('is_nsfw') == 'true';
|
||||
$group->metadata = $metadata;
|
||||
if ($group->isDirty()) {
|
||||
$changes = $group->getDirty();
|
||||
|
@ -285,6 +251,7 @@ class GroupController extends GroupFederationController
|
|||
GroupService::del($group->id);
|
||||
|
||||
$res = $this->toJson($group, $pid);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -384,7 +351,7 @@ class GroupController extends GroupFederationController
|
|||
'copyright',
|
||||
'impersonation',
|
||||
'scam',
|
||||
'terrorism'
|
||||
'terrorism',
|
||||
];
|
||||
|
||||
$gp = GroupPost::whereGroupId($group->id)->find($id);
|
||||
|
@ -421,7 +388,7 @@ class GroupController extends GroupFederationController
|
|||
'profile_id' => $gp->profile_id,
|
||||
'username' => optional(AccountService::get($gp->profile_id))['acct'],
|
||||
'gpid' => $gp->id,
|
||||
'url' => $gp->url()
|
||||
'url' => $gp->url(),
|
||||
],
|
||||
GroupReport::class,
|
||||
$report->id
|
||||
|
@ -440,7 +407,7 @@ class GroupController extends GroupFederationController
|
|||
|
||||
$this->validate($request, [
|
||||
'action' => 'required|in:cw,delete,ignore',
|
||||
'id' => 'required|string'
|
||||
'id' => 'required|string',
|
||||
]);
|
||||
|
||||
$action = $request->input('action');
|
||||
|
@ -473,11 +440,12 @@ class GroupController extends GroupFederationController
|
|||
'report_id' => $report->id,
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'status_url' => $gp->url()
|
||||
'status_url' => $gp->url(),
|
||||
],
|
||||
GroupReport::class,
|
||||
$report->id
|
||||
);
|
||||
|
||||
return response()->json([200]);
|
||||
break;
|
||||
|
||||
|
@ -496,11 +464,12 @@ class GroupController extends GroupFederationController
|
|||
'report_id' => $report->id,
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'status_url' => $gp->url()
|
||||
'status_url' => $gp->url(),
|
||||
],
|
||||
GroupReport::class,
|
||||
$report->id
|
||||
);
|
||||
|
||||
return response()->json([200]);
|
||||
break;
|
||||
}
|
||||
|
@ -517,6 +486,7 @@ class GroupController extends GroupFederationController
|
|||
$profile_id = $request->input('profile_id');
|
||||
abort_if(! $group->isMember($profile_id), 404);
|
||||
$limits = GroupService::getInteractionLimits($group->id, $profile_id);
|
||||
|
||||
return response()->json($limits);
|
||||
}
|
||||
|
||||
|
@ -532,7 +502,7 @@ class GroupController extends GroupFederationController
|
|||
'profile_id' => 'required|exists:profiles,id',
|
||||
'can_post' => 'required',
|
||||
'can_comment' => 'required',
|
||||
'can_like' => 'required'
|
||||
'can_like' => 'required',
|
||||
]);
|
||||
|
||||
$member = $request->input('profile_id');
|
||||
|
@ -546,7 +516,7 @@ class GroupController extends GroupFederationController
|
|||
|
||||
$limit = GroupLimit::firstOrCreate([
|
||||
'profile_id' => $member,
|
||||
'group_id' => $group->id
|
||||
'group_id' => $group->id,
|
||||
]);
|
||||
|
||||
if ($limit->wasRecentlyCreated) {
|
||||
|
@ -558,7 +528,7 @@ class GroupController extends GroupFederationController
|
|||
$limit->limits = [
|
||||
'can_post' => $can_post,
|
||||
'can_comment' => $can_comment,
|
||||
'can_like' => $can_like
|
||||
'can_like' => $can_like,
|
||||
];
|
||||
$limit->save();
|
||||
|
||||
|
@ -572,7 +542,7 @@ class GroupController extends GroupFederationController
|
|||
'profile_id' => $account['id'],
|
||||
'username' => $account['username'],
|
||||
'previousLimits' => $previousLimits,
|
||||
'newLimits' => $limit->limits
|
||||
'newLimits' => $limit->limits,
|
||||
],
|
||||
GroupLimit::class,
|
||||
$limit->id
|
||||
|
@ -581,7 +551,6 @@ class GroupController extends GroupFederationController
|
|||
return $request->all();
|
||||
}
|
||||
|
||||
|
||||
public function showProfile(Request $request, $id, $pid)
|
||||
{
|
||||
$group = Group::find($id);
|
||||
|
@ -619,17 +588,18 @@ class GroupController extends GroupFederationController
|
|||
|
||||
if ($profile) {
|
||||
$url = url("/groups/{$id}/user/{$profile->id}");
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
abort(404, 'Invalid username');
|
||||
}
|
||||
|
||||
|
||||
public function groupInviteLanding(Request $request, $id)
|
||||
{
|
||||
abort(404, 'Not yet implemented');
|
||||
$group = Group::findOrFail($id);
|
||||
|
||||
return view('groups.invite', compact('group'));
|
||||
}
|
||||
|
||||
|
@ -637,6 +607,7 @@ class GroupController extends GroupFederationController
|
|||
{
|
||||
$gid = HashidService::decode($hid);
|
||||
$group = Group::findOrFail($gid);
|
||||
|
||||
return redirect($group->url());
|
||||
}
|
||||
|
||||
|
@ -644,6 +615,7 @@ class GroupController extends GroupFederationController
|
|||
{
|
||||
$group = GroupService::get($id);
|
||||
abort_if(! $group || empty($group), 404);
|
||||
|
||||
return view('groups.invite-claim', compact('group'));
|
||||
}
|
||||
|
||||
|
@ -658,7 +630,7 @@ class GroupController extends GroupFederationController
|
|||
|
||||
return response()->json([
|
||||
'gid' => $id,
|
||||
'can_join' => (bool) $exists
|
||||
'can_join' => (bool) $exists,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -693,6 +665,7 @@ class GroupController extends GroupFederationController
|
|||
$pid = $request->user()->profile_id;
|
||||
$group = Group::findOrFail($id);
|
||||
abort_if($group->isMember($pid), 422, 'Already a member');
|
||||
|
||||
return ['next_url' => '/'];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue