Comments (11)
A elegant solution is use configuration model class file on configuration on config/musonza_chat.php. With this, is easily to change any model. Like:
'conversations_model_class' => \Musonza\Chat\Models\Conversation::class,
'messages_model_class' => \Musonza\Chat\Models\Message::class,
'message_notifications_model_class' => \Musonza\Chat\Models\MessageNotification::class,
'participation_model_class' => \Musonza\Chat\Models\Participation::class,
I'll create this and make a PR.
from chat.
I did a research. maybe it will work for you. Who knows, you did the same.
foreach (array_chunk($data,1000) as $t)
{
DB::table('table_name')->insert($t);
}
$i = 0;
foreach ($conversation->participants as $participation) {
$is_sender = ($message->participation_id == $participation->id) ? 1 : 0;
$notification[] = [
'messageable_id' => $participation->messageable_id,
'messageable_type' => $participation->messageable_type,
'message_id' => $message->id,
'participation_id' => $participation->id,
'conversation_id' => $conversation->id,
'is_seen' => $is_sender,
'is_sender' => $is_sender,
'created_at' => $message->created_at,
];
if($i>1000){
self::insert($notification);
$i = 0;
$notification=[]
}
$i++;
}
self::insert($notification);
from chat.
I'm understand. But how you override this method?
from chat.
I'm understand. But how you override this method?
the code below didn't work?
I did a research. maybe it will work for you. Who knows, you did the same.
foreach (array_chunk($data,1000) as $t) { DB::table('table_name')->insert($t); }
$i = 0; foreach ($conversation->participants as $participation) { $is_sender = ($message->participation_id == $participation->id) ? 1 : 0; $notification[] = [ 'messageable_id' => $participation->messageable_id, 'messageable_type' => $participation->messageable_type, 'message_id' => $message->id, 'participation_id' => $participation->id, 'conversation_id' => $conversation->id, 'is_seen' => $is_sender, 'is_sender' => $is_sender, 'created_at' => $message->created_at, ]; if($i>1000){ self::insert($notification); $i = 0; $notification=[] } $i++; } self::insert($notification);
from chat.
My doubt is about how override without change the original file (src/Models/MessageNotification.php).
from chat.
I am so sorry. I guess it's because this notification has fired up. It's like we can't manipulate it. The repo owner can help better.
@musonza
from chat.
I am so sorry. I guess it's because this notification has fired up. It's like we can't manipulate it. The repo owner can help better.
@musonza
Tks
from chat.
Good!
from chat.
@silasrm Yeah 20k is a lot. You can make a PR that adds a config option for batch insert and modify src/Models/MessageNotification.php
to check for the configuration
from chat.
@silasrm Yeah 20k is a lot. You can make a PR that adds a config option for batch insert and modify
src/Models/MessageNotification.php
to check for the configuration
@tolgatasci fix, modifing the insert to insert 1k per time. When will a new version be released?
from chat.
My temporary solution, without modification of files package:
- Add entry in PSR-4 autoload on composer.json
"autoload": {
"psr-4": {
....
"Musonza\\Chat\\Models\\": "app/Models/Chat/Overrider/"
}
},
- Execute composer dump-autoload
- Create a copy of original MessageNotification class and change to use Job to insert processing:
<?php
namespace Musonza\Chat\Models;
use App\Jobs\Chat\Message\CreateNotification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Log;
use Musonza\Chat\BaseModel;
use Musonza\Chat\ConfigurationManager;
class MessageNotification extends BaseModel
{
use SoftDeletes;
protected $table = ConfigurationManager::MESSAGE_NOTIFICATIONS_TABLE;
protected $fillable = ['messageable_id', 'messageable_type', 'message_id', 'conversation_id'];
protected $dates = ['deleted_at'];
/**
* Creates a new notification.
*
* @param Message $message
* @param Conversation $conversation
*/
public static function make(Message $message, Conversation $conversation)
{
self::createCustomNotifications($message, $conversation);
}
public function unReadNotifications(Model $participant)
{
return self::where([
['messageable_id', '=', $participant->getKey()],
['messageable_type', '=', $participant->getMorphClass()],
['is_seen', '=', 0],
])->get();
}
public static function createCustomNotifications($message, $conversation)
{
Log::debug('aaaaaaaaaaaaaaaaaaaaaa');
$notification = [];
$i = 0;
foreach ($conversation->participants as $participation) {
$is_sender = ($message->participation_id == $participation->id) ? 1 : 0;
$notification[] = [
'messageable_id' => $participation->messageable_id,
'messageable_type' => $participation->messageable_type,
'message_id' => $message->id,
'participation_id' => $participation->id,
'conversation_id' => $conversation->id,
'is_seen' => $is_sender,
'is_sender' => $is_sender,
'created_at' => $message->created_at,
];
$i++;
if ($i > 1000) {
CreateNotification::dispatch($notification);
$i = 0;
$notification = [];
}
}
CreateNotification::dispatch($notification);
}
public function markAsRead()
{
$this->is_seen = 1;
$this->update(['is_seen' => 1]);
$this->save();
}
}
- Create the job class:
<?php
namespace App\Jobs\Chat\Message;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class CreateNotification implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $data;
/**
* CreateNotification constructor.
* @param $data
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* @throws Exception
*/
public function handle()
{
DB::table('chat_message_notifications')->insert($this->data);
}
}
from chat.
Related Issues (20)
- any way to query specific types of messages HOT 2
- Additional field in chat_message model HOT 5
- Get all messages for a user
- Call to a member function only() on null error HOT 1
- Error Call to undefined method Musonza\Chat\Services\MessageService::data() HOT 1
- Customize broadcast queue and connection in config
- A way of including all participation message_notifications
- Laravel 9 Support HOT 9
- Get all participant Models that a Model ever had a conversation with
- Method ConversationService::common() does not exist HOT 1
- $conversation = Chat::conversations()->between($participantModel1, $participantModel2); is not work HOT 2
- how to get conversations with unreadCount HOT 1
- make sure you get conversations that are direct, and make sure direct_message column is 1.
- Attempted to lazy load [participation] on model [Musonza\Chat\Models\Message] but lazy loading is disabled.
- The conversation's method 'between' is not giving the correct count
- Chat/messaging
- how to specify columns in chat participants HOT 1
- Participation always returns the first one regardless of the assigned conversation
- Current message pagination approach is not well-suited to a realtime chat application
- New Readme File Update Document v6.3 ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chat.