tbmsg icon indicating copy to clipboard operation
tbmsg copied to clipboard

TBMsg::getUserConversations Not Returning Convo

Open alexpell00 opened this issue 9 years ago • 3 comments

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.

alexpell00 avatar Mar 15 '15 02:03 alexpell00

Can you attach your db data?

And which db? Mysql? Sqlite...

tzookb avatar Mar 16 '15 10:03 tzookb

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 :)

dubcanada avatar Jun 23 '15 19:06 dubcanada

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.

tzookb avatar Jul 01 '15 20:07 tzookb