|
1
|
|
|
<?php |
|
2
|
|
|
namespace Slack; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Contains information about a private group channel. |
|
6
|
|
|
*/ |
|
7
|
|
|
class Group extends Channel |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Renames the group. |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $name The name to set to. |
|
13
|
|
|
* |
|
14
|
|
|
* @return \React\Promise\PromiseInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
public function rename($name) |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->client->apiCall('groups.rename', [ |
|
19
|
|
|
'channel' => $this->getId(), |
|
20
|
|
|
'name' => $name, |
|
21
|
|
|
])->then(function () use ($name) { |
|
22
|
|
|
$this->data['name'] = $name; |
|
23
|
|
|
return $name; |
|
24
|
|
|
}); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Sets the group's purpose text. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $text The new purpose text to set to. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \React\Promise\PromiseInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
public function setPurpose($text) |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->client->apiCall('groups.setPurpose', [ |
|
37
|
|
|
'channel' => $this->getId(), |
|
38
|
|
|
'purpose' => $text, |
|
39
|
|
|
])->then(function () use ($text) { |
|
40
|
|
|
$this->data['purpose']['value'] = $text; |
|
41
|
|
|
return $text; |
|
42
|
|
|
}); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Sets the group topic text. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $text The new topic text to set to. |
|
49
|
|
|
* |
|
50
|
|
|
* @return \React\Promise\PromiseInterface |
|
51
|
|
|
*/ |
|
52
|
|
|
public function setTopic($text) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->client->apiCall('groups.setTopic', [ |
|
55
|
|
|
'channel' => $this->getId(), |
|
56
|
|
|
'topic' => $text, |
|
57
|
|
|
])->then(function () use ($text) { |
|
58
|
|
|
$this->data['topic']['value'] = $text; |
|
59
|
|
|
return $text; |
|
60
|
|
|
}); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Archives the group. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \React\Promise\PromiseInterface |
|
67
|
|
|
*/ |
|
68
|
|
View Code Duplication |
public function archive() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->client->apiCall('groups.archive', [ |
|
71
|
|
|
'channel' => $this->getId(), |
|
72
|
|
|
])->then(function () { |
|
73
|
|
|
$this->data['is_archived'] = true; |
|
74
|
|
|
}); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Un-archives the group. |
|
79
|
|
|
* |
|
80
|
|
|
* @return \React\Promise\PromiseInterface |
|
81
|
|
|
*/ |
|
82
|
|
View Code Duplication |
public function unarchive() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->client->apiCall('groups.unarchive', [ |
|
85
|
|
|
'channel' => $this->getId(), |
|
86
|
|
|
])->then(function () { |
|
87
|
|
|
$this->data['is_archived'] = false; |
|
88
|
|
|
}); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Invites a user to the group. |
|
93
|
|
|
* |
|
94
|
|
|
* @param User $user The user to invite. |
|
95
|
|
|
* |
|
96
|
|
|
* @return \React\Promise\PromiseInterface |
|
97
|
|
|
*/ |
|
98
|
|
View Code Duplication |
public function inviteUser(User $user) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->client->apiCall('groups.invite', [ |
|
101
|
|
|
'channel' => $this->getId(), |
|
102
|
|
|
'user' => $user->getId(), |
|
103
|
|
|
])->then(function () use ($user) { |
|
104
|
|
|
$this->data['members'][] = $user->getId(); |
|
105
|
|
|
}); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Kicks a user from the group. |
|
110
|
|
|
* |
|
111
|
|
|
* @param User $user The user to kick. |
|
112
|
|
|
* |
|
113
|
|
|
* @return \React\Promise\PromiseInterface |
|
114
|
|
|
*/ |
|
115
|
|
View Code Duplication |
public function kickUser(User $user) |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->client->apiCall('groups.kick', [ |
|
118
|
|
|
'channel' => $this->getId(), |
|
119
|
|
|
'user' => $user->getId(), |
|
120
|
|
|
])->then(function () use ($user) { |
|
121
|
|
|
unset($this->data['members'][$user->getId()]); |
|
122
|
|
|
}); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Opens the group. |
|
127
|
|
|
* |
|
128
|
|
|
* @return \React\Promise\PromiseInterface |
|
129
|
|
|
*/ |
|
130
|
|
View Code Duplication |
public function open() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->client->apiCall('groups.open', [ |
|
133
|
|
|
'channel' => $this->getId(), |
|
134
|
|
|
])->then(function ($response) { |
|
135
|
|
|
return !isset($response['no_op']); |
|
136
|
|
|
}); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* {@inheritDoc} |
|
141
|
|
|
*/ |
|
142
|
|
View Code Duplication |
public function close() |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->client->apiCall('groups.close', [ |
|
145
|
|
|
'channel' => $this->getId(), |
|
146
|
|
|
])->then(function ($response) { |
|
147
|
|
|
return !isset($response['no_op']); |
|
148
|
|
|
}); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|