Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion VERSION.txt

This file was deleted.

1 change: 1 addition & 0 deletions app/Jobs/Outline/OutlinePullRecentDayNotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Integrations\Outline\OutlineApi;
use App\Jobs\Base\BaseFetchJob;
use Carbon\CarbonImmutable;

class OutlinePullRecentDayNotes extends BaseFetchJob
{
Expand Down
183 changes: 183 additions & 0 deletions app/Models/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Jenssegers\Agent\Agent;

class Session extends Model
{
/**
* Indicates if the IDs are auto-incrementing.
*/
public $incrementing = false;

/**
* Indicates if the model should be timestamped.
*/
public $timestamps = false;

/**
* The table associated with the model.
*/
protected string $table = 'sessions';

/**
* The primary key for the model.
*/
protected $primaryKey = 'id';

/**
* The "type" of the auto-incrementing ID.
*/
protected $keyType = 'string';

/**
* The attributes that should be cast.
*/
protected $casts = [
'last_activity' => 'datetime',
];

/**
* Get the user that owns the session.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/**
* Get the device information for the session.
*/
public function getDeviceAttribute(): array
{
$agent = new Agent;
$agent->setUserAgent($this->user_agent);

return [
'platform' => $this->getPlatform($agent),
'browser' => $agent->browser(),
'is_desktop' => $agent->isDesktop(),
'is_mobile' => $agent->isMobile(),
'is_tablet' => $agent->isTablet(),
'device_name' => $this->getDeviceName($agent),
];
}

/**
* Get a human-readable device name.
*/
public function getDeviceNameAttribute(): string
{
$device = $this->device;

if ($device['is_mobile']) {
return $device['platform'] . ' Mobile - ' . $device['browser'];
}

if ($device['is_tablet']) {
return $device['platform'] . ' Tablet - ' . $device['browser'];
}

return $device['platform'] . ' Desktop - ' . $device['browser'];
}

/**
* Check if this is the current session.
*/
public function getIsCurrentAttribute(): bool
{
return $this->id === session()->getId();
}

/**
* Get the last activity in human readable format.
*/
public function getLastActivityHumanAttribute(): string
{
return $this->last_activity->diffForHumans();
}

/**
* Get the location information (if available).
*/
public function getLocationAttribute(): ?string
{
// You could integrate with a GeoIP service here
// For now, we'll just return the IP address
return $this->ip_address;
}

/**
* Scope to get sessions for a specific user.
*/
public function scopeForUser($query, $userId)
{
return $query->where('user_id', $userId);
}

/**
* Scope to get active sessions (recent activity).
*/
public function scopeActive($query, $minutes = 60)
{
return $query->where('last_activity', '>=', now()->subMinutes($minutes)->timestamp);
}

/**
* Invalidate this session.
*/
public function invalidate(): bool
{
return $this->delete();
}

/**
* Get the platform name from the user agent.
*/
protected function getPlatform(Agent $agent): string
{
if ($agent->isAndroidOS()) {
return 'Android';
}

if ($agent->isIOS()) {
return 'iOS';
}

if ($agent->isMac()) {
return 'macOS';
}

if ($agent->isWindows()) {
return 'Windows';
}

if ($agent->isLinux()) {
return 'Linux';
}

return $agent->platform() ?: 'Unknown';
}

/**
* Get a more specific device name.
*/
protected function getDeviceName(Agent $agent): string
{
$platform = $this->getPlatform($agent);
$browser = $agent->browser();

if ($agent->isMobile()) {
return "{$platform} Mobile";
}

if ($agent->isTablet()) {
return "{$platform} Tablet";
}

return "{$platform} Desktop";
}
}
8 changes: 8 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public function events()
return $this->hasMany(Event::class);
}

/**
* Get the user's sessions
*/
public function sessions()
{
return $this->hasMany(Session::class)->orderBy('last_activity', 'desc');
}

/**
* Get the attributes that should be cast.
*
Expand Down
11 changes: 4 additions & 7 deletions app/View/Components/AppBrand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ public function render(): View|Closure|string
return <<<'HTML'
<a href="/" wire:navigate>
<!-- Hidden when collapsed -->
<div {{ $attributes->class(["hidden-when-collapsed"]) }}>
<div class="flex items-center gap-2 block lg:hidden align-middle">
<div class="flex items-center gap-2 w-fit">
<x-icon name="o-cube" class="w-6 -mb-1.5 text-purple-500" />
<span class="font-bold text-3xl me-3 bg-gradient-to-r from-purple-500 to-pink-300 bg-clip-text text-transparent ">
app
</span>
<x-app-logo class="w-20 -mb-1"/>
</div>
</div>

<!-- Display when collapsed -->
<div class="display-when-collapsed hidden mx-5 mt-5 mb-1 h-[28px]">
<x-icon name="s-cube" class="w-6 -mb-1.5 text-purple-500" />
<div class="flex items-center gap-2 hidden lg:block lg:inline-block align-middle">
<x-app-logo class="w-26 mt-1 -mb-1"/>
</div>
</a>
HTML;
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"require": {
"php": "^8.2",
"jenssegers/agent": "^2.6",
"laravel/framework": "^12.0",
"laravel/horizon": "^5.30.3",
"laravel/sanctum": "^4.0",
Expand All @@ -20,7 +21,7 @@
"pgvector/pgvector": "^0.2.2",
"pragmarx/version": "dev-master",
"predis/predis": "^3.2",
"robsontenorio/mary": "^2.4",
"robsontenorio/mary": "dev-main",
"sentry/sentry-laravel": "^4.9",
"socialiteproviders/authelia": "^4.0",
"spatie/laravel-activitylog": "^4",
Expand Down Expand Up @@ -104,6 +105,10 @@
"type": "vcs",
"url": "git@github.com:cronxco/graby.git"
},
{
"type": "vcs",
"url": "git@github.com:cronxco/mary.git"
},
{
"type": "vcs",
"url": "git@github.com:willscottuk/monzo-php.git"
Expand Down
Loading