-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathMuteAllMembers.java
More file actions
144 lines (127 loc) · 5.6 KB
/
Copy pathMuteAllMembers.java
File metadata and controls
144 lines (127 loc) · 5.6 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
package io.rong.methods.group.mute;
import io.rong.RongCloud;
import io.rong.methods.group.ban.user.User;
import io.rong.methods.group.ban.whitelist.Whitelist;
import io.rong.models.CheckMethod;
import io.rong.models.Result;
import io.rong.models.response.GroupMuteAllMembersCheckResult;
import io.rong.models.response.GroupMuteAllMembersListResult;
import io.rong.models.response.ResponseResult;
import io.rong.util.CommonUtil;
import io.rong.util.GsonUtil;
import io.rong.util.HttpUtil;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
/**
* Group Mute Service
* Mute all members in a group. If certain users need to speak while the group is muted, add them to the group mute allowlist.
*
* */
public class MuteAllMembers {
private static final String UTF8 = "UTF-8";
private static final String PATH = "group/mute/all";
private String appKey;
private String appSecret;
private RongCloud rongCloud;
public User user;
public Whitelist whitelist;
public RongCloud getRongCloud() {
return rongCloud;
}
public void setRongCloud(RongCloud rongCloud) {
this.rongCloud = rongCloud;
}
public MuteAllMembers(String appKey, String appSecret, RongCloud rongCloud) {
this.appKey = appKey;
this.appSecret = appSecret;
this.rongCloud = rongCloud;
this.user = new User(appKey,appSecret,rongCloud);
this.whitelist = new Whitelist(appKey,appSecret,rongCloud);
}
/**
* Add group mute method
*
* @param groupIds: Group ID
* @return Result
**/
public Result add(String[] groupIds) throws Exception {
String message = CommonUtil.checkParam("id",groupIds,PATH,CheckMethod.ADD);
if(null != message){
return (ResponseResult)GsonUtil.fromJson(message,ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
for(String groupId : groupIds){
sb.append("&groupId=").append(URLEncoder.encode(groupId, UTF8));
}
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/group/ban/add.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.ADD,HttpUtil.returnResult(conn, rongCloud.getConfig())), ResponseResult.class);
}
/**
* Query muted groups method
*
* @return ListGagGroupUserResult
**/
public Result getList() throws Exception {
StringBuilder sb = new StringBuilder();
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/group/ban/query.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (GroupMuteAllMembersListResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.GETLIST,HttpUtil.returnResult(conn, rongCloud.getConfig())), GroupMuteAllMembersListResult.class);
}
/**
* Query muted groups method
*
* @param groupIds: Group IDs. (Required)
*
* @return ListGagGroupUserResult
**/
public Result check(String[] groupIds) throws Exception {
String message = CommonUtil.checkParam("id",groupIds,PATH,CheckMethod.ADD);
if(null != message){
return (ResponseResult)GsonUtil.fromJson(message,ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
for(String groupId : groupIds){
sb.append("&groupId=").append(URLEncoder.encode(groupId, UTF8));
}
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/group/ban/query.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (GroupMuteAllMembersCheckResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.GETLIST,HttpUtil.returnResult(conn, rongCloud.getConfig())), GroupMuteAllMembersCheckResult.class);
}
/**
* Remove global group mute method
*
* @param groupIds: Group ID (required)
*
* @return ResponseResult
**/
public Result remove(String[] groupIds) throws Exception {
String message = CommonUtil.checkParam("id",groupIds,PATH,CheckMethod.ADD);
if(null != message){
return (ResponseResult)GsonUtil.fromJson(message,ResponseResult.class);
}
StringBuilder sb = new StringBuilder();
for(String groupId : groupIds){
sb.append("&groupId=").append(URLEncoder.encode(groupId, UTF8));
}
String body = sb.toString();
if (body.indexOf("&") == 0) {
body = body.substring(1, body.length());
}
HttpURLConnection conn = HttpUtil.CreatePostHttpConnection(rongCloud.getConfig(), appKey, appSecret, "/group/ban/rollback.json", "application/x-www-form-urlencoded");
HttpUtil.setBodyParameter(body, conn, rongCloud.getConfig());
return (ResponseResult) GsonUtil.fromJson(CommonUtil.getResponseByCode(PATH,CheckMethod.REMOVE,HttpUtil.returnResult(conn, rongCloud.getConfig())), ResponseResult.class);
}
}