Skip to content

Commit

Permalink
"image upload and room function implemented"
Browse files Browse the repository at this point in the history
  • Loading branch information
mjjabarullah committed Jan 6, 2022
1 parent e1e0a15 commit e03d337
Show file tree
Hide file tree
Showing 35 changed files with 1,205 additions and 694 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MessageDeleteEvent implements ShouldBroadcast
class MessageDelete implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

use Dispatchable, InteractsWithSockets, SerializesModels;

public $id;
public $roomId;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($id)
public function __construct($id, $roomId)
{
$this->id = $id;
$this->roomId = $roomId;
}

/**
Expand All @@ -34,6 +35,6 @@ public function __construct($id)
*/
public function broadcastOn()
{
return new Channel('chat');
return new PresenceChannel("chat.$this->roomId");
}
}
6 changes: 2 additions & 4 deletions app/Events/MessageEvent.php → app/Events/NewMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class MessageEvent implements ShouldBroadcast
class NewMessage implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

Expand All @@ -32,7 +31,6 @@ public function __construct($message)
*/
public function broadcastOn()
{
return new Channel('chat');
return new PresenceChannel("chat.{$this->message->room_id}");
}

}
16 changes: 13 additions & 3 deletions app/Http/Livewire/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
namespace App\Http\Livewire;

use App\Models\Message;
use App\Models\Room;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class Chat extends Component
{
public User $user;
public Room $room;

public function mount(User $user, Room $room)
{
$this->user = $user;
$this->room = $room;
}

public function render()
{
return view('livewire.chat',[
'messages' => Message::orderBy('id', 'desc')->take(15)->get()
]);
return view('livewire.chat');
}
}
20 changes: 20 additions & 0 deletions app/Http/Livewire/ChatRight.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,28 @@

class ChatRight extends Component
{
public bool $showLoader = true;

protected function getListeners(): array
{
return [
'hideLoader',
'showLoader'
];
}

public function render()
{
return view('livewire.chat-right');
}

public function hideLoader()
{
$this->showLoader = false;
}

public function showLoader()
{
$this->showLoader = true;
}
}
19 changes: 19 additions & 0 deletions app/Http/Livewire/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@

namespace App\Http\Livewire;

use App\Models\Room;
use Livewire\Component;

class Header extends Component
{

public Room $room;
public bool $showMenu = false;

protected $listeners =['roomChanged'];

public function mount(Room $room){
$this->room = $room;
}

public function render()
{
return view('livewire.header');
}

public function roomChanged(Room $room){
$this->room = $room;
}

public function showMenu(){
$this->showMenu = !$this->showMenu;
}
}
Loading

0 comments on commit e03d337

Please sign in to comment.