Skip to content

Commit

Permalink
Store loaded messages internally
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Mar 2, 2018
1 parent 4dbb472 commit 3da3b8b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/SlackRTMDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SlackRTMDriver implements DriverInterface

protected $file;

protected $messages = [];

/**
* Driver constructor.
* @param array $config
Expand All @@ -54,6 +56,7 @@ public function __construct(array $config, RealTimeClient $client)
$this->client = $client;

$this->client->on('_internal_message', function ($type, $data) {
$this->messages = [];
$this->event = Collection::make($data);
if ($type !== 'message') {
$this->slackEventData = [$type, $data];
Expand Down Expand Up @@ -174,6 +177,18 @@ private function convertQuestion(Question $question)
* @return array
*/
public function getMessages()
{
if (empty($this->messages)) {
$this->loadMessages();
}

return $this->messages;
}

/**
* Load Slack messages.
*/
protected function loadMessages()
{
$messageText = $this->event->get('text');

Expand Down Expand Up @@ -213,7 +228,7 @@ public function getMessages()
$message = new IncomingMessage($messageText, $user_id, $channel_id, $this->event);
$message->setIsFromBot($this->isBot());

return [$message];
$this->messages = [$message];
}

/**
Expand Down

0 comments on commit 3da3b8b

Please sign in to comment.