Exemplo n.º 1
0
 public function destroy($id)
 {
     $chat = CarChat::find($id);
     if (!$chat) {
         return $this->respondNotFound(trans('chat.not-found'));
     }
     $chat->messages->each(function ($message) use($chat) {
         if ($chat->isOwner($this->user->id)) {
             $message->deleted_by_owner = true;
         } else {
             $message->deleted_by_receiver = true;
         }
         $message->save();
     });
     if ($chat->isOwner($this->user->id)) {
         $chat->deleted_by_owner = true;
     } else {
         $chat->deleted_by_receiver = true;
     }
     $chat->save();
     $this->user->devices->each(function ($token) use($chat) {
         //		$chat->getMembersTokens()->each(function($token) use($chat) {
         $state = new StateSender($token->auth_token, true);
         $this->remove($state, $chat);
         $state->send();
     });
     return $this->respondNoContent();
 }
Exemplo n.º 2
0
 public function deliver($id, $message_id)
 {
     $chat = CarChat::find($id);
     if (!$chat) {
         return $this->respondNotFound('chat.not-found');
     }
     $message = $chat->messages()->find($message_id);
     if (!$message) {
         return $this->respondNotFound('Message not found');
     }
     $message->delivered_at = Carbon::now();
     $message->save();
     $chat->getMembersTokens()->each(function ($token) use($chat, $message) {
         $state = new StateSender($token->auth_token, true);
         $state->setMessageAsDelivered($chat->id, $message->id, $message->delivered_at);
         $state->send();
     });
     return $this->respondNoContent();
 }