-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathConversation.php
173 lines (162 loc) · 5.32 KB
/
Conversation.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
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
<?php
/**
* Conversation Module
* conversation=> hejinyu
* Date=> 2018/7/23
* Time=> 11=>41
*/
namespace RongCloud\Lib\Conversation;
use RongCloud\Lib\ConversationType;
use RongCloud\Lib\Request;
use RongCloud\Lib\Utils;
class Conversation
{
/**
* Session module path
*
* @var string
*/
private $jsonPath = 'Lib/Conversation/';
/**
* Request configuration file
*
* @var string
*/
private $conf = '';
/**
* Configuration file for validation
*
* @var string
*/
private $verify = '';
/**
* Conversation constructor.
*/
function __construct()
{
$this->conf = Utils::getJson($this->jsonPath . 'api.json');
$this->verify = Utils::getJson($this->jsonPath . 'verify.json');
}
/**
* Screen Session Push
*
* @param array $Conversation Screen session push parameters
* @param
* $Conversation = [
* 'type'=> 'PRIVATE',//Session type: PRIVATE, GROUP, DISCUSSION, SYSTEM
* 'userId'=>'mka091amn',//Session owner
* 'targetId'=>'adm1klnm'//Session ID
* ];
* @return array
*/
public function mute(array $Conversation = [])
{
$conf = $this->conf['mute'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'conversation',
'data' => $Conversation,
'verify' => $this->verify['conversation']
]);
if ($error) return $error;
$Conversation['type'] = ConversationType::t()[$Conversation['type']];
$Conversation['isMuted'] = 1;
$Conversation = (new Utils())->rename($Conversation, [
'type' => 'conversationType',
'userId' => 'requestId'
]);
$result = (new Request())->Request($conf['url'], $Conversation);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Receive Conversation Push
*
* @param array $Conversation Parameters for receiving Conversation Push
* @param
* $Conversation = [
* 'type'=> 'PRIVATE',//Conversation type PRIVATE, GROUP, DISCUSSION, SYSTEM
* 'userId'=>'mka091amn',//Conversation owner
* 'targetId'=>'adm1klnm'//Conversation id
* ];
* @return array
*/
public function unmute(array $Conversation = [])
{
$conf = $this->conf['mute'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'conversation',
'data' => $Conversation,
'verify' => $this->verify['conversation']
]);
if ($error) return $error;
$Conversation['type'] = ConversationType::t()[$Conversation['type']];
$Conversation['isMuted'] = 0;
$Conversation = (new Utils())->rename($Conversation, [
'type' => 'conversationType',
'userId' => 'requestId'
]);
$result = (new Request())->Request($conf['url'], $Conversation);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Get the conversation state without interruption
*
* @param array $Conversation Receive conversation Push parameters
* @param
* $Conversation = [
* 'type'=> 'PRIVATE',// Conversation type PRIVATE, GROUP, DISCUSSION, SYSTEM
* 'userId'=>'mka091amn',// Conversation owner
* 'targetId'=>'adm1klnm'// Conversation id
* ];
* @return array
*/
public function get(array $Conversation = [])
{
$conf = $this->conf['mute'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'conversation',
'data' => $Conversation,
'verify' => $this->verify['conversation']
]);
if ($error) return $error;
$Conversation['type'] = ConversationType::t()[$Conversation['type']];
$Conversation['isMuted'] = 0;
$Conversation = (new Utils())->rename($Conversation, [
'type' => 'conversationType',
'userId' => 'requestId'
]);
$result = (new Request())->Request($conf['url'], $Conversation);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
/**
* Pin Conversation
*
* @param array
* $Conversation = [
* 'userId'=>'mka091amn',// User ID, the user to whom the conversation belongs
* 'conversationType'=>'1',// Conversation type. Supported conversation types include: 1 (one-to-one chat), 3 (group chat), 6 (system conversation).
* 'targetId'=>'adm1klnd',// Target ID to be set, which varies depending on the conversation type: user ID for one-to-one chat, group ID for group chat, or system target ID.
* 'setTop'=>'true'// true means pin, false means unpin.
* ];
* @return void
*/
public function pinned(array $Conversation = [])
{
$conf = $this->conf['pinned'];
$error = (new Utils())->check([
'api' => $conf,
'model' => 'pinned',
'data' => $Conversation,
'verify' => $this->verify['pinned']
]);
if ($error) return $error;
$result = (new Request())->Request($conf['url'], $Conversation);
$result = (new Utils())->responseError($result, $conf['response']['fail']);
return $result;
}
}