1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This Driver is based entirely on official documentation of the Mattermost Web
|
4
|
|
|
* Services API and you can extend it by following the directives of the documentation.
|
5
|
|
|
*
|
6
|
|
|
* For the full copyright and license information, please read the LICENSE.txt
|
7
|
|
|
* file that was distributed with this source code. For the full list of
|
8
|
|
|
* contributors, visit https://github.com/gnello/php-mattermost-driver/contributors
|
9
|
|
|
*
|
10
|
|
|
* God bless this mess.
|
11
|
|
|
*
|
12
|
|
|
* @author Luca Agnello <[email protected]>
|
13
|
|
|
* @link https://api.mattermost.com/
|
14
|
|
|
*/
|
15
|
|
|
|
16
|
|
|
namespace Gnello\Mattermost\Models;
|
17
|
|
|
|
18
|
|
|
use Psr\Http\Message\ResponseInterface;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* Class ChannelModel
|
22
|
|
|
*
|
23
|
|
|
* @package Gnello\Mattermost\Models
|
24
|
|
|
*/
|
25
|
|
|
class ChannelModel extends AbstractModel
|
26
|
|
|
{
|
27
|
|
|
/**
|
28
|
|
|
* @var string
|
29
|
|
|
*/
|
30
|
|
|
public static $endpoint = '/channels';
|
31
|
|
|
|
32
|
|
|
/**
|
33
|
|
|
* @param array $requestOptions
|
34
|
|
|
* @return ResponseInterface
|
35
|
|
|
*/
|
36
|
|
|
public function createChannel(array $requestOptions)
|
37
|
|
|
{
|
38
|
|
|
return $this->client->post(self::$endpoint, $requestOptions);
|
39
|
|
|
}
|
40
|
|
|
|
41
|
|
|
/**
|
42
|
|
|
* @param array $requestOptions
|
43
|
|
|
* @return ResponseInterface
|
44
|
|
|
*/
|
45
|
|
|
public function createDirectMessageChannel(array $requestOptions)
|
46
|
|
|
{
|
47
|
|
|
return $this->client->post(self::$endpoint . '/direct', $requestOptions);
|
48
|
|
|
}
|
49
|
|
|
|
50
|
|
|
/**
|
51
|
|
|
* @param array $requestOptions
|
52
|
|
|
* @return ResponseInterface
|
53
|
|
|
*/
|
54
|
|
|
public function createGroupMessageChannel(array $requestOptions)
|
55
|
|
|
{
|
56
|
|
|
return $this->client->post(self::$endpoint . '/group', $requestOptions);
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
/**
|
60
|
|
|
* @param $teamId
|
61
|
|
|
* @param array $requestOptions
|
62
|
|
|
* @return ResponseInterface
|
63
|
|
|
*/
|
64
|
|
|
public function getChannelsListByIds($teamId, array $requestOptions)
|
65
|
|
|
{
|
66
|
|
|
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/ids', $requestOptions);
|
67
|
|
|
}
|
68
|
|
|
|
69
|
|
|
/**
|
70
|
|
|
* @param $channelId
|
71
|
|
|
* @return ResponseInterface
|
72
|
|
|
*/
|
73
|
|
|
public function getChannel($channelId)
|
74
|
|
|
{
|
75
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId);
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* @param $channelId
|
80
|
|
|
* @return ResponseInterface
|
81
|
|
|
*/
|
82
|
|
|
public function getTimezone($channelId)
|
83
|
|
|
{
|
84
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/timezones');
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
/**
|
88
|
|
|
* @param $channelId
|
89
|
|
|
* @param array $requestOptions
|
90
|
|
|
* @return ResponseInterface
|
91
|
|
|
*/
|
92
|
|
|
public function updateChannel($channelId, array $requestOptions)
|
93
|
|
|
{
|
94
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId, $requestOptions);
|
95
|
|
|
}
|
96
|
|
|
|
97
|
|
|
/**
|
98
|
|
|
* @param $channelId
|
99
|
|
|
* @return ResponseInterface
|
100
|
|
|
*/
|
101
|
|
|
public function deleteChannel($channelId)
|
102
|
|
|
{
|
103
|
|
|
return $this->client->delete(self::$endpoint . '/' . $channelId);
|
104
|
|
|
}
|
105
|
|
|
|
106
|
|
|
/**
|
107
|
|
|
* @param $channelId
|
108
|
|
|
* @param array $requestOptions
|
109
|
|
|
* @return ResponseInterface
|
110
|
|
|
*/
|
111
|
|
|
public function patchChannel($channelId, array $requestOptions)
|
112
|
|
|
{
|
113
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/patch', $requestOptions);
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
/**
|
117
|
|
|
* @param $channelId
|
118
|
|
|
* @return ResponseInterface
|
119
|
|
|
*/
|
120
|
|
|
public function restoreChannel($channelId)
|
121
|
|
|
{
|
122
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/restore');
|
123
|
|
|
}
|
124
|
|
|
|
125
|
|
|
/**
|
126
|
|
|
* @param $channelId
|
127
|
|
|
* @return ResponseInterface
|
128
|
|
|
*/
|
129
|
|
|
public function getChannelStatistics($channelId)
|
130
|
|
|
{
|
131
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/stats');
|
132
|
|
|
}
|
133
|
|
|
|
134
|
|
|
/**
|
135
|
|
|
* @param $channelId
|
136
|
|
|
* @return ResponseInterface
|
137
|
|
|
*/
|
138
|
|
|
public function getChannelsPinnedPosts($channelId)
|
139
|
|
|
{
|
140
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/pinned');
|
141
|
|
|
}
|
142
|
|
|
|
143
|
|
|
/**
|
144
|
|
|
* @param $teamId
|
145
|
|
|
* @param $channelName
|
146
|
|
|
* @return ResponseInterface
|
147
|
|
|
*/
|
148
|
|
|
public function getChannelByName($teamId, $channelName)
|
149
|
|
|
{
|
150
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/name/' . $channelName);
|
151
|
|
|
}
|
152
|
|
|
|
153
|
|
|
/**
|
154
|
|
|
* @param $teamName
|
155
|
|
|
* @param $channelName
|
156
|
|
|
* @return ResponseInterface
|
157
|
|
|
*/
|
158
|
|
|
public function getChannelByNameAndTeamName($teamName, $channelName)
|
159
|
|
|
{
|
160
|
|
|
return $this->client->get(TeamModel::$endpoint . '/name/' . $teamName . self::$endpoint . '/name/' . $channelName);
|
161
|
|
|
}
|
162
|
|
|
|
163
|
|
|
/**
|
164
|
|
|
* @param $channelId
|
165
|
|
|
* @param array $requestOptions
|
166
|
|
|
* @return ResponseInterface
|
167
|
|
|
*/
|
168
|
|
|
public function getChannelMembers($channelId, array $requestOptions)
|
169
|
|
|
{
|
170
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
|
171
|
|
|
}
|
172
|
|
|
|
173
|
|
|
/**
|
174
|
|
|
* @param $channelId
|
175
|
|
|
* @param array $requestOptions
|
176
|
|
|
* @return ResponseInterface
|
177
|
|
|
*/
|
178
|
|
|
public function addUser($channelId, array $requestOptions)
|
179
|
|
|
{
|
180
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
|
181
|
|
|
}
|
182
|
|
|
|
183
|
|
|
/**
|
184
|
|
|
* @param $channelId
|
185
|
|
|
* @param array $requestOptions
|
186
|
|
|
* @return ResponseInterface
|
187
|
|
|
*/
|
188
|
|
|
public function getChannelMembersByIds($channelId, array $requestOptions)
|
189
|
|
|
{
|
190
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
|
191
|
|
|
}
|
192
|
|
|
|
193
|
|
|
/**
|
194
|
|
|
* @param $channelId
|
195
|
|
|
* @param $userId
|
196
|
|
|
* @return ResponseInterface
|
197
|
|
|
*/
|
198
|
|
|
public function getChannelMember($channelId, $userId)
|
199
|
|
|
{
|
200
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/members/' . $userId);
|
201
|
|
|
}
|
202
|
|
|
|
203
|
|
|
/**
|
204
|
|
|
* @param $channelId
|
205
|
|
|
* @param $userId
|
206
|
|
|
* @return ResponseInterface
|
207
|
|
|
*/
|
208
|
|
|
public function removeUserFromChannel($channelId, $userId)
|
209
|
|
|
{
|
210
|
|
|
return $this->client->delete(self::$endpoint . '/' . $channelId . '/members/' . $userId);
|
211
|
|
|
}
|
212
|
|
|
|
213
|
|
|
/**
|
214
|
|
|
* @param $channelId
|
215
|
|
|
* @param $userId
|
216
|
|
|
* @param array $requestOptions
|
217
|
|
|
* @return ResponseInterface
|
218
|
|
|
*/
|
219
|
|
|
public function updateChannelRoles($channelId, $userId, array $requestOptions)
|
220
|
|
|
{
|
221
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/roles', $requestOptions);
|
222
|
|
|
}
|
223
|
|
|
|
224
|
|
|
/**
|
225
|
|
|
* @param $channelId
|
226
|
|
|
* @param $userId
|
227
|
|
|
* @param array $requestOptions
|
228
|
|
|
* @return ResponseInterface
|
229
|
|
|
*/
|
230
|
|
|
public function updateChannelNotifications($channelId, $userId, array $requestOptions)
|
231
|
|
|
{
|
232
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/notify_props', $requestOptions);
|
233
|
|
|
}
|
234
|
|
|
|
235
|
|
|
/**
|
236
|
|
|
* @param $userId
|
237
|
|
|
* @param array $requestOptions
|
238
|
|
|
* @return ResponseInterface
|
239
|
|
|
*/
|
240
|
|
|
public function viewChannel($userId, array $requestOptions)
|
241
|
|
|
{
|
242
|
|
|
return $this->client->post(self::$endpoint . '/members/' . $userId . '/view', $requestOptions);
|
243
|
|
|
}
|
244
|
|
|
|
245
|
|
|
/**
|
246
|
|
|
* @param $userId
|
247
|
|
|
* @param $teamId
|
248
|
|
|
* @return ResponseInterface
|
249
|
|
|
*/
|
250
|
|
|
public function getChannelMembersForTheUser($userId, $teamId)
|
251
|
|
|
{
|
252
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/members');
|
253
|
|
|
}
|
254
|
|
|
|
255
|
|
|
/**
|
256
|
|
|
* @param $userId
|
257
|
|
|
* @param $teamId
|
258
|
|
|
* @return ResponseInterface
|
259
|
|
|
*/
|
260
|
|
|
public function getChannelsForUser($userId, $teamId)
|
261
|
|
|
{
|
262
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . self::$endpoint);
|
263
|
|
|
}
|
264
|
|
|
|
265
|
|
|
/**
|
266
|
|
|
* @param $userId
|
267
|
|
|
* @param $channelId
|
268
|
|
|
* @return ResponseInterface
|
269
|
|
|
*/
|
270
|
|
|
public function getUnreadMessages($userId, $channelId)
|
271
|
|
|
{
|
272
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . self::$endpoint . '/' . $channelId . '/unread');
|
273
|
|
|
}
|
274
|
|
|
|
275
|
|
|
/**
|
276
|
|
|
* @param $channelId
|
277
|
|
|
* @return ResponseInterface
|
278
|
|
|
*/
|
279
|
|
|
public function convertChannelFromPublicToPrivate($channelId)
|
280
|
|
|
{
|
281
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/convert');
|
282
|
|
|
}
|
283
|
|
|
|
284
|
|
|
/**
|
285
|
|
|
* @param $teamId
|
286
|
|
|
* @param array $requestOptions
|
287
|
|
|
* @return ResponseInterface
|
288
|
|
|
*/
|
289
|
|
|
public function getPublicChannels($teamId, array $requestOptions)
|
290
|
|
|
{
|
291
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint, $requestOptions);
|
292
|
|
|
}
|
293
|
|
|
|
294
|
|
|
/**
|
295
|
|
|
* @param $teamId
|
296
|
|
|
* @param array $requestOptions
|
297
|
|
|
* @return ResponseInterface
|
298
|
|
|
*/
|
299
|
|
|
public function getDeletedChannels($teamId, array $requestOptions)
|
300
|
|
|
{
|
301
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/deleted', $requestOptions);
|
302
|
|
|
}
|
303
|
|
|
|
304
|
|
|
/**
|
305
|
|
|
* @param $teamId
|
306
|
|
|
* @param array $requestOptions
|
307
|
|
|
* @return ResponseInterface
|
308
|
|
|
*/
|
309
|
|
|
public function autocompleteChannels($teamId, array $requestOptions)
|
310
|
|
|
{
|
311
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/autocomplete', $requestOptions);
|
312
|
|
|
}
|
313
|
|
|
|
314
|
|
|
/**
|
315
|
|
|
* @param $teamId
|
316
|
|
|
* @param array $requestOptions
|
317
|
|
|
* @return ResponseInterface
|
318
|
|
|
*/
|
319
|
|
|
public function autocompleteChannelsForSearch($teamId, array $requestOptions)
|
320
|
|
|
{
|
321
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_autocomplete', $requestOptions);
|
322
|
|
|
}
|
323
|
|
|
|
324
|
|
|
/**
|
325
|
|
|
* @param $teamId
|
326
|
|
|
* @param array $requestOptions
|
327
|
|
|
* @return ResponseInterface
|
328
|
|
|
*/
|
329
|
|
|
public function searchChannels($teamId, array $requestOptions)
|
330
|
|
|
{
|
331
|
|
|
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search', $requestOptions);
|
332
|
|
|
}
|
333
|
|
|
|
334
|
|
|
/**
|
335
|
|
|
* @param $teamId
|
336
|
|
|
* @param array $requestOptions
|
337
|
|
|
* @return ResponseInterface
|
338
|
|
|
*/
|
339
|
|
|
public function searchArchivedChannels($teamId, array $requestOptions)
|
340
|
|
|
{
|
341
|
|
|
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . self::$endpoint . '/search_archived', $requestOptions);
|
342
|
|
|
}
|
343
|
|
|
|
344
|
|
|
/**
|
345
|
|
|
* @param array $requestOptions
|
346
|
|
|
* @return ResponseInterface
|
347
|
|
|
*/
|
348
|
|
|
public function searchAllPrivateAndOpenTypeChannels(array $requestOptions)
|
349
|
|
|
{
|
350
|
|
|
return $this->client->post(self::$endpoint . '/search', $requestOptions);
|
351
|
|
|
}
|
352
|
|
|
|
353
|
|
|
/**
|
354
|
|
|
* @param array $requestOptions
|
355
|
|
|
* @return ResponseInterface
|
356
|
|
|
*/
|
357
|
|
|
public function searchGroupChannels(array $requestOptions)
|
358
|
|
|
{
|
359
|
|
|
return $this->client->post('/group/search', $requestOptions);
|
360
|
|
|
}
|
361
|
|
|
}
|
362
|
|
|
|