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\ImMarkPayload; |
15
|
|
|
use CL\Slack\Payload\ImMarkPayloadResponse; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Cas Leentfaar <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ImMarkCommand extends AbstractApiCommand |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
|
|
protected function configure() |
27
|
|
|
{ |
28
|
|
|
parent::configure(); |
29
|
|
|
|
30
|
|
|
$this->setName('im:mark'); |
31
|
|
|
$this->setDescription('Moves the read cursor in a Slack IM channel'); |
32
|
|
|
$this->addArgument('im-id', InputArgument::REQUIRED, 'ID of the IM channel 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>im:mark</info> command is used to move the read cursor in a Slack im. |
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 im). This is useful for when reading scroll-back history, or following a busy live im. |
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/im.mark</comment> |
48
|
|
|
EOT |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return ImMarkPayload |
54
|
|
|
*/ |
55
|
|
|
protected function createPayload() |
56
|
|
|
{ |
57
|
|
|
$payload = new ImMarkPayload(); |
58
|
|
|
$payload->setImId($this->input->getArgument('im-id')); |
59
|
|
|
$payload->setSlackTimestamp($this->input->getArgument('timestamp')); |
60
|
|
|
|
61
|
|
|
return $payload; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
* |
67
|
|
|
* @param ImMarkPayloadResponse $payloadResponse |
68
|
|
|
*/ |
69
|
|
|
protected function handleResponse($payloadResponse) |
70
|
|
|
{ |
71
|
|
|
if ($payloadResponse->isOk()) { |
72
|
|
|
$this->writeOk('Successfully moved the read cursor!'); |
73
|
|
|
} else { |
74
|
|
|
$this->writeError(sprintf('Failed to move the read cursor in the IM channel: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|