mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-21 22:11:26 +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;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use DB;
|
use App\Instance;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use App\Models\Group;
|
use App\Models\Group;
|
||||||
use App\Models\GroupActivityGraph;
|
|
||||||
use App\Models\GroupBlock;
|
use App\Models\GroupBlock;
|
||||||
use App\Models\GroupCategory;
|
use App\Models\GroupCategory;
|
||||||
use App\Models\GroupComment;
|
|
||||||
use App\Models\GroupEvent;
|
|
||||||
use App\Models\GroupInteraction;
|
|
||||||
use App\Models\GroupInvitation;
|
use App\Models\GroupInvitation;
|
||||||
use App\Models\GroupLimit;
|
|
||||||
use App\Models\GroupLike;
|
use App\Models\GroupLike;
|
||||||
|
use App\Models\GroupLimit;
|
||||||
use App\Models\GroupMember;
|
use App\Models\GroupMember;
|
||||||
use App\Models\GroupPost;
|
use App\Models\GroupPost;
|
||||||
use App\Models\GroupPostHashtag;
|
|
||||||
use App\Models\GroupReport;
|
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\Profile;
|
||||||
|
use App\Services\AccountService;
|
||||||
|
use App\Services\GroupService;
|
||||||
|
use App\Services\HashidService;
|
||||||
|
use App\Services\StatusService;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use App\User;
|
use App\User;
|
||||||
use App\Util\Lexer\Autolink;
|
use Illuminate\Http\Request;
|
||||||
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 Storage;
|
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
|
class GroupController extends GroupFederationController
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
// $this->middleware('auth');
|
$this->middleware('auth');
|
||||||
|
abort_unless(config('groups.enabled'), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
abort_if(! $request->user(), 404);
|
abort_if(! $request->user(), 404);
|
||||||
|
|
||||||
return view('layouts.spa');
|
return view('layouts.spa');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function home(Request $request)
|
public function home(Request $request)
|
||||||
{
|
{
|
||||||
abort_if(! $request->user(), 404);
|
abort_if(! $request->user(), 404);
|
||||||
|
|
||||||
return view('layouts.spa');
|
return view('layouts.spa');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +55,7 @@ class GroupController extends GroupFederationController
|
||||||
if ($request->wantsJson()) {
|
if ($request->wantsJson()) {
|
||||||
return $this->showGroupObject($group);
|
return $this->showGroupObject($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('layouts.spa', compact('id', 'path'));
|
return view('layouts.spa', compact('id', 'path'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +75,7 @@ class GroupController extends GroupFederationController
|
||||||
|
|
||||||
$gp = GroupPost::whereGroupId($gid)
|
$gp = GroupPost::whereGroupId($gid)
|
||||||
->findOrFail($sid);
|
->findOrFail($sid);
|
||||||
|
|
||||||
return view('layouts.spa', compact('group', 'gp'));
|
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);
|
return response()->json($group, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function showStatusLikes(Request $request, $id, $sid)
|
public function showStatusLikes(Request $request, $id, $sid)
|
||||||
{
|
{
|
||||||
$group = Group::findOrFail($id);
|
$group = Group::findOrFail($id);
|
||||||
|
@ -137,12 +101,14 @@ class GroupController extends GroupFederationController
|
||||||
->map(function ($l) use ($group) {
|
->map(function ($l) use ($group) {
|
||||||
$account = AccountService::get($l->profile_id);
|
$account = AccountService::get($l->profile_id);
|
||||||
$account['url'] = "/groups/{$group->id}/user/{$account['id']}";
|
$account['url'] = "/groups/{$group->id}/user/{$account['id']}";
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
})
|
})
|
||||||
->filter(function ($l) {
|
->filter(function ($l) {
|
||||||
return $l && isset($l['id']);
|
return $l && isset($l['id']);
|
||||||
})
|
})
|
||||||
->values();
|
->values();
|
||||||
|
|
||||||
return $likes;
|
return $likes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +167,7 @@ class GroupController extends GroupFederationController
|
||||||
'discoverable' => 'required',
|
'discoverable' => 'required',
|
||||||
'activitypub' => 'required',
|
'activitypub' => 'required',
|
||||||
'is_nsfw' => 'required',
|
'is_nsfw' => 'required',
|
||||||
'category' => 'required|string|in:' . implode(',',GroupService::categories())
|
'category' => 'required|string|in:'.implode(',', GroupService::categories()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
@ -230,7 +196,7 @@ class GroupController extends GroupFederationController
|
||||||
$metadata['avatar'] = [
|
$metadata['avatar'] = [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'updated_at' => now()
|
'updated_at' => now(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,7 +218,7 @@ class GroupController extends GroupFederationController
|
||||||
$metadata['header'] = [
|
$metadata['header'] = [
|
||||||
'path' => $path,
|
'path' => $path,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'updated_at' => now()
|
'updated_at' => now(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,9 +232,9 @@ class GroupController extends GroupFederationController
|
||||||
$group->description = e($request->input('description', null));
|
$group->description = e($request->input('description', null));
|
||||||
$group->is_private = $request->input('membership') == 'private';
|
$group->is_private = $request->input('membership') == 'private';
|
||||||
$group->local_only = $request->input('membership') == 'local';
|
$group->local_only = $request->input('membership') == 'local';
|
||||||
$group->activitypub = $request->input('activitypub') == "true";
|
$group->activitypub = $request->input('activitypub') == 'true';
|
||||||
$group->discoverable = $request->input('discoverable') == "true";
|
$group->discoverable = $request->input('discoverable') == 'true';
|
||||||
$group->is_nsfw = $request->input('is_nsfw') == "true";
|
$group->is_nsfw = $request->input('is_nsfw') == 'true';
|
||||||
$group->metadata = $metadata;
|
$group->metadata = $metadata;
|
||||||
if ($group->isDirty()) {
|
if ($group->isDirty()) {
|
||||||
$changes = $group->getDirty();
|
$changes = $group->getDirty();
|
||||||
|
@ -285,6 +251,7 @@ class GroupController extends GroupFederationController
|
||||||
GroupService::del($group->id);
|
GroupService::del($group->id);
|
||||||
|
|
||||||
$res = $this->toJson($group, $pid);
|
$res = $this->toJson($group, $pid);
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +351,7 @@ class GroupController extends GroupFederationController
|
||||||
'copyright',
|
'copyright',
|
||||||
'impersonation',
|
'impersonation',
|
||||||
'scam',
|
'scam',
|
||||||
'terrorism'
|
'terrorism',
|
||||||
];
|
];
|
||||||
|
|
||||||
$gp = GroupPost::whereGroupId($group->id)->find($id);
|
$gp = GroupPost::whereGroupId($group->id)->find($id);
|
||||||
|
@ -421,7 +388,7 @@ class GroupController extends GroupFederationController
|
||||||
'profile_id' => $gp->profile_id,
|
'profile_id' => $gp->profile_id,
|
||||||
'username' => optional(AccountService::get($gp->profile_id))['acct'],
|
'username' => optional(AccountService::get($gp->profile_id))['acct'],
|
||||||
'gpid' => $gp->id,
|
'gpid' => $gp->id,
|
||||||
'url' => $gp->url()
|
'url' => $gp->url(),
|
||||||
],
|
],
|
||||||
GroupReport::class,
|
GroupReport::class,
|
||||||
$report->id
|
$report->id
|
||||||
|
@ -440,7 +407,7 @@ class GroupController extends GroupFederationController
|
||||||
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'action' => 'required|in:cw,delete,ignore',
|
'action' => 'required|in:cw,delete,ignore',
|
||||||
'id' => 'required|string'
|
'id' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$action = $request->input('action');
|
$action = $request->input('action');
|
||||||
|
@ -473,11 +440,12 @@ class GroupController extends GroupFederationController
|
||||||
'report_id' => $report->id,
|
'report_id' => $report->id,
|
||||||
'status_id' => $status->id,
|
'status_id' => $status->id,
|
||||||
'profile_id' => $status->profile_id,
|
'profile_id' => $status->profile_id,
|
||||||
'status_url' => $gp->url()
|
'status_url' => $gp->url(),
|
||||||
],
|
],
|
||||||
GroupReport::class,
|
GroupReport::class,
|
||||||
$report->id
|
$report->id
|
||||||
);
|
);
|
||||||
|
|
||||||
return response()->json([200]);
|
return response()->json([200]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -496,11 +464,12 @@ class GroupController extends GroupFederationController
|
||||||
'report_id' => $report->id,
|
'report_id' => $report->id,
|
||||||
'status_id' => $status->id,
|
'status_id' => $status->id,
|
||||||
'profile_id' => $status->profile_id,
|
'profile_id' => $status->profile_id,
|
||||||
'status_url' => $gp->url()
|
'status_url' => $gp->url(),
|
||||||
],
|
],
|
||||||
GroupReport::class,
|
GroupReport::class,
|
||||||
$report->id
|
$report->id
|
||||||
);
|
);
|
||||||
|
|
||||||
return response()->json([200]);
|
return response()->json([200]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -517,6 +486,7 @@ class GroupController extends GroupFederationController
|
||||||
$profile_id = $request->input('profile_id');
|
$profile_id = $request->input('profile_id');
|
||||||
abort_if(! $group->isMember($profile_id), 404);
|
abort_if(! $group->isMember($profile_id), 404);
|
||||||
$limits = GroupService::getInteractionLimits($group->id, $profile_id);
|
$limits = GroupService::getInteractionLimits($group->id, $profile_id);
|
||||||
|
|
||||||
return response()->json($limits);
|
return response()->json($limits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +502,7 @@ class GroupController extends GroupFederationController
|
||||||
'profile_id' => 'required|exists:profiles,id',
|
'profile_id' => 'required|exists:profiles,id',
|
||||||
'can_post' => 'required',
|
'can_post' => 'required',
|
||||||
'can_comment' => 'required',
|
'can_comment' => 'required',
|
||||||
'can_like' => 'required'
|
'can_like' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$member = $request->input('profile_id');
|
$member = $request->input('profile_id');
|
||||||
|
@ -546,7 +516,7 @@ class GroupController extends GroupFederationController
|
||||||
|
|
||||||
$limit = GroupLimit::firstOrCreate([
|
$limit = GroupLimit::firstOrCreate([
|
||||||
'profile_id' => $member,
|
'profile_id' => $member,
|
||||||
'group_id' => $group->id
|
'group_id' => $group->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($limit->wasRecentlyCreated) {
|
if ($limit->wasRecentlyCreated) {
|
||||||
|
@ -558,7 +528,7 @@ class GroupController extends GroupFederationController
|
||||||
$limit->limits = [
|
$limit->limits = [
|
||||||
'can_post' => $can_post,
|
'can_post' => $can_post,
|
||||||
'can_comment' => $can_comment,
|
'can_comment' => $can_comment,
|
||||||
'can_like' => $can_like
|
'can_like' => $can_like,
|
||||||
];
|
];
|
||||||
$limit->save();
|
$limit->save();
|
||||||
|
|
||||||
|
@ -572,7 +542,7 @@ class GroupController extends GroupFederationController
|
||||||
'profile_id' => $account['id'],
|
'profile_id' => $account['id'],
|
||||||
'username' => $account['username'],
|
'username' => $account['username'],
|
||||||
'previousLimits' => $previousLimits,
|
'previousLimits' => $previousLimits,
|
||||||
'newLimits' => $limit->limits
|
'newLimits' => $limit->limits,
|
||||||
],
|
],
|
||||||
GroupLimit::class,
|
GroupLimit::class,
|
||||||
$limit->id
|
$limit->id
|
||||||
|
@ -581,7 +551,6 @@ class GroupController extends GroupFederationController
|
||||||
return $request->all();
|
return $request->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function showProfile(Request $request, $id, $pid)
|
public function showProfile(Request $request, $id, $pid)
|
||||||
{
|
{
|
||||||
$group = Group::find($id);
|
$group = Group::find($id);
|
||||||
|
@ -619,17 +588,18 @@ class GroupController extends GroupFederationController
|
||||||
|
|
||||||
if ($profile) {
|
if ($profile) {
|
||||||
$url = url("/groups/{$id}/user/{$profile->id}");
|
$url = url("/groups/{$id}/user/{$profile->id}");
|
||||||
|
|
||||||
return redirect($url);
|
return redirect($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
abort(404, 'Invalid username');
|
abort(404, 'Invalid username');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function groupInviteLanding(Request $request, $id)
|
public function groupInviteLanding(Request $request, $id)
|
||||||
{
|
{
|
||||||
abort(404, 'Not yet implemented');
|
abort(404, 'Not yet implemented');
|
||||||
$group = Group::findOrFail($id);
|
$group = Group::findOrFail($id);
|
||||||
|
|
||||||
return view('groups.invite', compact('group'));
|
return view('groups.invite', compact('group'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,6 +607,7 @@ class GroupController extends GroupFederationController
|
||||||
{
|
{
|
||||||
$gid = HashidService::decode($hid);
|
$gid = HashidService::decode($hid);
|
||||||
$group = Group::findOrFail($gid);
|
$group = Group::findOrFail($gid);
|
||||||
|
|
||||||
return redirect($group->url());
|
return redirect($group->url());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,6 +615,7 @@ class GroupController extends GroupFederationController
|
||||||
{
|
{
|
||||||
$group = GroupService::get($id);
|
$group = GroupService::get($id);
|
||||||
abort_if(! $group || empty($group), 404);
|
abort_if(! $group || empty($group), 404);
|
||||||
|
|
||||||
return view('groups.invite-claim', compact('group'));
|
return view('groups.invite-claim', compact('group'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +630,7 @@ class GroupController extends GroupFederationController
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'gid' => $id,
|
'gid' => $id,
|
||||||
'can_join' => (bool) $exists
|
'can_join' => (bool) $exists,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,6 +665,7 @@ class GroupController extends GroupFederationController
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$group = Group::findOrFail($id);
|
$group = Group::findOrFail($id);
|
||||||
abort_if($group->isMember($pid), 422, 'Already a member');
|
abort_if($group->isMember($pid), 422, 'Already a member');
|
||||||
|
|
||||||
return ['next_url' => '/'];
|
return ['next_url' => '/'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue