Skip to content

Commit 3da3b8b

Browse files
committed
Store loaded messages internally
1 parent 4dbb472 commit 3da3b8b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/SlackRTMDriver.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class SlackRTMDriver implements DriverInterface
4242

4343
protected $file;
4444

45+
protected $messages = [];
46+
4547
/**
4648
* Driver constructor.
4749
* @param array $config
@@ -54,6 +56,7 @@ public function __construct(array $config, RealTimeClient $client)
5456
$this->client = $client;
5557

5658
$this->client->on('_internal_message', function ($type, $data) {
59+
$this->messages = [];
5760
$this->event = Collection::make($data);
5861
if ($type !== 'message') {
5962
$this->slackEventData = [$type, $data];
@@ -174,6 +177,18 @@ private function convertQuestion(Question $question)
174177
* @return array
175178
*/
176179
public function getMessages()
180+
{
181+
if (empty($this->messages)) {
182+
$this->loadMessages();
183+
}
184+
185+
return $this->messages;
186+
}
187+
188+
/**
189+
* Load Slack messages.
190+
*/
191+
protected function loadMessages()
177192
{
178193
$messageText = $this->event->get('text');
179194

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

216-
return [$message];
231+
$this->messages = [$message];
217232
}
218233

219234
/**

0 commit comments

Comments
 (0)