tbmsg
tbmsg copied to clipboard
TBMsg::getUserConversations Not Returning Convo
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.
Can you attach your db data?
And which db? Mysql? Sqlite...
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 :)
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.