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

TBMsg::getUserConversations Not Returning Convo #41

Open
alexpell00 opened this issue Mar 15, 2015 · 3 comments
Open

TBMsg::getUserConversations Not Returning Convo #41

alexpell00 opened this issue Mar 15, 2015 · 3 comments

Comments

@alexpell00
Copy link

I am trying to retrieve a newly created convo with 'TBMsg::getUserConversations($self->id)' but no convos are being returned. I check the database and there a convo with 2 participants. participants id 1 and 6. For some reason I am not getting the open convo.

@tzookb
Copy link
Owner

tzookb commented Mar 16, 2015

Can you attach your db data?

And which db? Mysql? Sqlite...

@dubcanada
Copy link

It's because at this moment the repo is broken. In the TBMsgRepo file you have

        SELECT msg.conv_id as conv_id, msg.created_at, msg.id "msgId", msg.content, mst.status, mst.self, us.'.$this->usersTableKey.' "userId"
        FROM '.$this->tablePrefix.'messages msg
        INNER JOIN (
            SELECT MAX(created_at) created_at
            FROM '.$this->tablePrefix.'messages
            GROUP BY conv_id
        ) m2 ON msg.created_at = m2.created_at
        INNER JOIN '.$this->tablePrefix.'messages_status mst ON msg.id=mst.msg_id
        INNER JOIN '.$this->usersTable.' us ON msg.sender_id=us.'.$this->usersTableKey.'
        WHERE mst.user_id = ? AND mst.status NOT IN (?, ?)
        ORDER BY msg.created_at DESC

This won't work. It will actually create many rows of the same message depending on how many messages are in the conv. And created_at should not be your max, id should be.

On line 103 you should probably just return $this->tbmRepo->getConversations($user_id); there is no need to do what ever is below that line, which seems to be adding additional messages to the conversation? I also have no idea why lines 132 to 145 are even there. Why would you add participants in a function thats supposed to get data?

Anyways I am really confused :)

@tzookb
Copy link
Owner

tzookb commented Jul 1, 2015

well finally had time to look at it, and trying to add tests and fixes.

this method is only for fetching the conversation
BUT
it fetches its user ids and last message.

*** important if you create a conversation but dont send any message to it, so it will not appear in this method and the method will return blank.

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

3 participants