From 54ff42e79fef628e5c4fc9defa06063b90616f45 Mon Sep 17 00:00:00 2001 From: Qingyang Hu Date: Thu, 26 Jul 2018 03:07:25 +0800 Subject: [PATCH] Feature: find valid --- src/Repository/User/DeviceRepository.php | 12 ++++++++++++ src/Service/NotificationService.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Repository/User/DeviceRepository.php b/src/Repository/User/DeviceRepository.php index 92a2a07..4d0ff31 100644 --- a/src/Repository/User/DeviceRepository.php +++ b/src/Repository/User/DeviceRepository.php @@ -22,6 +22,18 @@ public function findByUserAndType(User $user, int $type) { return $this->findBy(["user" => $user, "type" => $type]); } + public function findValidByUserAndType(User $user, int $type) { + return $this->createQueryBuilder("u") + ->where("u.user = :user") + ->andWhere("u.type = :type") + ->andWhere("u.status > :status") + ->setParameter("user", $user) + ->setParameter("type", $type) + ->setParameter("status", -1) + ->getQuery() + ->getResult(); + } + public function findByType(int $type) { return $this->findBy(["type" => $type]); } diff --git a/src/Service/NotificationService.php b/src/Service/NotificationService.php index ad7099e..e94cb64 100644 --- a/src/Service/NotificationService.php +++ b/src/Service/NotificationService.php @@ -228,7 +228,7 @@ public function notifyNewMessage(Chat $chat) { } private function getDevices(User $user) { - return $this->objectManager->getRepository(Device::class)->findByUserAndType($user, DeviceType::IOS); + return $this->objectManager->getRepository(Device::class)->findValidByUserAndType($user, DeviceType::IOS, true); } private function isPhoneUsed(?string $phone) {