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