/** * @param Payload $payload * @param OutputInterface $output */ private function onReaction(Payload $payload, OutputInterface $output) { try { // Always ignore messages without a user if ($payload->offsetExists('user') == false) { return; } $reaction = Reaction::fromSlack($payload->offsetGet('reaction'), $payload->offsetGet('event_ts'), $payload->offsetGet('item')['ts'], $payload->offsetGet('user')); $this->reactionProcessor->process($reaction); } catch (\Exception $e) { $output->writeln(sprintf('<error>Error: %s, %s</error>', get_class($e), $e->getMessage())); } }
/** * @param Reaction $reaction */ public function process(Reaction $reaction) { // Only process reaction on saved links $link = $this->linkRepository->findOneBySlackMessageId($reaction->getMessageId()); if (!$link instanceof Link) { return; } $user = $this->userRepository->findOneBySlackId($reaction->getUserId()); if (!$user instanceof User) { $this->logger->error(sprintf('User "%s" not found', $reaction->getUserId())); return; } if ($reaction->isLike()) { $link->likedBy($user); } if ($reaction->isDislike()) { $link->dislikedBy($user); } $this->objectManager->flush(); $this->objectManager->clear(); }