1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the slack-cli package. |
5
|
|
|
* |
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CL\SlackCli\Command; |
13
|
|
|
|
14
|
|
|
use CL\Slack\Payload\ChannelsMarkPayload; |
15
|
|
|
use CL\Slack\Payload\ChannelsMarkPayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ChannelsMarkCommand extends AbstractApiCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
1 |
|
protected function configure() |
27
|
|
|
{ |
28
|
1 |
|
parent::configure(); |
29
|
|
|
|
30
|
1 |
|
$this->setName('channels:mark'); |
31
|
1 |
|
$this->setDescription('Moves the read cursor in a Slack channel'); |
32
|
1 |
|
$this->addArgument('channel-id', InputArgument::REQUIRED, 'ID of the channel to set reading cursor in.'); |
33
|
1 |
|
$this->addArgument('timestamp', InputArgument::REQUIRED, 'Timestamp of the most recently seen message.'); |
34
|
1 |
|
$this->setHelp(<<<EOT |
35
|
|
|
The <info>channels:mark</info> command is used to move the read cursor in a Slack channel. |
36
|
|
|
|
37
|
|
|
After making this call, the mark is saved to the database and broadcast via the message server to all open connections |
38
|
|
|
for the calling user. |
39
|
|
|
|
40
|
|
|
Clients should try to avoid making this call too often. When needing to mark a read position, a client should set a |
41
|
|
|
timer before making the call. In this way, any further updates needed during the timeout will not generate extra calls |
42
|
|
|
(just one per channel). This is useful for when reading scroll-back history, or following a busy live channel. |
43
|
|
|
|
44
|
|
|
A timeout of 5 seconds is a good starting point. Be sure to flush these calls on shutdown/logout. |
45
|
|
|
|
46
|
|
|
For more information about the related API method, check out the official documentation: |
47
|
|
|
<comment>https://api.slack.com/methods/channels.mark</comment> |
48
|
|
|
EOT |
49
|
1 |
|
); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return ChannelsMarkPayload |
54
|
|
|
*/ |
55
|
1 |
|
protected function createPayload() |
56
|
|
|
{ |
57
|
1 |
|
$payload = new ChannelsMarkPayload(); |
58
|
1 |
|
$payload->setChannelId($this->input->getArgument('channel-id')); |
59
|
|
|
|
60
|
1 |
|
return $payload; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
* |
66
|
|
|
* @param ChannelsMarkPayloadResponse $payloadResponse |
67
|
|
|
*/ |
68
|
1 |
|
protected function handleResponse($payloadResponse) |
69
|
|
|
{ |
70
|
1 |
|
if ($payloadResponse->isOk()) { |
71
|
1 |
|
$this->writeOk('Successfully moved the read cursor!'); |
72
|
1 |
|
} else { |
73
|
1 |
|
$this->writeError(sprintf('Failed to move the read cursor in the channel: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
74
|
|
|
} |
75
|
1 |
|
} |
76
|
|
|
} |
77
|
|
|
|