├── .babelrc ├── .dockerignore ├── .editorconfig ├── .env.example ├── .env.example.prod ├── .gitattributes ├── .gitignore ├── .styleci.yml ├── README.md ├── TODOS.md ├── apache-config.conf ├── app ├── Channel.php ├── Console │ ├── Commands │ │ └── SendChatMessage.php │ └── Kernel.php ├── Details.php ├── Events │ ├── AcceptRequest.php │ ├── ChatMessageWasReceived.php │ ├── MessageSent.php │ ├── UserOffline.php │ └── UserOnline.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── ConfirmPasswordController.php │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── RegisterController.php │ │ │ ├── ResetPasswordController.php │ │ │ └── VerificationController.php │ │ ├── AuthController.php │ │ ├── ChatController.php │ │ ├── Controller.php │ │ ├── HomeController.php │ │ └── ImageUploadController.php │ ├── Kernel.php │ └── Middleware │ │ ├── Authenticate.php │ │ ├── CheckForMaintenanceMode.php │ │ ├── EncryptCookies.php │ │ ├── LastUserActivity.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustHosts.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php ├── Invite.php ├── Logging │ └── CustomizeFormatter.php ├── Message.php ├── Notifications │ └── NotificationRequest.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php ├── User.php └── UserDetail.php ├── artisan ├── bin ├── init.sh └── react_laravel_websockets.sql ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── cors.php ├── database.php ├── filesystems.php ├── hashing.php ├── laravolt │ └── avatar.php ├── logging.php ├── mail.php ├── queue.php ├── services.php ├── session.php ├── view.php └── websockets.php ├── database ├── .gitignore ├── factories │ └── UserFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2019_08_19_000000_create_failed_jobs_table.php │ ├── 2020_06_21_090843_create_channels_table.php │ ├── 2020_06_21_105102_create_user_channel_table.php │ ├── 2020_06_24_142853_create_messages_table.php │ ├── 2020_09_02_090607_create_details_table.php │ ├── 2020_09_14_111713_create_notifications_table.php │ ├── 2020_09_15_085747_create_invites_table.php │ └── 2021_02_22_111109_create_user_details_table.php └── seeds │ ├── DatabaseSeeder.php │ ├── GeneralChannelSeeder.php │ └── UserSeeder.php ├── docker-compose-old.yml ├── docker-compose.yml ├── dockerfile ├── initlocal.sh ├── nginx └── nginx.conf ├── package-lock.json ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── assets │ └── images │ │ ├── SYSTEM.jpg │ │ ├── defaultuser.png │ │ ├── tile_background.png │ │ └── upload.svg ├── css │ └── app.css ├── favicon.ico ├── index.php ├── mix-manifest.json ├── robots.txt └── web.config ├── resources ├── css │ └── custom.css ├── js │ ├── App.js │ ├── actions │ │ ├── authActions.js │ │ ├── chatActions.js │ │ ├── statusActions.js │ │ ├── types.js │ │ └── uiActions.js │ ├── bootstrap.js │ ├── components │ │ ├── AllChannelsList.js │ │ ├── AllUsersList.js │ │ ├── AuthContainer.js │ │ ├── ChannelDetailsModal.js │ │ ├── Chat.js │ │ ├── ChatChannelsList.js │ │ ├── ChatDmUserList.js │ │ ├── ChatInputBox.js │ │ ├── ChatMessageList.js │ │ ├── ChatRoomUsersList.js │ │ ├── CreateChannelModal.js │ │ ├── Home.js │ │ ├── HomeNav.js │ │ ├── ImageUploadModal.js │ │ ├── InviteUsersModal.js │ │ ├── Landing.js │ │ ├── LoadingSpinner.js │ │ ├── Login.js │ │ ├── Main.js │ │ ├── NavbarMain.js │ │ ├── NotificationDropdown.js │ │ ├── Register.js │ │ ├── UserControlPanel.js │ │ ├── UserProfileModal.js │ │ ├── cropImage.js │ │ ├── router │ │ │ ├── MainRouter.js │ │ │ ├── ProtectedRoute.js │ │ │ └── ProtectedRouteIfAuth.js │ │ └── utils │ │ │ └── echoHelpers.js │ ├── index.js │ ├── reducers │ │ ├── authReducer.js │ │ ├── chatReducer.js │ │ ├── index.js │ │ ├── statusReducer.js │ │ └── uiReducer.js │ └── store.js ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php ├── sass │ ├── _variables.scss │ └── app.scss └── views │ └── index.blade.php ├── routes ├── api.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── avatars │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── CreatesApplication.php ├── Feature │ └── ExampleTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php └── webpack.mix.js /.babelrc: -------------------------------------------------------------------------------- 1 | { "plugins": ["@babel/plugin-proposal-class-properties"] } 2 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | client 3 | vendor -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME="Laravel React Chat" 2 | APP_ENV=local 3 | APP_KEY=base64:8m3E63yUr6kFLrVA1ubG5o+ffHscy36zHOldtTw7JIo= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=pgsql 10 | DB_HOST=127.0.0.1 11 | DB_PORT=5432 12 | DB_DATABASE=laravel_react_chat 13 | DB_USERNAME=admin 14 | DB_PASSWORD=123456 15 | 16 | BROADCAST_DRIVER=pusher 17 | CACHE_DRIVER=file 18 | QUEUE_CONNECTION=sync 19 | SESSION_DRIVER=file 20 | SESSION_LIFETIME=120 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_MAILER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | MAIL_FROM_ADDRESS=null 33 | MAIL_FROM_NAME="${APP_NAME}" 34 | 35 | AWS_ACCESS_KEY_ID= 36 | AWS_SECRET_ACCESS_KEY= 37 | AWS_DEFAULT_REGION=us-east-1 38 | AWS_BUCKET= 39 | 40 | PUSHER_APP_ID=pusherappid 41 | PUSHER_APP_KEY=websocketkey 42 | PUSHER_APP_SECRET=pushersecret 43 | PUSHER_APP_CLUSTER=mt1 44 | 45 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 46 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 47 | MIX_BASENAME='/' 48 | MIX_WS_HOST_URL=localhost 49 | MIX_AUTH_ENDPOINT=http://localhost:8000/broadcasting/auth -------------------------------------------------------------------------------- /.env.example.prod: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=https://demos.shawndsilva.com/realtime-chat-app 6 | ASSET_URL="${APP_URL}" 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=pgsql 10 | DB_HOST=postgres-rca 11 | DB_PORT=5432 12 | DB_DATABASE=react_laravel_websockets 13 | DB_USERNAME=admin 14 | DB_PASSWORD=123456 15 | 16 | BROADCAST_DRIVER=pusher 17 | CACHE_DRIVER=file 18 | QUEUE_CONNECTION=sync 19 | SESSION_DRIVER=file 20 | SESSION_LIFETIME=120 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_MAILER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | MAIL_FROM_ADDRESS=null 33 | MAIL_FROM_NAME="${APP_NAME}" 34 | 35 | AWS_ACCESS_KEY_ID= 36 | AWS_SECRET_ACCESS_KEY= 37 | AWS_DEFAULT_REGION=us-east-1 38 | AWS_BUCKET= 39 | 40 | PUSHER_APP_ID=pusherappid 41 | PUSHER_APP_KEY=websocketkey 42 | PUSHER_APP_SECRET=pushersecret 43 | PUSHER_APP_CLUSTER=mt1 44 | 45 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 46 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 47 | MIX_APP_URL="${APP_URL}" 48 | MIX_WS_HOST_URL=demos.shawndsilva.com/realtime-chat-app/wss 49 | MIX_AUTH_ENDPOINT=https://demos.shawndsilva.com/realtime-chat-app/broadcasting/auth 50 | MIX_BASENAME='/realtime-chat-app' -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | /public/js 7 | .env 8 | .env.backup 9 | .phpunit.result.cache 10 | Homestead.json 11 | Homestead.yaml 12 | npm-debug.log 13 | yarn-error.log 14 | /mysql-data -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | php: 2 | preset: laravel 3 | disabled: 4 | - unused_use 5 | finder: 6 | not-name: 7 | - index.php 8 | - server.php 9 | js: 10 | finder: 11 | not-name: 12 | - webpack.mix.js 13 | css: true 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel React RealTime Chat App 💬 2 | 3 | Full Featured Chat Web App with User-to-User and User to Group Real Time chatting, Profile Picture Uploading and Notifications. 4 | Built with React, Redux, Laravel, PostgreSQL and powered by WebSockets, hosted in Docker containers running NGINX and PHP-FPM. 5 | 6 | Live Demo( Desktop & Tablet only, Mobile responsiveness is WIP ) at https://demos.shawndsilva.com/realtime-chat-app 7 | 8 | ## ⭐ Features 9 | 10 | - Public chatting with all user in site. 11 | - Create your own Chat Rooms/Channels and make them Public or Private( needing your permission or invitation to join ) 12 | - User To User Private Messaging 13 | 14 | For complete ✨Feature List✨ screenshots and a video of the features check out https://www.shawndsilva.com/projects/laravel-react-chat.html 15 | 16 | ## ✅ Requirements 17 | 18 | - PHP 7.2 19 | - Composer 20 | - NPM 21 | - React 22 | - PostgreSQL 23 | 24 | A PostgresSQL service needs to be running with user, password, database name, port and hostname supplied in .env 25 | 26 | Following are the default values provided in `.env.example`, either setup your pgsql instance with these values, or change them with your own accordingly 27 | ``` 28 | DB_CONNECTION=pgsql 29 | DB_HOST=127.0.0.1 30 | DB_PORT=5432 31 | DB_DATABASE=laravel_react_chat 32 | DB_USERNAME=admin 33 | DB_PASSWORD=123456 34 | ``` 35 | 36 | ## 🚀 Quick Start 37 | 38 | Clone the repository 39 | 40 | ``` 41 | git clone https://github.com/shawn-dsilva/laravel-react-realtime-chat 42 | ``` 43 | 44 | Install dependencies 45 | 46 | ``` 47 | composer update && npm install 48 | ``` 49 | 50 | Create .env file from local development template .env 51 | 52 | ``` 53 | cp .env.example .env 54 | ``` 55 | 56 | Make executable and run the Local Development Init script 57 | 58 | ``` 59 | chmod +x initlocal.sh 60 | ``` 61 | ``` 62 | ./initlocal.sh 63 | ``` 64 | 65 | Run the app 66 | 67 | ``` 68 | npm run all 69 | ``` 70 | 71 | ## 📘 Changelog 72 | 73 | 74 | For Changelog, TODOS and Error Notes about this project, see `TODOS.md` within this repository. 75 | 76 | 77 | ## 👨‍💻 Author 78 | 79 | | [
Shawn D'silva](https://www.shawndsilva.com)
| 80 | | :---: | 81 | 82 | -------------------------------------------------------------------------------- /apache-config.conf: -------------------------------------------------------------------------------- 1 | 2 | ServerName demos.shawndsilva.com 3 | ServerAdmin me@mydomain.com 4 | DocumentRoot /var/www/site/public 5 | 6 | Options Indexes FollowSymLinks MultiViews 7 | AllowOverride All 8 | Order deny,allow 9 | Allow from all 10 | 11 | 12 | ErrorLog ${APACHE_LOG_DIR}/error.log 13 | CustomLog ${APACHE_LOG_DIR}/access.log combined 14 | 15 | -------------------------------------------------------------------------------- /app/Channel.php: -------------------------------------------------------------------------------- 1 | null, 13 | ]; 14 | 15 | protected $fillable = [ 16 | 'name' 17 | ]; 18 | 19 | protected $hidden = ['pivot']; 20 | 21 | public function users() { 22 | return $this->belongsToMany('App\User', 'user_channel')->withTimestamps()->select('name','id'); 23 | } 24 | 25 | public static function findOrNew($sender, $receiver) { 26 | $channelIsFound = Channel::where('type', 'dm')->whereHas('users', function($q) use ($sender) { 27 | $q->where('user_id',$sender ); 28 | })->whereHas('users', function($q) use ($receiver) { 29 | $q->where('user_id',$receiver); 30 | })->get(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Console/Commands/SendChatMessage.php: -------------------------------------------------------------------------------- 1 | argument('message'); 18 | 19 | event(new \App\Events\ChatMessageWasReceived($message, $user)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 28 | } 29 | 30 | /** 31 | * Register the commands for the application. 32 | * 33 | * @return void 34 | */ 35 | protected function commands() 36 | { 37 | $this->load(__DIR__.'/Commands'); 38 | 39 | require base_path('routes/console.php'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Details.php: -------------------------------------------------------------------------------- 1 | null, 13 | ]; 14 | 15 | protected $fillable = [ 16 | 'name', 'desc','visible','type' 17 | ]; 18 | 19 | public function channel() { 20 | return $this->belongsTo(Channel::class); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /app/Events/AcceptRequest.php: -------------------------------------------------------------------------------- 1 | friendChannel = $friendChannel; 30 | $this->userId = $userId; 31 | $this->type = $type; 32 | 33 | } 34 | 35 | public function broadcastWith() { 36 | return [ '0' => $this->friendChannel, 37 | '1' => $this->type]; 38 | } 39 | 40 | /** 41 | * Get the channels the event should broadcast on. 42 | * 43 | * @return \Illuminate\Broadcasting\Channel|array 44 | */ 45 | public function broadcastOn() 46 | { 47 | return new PresenceChannel('event.acceptRequest.'.$this->userId); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/Events/ChatMessageWasReceived.php: -------------------------------------------------------------------------------- 1 | chatMessage = $chatMessage; 24 | $this->user = $user; 25 | } 26 | 27 | public function broadcastOn() 28 | { 29 | return new PresenceChannel("chat"); 30 | } 31 | 32 | public function broadcastAs() { 33 | return "ChatMessageWasReceived"; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/Events/MessageSent.php: -------------------------------------------------------------------------------- 1 | user = $user; 48 | 49 | $this->message = $message; 50 | 51 | $this->channel = $channel; 52 | 53 | $this->type = $type; 54 | 55 | } 56 | 57 | /** 58 | * Get the channels the event should broadcast on. 59 | * 60 | * @return Channel|array 61 | */ 62 | public function broadcastOn() 63 | { 64 | if($this->type === "channel") { 65 | return new PresenceChannel("chat.channel.".$this->channel); 66 | } else if ($this->type === "dm") { 67 | return new PresenceChannel("chat.dm.".$this->channel); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/Events/UserOffline.php: -------------------------------------------------------------------------------- 1 | user = $user; 26 | } 27 | 28 | /** 29 | * Get the channels the event should broadcast on. 30 | * 31 | * @return \Illuminate\Broadcasting\Channel|array 32 | */ 33 | public function broadcastOn() 34 | { 35 | error_log("IN USEROFFLINE EVENT"); 36 | return new PresenceChannel('chat'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Events/UserOnline.php: -------------------------------------------------------------------------------- 1 | user = $user; 26 | } 27 | 28 | /** 29 | * Get the channels the event should broadcast on. 30 | * 31 | * @return \Illuminate\Broadcasting\Channel|array 32 | */ 33 | public function broadcastOn() 34 | { 35 | error_log("IN USERONLINE EVENT"); 36 | return new PresenceChannel('chat'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 42 | } 43 | 44 | /** 45 | * Get a validator for an incoming registration request. 46 | * 47 | * @param array $data 48 | * @return \Illuminate\Contracts\Validation\Validator 49 | */ 50 | protected function validator(array $data) 51 | { 52 | return Validator::make($data, [ 53 | 'name' => ['required', 'string', 'max:255'], 54 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 55 | 'password' => ['required', 'string', 'min:8', 'confirmed'], 56 | ]); 57 | } 58 | 59 | /** 60 | * Create a new user instance after a valid registration. 61 | * 62 | * @param array $data 63 | * @return \App\User 64 | */ 65 | protected function create(array $data) 66 | { 67 | return User::create([ 68 | 'name' => $data['name'], 69 | 'email' => $data['email'], 70 | 'password' => Hash::make($data['password']), 71 | ]); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 39 | $this->middleware('signed')->only('verify'); 40 | $this->middleware('throttle:6,1')->only('verify', 'resend'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 17 | } 18 | 19 | /** 20 | * Show the application dashboard. 21 | * 22 | * @return \Illuminate\Contracts\Support\Renderable 23 | */ 24 | public function index() 25 | { 26 | return view('home'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Controllers/ImageUploadController.php: -------------------------------------------------------------------------------- 1 | file('profileImage'); 15 | 16 | // Stores the Image into a folder called Avatars, 17 | // image name is generated and assigned to $path 18 | // disk("public") is the local directory storage/app/public 19 | 20 | $details = new UserDetail; 21 | $path = Storage::disk('public')->put('avatars', $image); 22 | $details->avatar = $path; 23 | 24 | $user = User::find(auth()->user()->id); 25 | 26 | $user->details()->updateOrCreate(['user_id' => auth()->user()->id], 27 | ['avatar'=> $path]); 28 | 29 | error_log('File Name: '.$image->getClientOriginalName()); 30 | error_log('File Extension: '.$image->getClientOriginalExtension()); 31 | error_log('File Real Path: '.$image->getRealPath()); 32 | error_log('File Size: '.$image->getSize()); 33 | error_log('File Mime Type: '.$image->getMimeType()); 34 | error_log($path); 35 | 36 | return response()->json($path); 37 | 38 | 39 | } 40 | 41 | public function getProfilePicture(Request $request) { 42 | $user = User::find(auth()->user()->id); 43 | $avatar = User::find(1)->avatar; 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 34 | \App\Http\Middleware\EncryptCookies::class, 35 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 36 | \Illuminate\Session\Middleware\StartSession::class, 37 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 38 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 39 | \App\Http\Middleware\VerifyCsrfToken::class, 40 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 41 | 42 | ], 43 | 44 | 'api' => [ 45 | 'throttle:60,1', 46 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 47 | ], 48 | ]; 49 | 50 | /** 51 | * The application's route middleware. 52 | * 53 | * These middleware may be assigned to groups or used individually. 54 | * 55 | * @var array 56 | */ 57 | protected $routeMiddleware = [ 58 | 'auth' => \App\Http\Middleware\Authenticate::class, 59 | 'auth.online' => \App\Http\Middleware\LastUserActivity::class, 60 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 61 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 62 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 63 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 64 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 65 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 66 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 67 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 68 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 69 | ]; 70 | } 71 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 19 | return route('login'); 20 | } 21 | } 22 | 23 | public function handle($request, Closure $next, ...$guards) 24 | { 25 | if ($request->cookie('jwt')) { 26 | $request->headers->set('Authorization', 'Bearer ' . $request->cookie('jwt')); 27 | 28 | } 29 | 30 | $this->authenticate($request, $guards); 31 | 32 | return $next($request); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/Http/Middleware/CheckForMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | addMinutes(1); 23 | error_log("IN LASTUSERACTIVITY MIDDLEWARE"); 24 | error_log(Auth::user()->id); 25 | $userData = Auth::user(); 26 | Cache::put('user-is-online-' . Auth::user()->id, $userData, $expiresAt); 27 | } 28 | return $next($request); 29 | } 30 | } -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 22 | return redirect(RouteServiceProvider::HOME); 23 | } 24 | 25 | return $next($request); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | getHandlers() as $handler) { 19 | $handler->setFormatter(new ColoredLineFormatter(new TrafficLight())); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /app/Message.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/Notifications/NotificationRequest.php: -------------------------------------------------------------------------------- 1 | invite = $invite; 24 | } 25 | 26 | /** 27 | * Get the notification's delivery channels. 28 | * 29 | * @param mixed $notifiable 30 | * @return array 31 | */ 32 | public function via($notifiable) 33 | { 34 | return ['database', 'broadcast']; 35 | } 36 | 37 | /** 38 | * Get the mail representation of the notification. 39 | * 40 | * @param mixed $notifiable 41 | * @return \Illuminate\Notifications\Messages\MailMessage 42 | */ 43 | public function toMail($notifiable) 44 | { 45 | return (new MailMessage) 46 | ->line('The introduction to the notification.') 47 | ->action('Notification Action', url('/')) 48 | ->line('Thank you for using our application!'); 49 | } 50 | 51 | 52 | /** 53 | * Get the array representation of the notification. 54 | * 55 | * @param mixed $notifiable 56 | * @return array 57 | */ 58 | // public function toBroadcast($notifiable) 59 | // { 60 | // $id = \Laravel\Spark\Notification::whereUserId($notifiable->id)->latest()->first()->id; 61 | 62 | // $desc = ""; 63 | 64 | // switch($this->invite->type) { 65 | // case "FRND": 66 | // $desc = "wants to be friends!"; 67 | // break; 68 | 69 | // case "JOIN": 70 | // $desc = "wants to join your channel {$this->invite->to}!"; 71 | // break; 72 | 73 | // case "INVT": 74 | // $desc = "has invited you to join channel {$this->invite->to}!"; 75 | // default: 76 | // break; 77 | // } 78 | 79 | // return new BroadcastMessage ( [ 80 | // 'invite_id' => $this->invite->id, 81 | // 'desc' => $desc, 82 | // 'id' => $id, 83 | // ]); 84 | // } 85 | 86 | public function toArray($notifiable) 87 | { 88 | $desc = ""; 89 | 90 | switch($this->invite->type) { 91 | case "FRND": 92 | $desc = "wants to be friends!"; 93 | break; 94 | 95 | case "JOIN": 96 | $desc = "wants to join your channel {$this->invite->recv_name}!"; 97 | break; 98 | 99 | case "INVT": 100 | $desc = "has invited you to join channel {$this->invite->recv_name}!"; 101 | default: 102 | break; 103 | } 104 | 105 | return [ 106 | 'sender_name' => $this->invite->name, 107 | 'invite_id' => $this->invite->id, 108 | 'request_type' => $this->invite->type, 109 | 'recv_channel' => $this->invite->recv_name, 110 | 'desc' => $desc, 111 | 'id' => $this->id, 112 | ]; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 18 | ]; 19 | 20 | /** 21 | * Register any authentication / authorization services. 22 | * 23 | * @return void 24 | */ 25 | public function boot() 26 | { 27 | $this->registerPolicies(); 28 | 29 | Passport::routes(); 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | ["auth:api"] ]); 18 | 19 | require base_path('routes/channels.php'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Providers/EventServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | parent::boot(); 31 | 32 | // 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 46 | 47 | $this->mapWebRoutes(); 48 | 49 | // 50 | } 51 | 52 | /** 53 | * Define the "web" routes for the application. 54 | * 55 | * These routes all receive session state, CSRF protection, etc. 56 | * 57 | * @return void 58 | */ 59 | protected function mapWebRoutes() 60 | { 61 | Route::middleware('web') 62 | ->namespace($this->namespace) 63 | ->group(base_path('routes/web.php')); 64 | } 65 | 66 | /** 67 | * Define the "api" routes for the application. 68 | * 69 | * These routes are typically stateless. 70 | * 71 | * @return void 72 | */ 73 | protected function mapApiRoutes() 74 | { 75 | Route::prefix('api') 76 | ->middleware('api') 77 | ->namespace($this->namespace) 78 | ->group(base_path('routes/api.php')); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | 'datetime', 41 | ]; 42 | 43 | public function messages() 44 | { 45 | return $this->hasMany(Message::class); 46 | } 47 | 48 | public function channels() { 49 | return $this->belongsToMany('App\Channel', 'user_channel')->withTimestamps(); 50 | } 51 | 52 | public function markAsOnline() 53 | { 54 | return Cache::has('user-is-online-' . $this->id); 55 | } 56 | 57 | public function details() 58 | { 59 | return $this->hasOne('App\UserDetail'); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/UserDetail.php: -------------------------------------------------------------------------------- 1 | belongsTo('App\User'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bin/init.sh: -------------------------------------------------------------------------------- 1 | composer update 2 | composer require react/promise:^2.7 3 | composer require pusher/pusher-php-server "~4.0" 4 | php artisan key:generate 5 | php artisan storage:link 6 | php artisan migrate:fresh --seed 7 | php artisan passport:install 8 | php artisan config:clear 9 | chmod 777 -R storage/ 10 | php-fpm -D 11 | npm run prod -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "type": "project", 4 | "description": "The Laravel Framework.", 5 | "keywords": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": "^7.2.5", 12 | "beyondcode/laravel-websockets": "^1.4", 13 | "bramus/monolog-colored-line-formatter": "~3.0", 14 | "fideloper/proxy": "^4.2", 15 | "fruitcake/laravel-cors": "^1.0", 16 | "guzzlehttp/guzzle": "^6.3", 17 | "laravel/framework": "^7.0", 18 | "laravel/passport": "^9.2", 19 | "laravel/tinker": "^2.0", 20 | "laravel/ui": "^2.0", 21 | "laravolt/avatar": "^3.2", 22 | "pusher/pusher-php-server": "~4.0", 23 | "react/promise": "^2.7" 24 | }, 25 | "require-dev": { 26 | "facade/ignition": "^2.0", 27 | "fzaninotto/faker": "^1.9.1", 28 | "mockery/mockery": "^1.3.1", 29 | "nunomaduro/collision": "^4.1", 30 | "phpunit/phpunit": "^8.5" 31 | }, 32 | "config": { 33 | "optimize-autoloader": true, 34 | "preferred-install": "dist", 35 | "sort-packages": true 36 | }, 37 | "extra": { 38 | "laravel": { 39 | "dont-discover": [] 40 | } 41 | }, 42 | "autoload": { 43 | "psr-4": { 44 | "App\\": "app/" 45 | }, 46 | "classmap": [ 47 | "database/seeds", 48 | "database/factories" 49 | ] 50 | }, 51 | "autoload-dev": { 52 | "psr-4": { 53 | "Tests\\": "tests/" 54 | } 55 | }, 56 | "minimum-stability": "dev", 57 | "prefer-stable": true, 58 | "scripts": { 59 | "post-autoload-dump": [ 60 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 61 | "@php artisan package:discover --ansi" 62 | ], 63 | "post-root-package-install": [ 64 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 65 | ], 66 | "post-create-project-cmd": [ 67 | "@php artisan key:generate --ansi" 68 | ] 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'passport', 46 | 'provider' => 'users', 47 | 'hash' => false, 48 | ], 49 | ], 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | User Providers 54 | |-------------------------------------------------------------------------- 55 | | 56 | | All authentication drivers have a user provider. This defines how the 57 | | users are actually retrieved out of your database or other storage 58 | | mechanisms used by this application to persist your user's data. 59 | | 60 | | If you have multiple user tables or models you may configure multiple 61 | | sources which represent each model / table. These sources may then 62 | | be assigned to any extra authentication guards you have defined. 63 | | 64 | | Supported: "database", "eloquent" 65 | | 66 | */ 67 | 68 | 'providers' => [ 69 | 'users' => [ 70 | 'driver' => 'eloquent', 71 | 'model' => App\User::class, 72 | ], 73 | 74 | // 'users' => [ 75 | // 'driver' => 'database', 76 | // 'table' => 'users', 77 | // ], 78 | ], 79 | 80 | /* 81 | |-------------------------------------------------------------------------- 82 | | Resetting Passwords 83 | |-------------------------------------------------------------------------- 84 | | 85 | | You may specify multiple password reset configurations if you have more 86 | | than one user table or model in the application and you want to have 87 | | separate password reset settings based on the specific user types. 88 | | 89 | | The expire time is the number of minutes that the reset token should be 90 | | considered valid. This security feature keeps tokens short-lived so 91 | | they have less time to be guessed. You may change this as needed. 92 | | 93 | */ 94 | 95 | 'passwords' => [ 96 | 'users' => [ 97 | 'provider' => 'users', 98 | 'table' => 'password_resets', 99 | 'expire' => 60, 100 | 'throttle' => 60, 101 | ], 102 | ], 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Password Confirmation Timeout 107 | |-------------------------------------------------------------------------- 108 | | 109 | | Here you may define the amount of seconds before a password confirmation 110 | | times out and the user is prompted to re-enter their password via the 111 | | confirmation screen. By default, the timeout lasts for three hours. 112 | | 113 | */ 114 | 115 | 'password_timeout' => 10800, 116 | 117 | ]; 118 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'pusher'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'encrypted' => false, 41 | 'host' => env('MIX_WS_HOST_URL'), 42 | 'port' => 6001, 43 | 'scheme' => 'http', 44 | // 'scheme' => 'https', 45 | // 'useTLS' => true, 46 | // 'curl_options' => [ 47 | // CURLOPT_SSL_VERIFYHOST => 0, 48 | // CURLOPT_SSL_VERIFYPEER => 0, 49 | // ], 50 | ], 51 | ], 52 | 53 | 'redis' => [ 54 | 'driver' => 'redis', 55 | 'connection' => 'default', 56 | ], 57 | 58 | 'log' => [ 59 | 'driver' => 'log', 60 | ], 61 | 62 | 'null' => [ 63 | 'driver' => 'null', 64 | ], 65 | 66 | ], 67 | 68 | ]; 69 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Cache Stores 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may define all of the cache "stores" for your application as 29 | | well as their drivers. You may even define multiple stores for the 30 | | same cache driver to group types of items stored in your caches. 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'apc' => [ 37 | 'driver' => 'apc', 38 | ], 39 | 40 | 'array' => [ 41 | 'driver' => 'array', 42 | 'serialize' => false, 43 | ], 44 | 45 | 'database' => [ 46 | 'driver' => 'database', 47 | 'table' => 'cache', 48 | 'connection' => null, 49 | ], 50 | 51 | 'file' => [ 52 | 'driver' => 'file', 53 | 'path' => storage_path('framework/cache/data'), 54 | ], 55 | 56 | 'memcached' => [ 57 | 'driver' => 'memcached', 58 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 59 | 'sasl' => [ 60 | env('MEMCACHED_USERNAME'), 61 | env('MEMCACHED_PASSWORD'), 62 | ], 63 | 'options' => [ 64 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 65 | ], 66 | 'servers' => [ 67 | [ 68 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 69 | 'port' => env('MEMCACHED_PORT', 11211), 70 | 'weight' => 100, 71 | ], 72 | ], 73 | ], 74 | 75 | 'redis' => [ 76 | 'driver' => 'redis', 77 | 'connection' => 'cache', 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Cache Key Prefix 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When utilizing a RAM based store such as APC or Memcached, there might 97 | | be other applications utilizing the same cache. So, we'll specify a 98 | | value to get prefixed to all our keys so we can avoid collisions. 99 | | 100 | */ 101 | 102 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /config/cors.php: -------------------------------------------------------------------------------- 1 | ['api/*', 'broadcasting/auth'], 19 | 20 | 'allowed_methods' => ['*'], 21 | 22 | 'allowed_origins' => ['*'], 23 | 24 | 'allowed_origins_patterns' => [], 25 | 26 | 'allowed_headers' => ['*'], 27 | 28 | 'exposed_headers' => [], 29 | 30 | 'max_age' => 0, 31 | 32 | 'supports_credentials' => false, 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "sftp", "s3" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | 'endpoint' => env('AWS_ENDPOINT'), 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Symbolic Links 73 | |-------------------------------------------------------------------------- 74 | | 75 | | Here you may configure the symbolic links that will be created when the 76 | | `storage:link` Artisan command is executed. The array keys should be 77 | | the locations of the links and the values should be their targets. 78 | | 79 | */ 80 | 81 | 'links' => [ 82 | public_path('storage') => storage_path('app/public'), 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/laravolt/avatar.php: -------------------------------------------------------------------------------- 1 | env('IMAGE_DRIVER', 'gd'), 21 | 22 | // Initial generator class 23 | 'generator' => \Laravolt\Avatar\Generator\DefaultGenerator::class, 24 | 25 | // Whether all characters supplied must be replaced with their closest ASCII counterparts 26 | 'ascii' => false, 27 | 28 | // Image shape: circle or square 29 | 'shape' => 'circle', 30 | 31 | // Image width, in pixel 32 | 'width' => 200, 33 | 34 | // Image height, in pixel 35 | 'height' => 200, 36 | 37 | // Number of characters used as initials. If name consists of single word, the first N character will be used 38 | 'chars' => 2, 39 | 40 | // font size 41 | 'fontSize' => 88, 42 | 43 | // convert initial letter in uppercase 44 | 'uppercase' => false, 45 | 46 | // Fonts used to render text. 47 | // If contains more than one fonts, randomly selected based on name supplied 48 | 'fonts' => [__DIR__ . '/../fonts/OpenSans-Bold.ttf', __DIR__ . '/../fonts/rockwell.ttf'], 49 | 50 | // List of foreground colors to be used, randomly selected based on name supplied 51 | 'foregrounds' => [ 52 | '#FFFFFF', 53 | ], 54 | 55 | // List of background colors to be used, randomly selected based on name supplied 56 | 'backgrounds' => [ 57 | '#f44336', 58 | '#E91E63', 59 | '#9C27B0', 60 | '#673AB7', 61 | '#3F51B5', 62 | '#2196F3', 63 | '#03A9F4', 64 | '#00BCD4', 65 | '#009688', 66 | '#4CAF50', 67 | '#8BC34A', 68 | '#CDDC39', 69 | '#FFC107', 70 | '#FF9800', 71 | '#FF5722', 72 | ], 73 | 74 | 'border' => [ 75 | 'size' => 1, 76 | 77 | // border color, available value are: 78 | // 'foreground' (same as foreground color) 79 | // 'background' (same as background color) 80 | // or any valid hex ('#aabbcc') 81 | 'color' => 'background', 82 | 83 | // border radius, currently only work for SVG 84 | 'radius' => 0, 85 | ], 86 | 87 | // List of theme name to be used when rendering avatar 88 | // Possible values are: 89 | // 1. Theme name as string: 'colorful' 90 | // 2. Or array of string name: ['grayscale-light', 'grayscale-dark'] 91 | // 3. Or wildcard "*" to use all defined themes 92 | 'theme' => ['colorful'], 93 | 94 | // Predefined themes 95 | // Available theme attributes are: 96 | // shape, chars, backgrounds, foregrounds, fonts, fontSize, width, height, ascii, uppercase, and border. 97 | 'themes' => [ 98 | 'grayscale-light' => [ 99 | 'backgrounds' => ['#edf2f7', '#e2e8f0', '#cbd5e0'], 100 | 'foregrounds' => ['#a0aec0'], 101 | ], 102 | 'grayscale-dark' => [ 103 | 'backgrounds' => ['#2d3748', '#4a5568', '#718096'], 104 | 'foregrounds' => ['#e2e8f0'], 105 | ], 106 | 'colorful' => [ 107 | 'backgrounds' => [ 108 | '#f44336', 109 | '#E91E63', 110 | '#9C27B0', 111 | '#673AB7', 112 | '#3F51B5', 113 | '#2196F3', 114 | '#03A9F4', 115 | '#00BCD4', 116 | '#009688', 117 | '#4CAF50', 118 | '#8BC34A', 119 | '#CDDC39', 120 | '#FFC107', 121 | '#FF9800', 122 | '#FF5722', 123 | ], 124 | 'foregrounds' => ['#FFFFFF'], 125 | ], 126 | 'pastel' => [ 127 | 'backgrounds' => [ 128 | '#ef9a9a', 129 | '#F48FB1', 130 | '#CE93D8', 131 | '#B39DDB', 132 | '#9FA8DA', 133 | '#90CAF9', 134 | '#81D4FA', 135 | '#80DEEA', 136 | '#80CBC4', 137 | '#A5D6A7', 138 | '#E6EE9C', 139 | '#FFAB91', 140 | '#FFCCBC', 141 | '#D7CCC8', 142 | ], 143 | 'foregrounds' => [ 144 | '#FFF', 145 | ], 146 | ], 147 | ], 148 | ]; 149 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 21 | 22 | /* 23 | |-------------------------------------------------------------------------- 24 | | Log Channels 25 | |-------------------------------------------------------------------------- 26 | | 27 | | Here you may configure the log channels for your application. Out of 28 | | the box, Laravel uses the Monolog PHP logging library. This gives 29 | | you a variety of powerful log handlers / formatters to utilize. 30 | | 31 | | Available Drivers: "single", "daily", "slack", "syslog", 32 | | "errorlog", "monolog", 33 | | "custom", "stack" 34 | | 35 | */ 36 | 37 | 'channels' => [ 38 | 'stack' => [ 39 | 'driver' => 'stack', 40 | 'channels' => ['single', 'stderr'], 41 | 'ignore_exceptions' => false, 42 | ], 43 | 44 | 'single' => [ 45 | 'driver' => 'single', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => 'debug', 48 | ], 49 | 50 | 'daily' => [ 51 | 'driver' => 'daily', 52 | 'path' => storage_path('logs/laravel.log'), 53 | 'level' => 'debug', 54 | 'days' => 14, 55 | ], 56 | 57 | 'slack' => [ 58 | 'driver' => 'slack', 59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 60 | 'username' => 'Laravel Log', 61 | 'emoji' => ':boom:', 62 | 'level' => 'critical', 63 | ], 64 | 65 | 'papertrail' => [ 66 | 'driver' => 'monolog', 67 | 'level' => 'debug', 68 | 'handler' => SyslogUdpHandler::class, 69 | 'handler_with' => [ 70 | 'host' => env('PAPERTRAIL_URL'), 71 | 'port' => env('PAPERTRAIL_PORT'), 72 | ], 73 | ], 74 | 75 | 'stderr' => [ 76 | 'driver' => 'monolog', 77 | 'handler' => StreamHandler::class, 78 | 'tap' => [App\Logging\CustomizeFormatter::class], 79 | 'formatter' => env('LOG_STDERR_FORMATTER'), 80 | 'with' => [ 81 | 'stream' => 'php://stdout', 82 | ], 83 | 'level' => 'debug', 84 | ], 85 | 86 | 'stdout' => [ 87 | 'driver' => 'monolog', 88 | 'handler' => StreamHandler::class, 89 | 'with' => [ 90 | 'stream' => 'php://stdout', 91 | ], 92 | ], 93 | 94 | 'syslog' => [ 95 | 'driver' => 'syslog', 96 | 'level' => 'debug', 97 | ], 98 | 99 | 'errorlog' => [ 100 | 'driver' => 'errorlog', 101 | 'level' => 'debug', 102 | ], 103 | 104 | 'null' => [ 105 | 'driver' => 'monolog', 106 | 'handler' => NullHandler::class, 107 | ], 108 | 109 | 'emergency' => [ 110 | 'path' => storage_path('logs/laravel.log'), 111 | ], 112 | ], 113 | 114 | ]; 115 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'smtp'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Mailer Configurations 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure all of the mailers used by your application plus 24 | | their respective settings. Several examples have been configured for 25 | | you and you are free to add your own as your application requires. 26 | | 27 | | Laravel supports a variety of mail "transport" drivers to be used while 28 | | sending an e-mail. You will specify which one you are using for your 29 | | mailers below. You are free to add additional mailers as required. 30 | | 31 | | Supported: "smtp", "sendmail", "mailgun", "ses", 32 | | "postmark", "log", "array" 33 | | 34 | */ 35 | 36 | 'mailers' => [ 37 | 'smtp' => [ 38 | 'transport' => 'smtp', 39 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 40 | 'port' => env('MAIL_PORT', 587), 41 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 42 | 'username' => env('MAIL_USERNAME'), 43 | 'password' => env('MAIL_PASSWORD'), 44 | 'timeout' => null, 45 | 'auth_mode' => null, 46 | ], 47 | 48 | 'ses' => [ 49 | 'transport' => 'ses', 50 | ], 51 | 52 | 'mailgun' => [ 53 | 'transport' => 'mailgun', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | ], 59 | 60 | 'sendmail' => [ 61 | 'transport' => 'sendmail', 62 | 'path' => '/usr/sbin/sendmail -bs', 63 | ], 64 | 65 | 'log' => [ 66 | 'transport' => 'log', 67 | 'channel' => env('MAIL_LOG_CHANNEL'), 68 | ], 69 | 70 | 'array' => [ 71 | 'transport' => 'array', 72 | ], 73 | ], 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Global "From" Address 78 | |-------------------------------------------------------------------------- 79 | | 80 | | You may wish for all e-mails sent by your application to be sent from 81 | | the same address. Here, you may specify a name and address that is 82 | | used globally for all e-mails that are sent by your application. 83 | | 84 | */ 85 | 86 | 'from' => [ 87 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 88 | 'name' => env('MAIL_FROM_NAME', 'Example'), 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Markdown Mail Settings 94 | |-------------------------------------------------------------------------- 95 | | 96 | | If you are using Markdown based email rendering, you may configure your 97 | | theme and component paths here, allowing you to customize the design 98 | | of the emails. Or, you may simply stick with the Laravel defaults! 99 | | 100 | */ 101 | 102 | 'markdown' => [ 103 | 'theme' => 'default', 104 | 105 | 'paths' => [ 106 | resource_path('views/vendor/mail'), 107 | ], 108 | ], 109 | 110 | ]; 111 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | 'block_for' => 0, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => env('AWS_ACCESS_KEY_ID'), 55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 58 | 'suffix' => env('SQS_SUFFIX'), 59 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 60 | ], 61 | 62 | 'redis' => [ 63 | 'driver' => 'redis', 64 | 'connection' => 'default', 65 | 'queue' => env('REDIS_QUEUE', 'default'), 66 | 'retry_after' => 90, 67 | 'block_for' => null, 68 | ], 69 | 70 | ], 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Failed Queue Jobs 75 | |-------------------------------------------------------------------------- 76 | | 77 | | These options configure the behavior of failed queue job logging so you 78 | | can control which database and table are used to store the jobs that 79 | | have failed. You may change them to any database / table you wish. 80 | | 81 | */ 82 | 83 | 'failed' => [ 84 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database'), 85 | 'database' => env('DB_CONNECTION', 'mysql'), 86 | 'table' => 'failed_jobs', 87 | ], 88 | 89 | ]; 90 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'postmark' => [ 24 | 'token' => env('POSTMARK_TOKEN'), 25 | ], 26 | 27 | 'ses' => [ 28 | 'key' => env('AWS_ACCESS_KEY_ID'), 29 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 30 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 31 | ], 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /config/websockets.php: -------------------------------------------------------------------------------- 1 | [ 13 | [ 14 | 'id' => env('PUSHER_APP_ID'), 15 | 'name' => env('APP_NAME'), 16 | 'key' => env('PUSHER_APP_KEY'), 17 | 'secret' => env('PUSHER_APP_SECRET'), 18 | 'enable_client_messages' => true, 19 | 'enable_statistics' => true, 20 | ], 21 | ], 22 | 23 | /** 24 | * This class is responsible for finding the apps. The default provider 25 | * will use the apps defined in this config file. 26 | * 27 | * You can create a custom provider by implementing the 28 | * `appProvier` interface. 29 | */ 30 | 'app_provider' => BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class, 31 | 32 | /* 33 | * This array contains the hosts of which you want to allow incoming requests. 34 | * Leave this empty if you want to accepts requests from all hosts. 35 | */ 36 | 'allowed_origins' => [ 37 | // 38 | ], 39 | 40 | /* 41 | * The maximum request size in kilobytes that is allowed for an incoming WebSocket request. 42 | */ 43 | 'max_request_size_in_kb' => 250, 44 | 45 | /* 46 | * This path will be used to register the necessary routes for the package. 47 | */ 48 | 'path' => 'laravel-websockets', 49 | 50 | /* 51 | * Define the optional SSL context for your WebSocket connections. 52 | * You can see all available options at: http://php.net/manual/en/context.ssl.php 53 | */ 54 | 'ssl' => [ 55 | /* 56 | * Path to local certificate file on filesystem. It must be a PEM encoded file which 57 | * contains your certificate and private key. It can optionally contain the 58 | * certificate chain of issuers. The private key also may be contained 59 | * in a separate file specified by local_pk. 60 | */ 61 | 'local_cert' => null, 62 | 63 | /* 64 | * Path to local private key file on filesystem in case of separate files for 65 | * certificate (local_cert) and private key. 66 | */ 67 | 'local_pk' => null, 68 | 69 | /* 70 | * Passphrase with which your local_cert file was encoded. 71 | */ 72 | 'passphrase' => null 73 | ], 74 | 75 | 'statistics' => [ 76 | /* 77 | * This model will be used to store the statistics of the WebSocketsServer. 78 | * The only requirement is that the model should be or extend 79 | * `WebSocketsStatisticsEntry` provided by this package. 80 | */ 81 | 'model' => \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry::class, 82 | 83 | /* 84 | * Here you can specify the interval in seconds at which statistics should be logged. 85 | */ 86 | 'interval_in_seconds' => 60, 87 | 88 | /* 89 | * When the clean-command is executed, all recorded statistics older than 90 | * the number of days specified here will be deleted. 91 | */ 92 | 'delete_statistics_older_than_days' => 60 93 | ], 94 | ]; -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | *.sqlite-journal 3 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(User::class, function (Faker $faker) { 21 | return [ 22 | 'name' => $faker->name, 23 | 'email' => $faker->unique()->safeEmail, 24 | 'email_verified_at' => now(), 25 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 26 | 'remember_token' => Str::random(10), 27 | ]; 28 | }); 29 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | // $table->string('avatar'); 21 | $table->timestamp('email_verified_at')->nullable(); 22 | $table->string('password'); 23 | $table->rememberToken(); 24 | $table->timestamps(); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::dropIfExists('users'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->text('connection'); 19 | $table->text('queue'); 20 | $table->longText('payload'); 21 | $table->longText('exception'); 22 | $table->timestamp('failed_at')->useCurrent(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('failed_jobs'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2020_06_21_090843_create_channels_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->timestamps(); 19 | $table->string('name'); 20 | $table->enum("type", array("dm", "channel")); 21 | }); 22 | 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('channels'); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2020_06_21_105102_create_user_channel_table.php: -------------------------------------------------------------------------------- 1 | bigInteger('user_id')->unsigned(); 18 | $table->foreign('user_id')->references('id')->on('users'); 19 | 20 | $table->bigInteger('channel_id')->unsigned(); 21 | $table->foreign('channel_id')->references('id')->on('channels'); 22 | 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('user_channel'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2020_06_24_142853_create_messages_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 19 | $table->integer('user_id')->unsigned(); 20 | $table->text('message'); 21 | $table->integer('channel_id')->unsigned(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('messages'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2020_09_02_090607_create_details_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->timestamps(); 19 | $table->bigInteger('owner_id')->unsigned(); 20 | $table->bigInteger('channel_id')->unsigned(); 21 | $table->text('name'); 22 | $table->text('desc'); 23 | $table->text('image'); 24 | $table->boolean('visible'); 25 | $table->enum("type", array("public", "private")); 26 | 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('channel_details'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /database/migrations/2020_09_14_111713_create_notifications_table.php: -------------------------------------------------------------------------------- 1 | uuid('id')->primary(); 18 | $table->string('type'); 19 | $table->morphs('notifiable'); 20 | $table->text('data'); 21 | $table->timestamp('read_at')->nullable(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('notifications'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2020_09_15_085747_create_invites_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->integer('from_id')->unsigned(); 19 | $table->integer('to_id')->unsigned(); 20 | $table->enum('type', array('FRND','JOIN','INVT')); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('invites'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2021_02_22_111109_create_user_details_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->text('avatar'); 19 | $table->text('desc')->nullable(); 20 | $table->bigInteger('user_id')->unsigned(); 21 | $table->foreign('user_id')->references('id')->on('users'); 22 | 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('user_details'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(GeneralChannelSeeder::class); 15 | $this->call(UserSeeder::class); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /database/seeds/GeneralChannelSeeder.php: -------------------------------------------------------------------------------- 1 | insert([ 16 | 'name' => 'General', 17 | 'type' => 'channel', 18 | ]); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /database/seeds/UserSeeder.php: -------------------------------------------------------------------------------- 1 | [ 22 | "name" => "Shawn D'silva", 23 | "email" => "shawn@shawndsilva.com" 24 | ], 25 | 1 => [ 26 | "name" => "Dio Brando", 27 | "email" => "dio.brando@cairo.eg" 28 | ], 29 | 2 => [ 30 | "name" => "Jotaro Kujo", 31 | "email" => "jojo@yahoo.co.jp" 32 | ], 33 | 3 => [ 34 | "name" => "Steven Armstrong", 35 | "email" => "senator@desperado-llc.com" 36 | ], 37 | 4 => [ 38 | "name" => "Samuel Rodriguez", 39 | "email" => "jetstream.sam@desperado-llc.com" 40 | ], 41 | ]; 42 | 43 | // DB::table('users')->insert([ 44 | // 'name' => "Shawn D'silva", 45 | // 'email' => 'shawn@shawndsilva.com', 46 | // 'password' => Hash::make('123456'), 47 | // 'avatar' => "avatars/Shawn D'silva-default.jpg", 48 | // ]); 49 | 50 | // $user = new User([ 51 | // 'name' => "Shawn D'silva", 52 | // 'email' => "shawn@shawndsilva.com", 53 | // 'password' => Hash::make('123456'), 54 | // ]); 55 | // $user->save(); 56 | 57 | // Avatar::create("Shawn D'silva")->save("storage/app/public/avatars/Shawn D'silva-default.jpg", 100); 58 | // $user->details()->updateOrCreate(['user_id' => $user->id], ['avatar'=> "avatars/Shawn D'silva-default.jpg"]); 59 | 60 | // $channel = Channel::find(1); 61 | // $channel->users()->attach($user->id); 62 | 63 | foreach( $userArray as $userItem ) { 64 | $user = new User([ 65 | 'name' => $userItem["name"], 66 | 'email' => $userItem["email"], 67 | 'password' => Hash::make('123456'), 68 | ]); 69 | $user->save(); 70 | 71 | Avatar::create($userItem["name"])->save("storage/app/public/avatars/".$userItem["name"]."-default.jpg", 100); 72 | $user->details()->updateOrCreate(['user_id' => $user->id], ['avatar'=> "avatars/".$userItem["name"]."-default.jpg"]); 73 | 74 | $channel = Channel::find(1); 75 | $channel->users()->attach($user->id); 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /docker-compose-old.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | server: 4 | container_name: server 5 | build: 6 | context: . 7 | dockerfile: dockerfile 8 | ports: 9 | - "5000:5000" 10 | volumes: 11 | - .:/server 12 | - /server/node_modules 13 | 14 | client: 15 | container_name: client 16 | build: 17 | context: ./client 18 | dockerfile: dockerfile 19 | ports: 20 | - "80:3000" 21 | volumes: 22 | - ./client:/client 23 | - /client/node_modules 24 | links: 25 | - server 26 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | # IMPORTANT, NAME HOST IN .env THE SAME AS THE SERVICE NAME HERE, IN THIS CASE MYSQL 4 | postgres-rca: 5 | container_name: postgres-rca #container name should not conflict with existing containers/images 6 | image: postgres 7 | ports: 8 | - "3315:5432" 9 | environment: 10 | - POSTGRES_DB=react_laravel_websockets 11 | - POSTGRES_USER=admin 12 | - POSTGRES_PASSWORD=123456 13 | main: 14 | container_name: main 15 | # hostname: main 16 | depends_on: 17 | - postgres-rca 18 | build: 19 | context: . 20 | dockerfile: dockerfile 21 | restart: unless-stopped 22 | ports: 23 | - "9000:9000" # Main App 24 | - "6001:6001" # Websocket server 25 | volumes: 26 | - .:/var/www 27 | - /var/www/node_modules # empty node_modules folder, npm cannot create folder in container build,reason unknown 28 | - /var/www/vendor # empty vendor folder, composer create folder in container build,reason unknown 29 | command: sh "./bin/init.sh" 30 | 31 | nginx: 32 | image: nginx:alpine 33 | container_name: nginx_laravel 34 | restart: unless-stopped 35 | ports: 36 | - "8000:8000" 37 | volumes: 38 | - "./:/var/www" 39 | - "./nginx:/etc/nginx/conf.d/" 40 | depends_on: 41 | - main 42 | # networks: 43 | # default: 44 | # external: 45 | # name: nginxrpgateway_default 46 | -------------------------------------------------------------------------------- /dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:7.3-fpm 2 | 3 | # Copy current directory contents to directory /main in container 4 | COPY . /var/www/ 5 | 6 | # Change current directory to /main 7 | WORKDIR /var/www/ 8 | 9 | # Arguments defined in docker-compose.yml 10 | 11 | # Install system dependencies 12 | RUN apt-get update && apt-get install -y \ 13 | git \ 14 | curl \ 15 | libpng-dev \ 16 | libonig-dev \ 17 | libxml2-dev \ 18 | zip \ 19 | unzip \ 20 | libpq-dev libgd3 libgd-dev \ 21 | libwebp-dev \ 22 | libjpeg62-turbo-dev \ 23 | libpng-dev libxpm-dev \ 24 | libfreetype6-dev 25 | 26 | # Clear cache 27 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* 28 | 29 | RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql 30 | RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ 31 | 32 | # Install PHP extensions 33 | RUN docker-php-ext-install pdo pdo_pgsql mbstring exif pcntl bcmath gd 34 | 35 | # Install Composer and NodeJS v12 36 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer 37 | RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - 38 | RUN apt-get install -y nodejs 39 | 40 | # Install Composer and NPM packages 41 | RUN composer update 42 | RUN npm install 43 | 44 | # Create system user to run Composer and Artisan Commands 45 | RUN chown -R root:root * 46 | 47 | # Creates php.ini file from php.ini-production, lets php-fpm return correct status codes 48 | RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini 49 | 50 | -------------------------------------------------------------------------------- /initlocal.sh: -------------------------------------------------------------------------------- 1 | php artisan key:generate # Generates Application key 2 | php artisan storage:link # creates link between storage/app/public/avatars and /public/storage/avatars 3 | php artisan migrate:fresh --seed # Seeds Database with default values 4 | php artisan passport:install # installs passport and generates keys 5 | php artisan config:clear # clears config of stale data 6 | chmod 777 -R storage/ # fixes permissions issues -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | upstream main-ws { 2 | server main:6001; 3 | } 4 | 5 | server { 6 | listen 8000; 7 | index index.php index.html; 8 | error_log /var/log/nginx/error.log; 9 | access_log /var/log/nginx/access.log; 10 | root /var/www/public; 11 | 12 | # Without the below config, requests to the API will be blocked as "mixed content" 13 | # The below config forces all HTTP requests to HTTPS 14 | add_header Strict-Transport-Security "max-age=31536000" always; 15 | add_header Content-Security-Policy upgrade-insecure-requests; 16 | 17 | location /wss:6001/ { 18 | proxy_set_header Host $host; 19 | proxy_set_header X-Forwarded-Proto $scheme; 20 | proxy_set_header X-Real-IP $remote_addr; 21 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 22 | proxy_pass http://main-ws/; 23 | proxy_read_timeout 60; 24 | proxy_connect_timeout 60; 25 | proxy_redirect off; 26 | # Allow the use of websockets 27 | proxy_http_version 1.1; 28 | proxy_set_header Upgrade $http_upgrade; 29 | proxy_set_header Connection 'upgrade'; 30 | proxy_cache_bypass $http_upgrade; 31 | 32 | } 33 | 34 | location ~ \.php$ { 35 | 36 | try_files $uri =404; 37 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 38 | fastcgi_pass main:9000; 39 | fastcgi_index index.php; 40 | include fastcgi_params; 41 | fastcgi_buffers 16 16k; 42 | fastcgi_buffer_size 32k; 43 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 44 | fastcgi_param PATH_INFO $fastcgi_path_info; 45 | fastcgi_read_timeout 600; 46 | fastcgi_intercept_errors on; 47 | 48 | } 49 | location / { 50 | try_files $uri $uri/ /index.php?$query_string; 51 | gzip_static on; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production && php artisan websockets:serve", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 11 | "server": "php artisan websockets:serve & php artisan serve ", 12 | "all": "concurrently \"npm run server\" \"npm run watch\"", 13 | "nobs": "concurrently \"npm run dev\" \"npm run server\"" 14 | }, 15 | "devDependencies": { 16 | "@babel/plugin-proposal-class-properties": "^7.10.1", 17 | "@babel/preset-react": "^7.0.0", 18 | "axios": "^0.21.1", 19 | "bootstrap": "^4.0.0", 20 | "browser-sync": "^2.26.14", 21 | "browser-sync-webpack-plugin": "^2.0.1", 22 | "cross-env": "^7.0", 23 | "jquery": "^3.2", 24 | "laravel-mix": "^5.0.5", 25 | "lodash": "^4.17.20", 26 | "popper.js": "^1.12", 27 | "react": "^16.13.1", 28 | "react-dom": "^16.13.1", 29 | "resolve-url-loader": "^3.1.2", 30 | "sass": "^1.15.2", 31 | "sass-loader": "^8.0.0" 32 | }, 33 | "dependencies": { 34 | "concurrently": "^5.3.0", 35 | "laravel-echo": "^1.8.0", 36 | "moment": "^2.29.1", 37 | "moment-timezone": "^0.5.33", 38 | "pusher-js": "^6.0.3", 39 | "react-easy-crop": "^3.3.2", 40 | "react-moment": "^1.1.1", 41 | "react-redux": "^7.2.0", 42 | "react-router-dom": "^5.2.0", 43 | "reactstrap": "^8.4.1", 44 | "redux": "^4.0.5", 45 | "redux-thunk": "^2.3.0" 46 | }, 47 | "homepage": "https://demos.shawndsilva.com/realtime-chat-app" 48 | } 49 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/assets/images/SYSTEM.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawn-dsilva/laravel-react-realtime-chat/4985d2bb931bb1f023bd303e54c94034228ee011/public/assets/images/SYSTEM.jpg -------------------------------------------------------------------------------- /public/assets/images/defaultuser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawn-dsilva/laravel-react-realtime-chat/4985d2bb931bb1f023bd303e54c94034228ee011/public/assets/images/defaultuser.png -------------------------------------------------------------------------------- /public/assets/images/tile_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawn-dsilva/laravel-react-realtime-chat/4985d2bb931bb1f023bd303e54c94034228ee011/public/assets/images/tile_background.png -------------------------------------------------------------------------------- /public/assets/images/upload.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shawn-dsilva/laravel-react-realtime-chat/4985d2bb931bb1f023bd303e54c94034228ee011/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 2 | 9 | */ 10 | 11 | define('LARAVEL_START', microtime(true)); 12 | 13 | /* 14 | |-------------------------------------------------------------------------- 15 | | Register The Auto Loader 16 | |-------------------------------------------------------------------------- 17 | | 18 | | Composer provides a convenient, automatically generated class loader for 19 | | our application. We just need to utilize it! We'll simply require it 20 | | into the script here so that we don't have to worry about manual 21 | | loading any of our classes later on. It feels great to relax. 22 | | 23 | */ 24 | 25 | require __DIR__.'/../vendor/autoload.php'; 26 | 27 | /* 28 | |-------------------------------------------------------------------------- 29 | | Turn On The Lights 30 | |-------------------------------------------------------------------------- 31 | | 32 | | We need to illuminate PHP development, so let us turn on the lights. 33 | | This bootstraps the framework and gets it ready for use, then it 34 | | will load up this application so that we can run it and send 35 | | the responses back to the browser and delight our users. 36 | | 37 | */ 38 | 39 | $app = require_once __DIR__.'/../bootstrap/app.php'; 40 | 41 | /* 42 | |-------------------------------------------------------------------------- 43 | | Run The Application 44 | |-------------------------------------------------------------------------- 45 | | 46 | | Once we have the application, we can handle the incoming request 47 | | through the kernel, and send the associated response back to 48 | | the client's browser allowing them to enjoy the creative 49 | | and wonderful application we have prepared for them. 50 | | 51 | */ 52 | 53 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 54 | 55 | $response = $kernel->handle( 56 | $request = Illuminate\Http\Request::capture() 57 | ); 58 | 59 | $response->send(); 60 | 61 | $kernel->terminate($request, $response); 62 | -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/index.js": "/js/index.js", 3 | "/css/app.css": "/css/app.css" 4 | } 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /resources/js/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import ReactDOM from "react-dom"; 3 | import { BrowserRouter } from "react-router-dom"; 4 | import { Provider } from "react-redux"; 5 | import Main from "./components/Main"; 6 | import store from "./store"; 7 | import { getUser } from "./actions/authActions"; 8 | import { MainRouter } from "./components/router/MainRouter"; 9 | 10 | class App extends Component { 11 | componentDidMount() { 12 | store.dispatch(getUser()); 13 | } 14 | 15 | render() { 16 | return ( 17 | 18 |
19 | 20 | ); 21 | } 22 | } 23 | 24 | export default App; 25 | -------------------------------------------------------------------------------- /resources/js/actions/statusActions.js: -------------------------------------------------------------------------------- 1 | import { GET_STATUS, CLEAR_STATUS } from './types'; 2 | 3 | // RETURN STATUS 4 | export const returnStatus = (msg, status, id = null) => { 5 | return { 6 | type: GET_STATUS, 7 | payload: { msg, status, id} 8 | }; 9 | }; 10 | 11 | // CLEAR STATUS 12 | export const clearStatus = () => { 13 | return { 14 | type: CLEAR_STATUS 15 | }; 16 | }; -------------------------------------------------------------------------------- /resources/js/actions/types.js: -------------------------------------------------------------------------------- 1 | export const AUTH_ERROR = "AUTH_ERROR"; 2 | export const LOGIN_SUCCESS = "LOGIN_SUCCESS"; 3 | export const LOGIN_FAIL = "LOGIN_FAIL"; 4 | export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS"; 5 | export const REGISTER_SUCCESS = "REGISTER_SUCCESS"; 6 | export const REGISTER_FAIL = "REGISTER_FAIL"; 7 | export const GET_STATUS = 'GET_STATUS'; 8 | export const CLEAR_STATUS = 'CLEAR_STATUS'; 9 | export const BUTTON_CLICKED = 'BUTTON_CLICKED'; 10 | export const BUTTON_RESET = 'BUTTON_RESET'; 11 | export const AUTH_SUCCESS = 'AUTH_SUCCESS'; 12 | export const AUTH_FAIL = 'AUTH_FAIL'; 13 | export const IS_LOADING = 'IS_LOADING'; 14 | export const IS_AUTH = 'IS_AUTH'; 15 | export const GET_MESSAGES = 'GET_MESSAGES'; 16 | export const SET_MESSAGES = 'SET_MESSAGES'; 17 | export const ADD_MESSAGE = 'ADD_MESSAGE'; 18 | export const CLEAR_MESSAGES = 'CLEAR_MESSAGES'; 19 | export const SET_USERS_IN_ROOM = 'SET_USERS_IN_ROOM'; 20 | export const GET_DM_USERS = 'GET_DM_USERS'; 21 | export const ADD_USER_TO_ROOM = 'ADD_USER_TO_ROOM'; 22 | export const USER_LEAVES_ROOM = 'USER_LEAVES_ROOM'; 23 | export const SET_SELECTED_CHANNEL = 'SET_SELECTED_CHANNEL'; 24 | export const CREATE_CHANNEL_SUCCESS = 'CREATE_CHANNEL_SUCCESS'; 25 | export const GET_CHANNELS = 'GET_CHANNELS'; 26 | export const SEND_REQUEST_SUCCESS = 'SEND_REQUEST_SUCCESS'; 27 | export const ADD_NOTIFICATION = 'ADD_NOTIFICATION'; 28 | export const ACCEPT_REQUEST_SUCCESS = 'ACCEPT_REQUEST_SUCCESS'; 29 | export const GET_ALL_USERS = 'GET_ALL_USERS'; 30 | export const GET_NOTIFICATIONS = 'GET_NOTIFICATIONS'; 31 | export const GET_ALL_NOTIFICATIONS = 'GET_ALL_NOTIFICATIONS'; 32 | export const NOTIF_MARK_AS_READ = 'NOTIF_MARK_AS_READ'; 33 | export const GET_ALL_CHANNELS = 'GET_ALL_CHANNELS'; 34 | export const ADD_CHANNEL_SUCCESS = 'ADD_CHANNEL_SUCCESS'; 35 | export const IS_ONLINE = 'IS_ONLINE'; 36 | export const IS_OFFLINE = 'IS_OFFLINE'; 37 | export const ADD_CHANNEL_USERS = 'ADD_CHANNEL_USERS'; 38 | export const USER_AVATAR_UPDATED = 'USER_AVATAR_UPDATED'; 39 | export const USER_DESC_UPDATED = 'USER_DESC_UPDATED'; 40 | export const ADD_TYPING_EVENT = 'ADD_TYPING_EVENT'; 41 | export const REMOVE_TYPING_EVENT = 'REMOVE_TYPING_EVENT'; -------------------------------------------------------------------------------- /resources/js/actions/uiActions.js: -------------------------------------------------------------------------------- 1 | import { 2 | BUTTON_CLICKED, 3 | BUTTON_RESET, 4 | IS_LOADING 5 | 6 | } from "./types"; 7 | 8 | export const buttonClicked = () => (dispatch, getState) => { 9 | dispatch({type: BUTTON_CLICKED}); 10 | }; 11 | 12 | export const buttonReset = () => (dispatch, getState) => { 13 | dispatch({type: BUTTON_RESET}); 14 | }; 15 | 16 | export const isLoading = () => (dispatch, getState) => { 17 | dispatch({type: IS_LOADING}); 18 | }; -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | window._ = require('lodash'); 2 | 3 | /** 4 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 5 | * for JavaScript based Bootstrap features such as modals and tabs. This 6 | * code may be modified to fit the specific needs of your application. 7 | */ 8 | 9 | try { 10 | window.Popper = require('popper.js').default; 11 | window.$ = window.jQuery = require('jquery'); 12 | 13 | require('bootstrap'); 14 | } catch (e) {} 15 | 16 | /** 17 | * We'll load the axios HTTP library which allows us to easily issue requests 18 | * to our Laravel back-end. This library automatically handles sending the 19 | * CSRF token as a header based on the value of the "XSRF" token cookie. 20 | */ 21 | 22 | window.axios = require('axios'); 23 | 24 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 25 | 26 | window.axios.defaults.baseURL = process.env.MIX_APP_URL; 27 | 28 | 29 | /** 30 | * Echo exposes an expressive API for subscribing to channels and listening 31 | * for events that are broadcast by Laravel. Echo and event broadcasting 32 | * allows your team to easily build robust real-time web applications. 33 | */ 34 | 35 | // import Echo from 'laravel-echo'; 36 | 37 | // window.Pusher = require('pusher-js'); 38 | 39 | // window.Echo = new Echo({ 40 | // broadcaster: 'pusher', 41 | // key: process.env.MIX_PUSHER_APP_KEY, 42 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 43 | // forceTLS: true 44 | // }); 45 | -------------------------------------------------------------------------------- /resources/js/components/AllChannelsList.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from "react"; 2 | import { Button,Alert, Modal, ModalHeader, ModalBody, ModalFooter, Col, Card, CardImg, CardText, CardBody, 3 | CardTitle, CardSubtitle } from 'reactstrap'; 4 | 5 | export const AllChannelsList = (props) => { 6 | const channels = props.channels.filter( channel => props.currUser.id != channel.owner_id ); 7 | 8 | // console.log(typeof(channels)); 9 | const { joinChannelRequest } = props; 10 | 11 | const [modal, setModal] = useState(false); 12 | 13 | const toggle = (e) => { 14 | e.stopPropagation(); 15 | setModal(!modal); 16 | props.getAllChannelsList(); 17 | } 18 | 19 | 20 | console.log(channels); 21 | 22 | const channelList = channels.map((value, index) => { 23 | return ( 24 | 25 | 26 | 27 | 28 |
29 | {value.name} 30 |
31 |
32 | Owner: {value.owner} 33 | Type: {value.type} channel 34 | 35 | Channel Description: {value.desc} 36 | 37 | Visible : {value.visible ? "Yes": "No"} 38 | 39 | 46 |
47 |
48 | 49 |

50 | 51 | ); 52 | }); 53 | 54 | 55 | return ( 56 |
57 | 60 | 61 | Discover Channels 62 | 63 |

64 | This modal lists all the channels created by users on 65 | this site, some of which are public and need approval of the owner to join, 66 | while others are public and can be joined immediately. 67 | 68 | Channels created by you are excluded from this list 69 |

70 |
71 | {channelList} 72 | 73 | 76 | 77 |
78 |
79 | ); 80 | }; 81 | 82 | export default AllChannelsList; 83 | -------------------------------------------------------------------------------- /resources/js/components/AllUsersList.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from "react"; 2 | import { Button,Alert, Modal, ModalHeader, ModalBody, ModalFooter, Col } from 'reactstrap'; 3 | import { getAvatar } from './utils/echoHelpers'; 4 | 5 | 6 | export const AllUsersList = (props) => { 7 | const users = props.dmUsers.filter(u => u.id !== props.currUser.id); 8 | // console.log(typeof(users)); 9 | const { sendRequest } = props; 10 | 11 | const [modal, setModal] = useState(false); 12 | 13 | const toggle = (e) => { 14 | e.stopPropagation(); 15 | setModal(!modal); 16 | props.getAllUsersList(); 17 | }; 18 | 19 | 20 | console.log(users); 21 | const userList = users.map((value, index) => { 22 | return ( 23 | 24 | 25 | 30 | 35 |

36 | 37 | 38 | ); 39 | }); 40 | 41 | 42 | return ( 43 |
44 | 47 | 48 | All Users List 49 | 50 | {userList} 51 | 52 | 53 | 54 | 55 | 56 |
57 | ) 58 | }; 59 | 60 | export default AllUsersList; 61 | -------------------------------------------------------------------------------- /resources/js/components/AuthContainer.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | 4 | export const AuthContainer = (props) => { 5 | return ( 6 |
7 |

Laravel React Real-Time Chat App

8 |
9 | {props.children} 10 |
11 |

Made by Shawn D'silva

12 |
13 | ); 14 | } 15 | 16 | export default AuthContainer; -------------------------------------------------------------------------------- /resources/js/components/ChannelDetailsModal.js: -------------------------------------------------------------------------------- 1 | /* eslint react/no-multi-comp: 0, react/prop-types: 0 */ 2 | import React, { useState } from 'react'; 3 | import { Button, Modal, ModalHeader, ModalBody, UncontrolledTooltip,} from 'reactstrap'; 4 | 5 | const ChannelDetailsModal = (props) => { 6 | const [modalOpen, setModalOpen] = useState(false); 7 | 8 | const toggle = () => setModalOpen(!modalOpen); 9 | 10 | return ( 11 |
12 | 13 | About This Channel 14 | 15 | 18 | 19 | Channel Details 20 | 21 |

Channel Name

22 | {props.channel.name} 23 |

Channel Description

24 |

{props.channel.desc}

25 |

Owner

26 | { props.channel.id === 1 ? 27 |

SYSTEM

: 28 |

{props.channel.owner}

} 29 | 30 |
31 |
32 |
33 | ); 34 | } 35 | 36 | export default ChannelDetailsModal; -------------------------------------------------------------------------------- /resources/js/components/ChatChannelsList.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from "react"; 2 | import {Collapse , Button, CardBody, Card, Col, UncontrolledTooltip } from "reactstrap"; 3 | import CreateChannelModal from "./CreateChannelModal"; 4 | import AllChannelsList from "./AllChannelsList"; 5 | 6 | export const ChatChannelsList = props => { 7 | const channels = props.channels; 8 | 9 | const [isOpen, setIsOpen] = useState(true); 10 | 11 | const toggle = () => setIsOpen(!isOpen); 12 | 13 | // console.log(typeof(channels)); 14 | const { channelSelect } = props; 15 | console.log("in channels list"); 16 | console.log(channels); 17 | const channelList = channels.map((value, index) => { 18 | return ( 19 |
20 | 36 |

37 |
38 | ); 39 | }); 40 | 41 | return ( 42 |
43 | 44 | Discover Channels 45 | 46 | 47 | Create A Channel 48 | 49 | 50 | Open / Close Channel Section 51 | 52 | 53 |
54 |

Channels

55 | 61 | 62 | 63 | { !isOpen ? : } 64 |
65 | 66 |
67 |
68 |
69 | 84 |

85 |
86 | {channelList} 87 |
88 |
89 |
90 | 91 |
92 | ); 93 | }; 94 | 95 | export default ChatChannelsList; 96 | -------------------------------------------------------------------------------- /resources/js/components/ChatDmUserList.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import React, {useState} from "react"; 4 | import { Collapse, Col, Button, UncontrolledTooltip } from "reactstrap"; 5 | import AllUsersList from './AllUsersList'; 6 | export const ChatDmUsersList = (props) => { 7 | 8 | const users = props.dmUsers; 9 | const { dmSelect } = props; 10 | 11 | const [isOpen, setIsOpen] = useState(true); 12 | 13 | const toggle = () => setIsOpen(!isOpen); 14 | 15 | 16 | console.log("FROM CHATDMUSERSLIST "); 17 | console.log(users); 18 | const userList = users.map((value, index) => { 19 | return ( 20 |
21 | 28 |
29 | ); 30 | }); 31 | 32 | 33 | return ( 34 |
35 | 36 | Add Friend 37 | 38 | 39 | 40 | Open or Close DM Section 41 | 42 | 51 | 52 |
53 |
{userList}
54 |
55 |
56 |
57 | ) 58 | }; 59 | 60 | export default ChatDmUsersList; 61 | -------------------------------------------------------------------------------- /resources/js/components/ChatInputBox.js: -------------------------------------------------------------------------------- 1 | import { lowerCase } from 'lodash'; 2 | import React, { Component } from 'react' 3 | import { 4 | Button, 5 | Row, 6 | Input, 7 | InputGroup, 8 | InputGroupAddon 9 | } from 'reactstrap'; 10 | import { sendMessage } from './utils/echoHelpers'; 11 | 12 | 13 | export class ChatInputBox extends Component { 14 | 15 | state = { 16 | message:"" 17 | } 18 | 19 | onChange = (e) => { 20 | this.setState({ [e.target.name]: e.target.value }); 21 | setTimeout( () => { 22 | window.Echo.join(`chat.${this.props.selectedChannel.type}.${this.props.selectedChannel.id}`) 23 | .whisper("typing", { 24 | name: this.props.currUser 25 | }); 26 | }, 300) 27 | 28 | }; 29 | 30 | // Calls action to register user 31 | sendMessageWrapper = (e) => { 32 | e.stopPropagation(); 33 | console.log(this.state.message); 34 | sendMessage(this.state.message, this.props.selectedChannel.id, this.props.selectedChannel.type) 35 | this.setState({ message:'' }); 36 | 37 | } 38 | 39 | render() { 40 | return ( 41 | 42 | 43 | 44 | 45 | 46 | 47 | ) 48 | } 49 | } 50 | 51 | export default ChatInputBox 52 | -------------------------------------------------------------------------------- /resources/js/components/ChatMessageList.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useRef, useState } from 'react' 2 | import { 3 | Col, 4 | Row 5 | } from 'reactstrap'; 6 | import Moment from 'react-moment'; 7 | import 'moment-timezone'; 8 | import { getAvatar } from './utils/echoHelpers'; 9 | import UserProfileModal from './UserProfileModal'; 10 | import NavbarText from 'reactstrap/lib/NavbarText'; 11 | 12 | function ChatMessageList(props) { 13 | 14 | // Equivalent of a Div ID in React, remains even across re-renders 15 | const bottomRef = useRef(null); 16 | 17 | 18 | 19 | // function to scroll to dummy div places at the bottom of message list 20 | const scrollToBottom = () => { 21 | bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) 22 | } 23 | 24 | const messages = props.messages; 25 | // console.log(typeof(messages)); 26 | 27 | const typingArray = props.typings; 28 | const typingArrayReady = typingArray.map((value,index) => { 29 | return
30 | 31 |
32 | 33 |
34 |
35 |
36 | 37 | {value.user.name} is typing... 38 |
39 |
40 | }); 41 | 42 | const messagelist = messages.map((value, index) => { 43 | // console.log(value) 44 | // if(value.type === 'typing') { 45 | // const typingBubble =
46 | // 47 | //
48 | // 49 | //
50 | //
51 | //
52 | // 53 | // {value.user.name} is typing... 54 | //
55 | //
56 | 57 | // setTypingArray([ 58 | // ...typingArray, 59 | // typingBubble 60 | // ]); 61 | 62 | 63 | // } 64 | if(value.status === true) { 65 | return {value.user.name} has {value.message} the channel 66 | } else { 67 | if(value.user.name !== props.currUser.name) { 68 | value.user.avatar = value.user.details.avatar; 69 | return ( 70 |
71 | 72 | 73 |
74 | 75 | 76 | 82 |

{value.message} 83 |
84 | 85 | 89 |
90 |
91 | ); 92 | } else { 93 | value.user.avatar = value.user.details.avatar; 94 | 95 | return ( 96 |
97 |
98 | 99 | 100 | {value.message} 101 | 102 | 103 | 104 |
105 | 106 | 107 |
108 | ) 109 | } 110 | } 111 | }); 112 | 113 | // Runs on every re-render 114 | useEffect(() => { 115 | scrollToBottom(); 116 | }, [messagelist]); 117 | 118 | return ( 119 | 120 | {messagelist} 121 | {typingArrayReady} 122 |
123 | 124 | ) 125 | } 126 | 127 | export default ChatMessageList; -------------------------------------------------------------------------------- /resources/js/components/ChatRoomUsersList.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Col } from "reactstrap"; 3 | 4 | export const ChatRoomUsersList = props => { 5 | const onlineUsers = props.usersInRoom; 6 | const allUsers = props.selectedChannel.users; 7 | const allUsersLen = allUsers.length; 8 | 9 | console.log("ALL USERS OUTPUT BELOW"); 10 | console.log(allUsers); 11 | const userInRoomList = onlineUsers.map((value, index) => { 12 | return ( 13 |
14 | 15 | {value.name} 16 |
17 | ); 18 | }); 19 | 20 | function processOfflineUsersArray(allUsers, onlineUsers) { 21 | 22 | for(var i = 0, len = onlineUsers.length; i < len; i++) { 23 | for( var j = 0, len2 = allUsers.length; j < len2; j++) { 24 | if (allUsers[j].id === onlineUsers[i].id) { 25 | allUsers.splice(j, 1); 26 | len2=allUsers.length; 27 | } 28 | } 29 | } 30 | 31 | return allUsers; 32 | 33 | console.log(a); 34 | console.log(b); 35 | } 36 | 37 | let offlineUsers = processOfflineUsersArray( allUsers, onlineUsers) 38 | console.log("VARR OFFLINE USERS OUTPUT BELOW"); 39 | console.log(offlineUsers); 40 | 41 | offlineUsers = offlineUsers.map((value, index) => { 42 | return ( 43 |
44 | 45 | {value.name} 46 |
47 | ); 48 | }); 49 | 50 | 51 | return ( 52 | 53 |

Members List

54 |

55 |
Active ( {onlineUsers.length} )
56 | {userInRoomList} 57 |
Offline ( {offlineUsers.length} )
58 | {offlineUsers} 59 | 60 | ); 61 | }; 62 | 63 | export default ChatRoomUsersList; 64 | -------------------------------------------------------------------------------- /resources/js/components/CreateChannelModal.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Button,Alert, Modal, ModalHeader, ModalBody, ModalFooter, Form, FormGroup, Label, Input, FormText } from 'reactstrap'; 3 | import {connect} from 'react-redux'; 4 | import PropTypes from 'prop-types'; 5 | import { CreateChannel } from '../actions/chatActions'; 6 | 7 | class CreateChannelModal extends Component { 8 | 9 | state = { 10 | toggle:false, 11 | modal:false, 12 | channelName:"", 13 | description:"", 14 | type:"", 15 | visible:true, 16 | } 17 | 18 | static propTypes = { 19 | CreateChannel: PropTypes.func.isRequired 20 | } 21 | 22 | 23 | toggle = (e) => { 24 | e.stopPropagation(); 25 | e.preventDefault(); 26 | this.setState({ modal : !this.state.modal}); 27 | } 28 | onChange = (e) => { 29 | e.stopPropagation(); 30 | e.preventDefault(); 31 | this.setState({ [e.target.name]: e.target.value }); 32 | }; 33 | 34 | onCheck = (e) => { 35 | e.stopPropagation(); 36 | e.preventDefault(); 37 | this.setState({ visible : !this.state.visible}); 38 | } 39 | 40 | onSubmit = (e) => { 41 | e.preventDefault(); 42 | const { channelName, description, type, visible } = this.state; 43 | console.log("in form submit function"); 44 | const channelData = { channelName, description, type, visible }; 45 | this.props.CreateChannel(channelData); 46 | } 47 | 48 | render() { 49 | return ( 50 |
51 | 52 | 53 | Create A New Channel 54 | 55 | 56 | You can create a new channel using this modal, you will be the owner of the channel 57 | and can invite or remove members, set visibility/privacy settings etc. 58 | 59 |
60 | 61 | 62 | 67 | 68 | 69 | 70 | 71 | 76 | 77 | 78 | 79 | 80 | {' '} 81 | 84 | 85 | 86 | {' '} 87 | 90 | 91 | 92 | 93 | 94 | 95 | {' '} 96 | 99 | 100 | Check this box to make your channel not visible in searches and undiscoverable in the public channels list. 101 |

102 | Leave unchecked for public visibility 103 |
104 |
105 |
106 | 107 |
108 | 109 | {' '} 110 | 111 | 112 |
113 |
114 | ); 115 | } 116 | 117 | } 118 | 119 | 120 | export default connect( null, {CreateChannel})(CreateChannelModal); -------------------------------------------------------------------------------- /resources/js/components/Home.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import HomeNav from './HomeNav' 3 | 4 | export class Home extends Component { 5 | render() { 6 | return ( 7 |
8 | 9 |
10 |
11 |

Realtime Chat powered by WebSockets

12 |

Laravel React Chat is Single Page Web App that provides full fat Realtime Chat functionality. 13 | Like User-to-User Direct Messaging, Group Channels, Offline/Online status events and other SM features like Avatar uploading and Realtime Notifications 14 |

15 |

16 |

Utilizing ReactJS and Redux for the SPA, PHP on Laravel for the WebSocket server and Backend API, backed by a PostgresSQL Database.

17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 |

28 |

For the Motivations behind this project, Challenges Faced, Lessons Learned and more detailed Features List, 29 | Check the Project Details page.

30 |
31 |
32 |
33 | ) 34 | } 35 | } 36 | 37 | export default Home 38 | -------------------------------------------------------------------------------- /resources/js/components/HomeNav.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { 3 | Navbar, 4 | NavbarToggler, 5 | NavbarBrand, 6 | Nav, 7 | NavItem, 8 | NavLink, 9 | NavbarText, 10 | Collapse, 11 | Row 12 | } from 'reactstrap'; 13 | 14 | const HomeNav = (props) => { 15 | const [isOpen, setIsOpen] = useState(false); 16 | 17 | const toggle = () => setIsOpen(!isOpen); 18 | 19 | return ( 20 |
21 | 22 | 23 | 24 |

Laravel 25 | React Chat 26 |

27 | Made by Shawn D'silva 28 |
29 |
30 | 31 | 32 | 46 | 47 |
48 |
49 | ); 50 | } 51 | 52 | export default HomeNav; -------------------------------------------------------------------------------- /resources/js/components/InviteUsersModal.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Button, Modal, ModalHeader, ModalBody, ModalFooter , Col, UncontrolledTooltip} from 'reactstrap'; 3 | 4 | const InviteUsersModal = (props) => { 5 | const { 6 | buttonLabel, 7 | className, 8 | dmUsers, 9 | currUser, 10 | selectedChannel, 11 | inviteToChannel, 12 | } = props; 13 | 14 | const [modal, setModal] = useState(false); 15 | 16 | const toggle = () => setModal(!modal); 17 | 18 | const users = dmUsers; 19 | 20 | const userList = users.map((value, index) => { 21 | return ( 22 | 23 | 24 | 28 | 33 |

34 |

35 | 36 | 37 | 38 | ); 39 | }); 40 | 41 | 42 | return ( 43 |
44 | 45 | Invite Users 46 | 47 | 49 | 50 | Invite Users to your Channel 51 | 52 | 53 | Select Users you wish to invite to your channel 54 |
Friends
55 | {userList} 56 |
57 | 58 | {' '} 59 | 60 | 61 |
62 |
63 | ); 64 | } 65 | 66 | export default InviteUsersModal; -------------------------------------------------------------------------------- /resources/js/components/Landing.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { withRouter } from 'react-router-dom'; 3 | import Button from 'reactstrap/lib/Button'; 4 | 5 | export class Landing extends Component { 6 | 7 | componentDidMount() { 8 | 9 | let tokenValue = localStorage.getItem("LRC_Token"); 10 | 11 | axios.defaults.headers.common["Authorization"] = 12 | "Bearer " + tokenValue; 13 | 14 | axios.get("/api/auth/user") 15 | .then((res) =>{ 16 | // if(res.status === 201) { 17 | console.log(res.data.user); 18 | // } 19 | }) 20 | .catch((err) => { 21 | 22 | }); 23 | } 24 | 25 | 26 | 27 | 28 | render() { 29 | 30 | return ( 31 |
32 | 37 |
38 | ) 39 | } 40 | } 41 | 42 | export default withRouter(Landing); 43 | -------------------------------------------------------------------------------- /resources/js/components/LoadingSpinner.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Spinner } from "reactstrap"; 3 | export class LoadingSpinner extends Component { 4 | render() { 5 | return ( 6 |
7 |
8 | 12 |

LOADING...

13 |
14 |
15 | ); 16 | } 17 | } 18 | 19 | export default LoadingSpinner; 20 | -------------------------------------------------------------------------------- /resources/js/components/Login.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { 3 | Button, 4 | Form, 5 | FormGroup, 6 | Label, 7 | Input, 8 | UncontrolledAlert 9 | } from "reactstrap"; 10 | import { withRouter } from 'react-router-dom'; 11 | import {connect} from 'react-redux'; 12 | import PropTypes from 'prop-types'; 13 | import { login, getUser } from '../actions/authActions'; 14 | import {AuthContainer} from './AuthContainer'; 15 | 16 | class Login extends Component { 17 | 18 | state = { 19 | name: "", 20 | email: "", 21 | password: "", 22 | msg:"" 23 | }; 24 | 25 | static propTypes = { 26 | isAuthenticated: PropTypes.bool.isRequired, 27 | currUser: PropTypes.object.isRequired, 28 | token: PropTypes.string, 29 | login: PropTypes.func.isRequired, 30 | getUser: PropTypes.func.isRequired, 31 | status: PropTypes.object.isRequired, 32 | 33 | } 34 | 35 | componentDidUpdate(prevProps) { 36 | const status = this.props.status; 37 | 38 | if (status !== prevProps.status) { 39 | 40 | if (status.id === "LOGIN_FAIL") { 41 | this.setState({ msg: status.statusMsg.message }); 42 | } 43 | } 44 | }; 45 | 46 | onChange = (e) => { 47 | this.setState({ [e.target.name]: e.target.value }); 48 | }; 49 | 50 | // Calls action to register user 51 | onSubmit = (e) => { 52 | e.preventDefault(); 53 | const { email, password} = this.state; 54 | 55 | const user = { email, password}; 56 | this.props.login(user, this.props.history); 57 | // this.props.history.push(chat) 58 | 59 | // this.props.getUser(); 60 | 61 | // this.setState({isLoading:true}); 62 | 63 | // const { name, email, password } = this.state; 64 | 65 | // const body = JSON.stringify({ name, email, password }); 66 | 67 | // const headers = { 68 | // headers: { 69 | // "Content-Type": "application/json" 70 | // } 71 | // }; 72 | 73 | // axios 74 | // .post("/api/auth/login", body, headers) 75 | // .then((res) =>{ 76 | // if(res.status === 200) { 77 | // console.log(res); 78 | // console.log(res.data.user); 79 | // localStorage.setItem("LRC_Token", res.data.token); 80 | // console.log(localStorage.LRC_Token); 81 | // this.props.history.push("/chat") 82 | // // window.location.reload(); 83 | 84 | // } 85 | // }) 86 | // .catch((err) => { 87 | // const errors = err.response.data.errors; 88 | // console.log(errors); 89 | // Object.values(errors).map( error => { 90 | // console.log(error.toString()); 91 | // }); 92 | // }); 93 | 94 | 95 | }; 96 | 97 | 98 | render() { 99 | return ( 100 | 101 |
102 |

LOGIN

103 |

Don't have an account? Register.

104 | 105 | {this.state.msg ? ( 106 | {this.state.msg} 107 | ) : null} 108 | 109 | 110 | 111 | 121 | 122 | 123 | 133 | 137 | 138 |
139 |
140 | ) 141 | } 142 | } 143 | 144 | const mapStateToProps = (state) => ({ 145 | isAuthenticated: state.auth.isAuthenticated, 146 | currUser: state.auth.currUser, 147 | token: state.auth.token, 148 | status: state.status, 149 | 150 | }); 151 | 152 | export default connect(mapStateToProps, { login,getUser })(withRouter(Login)); 153 | -------------------------------------------------------------------------------- /resources/js/components/Main.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { Route, Switch } from 'react-router-dom'; 3 | import Login from './Login'; 4 | import Register from './Register'; 5 | import Home from './Home'; 6 | import Landing from './Landing'; 7 | import Chat from './Chat'; 8 | 9 | import { connect } from "react-redux"; 10 | import LoadingSpinner from './LoadingSpinner'; 11 | import ProtectedRoute from './router/ProtectedRoute'; 12 | import ProtectedRouteIfAuth from './router/ProtectedRouteIfAuth'; 13 | 14 | export class Main extends Component { 15 | render() { 16 | console.log(this.props.isAuthenticated); 17 | if(this.props.isAuthenticated === true || this.props.isAuthenticated === false) { 18 | return ( 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ) 27 | } else { 28 | return 29 | 30 | } 31 | } 32 | } 33 | 34 | const mapStateToProps = (state) => ({ 35 | //Maps state to redux store as props 36 | isAuthenticated: state.auth.isAuthenticated, 37 | auth: state.auth.user 38 | }); 39 | 40 | export default connect(mapStateToProps)(Main); 41 | -------------------------------------------------------------------------------- /resources/js/components/NotificationDropdown.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem, Button, div, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; 3 | import Row from 'reactstrap/lib/Row'; 4 | import { markAsRead } from '../actions/chatActions'; 5 | 6 | const NotificationDropdown = (props) => { 7 | const [dropdownOpen, setDropdownOpen] = useState(false); 8 | 9 | const toggle = () => setDropdownOpen(prevState => !prevState); 10 | 11 | const [modal, setModal] = useState(false); 12 | const [modalAN, setANModal] = useState(false); 13 | const [value, setValue] = useState([]); 14 | 15 | 16 | const toggleModal = () => setModal(!modal); 17 | const toggleModalAN = () => setANModal(!modalAN); 18 | 19 | const { notifications, allNotifications, acceptRequest, getAllNotifications, unreadNotifs, markAsRead } = props; 20 | 21 | const notificationsList = notifications.map((value, index) => { 22 | return ( 23 | acceptModalWrapper(value)} > 24 | {value.data.sender_name} {value.data.desc} 25 |

26 |
27 | ); 28 | }); 29 | 30 | 31 | const allNotificationsList = allNotifications.map((value, index) => { 32 | return ( 33 | acceptModalWrapper(value)} > 34 | {value.data.sender_name} {value.data.desc} 35 |

36 |
37 | ); 38 | }) 39 | 40 | function acceptRequestWrapper(invite_id, type) { 41 | acceptRequest(invite_id, type); 42 | toggleModal(); 43 | } 44 | 45 | function getAllNotificationsWrapper() { 46 | getAllNotifications(); 47 | toggleModalAN(); 48 | } 49 | 50 | function acceptModalWrapper(value) { 51 | markAsRead(value.id); 52 | setValue(value.data); 53 | toggleModal(); 54 | } 55 | 56 | function AcceptModal({sender_name, desc, toggleModal, modal, invite_id, recv_channel,request_type }) { 57 | 58 | let msg = ''; 59 | switch(request_type) { 60 | case 'FRND': 61 | msg = Do you want to accept {sender_name}'s friend request and add them to your Direct Message list? 62 | break; 63 | case 'JOIN': 64 | msg = Do you want to accept {sender_name}'s join request and add them to your channel {recv_channel} ?; 65 | break; 66 | case 'INVT': 67 | msg = Do you want to accept {sender_name}'s invite and join their channel {recv_channel} ?; 68 | break; 69 | default: 70 | null; 71 | } 72 | return ( 73 |
74 | 75 | 76 | Accept Request 77 | 78 | {sender_name} {desc} 79 |

80 |

81 | {msg} 82 |
83 | 84 | 85 | 86 | 87 | 88 | 89 |
90 |
91 | ) 92 | } 93 | 94 | function AllNotificationsModal({modalAN, toggleModalAN}) { 95 | 96 | return ( 97 |
98 | 99 | 100 | All Notifications 101 | 102 | {allNotificationsList} 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
111 | ) 112 | } 113 | 114 | return ( 115 | 116 | 117 | 118 | 119 | 120 |
{unreadNotifs}
121 |
122 | 123 | Your Notifications 124 | 125 | {notificationsList} 126 | 127 | 128 | 129 | Show All Notifications 130 | 131 | 132 | 133 | 134 |
135 | ); 136 | } 137 | 138 | export default NotificationDropdown; -------------------------------------------------------------------------------- /resources/js/components/Register.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { 3 | Button, 4 | Form, 5 | FormGroup, 6 | Label, 7 | Input, 8 | UncontrolledAlert 9 | } from "reactstrap"; 10 | import { withRouter } from 'react-router-dom'; 11 | import {connect} from 'react-redux'; 12 | import PropTypes from 'prop-types'; 13 | import { register } from '../actions/authActions'; 14 | import AuthContainer from './AuthContainer'; 15 | 16 | class Register extends Component { 17 | 18 | state = { 19 | name: "", 20 | email: "", 21 | password: "", 22 | msg:"" 23 | }; 24 | 25 | static propTypes = { 26 | register: PropTypes.func.isRequired, 27 | getUser: PropTypes.func.isRequired, 28 | status: PropTypes.object.isRequired, 29 | } 30 | 31 | componentDidUpdate(prevProps) { 32 | const status = this.props.status; 33 | 34 | if (status !== prevProps.status) { 35 | 36 | if (status.id === "REGISTER_FAIL") { 37 | this.setState({ msg: status.statusMsg.message }); 38 | } 39 | if (status.id === "REGISTER_SUCCESS") { 40 | this.setState({ msg: status.statusMsg.message }); 41 | setTimeout(() => { 42 | this.props.history.push("/login"); 43 | }, 2000); 44 | } 45 | } 46 | }; 47 | 48 | onChange = (e) => { 49 | this.setState({ [e.target.name]: e.target.value }); 50 | }; 51 | 52 | // Calls action to register user 53 | onSubmit = (e) => { 54 | e.preventDefault(); 55 | 56 | const { name, email, password } = this.state; 57 | 58 | const body = { name, email, password }; 59 | this.props.register(body) 60 | // const headers = { 61 | // headers: { 62 | // "Content-Type": "application/json" 63 | // } 64 | // }; 65 | 66 | // axios 67 | // .post("/api/auth/register", body, headers) 68 | // .then((res) =>{ 69 | // if(res.status === 201) { 70 | // console.log(res.data.message); 71 | // } 72 | // }) 73 | // .catch((err) => { 74 | // const errors = err.response.data.errors; 75 | // console.log(errors); 76 | // Object.values(errors).map( error => { 77 | // console.log(error.toString()); 78 | // }); 79 | // }); 80 | }; 81 | 82 | render() { 83 | return ( 84 | 85 |
86 |

REGISTER

87 |

Already have an account? Login.

88 | {this.props.status.id === "REGISTER_SUCCESS" ? ( 89 | {this.state.msg} 90 | ) : ( this.props.status.id === "REGISTER_FAIL" && 91 | {this.state.msg} ) 92 | } 93 | 94 | 95 | 105 | 106 | 107 | 117 | 118 | 119 | 129 | 133 | 134 |
135 |
136 | ) 137 | } 138 | } 139 | 140 | const mapStateToProps = (state) => ({ 141 | status: state.status, 142 | }); 143 | 144 | export default connect(mapStateToProps, { register })(withRouter(Register)); 145 | -------------------------------------------------------------------------------- /resources/js/components/UserProfileModal.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input } from 'reactstrap'; 3 | 4 | const UserProfileModal = (props) => { 5 | const { 6 | className, 7 | user, 8 | currUser, 9 | editDesc, 10 | userDetailsClass, 11 | addFriend 12 | } = props; 13 | 14 | const [modal, setModal] = useState(false); 15 | const [isEditOpen, setEdit] = useState(false); 16 | const [userDesc, setUserDesc] = useState(null); 17 | 18 | const toggle = () => setModal(!modal); 19 | const toggleEdit = () => { 20 | setEdit(!isEditOpen); 21 | if(isEditOpen) { 22 | editDesc(userDesc); 23 | setEdit(false); 24 | } 25 | }; 26 | 27 | const onChange = (e) => { 28 | setUserDesc(e.target.value); 29 | }; 30 | 31 | 32 | 33 | return ( 34 |
35 |
{ 36 | user.avatar ? 37 | : 38 | 39 | } 40 | {user.name} 41 | {console.log(user)} 42 |
43 | 44 | User Profile 45 | 46 | 47 | {user.name} 48 | {user.id !== currUser.id && } 49 |
50 |

About

51 | { user.id === currUser.id && } 52 |
53 |

54 | { isEditOpen === true ? : 55 | (user.desc ? user.desc : "This user prefers to keep an air of mystery about themselves...") } 56 |

57 |
58 |
59 |
60 | ); 61 | } 62 | 63 | export default UserProfileModal; -------------------------------------------------------------------------------- /resources/js/components/cropImage.js: -------------------------------------------------------------------------------- 1 | const createImage = url => 2 | new Promise((resolve, reject) => { 3 | const image = new Image() 4 | image.addEventListener('load', () => resolve(image)) 5 | image.addEventListener('error', error => reject(error)) 6 | image.setAttribute('crossOrigin', 'anonymous') // needed to avoid cross-origin issues on CodeSandbox 7 | image.src = url 8 | }) 9 | 10 | function getRadianAngle(degreeValue) { 11 | return (degreeValue * Math.PI) / 180 12 | } 13 | 14 | /** 15 | * This function was adapted from the one in the ReadMe of https://github.com/DominicTobias/react-image-crop 16 | * @param {File} image - Image File url 17 | * @param {Object} pixelCrop - pixelCrop Object provided by react-easy-crop 18 | * @param {number} rotation - optional rotation parameter 19 | */ 20 | export default async function getCroppedImg(imageSrc, pixelCrop, rotation = 0) { 21 | const image = await createImage(imageSrc) 22 | const canvas = document.createElement('canvas') 23 | const ctx = canvas.getContext('2d') 24 | 25 | const maxSize = Math.max(image.width, image.height) 26 | const safeArea = 2 * ((maxSize / 2) * Math.sqrt(2)) 27 | 28 | // set each dimensions to double largest dimension to allow for a safe area for the 29 | // image to rotate in without being clipped by canvas context 30 | canvas.width = safeArea 31 | canvas.height = safeArea 32 | 33 | // translate canvas context to a central location on image to allow rotating around the center. 34 | ctx.translate(safeArea / 2, safeArea / 2) 35 | ctx.rotate(getRadianAngle(rotation)) 36 | ctx.translate(-safeArea / 2, -safeArea / 2) 37 | 38 | // draw rotated image and store data. 39 | ctx.drawImage( 40 | image, 41 | safeArea / 2 - image.width * 0.5, 42 | safeArea / 2 - image.height * 0.5 43 | ) 44 | const data = ctx.getImageData(0, 0, safeArea, safeArea) 45 | 46 | // set canvas width to final desired crop size - this will clear existing context 47 | canvas.width = pixelCrop.width 48 | canvas.height = pixelCrop.height 49 | 50 | // paste generated rotate image with correct offsets for x,y crop values. 51 | ctx.putImageData( 52 | data, 53 | Math.round(0 - safeArea / 2 + image.width * 0.5 - pixelCrop.x), 54 | Math.round(0 - safeArea / 2 + image.height * 0.5 - pixelCrop.y) 55 | ) 56 | 57 | // As Base64 string 58 | // return canvas.toDataURL('image/jpeg'); 59 | 60 | // As a blob 61 | return new Promise(resolve => { 62 | canvas.toBlob(file => { 63 | resolve(file) 64 | }, 'image/jpeg') 65 | }) 66 | } -------------------------------------------------------------------------------- /resources/js/components/router/MainRouter.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { connect } from "react-redux"; 3 | // import { isAuth } from "../../actions/authActions"; 4 | // import HomePage from '../HomePage'; 5 | // import Profile from '../Profile'; 6 | // import ListPage from '../ListPage'; 7 | // import SingleList from '../SingleList'; 8 | import { withRouter, Switch} from 'react-router-dom' 9 | import ProtectedRoute from './ProtectedRoute'; 10 | import ProtectedRouteIfAuth from './ProtectedRouteIfAuth'; 11 | import LoadingSpinner from '../LoadingSpinner'; 12 | import PropTypes from 'prop-types'; 13 | 14 | // import Error404 from '../Error404'; 15 | import Chat from "../Chat"; 16 | 17 | 18 | 19 | export class MainRouter extends Component { 20 | // authChecker = () => { 21 | // isAuth().then(() => { 22 | // // if(this.props.isAuthenticated === true ) { 23 | // // const isAuthenticated = true; 24 | // // return isAuthenticated; 25 | // // } 26 | // return this.props.isAuthenticated 27 | // }); 28 | // }; 29 | 30 | // static propTypes = { 31 | // isAuthenticated: PropTypes.bool.isRequired, 32 | 33 | // } 34 | 35 | render() { 36 | console.log(this.props.auth.isAuthenticated); 37 | console.log(this.props.isAuthenticated); 38 | 39 | if(this.props.isAuthenticated === true || this.props.isAuthenticated === false) { 40 | return ( 41 | 42 | {/* */} 48 | 54 | {/* */} 60 | 61 | 62 | 63 | {/* */} 64 | 65 | ); 66 | } else { 67 | return 68 | } 69 | } 70 | } 71 | 72 | const mapStateToProps = (state) => ({ 73 | //Maps state to redux store as props 74 | isAuthenticated: state.auth.isAuthenticated, 75 | }); 76 | 77 | export default connect(mapStateToProps)(withRouter(MainRouter)); 78 | -------------------------------------------------------------------------------- /resources/js/components/router/ProtectedRoute.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Route, Redirect } from 'react-router-dom' 3 | 4 | 5 | function ProtectedRoute ({component: Component, isAuthenticated, ...rest}) { 6 | return ( 7 | isAuthenticated === true 10 | ? 11 | : } 12 | /> 13 | ) 14 | } 15 | 16 | // function ProtectedRoute({ children, ...rest }) { 17 | // return ( 18 | // 21 | // this.props.isAuthenticated ? ( 22 | // children 23 | // ) : ( 24 | // 30 | // ) 31 | // } 32 | // /> 33 | // ); 34 | // } 35 | 36 | export default ProtectedRoute; -------------------------------------------------------------------------------- /resources/js/components/router/ProtectedRouteIfAuth.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Route, Redirect } from 'react-router-dom' 3 | 4 | 5 | function ProtectedRoute ({component: Component, isAuthenticated, ...rest}) { 6 | return ( 7 | { 10 | if(isAuthenticated === false) { 11 | return 12 | } else { 13 | console.log(props); 14 | const loc = props.location.pathname; 15 | console.log(loc); 16 | if ((loc === '/' || loc === '/login' || loc === '/register') && props.location.state === undefined) { 17 | //Redirects all routes that are root /, /login or /register to /listpage if there are no previous routes in state 18 | return 19 | } else { 20 | return 21 | } 22 | } 23 | }} 24 | /> 25 | ) 26 | } 27 | 28 | // function ProtectedRoute({ children, ...rest }) { 29 | // return ( 30 | // 33 | // this.props.isAuthenticated ? ( 34 | // children 35 | // ) : ( 36 | // 42 | // ) 43 | // } 44 | // /> 45 | // ); 46 | // } 47 | 48 | export default ProtectedRoute; -------------------------------------------------------------------------------- /resources/js/components/utils/echoHelpers.js: -------------------------------------------------------------------------------- 1 | import Echo from "laravel-echo"; 2 | import axios from "axios"; 3 | import store from "../../store"; 4 | import { IS_ONLINE, IS_OFFLINE } from "../../actions/types"; 5 | 6 | export const echoInit = (token) => { 7 | window.Pusher = require("pusher-js"); 8 | 9 | window.Echo = new Echo({ 10 | broadcaster: "pusher", 11 | key: process.env.MIX_PUSHER_APP_KEY, 12 | wsHost: process.env.MIX_WS_HOST_URL, 13 | wsPort: 6001, 14 | wssPort: 6001, 15 | disableStats: false, 16 | forceTLS: false, 17 | authEndpoint: process.env.MIX_AUTH_ENDPOINT, 18 | }); 19 | 20 | window.Echo.connector.options.auth.headers["Authorization"] = 21 | "Bearer " + token; 22 | window.Echo.options.auth = { 23 | headers: { 24 | Authorization: "Bearer " + token, 25 | }, 26 | }; 27 | 28 | window.Echo.join("chat") 29 | .here((users) => { 30 | console.log(" IN HERE INSIDE ECHOHELPERS CHAT"); 31 | console.log(users); 32 | }) 33 | .joining((user) => { 34 | const headersObj = { 35 | headers: { 36 | "Content-type": "application/json", 37 | }, 38 | }; 39 | 40 | axios.get(`/api/online/${user.id}`, headersObj, { 41 | withCredentials: true, 42 | }); 43 | }) 44 | .leaving((user) => { 45 | const headersObj = { 46 | headers: { 47 | "Content-type": "application/json", 48 | }, 49 | }; 50 | 51 | console.log("IN LEAVING "); 52 | axios.get(`/api/offline/${user.id}`, headersObj, { 53 | withCredentials: true, 54 | }); 55 | }) 56 | .listen("UserOnline", (event) => { 57 | console.log(event.user.name + " IS ONLINE "); 58 | console.log(event.user); 59 | store.dispatch({ type: IS_ONLINE, payload: event.user.id }); 60 | }) 61 | .listen("UserOffline", (event) => { 62 | console.log(event.user.name + " IS OFFLINE "); 63 | console.log(event.user); 64 | store.dispatch({ type: IS_OFFLINE, payload: event.user.id }); 65 | }); 66 | }; 67 | 68 | export const sendMessage = (message, channel_id, channel_type) => { 69 | const body = JSON.stringify({ message, channel_id, channel_type }); 70 | 71 | const postHeaders = { 72 | headers: { 73 | Authorization: "Bearer " + localStorage.getItem("LRC_Token"), 74 | "Content-Type": "application/json", 75 | }, 76 | }; 77 | axios 78 | .post("/api/messages", body, postHeaders) 79 | .then((res) => { 80 | console.log(res); 81 | }) 82 | .catch((err) => { 83 | const errors = err.response.data.errors; 84 | console.log(errors); 85 | Object.values(errors).map((error) => { 86 | console.log(error.toString()); 87 | }); 88 | }); 89 | }; 90 | 91 | export const getAvatar = (value) => { 92 | let details = value.details; 93 | if (!details) { 94 | return "avatars/defaultuser.png"; 95 | } else { 96 | return details.avatar; 97 | } 98 | }; 99 | -------------------------------------------------------------------------------- /resources/js/index.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | require('./bootstrap'); 4 | import React from 'react'; 5 | import ReactDOM from 'react-dom'; 6 | import App from './App'; 7 | import { BrowserRouter } from 'react-router-dom' 8 | import { Provider } from "react-redux"; 9 | 10 | 11 | ReactDOM.render( 12 | 13 | 14 | 15 | , document.getElementById('root')); 16 | -------------------------------------------------------------------------------- /resources/js/reducers/authReducer.js: -------------------------------------------------------------------------------- 1 | import { 2 | 3 | AUTH_ERROR, 4 | LOGIN_SUCCESS, 5 | LOGIN_FAIL, 6 | LOGOUT_SUCCESS, 7 | REGISTER_SUCCESS, 8 | REGISTER_FAIL, 9 | AUTH_SUCCESS, 10 | AUTH_FAIL, 11 | USER_AVATAR_UPDATED, 12 | USER_DESC_UPDATED, 13 | } from "../actions/types"; 14 | 15 | 16 | const initialState = { 17 | token: localStorage.getItem('token'), 18 | isAuthenticated: null, 19 | currUser: {}, 20 | }; 21 | 22 | export default function (state = initialState, action) { 23 | 24 | switch (action.type) { 25 | 26 | case AUTH_SUCCESS: 27 | return { 28 | ...state, 29 | isAuthenticated: true, 30 | currUser: action.payload 31 | }; 32 | case LOGIN_SUCCESS: 33 | localStorage.setItem('token', action.payload.token); 34 | return { 35 | ...state, 36 | isAuthenticated: true, 37 | token: localStorage.getItem('token'), 38 | }; 39 | 40 | case AUTH_ERROR: 41 | case LOGIN_FAIL: 42 | case LOGOUT_SUCCESS: 43 | case REGISTER_SUCCESS: 44 | case REGISTER_FAIL: 45 | case AUTH_FAIL: 46 | localStorage.removeItem('token'); 47 | // window.Echo.disconnect(); 48 | return { 49 | ...state, 50 | isAuthenticated: false, 51 | user: null, 52 | }; 53 | 54 | case USER_AVATAR_UPDATED: 55 | // Correct way to update key in nested object 56 | return { 57 | ...state, 58 | currUser: { 59 | ...state.currUser, 60 | avatar:action.payload 61 | } 62 | }; 63 | case USER_DESC_UPDATED: 64 | return { 65 | ...state, 66 | currUser: { 67 | ...state.currUser, 68 | desc:action.payload 69 | } 70 | } 71 | default: 72 | return state; 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /resources/js/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers} from 'redux'; 2 | // import errorReducer from './errorReducer'; 3 | import authReducer from './authReducer'; 4 | import uiReducer from './uiReducer'; 5 | import statusReducer from './statusReducer'; 6 | import chatReducer from './chatReducer'; 7 | 8 | 9 | export default combineReducers({ 10 | // error: errorReducer, 11 | auth: authReducer, 12 | ui: uiReducer, 13 | status: statusReducer, 14 | chat: chatReducer 15 | }); 16 | -------------------------------------------------------------------------------- /resources/js/reducers/statusReducer.js: -------------------------------------------------------------------------------- 1 | import { GET_STATUS, CLEAR_STATUS} from '../actions/types'; 2 | 3 | const initialState = { 4 | statusMsg: {}, 5 | respCode: null, 6 | id: null 7 | } 8 | 9 | export default function(state = initialState, action) { 10 | switch(action.type) { 11 | case GET_STATUS: 12 | return { 13 | statusMsg: action.payload.msg, 14 | respCode: action.payload.status, 15 | id: action.payload.id 16 | } 17 | 18 | case CLEAR_STATUS: 19 | return { 20 | statusMsg: {}, 21 | respCode: null, 22 | id: null 23 | }; 24 | 25 | default: 26 | return state; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /resources/js/reducers/uiReducer.js: -------------------------------------------------------------------------------- 1 | import { 2 | BUTTON_CLICKED, 3 | BUTTON_RESET, 4 | IS_LOADING, 5 | } from "./../actions/types"; 6 | 7 | const initialState = { 8 | button: true 9 | }; 10 | 11 | export default function (state = initialState, action ) { 12 | switch (action.type) { 13 | case BUTTON_CLICKED: 14 | return { 15 | ...state, 16 | button: false 17 | }; 18 | 19 | case BUTTON_RESET: 20 | return { 21 | ...state, 22 | button: true 23 | }; 24 | 25 | case IS_LOADING: 26 | return { 27 | ...state, 28 | loading: !state.loading 29 | }; 30 | default: 31 | return state; 32 | } 33 | } -------------------------------------------------------------------------------- /resources/js/store.js: -------------------------------------------------------------------------------- 1 | import { createStore, applyMiddleware, compose } from 'redux' 2 | import thunk from 'redux-thunk'; 3 | import rootReducer from './reducers'; 4 | 5 | const initialState = {}; 6 | const middleware = [thunk]; 7 | const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 8 | 9 | const store = createStore(rootReducer, initialState, composeEnhancers( 10 | applyMiddleware(...middleware), 11 | // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() 12 | )); 13 | 14 | export default store; -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/sass/_variables.scss: -------------------------------------------------------------------------------- 1 | // Body 2 | $body-bg: #f8fafc; 3 | 4 | // Typography 5 | $font-family-sans-serif: 'Nunito', sans-serif; 6 | $font-size-base: 0.9rem; 7 | $line-height-base: 1.6; 8 | 9 | // Colors 10 | $blue: #3490dc; 11 | $indigo: #6574cd; 12 | $purple: #9561e2; 13 | $pink: #f66d9b; 14 | $red: #e3342f; 15 | $orange: #f6993f; 16 | $yellow: #ffed4a; 17 | $green: #38c172; 18 | $teal: #4dc0b5; 19 | $cyan: #6cb2eb; 20 | -------------------------------------------------------------------------------- /resources/sass/app.scss: -------------------------------------------------------------------------------- 1 | // Fonts 2 | @import url('https://fonts.googleapis.com/css?family=Nunito'); 3 | 4 | // Variables 5 | @import 'variables'; 6 | 7 | // Bootstrap 8 | @import '~bootstrap/scss/bootstrap'; 9 | 10 | .sidenav { 11 | border-right: solid 3px grey; 12 | } -------------------------------------------------------------------------------- /resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | {{ config('app.name', 'Laravel') }} 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | 'auth' 19 | ], function () { 20 | Route::post('login', 'AuthController@login'); 21 | Route::post('register', 'AuthController@register'); 22 | 23 | Route::group([ 24 | 'middleware' => ['auth:api', 'auth.online'] 25 | ], function() { 26 | Route::get('logout', 'AuthController@logout'); 27 | Route::get('user', 'AuthController@user'); 28 | }); 29 | }); 30 | 31 | Route::group([ 32 | 'middleware' => 'auth:api' 33 | ], function() { 34 | Route::post('messages', 'ChatController@sendMessage'); 35 | Route::get('messages/{channel_id}', 'ChatController@getMessages'); 36 | Route::get('getchannels', 'ChatController@getSubscribedChannels'); 37 | Route::get('getusers/{channel_id}', 'ChatController@getChannelsUsers'); 38 | Route::get('getallchannels', 'ChatController@getAllChannels'); 39 | Route::post('makerequest', 'ChatController@createInvite'); 40 | Route::get('acceptinvite/{invite_id}', 'ChatController@acceptRequest'); 41 | Route::get('online/{user_id}', 'ChatController@isOnline'); 42 | Route::get('offline/{user_id}', 'ChatController@isOffline'); 43 | Route::get('getfriendslist', 'ChatController@getFriendsList'); 44 | Route::get('notifications', 'ChatController@getNotifications'); 45 | Route::get('allnotifications', 'ChatController@getAllNotifications'); 46 | Route::get('markasread/{id}', 'ChatController@markNotificationAsRead'); 47 | Route::post('directmessage', 'ChatController@directMessage'); 48 | Route::get('allusers', 'AuthController@allUsersList'); 49 | Route::post('createchannel', 'ChatController@createChannel'); 50 | Route::post('joinchannel', 'ChatController@joinChannel'); 51 | Route::post('invitetochannel', 'ChatController@inviteToChannel'); 52 | Route::post('upload/profile', 'ImageUploadController@updateProfilePicture'); 53 | Route::post('editdesc', 'ChatController@updateUserDesc'); 54 | 55 | 56 | 57 | }); 58 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id)->whereHas('channels', function ($q) use ($channel_id) { 25 | $q->where('channel_id', $channel_id); 26 | })->first(); 27 | 28 | error_log($data); 29 | return $data; 30 | } 31 | // return $user; 32 | }); 33 | 34 | Broadcast::channel('chat.dm.{channel_id}', function ($user, $channel_id) { 35 | // return $user->id === Channel::find($channel_id)->user_id; 36 | return User::where('id', $user->id)->whereHas('channels', function ($q) use ($channel_id) { 37 | $q->where('channel_id', $channel_id); 38 | })->first(); 39 | }); 40 | 41 | Broadcast::channel('App.User.{id}', function ($user, $id) { 42 | return (int) $user->id === (int) $id; 43 | }); 44 | 45 | Broadcast::channel('event.acceptRequest.{id}', function ($user, $id) { 46 | return (int) $user->id === (int) $id; 47 | }); -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->describe('Display an inspiring quote'); 20 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('home'); 23 | 24 | Route::view('/{path?}', 'index'); 25 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | !.gitignore 2 | -------------------------------------------------------------------------------- /storage/app/public/avatars/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.react('resources/js/index.js', 'public/js') 15 | .sass('resources/sass/app.scss', 'public/css'); 16 | mix.browserSync({ 17 | proxy:'localhost:8000', 18 | ghostMode: false 19 | }); 20 | --------------------------------------------------------------------------------