Uname:Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64

Base Dir : /var/www/machinox.in

User : root


403WebShell
403Webshell
Server IP : 13.235.167.51  /  Your IP : 216.73.217.116
Web Server : Apache
System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64
User : root ( 0)
PHP Version : 8.2.29
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/app.machinox.in/app/Actions/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/app.machinox.in/app/Actions/MessageAction.php
<?php

namespace App\Actions;

use App\Helpers\NotificationHelper;
use App\Models\Advertisement;
use App\Models\GroupChat;
use App\Models\Message;
use App\Models\NotifiedUser;
use App\Models\User;
use App\Traits\UploadTrait;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use stdClass;

class MessageAction
{
    use UploadTrait;

    public function execute($request, $userId)
    {
        DB::beginTransaction();

        try {
            $ad = Advertisement::find($request->input('ad_id'));
            $currentUserId = USER_ID();
            $otherUserId = $userId;
            $adId = $request->input('ad_id');
            $type = $request->input('type', 'TEXT');

            $current_user = User::find($currentUserId);

            // Ensure user1_id is always smaller to avoid duplicate threads
            $user1 = min($currentUserId, $otherUserId);
            $user2 = max($currentUserId, $otherUserId);

            // Find or create the GroupChat
            $groupChat = GroupChat::firstOrCreate([
                'ad_id' => $adId,
                'user1_id' => $user1,
                'user2_id' => $user2,
            ]);

            // Create message
            $message = new Message();
            $message->gd_id = $groupChat->id;
            $message->sender_id = $currentUserId;
            $message->type = $type;
            $message->is_read = false;

            $res = new \stdClass();

            if ($type === 'TEXT') {
                $message->message = $request->input('message');
            } elseif ($request->hasFile('file')) {
                $file = $request->file('file');
                $filename = uniqid('attach_') . '.' . $file->getClientOriginalExtension();
                $folder = config('constants.ATTACHMENTS');
                $this->uploadOne($file, $folder, $filename);
                $message->message = $filename;
                $res->Path = $this->getURL($folder, $filename);
            }

            $message->save();

            // ✅ Push Notification Logic
            $notificationTitle = $current_user?->name ?? 'New Message';
            $notificationBody = ($type === 'TEXT')
                ? $message->message
                : 'Sent you an attachment';
            $notificationImage = $ad ? $ad->thumbnail ?? null : null;

            $params = [
                "user_id" => $otherUserId,
                "title" => $notificationTitle,
                "body" => $notificationBody,
                "image" => $notificationImage,
                "action" => "CHAT_MESSAGE",
                "action_id" => $groupChat->id,
                "ad_id"      => $ad->uuid,
                "chat_partner_id"  => $currentUserId
            ];

            // Send push
            NotificationHelper::SendPush($params);

            DB::commit();

            $res->message = trans('messages.MESSAGE_SENT_SUCCESSFULLY');
            return $res;
        } catch (\Throwable $th) {
            DB::rollBack();
            throw new \Exception($th->getMessage(), 500);
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit