src/bbn/appui/chat.php
public function talk(string $id_chat, string $message): ?int
  {
    if ( $this->check() && ($chat = $this->info($id_chat)) && !$chat['blocked'] ){
      $users = $this->get_participants($id_chat);
      if ( \in_array($this->user->get_id(), $users, true) ){
        $time = microtime(true);
        $st = bbn\util\enc::crypt(json_encode(['time' => $time, 'user' => $this->user->get_id(), 'message' => $message]));
        $day = date('Y-m-d');
        foreach ( $users as $user ){
          $dir = BBN_DATA_PATH.'users/'.$user.'/chat/'.$id_chat.'/'.$day;
          if ( bbn\file\dir::create_path($dir) ){
            file_put_contents($dir.'/'.$time.'.msg', $st);
          }
        }
        return $this->db->update('bbn_chats', ['last_message' => $time], ['id' => $id_chat]);
      }
    }
    return null;
  }
public function talk(string $id_chat, string $message): ?int
  {
    if ( $this->check() && ($chat = $this->info($id_chat)) && !$chat['blocked'] ){
      $users = $this->get_participants($id_chat);
      if ( \in_array($this->user->get_id(), $users, true) ){
        $time = microtime(true);
        $st = bbn\util\enc::crypt(json_encode(['time' => $time, 'user' => $this->user->get_id(), 'message' => $message]));
        $day = date('Y-m-d');
        foreach ( $users as $user ){
          $dir = BBN_DATA_PATH.'users/'.$user.'/chat/'.$id_chat.'/'.$day;
          if ( bbn\file\dir::create_path($dir) ){
            file_put_contents($dir.'/'.$time.'.msg', $st);
          }
        }
        return $this->db->update('bbn_chats', ['last_message' => $time], ['id' => $id_chat]);
      }
    }
    return null;
  }
public function talk ( string $ id_chat , string $ message ) : ? int { if ( $ this -> check ( ) && ( $ chat = $ this -> info ( $ id_chat ) ) && ! $ chat [ 'blocked' ] ) { $ users = $ this -> get_participants ( $ id_chat ) ; if ( \ in_array ( $ this -> user -> get_id ( ) , $ users , true ) ) { $ time = microtime ( true ) ; $ st = bbn \ util \ enc :: crypt ( json_encode ( [ 'time' => $ time , 'user' => $ this -> user -> get_id ( ) , 'message' => $ message ] ) ) ; $ day = date ( 'Y-m-d' ) ; foreach ( $ users as $ user ) { $ dir = BBN_DATA_PATH . 'users/' . $ user . '/chat/' . $ id_chat . '/' . $ day ; if ( bbn \ file \ dir :: create_path ( $ dir ) ) { file_put_contents ( $ dir . '/' . $ time . '.msg' , $ st ) ; } } return $ this -> db -> update ( 'bbn_chats' , [ 'last_message' => $ time ] , [ 'id' => $ id_chat ] ) ; } } return null ; }
Sends a new message from the current user in the given chat.

@param string $id_chat
@param string $message
@return int|null
Sends a new message from the current user in the given chat .