Example #1
0
 /**
  * Update the chat info
  *
  * @param int|null $chatId Chat ID
  * @return Response
  */
 public function update($chatId = null)
 {
     $user = Auth::user();
     if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) {
         if ((bool) Input::get('mark_as_read')) {
             $this->markAsRead($chat, $user);
         }
         if (strlen($newTopic = (string) Input::get('topic')) > 0) {
             $chat->topic = $newTopic;
             $chat->save();
             foreach ($chat->getMembersTokens() as $token) {
                 $state = new StateSender($token);
                 $state->setChatAsUpdated((int) $chatId, (int) Auth::user()->id);
                 $state->send();
             }
         }
         if (Input::has('typing')) {
             foreach ($chat->getMembersTokens() as $token) {
                 $state = new StateSender($token);
                 $state->setChatAsTyping($chatId, Auth::user()->id, (bool) Input::get('typing'));
                 $state->send();
             }
         }
         if (Input::has('delivered')) {
             $this->delivered($chat);
         }
         return $this->respondNoContent();
     } else {
         return $this->respondWithError('Chat doesn\'t exist');
     }
 }