-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathChatroom.php
More file actions
403 lines (379 loc) · 10.8 KB
/
Copy pathChatroom.php
File metadata and controls
403 lines (379 loc) · 10.8 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?php
/**
* Chatroom
*/
namespace RongCloud\Lib\Chatroom;
use RongCloud\Lib\Request;
use RongCloud\Lib\Utils;
use RongCloud\Lib\Chatroom\Ban\Ban;
use RongCloud\Lib\Chatroom\Block\Block;
use RongCloud\Lib\Chatroom\Demotion\Demotion;
use RongCloud\Lib\Chatroom\Distribute\Distribute;
use RongCloud\Lib\Chatroom\Gag\Gag;
use RongCloud\Lib\Chatroom\Keepalive\Keepalive;
use RongCloud\Lib\Chatroom\Whitelist\Whitelist;
use RongCloud\Lib\Chatroom\Whitelist\Message;
use RongCloud\Lib\Chatroom\Entry\Entry;
use RongCloud\Lib\Chatroom\MuteAllMembers\MuteAllMembers;
use RongCloud\Lib\Chatroom\MuteWhiteList\MuteWhiteList;
class Chatroom
{
/**
* Chat room module path
*
* @var string
*/
private $jsonPath = 'Lib/Chatroom/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Validation configuration file
*
* @var string
*/
private $verify = '';
/**
* Chatroom constructor.
*/
function __construct()
{
$this->conf = Utils::getJson($this->jsonPath.'api.json');
$this->verify = Utils::getJson($this->jsonPath.'verify.json');
}
/**
* Chatroom Creation
*
* @deprecated Deprecated, please use the createV2 method for creation
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992',//Chatroom ID
* 'name'=> 'RongCloud',//Chatroom name
* ];
* @return mixed|null
*/
public function create(array $Chatroom=[]){
if(!isset($Chatroom[0])){
$Chatroom = [$Chatroom];
}
$conf = $this->conf['create'];
$verify = $this->verify['chatroom'];
$verify = ['id'=>$verify['id'],'name'=>$verify['name']];
$data = [];
foreach ($Chatroom as $v){
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $v,
'verify'=> $verify
]);
if($error) return $error;
$data["chatroom[{$v['id']}]"] = $v['name'];
}
$result = (new Request())->Request($conf['url'],$data);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Chatroom Creation
*
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992',// Chatroom ID
* 'destroyType' => 0,// Specifies the destruction type of the chatroom 0: Default value, indicates destruction when inactive, 1: Fixed time destruction
* 'destroyTime' => 60,// Sets the destruction time of the chatroom
* 'isBan' => false,// Whether to ban all members of the chatroom, default false
* 'whiteUserIds' => ['user1','user2'],// Whitelist user list for banning, supports batch setting, maximum not exceeding 20
* 'entryOwnerId' => '',// The owner user ID of the chatroom's custom properties.
* 'entryInfo' => '',// Custom properties KV pair of the chatroom, JSON structure.
* ];
* @return mixed|null
*/
public function createV2(array $Chatroom=[]){
$conf = $this->conf['createV2'];
$verify = $this->verify['chatroom'];
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'], $Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Set chatroom destruction type
*
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992', //Chatroom id
* 'destroyType'=> 0, //Specifies the destruction method of the chatroom.
* 'destroyTime'=> 60 //Set the destruction time of the chatroom.
* ];
* @return mixed|null
*/
public function setDestroyType(array $Chatroom=[]){
$conf = $this->conf['setDestroyType'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Destroy chatroom
*
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992',//chatroom id
* ];
* @return mixed|null
*/
public function destory(array $Chatroom=[]){
$conf = $this->conf['destory'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Query chatroom basic information
*
* @DateTime 2023-06-14
* @deprecated Deprecated, please use the queryV2 method for creation
* @param array $Chatroom ['id'=> ['chatroom1','chatroom1','chatroom1']]
*
* @return array
*/
public function query(array $Chatroom=[]){
$conf = $this->conf['query'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Query chatroom basic information V2
*
* @DateTime 2023-10-08
* @param array $Chatroom ['id'=> ['chatroom1','chatroom1','chatroom1']]
*
* @return array
*/
public function queryV2(array $Chatroom=[]){
$conf = $this->conf['queryV2'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Get chatroom members
*
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992',// Chatroom ID
* 'count'=>10,// Number of chatroom members, maximum return 500 members
* 'order'=>2// Query order of chatroom members, 1: Join time ascending 2: Join time descending
* ];
* @return mixed|null
*/
public function get(array $Chatroom=[]){
$conf = $this->conf['get'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Check if the user is in the chatroom
*
* @param array $Chatroom
* $Chatroom = [
* 'id'=> 'chatroom9992',// Chatroom ID
* 'members'=>[
* ['id'=>"sea9902"]// Member ID
* ]
* ];
* @return mixed|null
*/
public function isExist(array $Chatroom=[]){
$conf = $this->conf['isExist'];
$verify = $this->verify['chatroom'] ;
$verify = ['id'=>$verify['id'],'members'=>$verify['members']];
$error = (new Utils())->check([
'api'=> $conf,
'model'=> 'chatroom',
'data'=> $Chatroom,
'verify'=> $verify
]);
if($error) return $error;
foreach ($Chatroom['members'] as &$v){
$v = $v['id'];
}
$Chatroom = (new Utils())->rename($Chatroom, [
'id'=> 'chatroomId',
'members'=>'userId'
]);
$result = (new Request())->Request($conf['url'],$Chatroom);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
if($result['code'] == 200){
$result = (new Utils())->rename($result,['result'=>'members']);
foreach ($result['members'] as $k=>&$v){
$v = (new Utils())->rename($v,['userId'=>'id']);
}
}
return $result;
}
/**
* Create a global mute object for the chat room
*
* @return MuteWhiteList
*/
public function Ban(){
return new Ban();
}
/**
* Create a chat room block object
*
* @return Block
*/
public function Block(){
return new Block();
}
/**
* Create a chat room message demotion object
*
* @return Demotion
*/
public function Demotion(){
return new Demotion();
}
/**
* Create a chat room message distribution object
*
* @return Distribute
*/
public function Distribute(){
return new Distribute();
}
/**
* Create a chat room member gag object
*
* @return Gag
*/
public function Gag(){
return new Gag();
}
/**
* Create a chat room keepalive object
*
* @return Keepalive
*/
public function Keepalive(){
return new Keepalive();
}
/**
* Create a chat room user whitelist object
*
* @return Whitelist
*/
public function Whitelist(){
return new Whitelist();
}
/**
* Create a chat room whitelist message object
*
* @return Message
*/
public function Message(){
return new Message();
}
/**
* Create a whitelist message object for the chat room
*
* @return Entry
*/
public function Entry(){
return new Entry();
}
/**
* Mute all members in the chat room
*
* @return MuteAllMembers
*/
public function MuteAllMembers(){
return new MuteAllMembers();
}
/**
* Chat room global mute whitelist
*
* @return MuteWhiteList
*/
public function MuteWhiteList(){
return new MuteWhiteList();
}
}