diff --git a/app/Http/Controllers/ViewerController.php b/app/Http/Controllers/ViewerController.php index f889aaa..5e029d0 100644 --- a/app/Http/Controllers/ViewerController.php +++ b/app/Http/Controllers/ViewerController.php @@ -12,7 +12,7 @@ class ViewerController extends Controller { public function index(ViewerRequest $request, string $viewer) { - $viewer = strtolower($viewer); + $viewer = strtolower(trim($viewer)); $message = Message::orderBy('timestamp', 'desc') ->where('author_id', $viewer) ->orWhere('author_login', $viewer) @@ -45,11 +45,26 @@ public function index(ViewerRequest $request, string $viewer) return $b->timestamp <=> $a->timestamp; }); + $user = $request->user(); + $moderatorActions = []; + $channelPerms = $user->channelPermissions(); + $channels = $user->getTraceChannels(); + + $channelPermsIds = $channelPerms->pluck('channel_provider_id')->toArray(); + + $moderatorActions = ModeratorAction::where('target_id', $viewerId) + ->orWhere('initiator_id', $viewerId) + ->whereIn('channel_id', $channelPermsIds) + ->orderBy('timestamp', 'desc') + ->paginate(50); + return view('viewer.index', [ 'id' => $viewerId, 'username' => $initialMessage->author_login, 'usernames' => $usernames, 'messages' => $messages, + 'actions' => $moderatorActions, + 'channels' => $channels, ]); } } diff --git a/app/Models/Trace/ModeratorAction.php b/app/Models/Trace/ModeratorAction.php index 1edfb1c..f4dbf28 100644 --- a/app/Models/Trace/ModeratorAction.php +++ b/app/Models/Trace/ModeratorAction.php @@ -72,7 +72,7 @@ public function formatted($asHtml = false) : string } /** - * Get the target of the action, if any + * Get the target name of the action, if any * * @param bool $linkToViewerPage Returns an HTML link to the viewer page * @return string @@ -106,6 +106,30 @@ public function targetName($linkToViewerPage = false) : ?string return ''; } + /** + * Get the target ID of the action, if any + * + * @return string|null + */ + public function targetId() : ?string + { + if (!empty($this->target_id)) { + return $this->target_id; + } + + return null; + } + + /** + * Get the channel that the action was executed in + * + * @return Channel + */ + public function channel() + { + return $this->belongsTo(Channel::class, 'channel_id', 'channel_id'); + } + /** * Get the user that executed the action * diff --git a/resources/views/components/moderator-actions.blade.php b/resources/views/components/moderator-actions.blade.php new file mode 100644 index 0000000..91497a0 --- /dev/null +++ b/resources/views/components/moderator-actions.blade.php @@ -0,0 +1,82 @@ +@php + $showChannel = $showChannel ?? false; +@endphp + + + + + + + @if ($showChannel) + + @endif + + + + @foreach ($actions as $action) + + + @if (empty($action->targetName())) + + @else + + @endif + + @if ($showChannel) + @php + $channel = $action->channel->username(); + @endphp + + + @endif + + @endforeach + + @if ($actions->hasPages()) + + + + + + @endif +
Time & dateCommandModeratorChannel
+ {{ $action->formatted() }} + + + {!! $action->formatted(true) !!} + + {{ $action->user->login }} + + {{ $channel }} + +
+ {{ $actions->links() }} +
+ + +@section('scripts') + +@endsection diff --git a/resources/views/dashboard/channel.blade.php b/resources/views/dashboard/channel.blade.php index 6280aeb..24c11c8 100644 --- a/resources/views/dashboard/channel.blade.php +++ b/resources/views/dashboard/channel.blade.php @@ -1,55 +1,18 @@ -

+

{{ __('Dashboard') }}

-
+
-

+

{{ $channel->username() }}

- - - - - - - - - - @foreach ($actions as $action) - - - @if (empty($action->targetName())) - - @else - - @endif - - - @endforeach - - @if ($actions->hasPages()) - - - - - - @endif -
Time & dateCommandModerator
{{ $action->timestamp }} - - {{ $action->formatted() }} - - - {!! $action->formatted(true) !!} - - {{ $action->user->login }}
- {{ $actions->links() }} -
+ @include('components.moderator-actions', ['actions' => $actions])
diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 5339774..437c8b0 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -1,19 +1,19 @@ -

+

{{ __('Dashboard') }}

-
+
{{ __("Hi :user!", ['user' => Auth::user()->display_name]) }}
-
-

+
+

{{ __('Channels') }}

diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 8a8110d..fb285b3 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -10,6 +10,7 @@ + @vite(['resources/css/app.css', 'resources/js/app.js']) @@ -17,13 +18,13 @@ @yield('head') -
+
@if (isset($header))
-
+
{{ $header }}
@@ -31,24 +32,28 @@
-
+
-

This is the initial implementation of this project. A few different things that are planned:

- -
    +

    This is the initial implementation of this project. A few different things that are planned:

    +
    • Channels that are tracked where you have moderator access will be automatically retrieved from Twitch's API upon login. At the moment I have to manually give permissions via the database, since this API is currently only "planned" by Twitch.
    • Different filtering options: Type of action (timeout, raid etc.), moderator (whodunit), user/viewer (next point).
    • -
    • See related moderation actions, for example if a specific viewer has been timed out or banned multiple times.
    • Searching by text.
    • -
    • Linking any affected viewer's to their Twitch viewer card.
    • -
    • Automatic conversion to local time. Currently time & date is displayed in UTC.
    • Ability to see a viewer's chat messages at the time of action, alongside messages before/after to see context.
    • ... and probably more I'll figure out as I go along.
    -

    List of things that were planned and has been implemented in some form:

    -
      -
    • Username history of a user - For any user that has been timed out, raided, etc. you can now click on their name (highlighted in orange/amber) and access their basic "viewer profile".
    • +

      List of things that were planned and has been implemented in some form:

      +
        +
      • Username history of a user - For any user that has been timed out, raided, etc. you can now click on their name (highlighted in orange/amber) and access their basic "viewer profile".
      • +
      • See related moderation actions, for example if a specific viewer has been timed out or banned multiple times. - Implemented on the viewer profile. Will display moderation actions for any channels you have access to.
      • +
      • Automatic conversion to local time. Currently time & date is displayed in UTC. - Original UTC timestamp is still available if you hover over the converted timestamp in the table.
      • +
      • Linking any affected viewer's to their Twitch viewer card. - Viewer card will be linked for any channel you have access to.
      • +
      + +

      Known bugs:

      +
        +
      • Attempting to access a viewer page of someone who has no tracked chat messages will give you a 404. Trying to decide how I want to tackle those scenarios.
@@ -56,25 +61,27 @@
-
+
{{ $slot }}
-