@frosticek
public function getThreadIsRead( $thread_id, $user_id, $secret ) {
$this->dao->select('coalesce(m.pk_i_id, 0) as pk_i_id, coalesce(m.i_read, 1) as i_read');
$this->dao->from( $this->getTable_threads() . ' as t' );
$this->dao->join( $this->getTable_messages() . ' as m', 't.i_thread_id = m.fk_i_thread_id AND ((t.i_from_user_id = ' . $user_id . ' AND m.i_type = 1 OR t.i_to_user_id = ' . $user_id . ' AND m.i_type = 0) OR (t.s_from_secret = "' . $secret . '" AND m.i_type = 1 OR t.s_to_secret = "' . $secret . '" AND m.i_type = 0))', 'LEFT OUTER' );
$this->dao->where('t.i_thread_id', $thread_id );
$this->dao->orderby('m.d_datetime DESC');
$this->dao->limit(1);
$result = $this->dao->get();
if( !$result ) { return array(); }
return $result->row();
}