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
|
|
|
/**
|
19
|
|
|
* Class ChannelModel
|
20
|
|
|
*
|
21
|
|
|
* @package Gnello\Mattermost\Models
|
22
|
|
|
*/
|
23
|
|
|
class ChannelModel extends AbstractModel
|
24
|
|
|
{
|
25
|
|
|
/**
|
26
|
|
|
* @var string
|
27
|
|
|
*/
|
28
|
|
|
public static $endpoint = '/channels';
|
29
|
|
|
|
30
|
|
|
/**
|
31
|
|
|
* @param array $requestOptions
|
32
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
33
|
|
|
*/
|
34
|
|
|
public function createChannel(array $requestOptions)
|
35
|
|
|
{
|
36
|
|
|
return $this->client->post(self::$endpoint . '/create', $requestOptions);
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
/**
|
40
|
|
|
* @param array $requestOptions
|
41
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
42
|
|
|
*/
|
43
|
|
|
public function createDirectMessageChannel(array $requestOptions)
|
44
|
|
|
{
|
45
|
|
|
return $this->client->post(self::$endpoint . '/direct', $requestOptions);
|
46
|
|
|
}
|
47
|
|
|
|
48
|
|
|
/**
|
49
|
|
|
* @param array $requestOptions
|
50
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
51
|
|
|
*/
|
52
|
|
|
public function createGroupMessageChannel(array $requestOptions)
|
53
|
|
|
{
|
54
|
|
|
return $this->client->post(self::$endpoint . '/group', $requestOptions);
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
/**
|
58
|
|
|
* @param $teamId
|
59
|
|
|
* @param array $requestOptions
|
60
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
61
|
|
|
*/
|
62
|
|
|
public function getChannelsListByIds($teamId, array $requestOptions)
|
63
|
|
|
{
|
64
|
|
|
return $this->client->post(TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint . '/ids', $requestOptions);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
/**
|
68
|
|
|
* @param $channelId
|
69
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
70
|
|
|
*/
|
71
|
|
|
public function getChannel($channelId)
|
72
|
|
|
{
|
73
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId);
|
74
|
|
|
}
|
75
|
|
|
|
76
|
|
|
/**
|
77
|
|
|
* @param $channelId
|
78
|
|
|
* @param array $requestOptions
|
79
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
80
|
|
|
*/
|
81
|
|
|
public function updateChannel($channelId, array $requestOptions)
|
82
|
|
|
{
|
83
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId, $requestOptions);
|
84
|
|
|
}
|
85
|
|
|
|
86
|
|
|
/**
|
87
|
|
|
* @param $channelId
|
88
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
89
|
|
|
*/
|
90
|
|
|
public function deleteChannel($channelId)
|
91
|
|
|
{
|
92
|
|
|
return $this->client->delete(self::$endpoint . '/' . $channelId);
|
93
|
|
|
}
|
94
|
|
|
|
95
|
|
|
/**
|
96
|
|
|
* @param $channelId
|
97
|
|
|
* @param array $requestOptions
|
98
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
99
|
|
|
*/
|
100
|
|
|
public function patchChannel($channelId, array $requestOptions)
|
101
|
|
|
{
|
102
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/patch', $requestOptions);
|
103
|
|
|
}
|
104
|
|
|
|
105
|
|
|
/**
|
106
|
|
|
* @param $channelId
|
107
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
108
|
|
|
*/
|
109
|
|
|
public function restoreChannel($channelId)
|
110
|
|
|
{
|
111
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/restore');
|
112
|
|
|
}
|
113
|
|
|
|
114
|
|
|
/**
|
115
|
|
|
* @param $channelId
|
116
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
117
|
|
|
*/
|
118
|
|
|
public function getChannelStatistics($channelId)
|
119
|
|
|
{
|
120
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/stats');
|
121
|
|
|
}
|
122
|
|
|
|
123
|
|
|
/**
|
124
|
|
|
* @param $channelId
|
125
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
126
|
|
|
*/
|
127
|
|
|
public function getChannelsPinnedPosts($channelId)
|
128
|
|
|
{
|
129
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/pinned');
|
130
|
|
|
}
|
131
|
|
|
|
132
|
|
|
/**
|
133
|
|
|
* @param $teamId
|
134
|
|
|
* @param $channelName
|
135
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
136
|
|
|
*/
|
137
|
|
|
public function getChannelByName($teamId, $channelName)
|
138
|
|
|
{
|
139
|
|
|
return $this->client->get(TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint . '/name/' . $channelName);
|
140
|
|
|
}
|
141
|
|
|
|
142
|
|
|
/**
|
143
|
|
|
* @param $teamName
|
144
|
|
|
* @param $channelName
|
145
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
146
|
|
|
*/
|
147
|
|
|
public function getChannelByNameAndTeamName($teamName, $channelName)
|
148
|
|
|
{
|
149
|
|
|
return $this->client->get(TeamModel::$endpoint . '/name/' . $teamName . '/' . self::$endpoint . '/name/' . $channelName);
|
150
|
|
|
}
|
151
|
|
|
|
152
|
|
|
/**
|
153
|
|
|
* @param $channelId
|
154
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
155
|
|
|
*/
|
156
|
|
|
public function getChannelMembers($channelId)
|
157
|
|
|
{
|
158
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/members');
|
159
|
|
|
}
|
160
|
|
|
|
161
|
|
|
/**
|
162
|
|
|
* @param $channelId
|
163
|
|
|
* @param array $requestOptions
|
164
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
165
|
|
|
*/
|
166
|
|
|
public function addUser($channelId, array $requestOptions)
|
167
|
|
|
{
|
168
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/members', $requestOptions);
|
169
|
|
|
}
|
170
|
|
|
|
171
|
|
|
/**
|
172
|
|
|
* @param $channelId
|
173
|
|
|
* @param array $requestOptions
|
174
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
175
|
|
|
*/
|
176
|
|
|
public function getChannelMembersByIds($channelId, array $requestOptions)
|
177
|
|
|
{
|
178
|
|
|
return $this->client->post(self::$endpoint . '/' . $channelId . '/members/ids', $requestOptions);
|
179
|
|
|
}
|
180
|
|
|
|
181
|
|
|
/**
|
182
|
|
|
* @param $channelId
|
183
|
|
|
* @param $userId
|
184
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
185
|
|
|
*/
|
186
|
|
|
public function getChannelMember($channelId, $userId)
|
187
|
|
|
{
|
188
|
|
|
return $this->client->get(self::$endpoint . '/' . $channelId . '/members/' . $userId);
|
189
|
|
|
}
|
190
|
|
|
|
191
|
|
|
/**
|
192
|
|
|
* @param $channelId
|
193
|
|
|
* @param $userId
|
194
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
195
|
|
|
*/
|
196
|
|
|
public function removeUserFromChannel($channelId, $userId)
|
197
|
|
|
{
|
198
|
|
|
return $this->client->delete(self::$endpoint . '/' . $channelId . '/members/' . $userId);
|
199
|
|
|
}
|
200
|
|
|
|
201
|
|
|
/**
|
202
|
|
|
* @param $channelId
|
203
|
|
|
* @param $userId
|
204
|
|
|
* @param array $requestOptions
|
205
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
206
|
|
|
*/
|
207
|
|
|
public function updateChannelRoles($channelId, $userId, array $requestOptions)
|
208
|
|
|
{
|
209
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/roles', $requestOptions);
|
210
|
|
|
}
|
211
|
|
|
|
212
|
|
|
/**
|
213
|
|
|
* @param $channelId
|
214
|
|
|
* @param $userId
|
215
|
|
|
* @param array $requestOptions
|
216
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
217
|
|
|
*/
|
218
|
|
|
public function updateChannelNotifications($channelId, $userId, array $requestOptions)
|
219
|
|
|
{
|
220
|
|
|
return $this->client->put(self::$endpoint . '/' . $channelId . '/members/' . $userId . '/notify_props', $requestOptions);
|
221
|
|
|
}
|
222
|
|
|
|
223
|
|
|
/**
|
224
|
|
|
* @param $userId
|
225
|
|
|
* @param array $requestOptions
|
226
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
227
|
|
|
*/
|
228
|
|
|
public function viewChannel($userId, array $requestOptions)
|
229
|
|
|
{
|
230
|
|
|
return $this->client->post(self::$endpoint . '/members/' . $userId . '/view', $requestOptions);
|
231
|
|
|
}
|
232
|
|
|
|
233
|
|
|
/**
|
234
|
|
|
* @param $userId
|
235
|
|
|
* @param $teamId
|
236
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
237
|
|
|
*/
|
238
|
|
|
public function getChannelMembersForTheUser($userId, $teamId)
|
239
|
|
|
{
|
240
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint . '/members');
|
241
|
|
|
}
|
242
|
|
|
|
243
|
|
|
/**
|
244
|
|
|
* @param $userId
|
245
|
|
|
* @param $teamId
|
246
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
247
|
|
|
*/
|
248
|
|
|
public function getChannelsForUser($userId, $teamId)
|
249
|
|
|
{
|
250
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . TeamModel::$endpoint . '/' . $teamId . '/' . self::$endpoint);
|
251
|
|
|
}
|
252
|
|
|
|
253
|
|
|
/**
|
254
|
|
|
* @param $userId
|
255
|
|
|
* @param $channelId
|
256
|
|
|
* @return \Psr\Http\Message\ResponseInterface
|
257
|
|
|
*/
|
258
|
|
|
public function getUnreadMessages($userId, $channelId)
|
259
|
|
|
{
|
260
|
|
|
return $this->client->get(UserModel::$endpoint . '/' . $userId . '/' . self::$endpoint . '/' . $channelId . '/unread');
|
261
|
|
|
}
|
262
|
|
|
} |