Bug with Talk::getMessagesByUserId()
visualight opened this issue · comments
nahid/talk v2.2.1 - Laravel 5.3
Hi, I'm having a bug with Talk :: getMessagesByUserId (). I have more than 3000 records in my database and I have configured Talk :: getMessagesByUserId ($ id, 0, 2000) which is supposed to retrieve 2000 messages from a user. I have 3000 messages in total in the messages table (from different users), the use of Talk :: getMessagesByUserId as I configured it prevents to retrieve the messages and blocks the distribution of the messages of ALL the users. I have to set Talk :: getMessagesByUserId with a max value of 1000000 to take the lead. I think this is a bug because Talk :: getMessagesByUserId is supposed to limit the number of messages to a single user and not to all.
Example of use now to avoid problems :
public function chatHistory($id=null)
{
$function = new Jfunction();
$me = $this->me;
if(!is_null($id))
{
$id = $function->uncrypt($id);
}
$conversations = Talk::getMessagesByUserId($id, 0, 1000000000);
$user = null;
$messages = [];
$msgs = Conversation::where('user_one', $me->id)->orWhere('user_two', $me->id)->with(['messages' => function($q) use($me){
$q->where('user_id', '!=', $me->id)->where('status', 2)->where('is_seen', 0);
}])->get();
$countMsg=0;
foreach ($msgs as $msg)
{
foreach ($msg->messages as $message)
{
$countMsg = $countMsg+1;
}
}
if($id)
{
if(!$conversations) {
$user = User::find($id);
} else {
$user = $conversations->withUser;
$messages = $conversations->messages;
foreach ($conversations->messages as $message)
{
if($message->user_id == $id)
{
Talk::makeSeen($message->id);
}
}
}
}
...
Maybe I'm wrong in the code too. An idea ?
Do you want to get All messages from all users?
I have a problem like yours, i've to do this Talk::getConversationsByUserId($userId, 0, 1000000); to get all the message between the user logged and $userId, i think because the $limit = 20 is taking all the messages in database
same here, have to do Talk::getConversationsById($conversationId, 0, 100000000); to get the conversation otherwise query limit will prevent retrieval
Hi there. Perhaps You've got a relatd problem.
To me this function produced an empty List of messages. Eventhough on user 1 in worked.
in vendor/nahid/talk/src/Conversations/ConversationRepository.php :: getMessagesById($conversationId, $userId, $offset, $take) the query doesnt seem to work properly.
I replaced the complex quere by just Conversation::find($conversationId); and that did the trick.
Also I filtered the deleted_from_sender inside of the retriever function "messages" of the Conversation class.
Let me know if that is of use or problematic. Good luck!
INFO: Laravel 5.7, nahid/talk v2.2.2 from composer
I found the same issue,
If we use getMessages the $limit=20 seems to have a bug in MySQL for Linux somehow it limits the query take to only 5 items. It doesn't happen in Windows running WAMP though.
The safest workaround would be to put "999999999" value on the last parameter.
I hope @nahid can check this.
Thanks.