Skip to content

Commit 21d4c95

Browse files
committed
Add File Sharing
1 parent 4a750d7 commit 21d4c95

22 files changed

+810
-111
lines changed

README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ return [
4242
'conversations_table' => 'conversations',
4343
'messages_table' => 'messages',
4444
'group_conversations_table' => 'group_conversations',
45-
'group_users_table' => 'group_users'
45+
'group_users_table' => 'group_users',
46+
'files_table' => 'files'
4647
],
4748
'channel' => [
4849
'new_conversation_created' => 'new-conversation-created',
4950
'chat_room' => 'chat-room',
5051
'group_chat_room' => 'group-chat-room'
52+
],
53+
'upload' => [
54+
'storage' => 'public'
5155
]
5256
];
5357
```
@@ -114,7 +118,9 @@ Run `npm run dev` to recompile your assets.
114118
## Features
115119

116120
- One To One Chat ( With Video Call )
121+
- Accept Message Request
117122
- Group Chat
123+
- File Sharing
118124

119125
## Usage
120126

@@ -129,12 +135,23 @@ $conversations = Chat::getAllConversations()
129135
<ul class="list-group">
130136
@foreach($conversations as $conversation)
131137
<li class="list-group-item">
138+
@if($conversation->message->conversation->is_accepted)
132139
<a href="#">
133140
<h2>{{$conversation->user->name}}</h2>
134141
@if(!is_null($conversation->message))
135142
<span>{{ substr($conversation->message->text, 0, 20)}}</span>
136143
@endif
137144
</a>
145+
@else
146+
<a href="#">
147+
<h2>{{$conversation->user->name}}</h2>
148+
@if($conversation->message->conversation->second_user_id == auth()->user()->id)
149+
<a href="accept_request_route" class="btn btn-xs btn-success">
150+
Accept Message Request
151+
</a>
152+
@endif
153+
</a>
154+
@endif
138155
</li>
139156
@endforeach
140157
@@ -154,6 +171,11 @@ $conversations = Chat::getAllConversations()
154171
Chat::startConversationWith($otherUserId);
155172
```
156173

174+
#### Accept Conversation
175+
```php
176+
Chat::acceptMessageRequest($conversationId);
177+
```
178+
157179
#### Get Conversation Messages
158180

159181
```php
@@ -222,14 +244,29 @@ Chat::removeMembersFromGroupConversation($groupConversationId, [ $otherUserId ,
222244
Chat::leaveFromGroupConversation($groupConversationId);
223245
```
224246

247+
## File Sharing
248+
249+
Run this command `php artisan storage:link`
250+
251+
#### Send Files in Conversation
252+
253+
```php
254+
Chat::sendFilesInConversation($conversationId , $request->file('files'));
255+
```
256+
257+
#### Send Files in Group Conversation
258+
259+
```php
260+
Chat::sendFilesInGroupConversation($groupConversationId , $request->file('files'));
261+
```
262+
225263
## ToDo
226264

227265
- Add Members to Group
228266
- Remove Member From Group
229267

230268
## Next Version
231269

232-
- File Sharing
233270
- Group Video Call
234271

235272
## Credits

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
],
2020
"require": {
2121
"php": ">=5.6.4",
22-
"predis/predis": "^1.1"
22+
"predis/predis": "^1.1",
23+
"dflydev/apache-mime-types": "^1.0",
2324
},
2425
"autoload": {
2526
"psr-4": {

config/laravel-video-chat.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
'conversations_table' => 'conversations',
2020
'messages_table' => 'messages',
2121
'group_conversations_table' => 'group_conversations',
22-
'group_users_table' => 'group_users'
22+
'group_users_table' => 'group_users',
23+
'files_table' => 'files'
2324
],
2425
'channel' => [
2526
'new_conversation_created' => 'new-conversation-created',
2627
'chat_room' => 'chat-room',
2728
'group_chat_room' => 'group-chat-room'
29+
],
30+
'upload' => [
31+
'storage' => 'public'
2832
]
2933
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddIsAcceptedColumnToConversationTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table(config('laravel-video-chat.table.conversations_table'), function (Blueprint $table) {
17+
$table->boolean('is_accepted')->default(false)->after('second_user_id');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateFilesTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create(config('laravel-video-chat.table.files_table'), function (Blueprint $table) {
17+
$table->increments('id');
18+
19+
$table->integer('conversation_id');
20+
$table->string('conversation_type');
21+
22+
$table->integer('message_id');
23+
24+
$table->integer('user_id');
25+
26+
$table->string('name');
27+
28+
$table->timestamps();
29+
});
30+
}
31+
32+
/**
33+
* Reverse the migrations.
34+
*
35+
* @return void
36+
*/
37+
public function down()
38+
{
39+
Schema::dropIfExists(config('laravel-video-chat.table.files_table'));
40+
}
41+
}

helper/helpers.php

+18
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,22 @@ function check()
1717
}
1818
}
1919

20+
}
21+
22+
if (! function_exists('human_file_size')) {
23+
24+
function human_file_size($bytes, $decimals = 2)
25+
{
26+
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
27+
$factor = floor((strlen($bytes) - 1) / 3);
28+
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
29+
}
30+
}
31+
32+
if (! function_exists('get_file_details')) {
33+
34+
function get_file_details($path)
35+
{
36+
return app('upload.manager')->fileDetails($path);
37+
}
2038
}

0 commit comments

Comments
 (0)