messages implemented
This commit is contained in:
@@ -6,10 +6,16 @@ use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Models\ArtworkAward;
|
||||
use App\Observers\ArtworkAwardObserver;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\ArtworkAward;
|
||||
use App\Models\ArtworkComment;
|
||||
use App\Models\ArtworkFavourite;
|
||||
use App\Models\ArtworkReaction;
|
||||
use App\Observers\ArtworkAwardObserver;
|
||||
use App\Observers\ArtworkCommentObserver;
|
||||
use App\Observers\ArtworkFavouriteObserver;
|
||||
use App\Observers\ArtworkObserver;
|
||||
use App\Observers\ArtworkReactionObserver;
|
||||
use App\Services\Upload\Contracts\UploadDraftServiceInterface;
|
||||
use App\Services\Upload\UploadDraftService;
|
||||
use Illuminate\Support\Facades\View;
|
||||
@@ -44,10 +50,14 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
$this->configureAuthRateLimiters();
|
||||
$this->configureUploadRateLimiters();
|
||||
$this->configureMessagingRateLimiters();
|
||||
$this->configureMailFailureLogging();
|
||||
|
||||
ArtworkAward::observe(ArtworkAwardObserver::class);
|
||||
Artwork::observe(ArtworkObserver::class);
|
||||
ArtworkFavourite::observe(ArtworkFavouriteObserver::class);
|
||||
ArtworkComment::observe(ArtworkCommentObserver::class);
|
||||
ArtworkReaction::observe(ArtworkReactionObserver::class);
|
||||
|
||||
// Provide toolbar counts and user info to layout views (port of legacy toolbar logic)
|
||||
View::composer(['layouts.nova', 'layouts.nova.*'], function ($view) {
|
||||
@@ -65,18 +75,23 @@ class AppServiceProvider extends ServiceProvider
|
||||
}
|
||||
|
||||
try {
|
||||
// legacy table name fallback handled elsewhere; here we look for user_favorites or favourites
|
||||
$favCount = DB::table('user_favorites')->where('user_id', $userId)->count();
|
||||
$favCount = DB::table('artwork_favourites')->where('user_id', $userId)->count();
|
||||
} catch (\Throwable $e) {
|
||||
try {
|
||||
$favCount = DB::table('favourites')->where('user_id', $userId)->count();
|
||||
} catch (\Throwable $e) {
|
||||
$favCount = 0;
|
||||
}
|
||||
$favCount = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
$msgCount = DB::table('messages')->where('reciever_id', $userId)->whereNull('read_at')->count();
|
||||
$msgCount = (int) DB::table('conversation_participants as cp')
|
||||
->join('messages as m', 'm.conversation_id', '=', 'cp.conversation_id')
|
||||
->where('cp.user_id', $userId)
|
||||
->whereNull('cp.left_at')
|
||||
->whereNull('m.deleted_at')
|
||||
->where('m.sender_id', '!=', $userId)
|
||||
->where(function ($q) {
|
||||
$q->whereNull('cp.last_read_at')
|
||||
->orWhereColumn('m.created_at', '>', 'cp.last_read_at');
|
||||
})
|
||||
->count();
|
||||
} catch (\Throwable $e) {
|
||||
$msgCount = 0;
|
||||
}
|
||||
@@ -179,4 +194,25 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
return $limits;
|
||||
}
|
||||
|
||||
private function configureMessagingRateLimiters(): void
|
||||
{
|
||||
RateLimiter::for('messages-send', function (Request $request): array {
|
||||
$userId = $request->user()?->id ?? 'guest';
|
||||
|
||||
return [
|
||||
Limit::perMinute(20)->by('messages:user:' . $userId),
|
||||
Limit::perMinute(40)->by('messages:ip:' . $request->ip()),
|
||||
];
|
||||
});
|
||||
|
||||
RateLimiter::for('messages-react', function (Request $request): array {
|
||||
$userId = $request->user()?->id ?? 'guest';
|
||||
|
||||
return [
|
||||
Limit::perMinute(60)->by('messages:react:user:' . $userId),
|
||||
Limit::perMinute(120)->by('messages:react:ip:' . $request->ip()),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvid
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use App\Models\Artwork;
|
||||
use App\Models\ArtworkAward;
|
||||
use App\Models\ArtworkComment;
|
||||
use App\Policies\ArtworkPolicy;
|
||||
use App\Policies\ArtworkAwardPolicy;
|
||||
use App\Policies\ArtworkCommentPolicy;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -16,8 +18,9 @@ class AuthServiceProvider extends ServiceProvider
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
protected $policies = [
|
||||
Artwork::class => ArtworkPolicy::class,
|
||||
ArtworkAward::class => ArtworkAwardPolicy::class,
|
||||
Artwork::class => ArtworkPolicy::class,
|
||||
ArtworkAward::class => ArtworkAwardPolicy::class,
|
||||
ArtworkComment::class => ArtworkCommentPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user