forked from alekseykuleshov/rocket-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessage.php
78 lines (67 loc) · 1.77 KB
/
Message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace ATDev\RocketChat\Messages;
use ATDev\RocketChat\Common\Request;
/**
* Class Message
* @package ATDev\RocketChat\Messages
*/
class Message extends Request
{
use Data;
/**
* Gets a single chat message
* @return Message|bool
*/
public function getMessage()
{
static::send('chat.getMessage', 'GET', ['msgId' => $this->getMessageId()]);
if (!static::getSuccess()) {
return false;
}
return $this->updateOutOfResponse(static::getResponse()->message);
}
/**
* @return Message|bool
*/
public function postMessage()
{
static::send('chat.postMessage', 'POST', $this);
if (!static::getSuccess()) {
return false;
}
return $this->updateOutOfResponse(static::getResponse()->message);
}
/**
* Updates chat message
* @return Message|bool
*/
public function update()
{
static::send(
'chat.update',
'POST',
['roomId' => $this->getRoomId(), 'msgId' => $this->getMessageId(), 'text' => $this->getMsg()]
);
if (!static::getSuccess()) {
return false;
}
return $this->updateOutOfResponse(static::getResponse()->message);
}
/**
* Deletes chat message
* @param bool $asUser Whether the message should be deleted as the user who sent it
* @return Message|bool
*/
public function delete($asUser = false)
{
static::send(
'chat.delete',
'POST',
['roomId' => $this->getRoomId(), 'msgId' => $this->getMessageId(), 'asUser' => $asUser]
);
if (!static::getSuccess()) {
return false;
}
return $this->setMessageId(null);
}
}