Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Talk::getMessagesByUserId() #123

Open
visualight opened this issue Jun 1, 2018 · 5 comments
Open

Bug with Talk::getMessagesByUserId() #123

visualight opened this issue Jun 1, 2018 · 5 comments

Comments

@visualight
Copy link

visualight commented Jun 1, 2018

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 ?

@nahid
Copy link
Owner

nahid commented Jul 2, 2018

Do you want to get All messages from all users?

@Gustavinho
Copy link

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

@haisham
Copy link

haisham commented Sep 19, 2019

same here, have to do Talk::getConversationsById($conversationId, 0, 100000000); to get the conversation otherwise query limit will prevent retrieval

@gitmschepp
Copy link

gitmschepp commented Dec 15, 2019

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

@arungpisyadi
Copy link

arungpisyadi commented Jun 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants