-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathChatroomExample.java
More file actions
109 lines (87 loc) · 3.29 KB
/
ChatroomExample.java
File metadata and controls
109 lines (87 loc) · 3.29 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
package io.rong.example.chatroom;
import io.rong.CenterEnum;
import io.rong.RongCloud;
import io.rong.methods.chatroom.Chatroom;
import io.rong.models.chatroom.ChatroomDataModel;
import io.rong.models.chatroom.ChatroomMember;
import io.rong.models.chatroom.ChatroomModel;
import io.rong.models.response.*;
public class ChatroomExample {
/**
* Replace with your App Key
*/
private static final String appKey = "appKey";
/**
* Replace with your App Secret
*/
private static final String appSecret = "appSecret";
public static void main(String[] args) throws Exception {
RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret, CenterEnum.BJ);
// Custom API URL
// RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret, api);
Chatroom chatroom = rongCloud.chatroom;
/**
*
*
* Create a chatroom
*/
ChatroomModel[] chatrooms = {
new ChatroomModel().setId("chatroomId1").setName("chatroomName1"),
new ChatroomModel().setId("chatroomId2").setName("chatroomName2")
};
ResponseResult result = chatroom.create(chatrooms);
System.out.println("create: " + result.toString());
ChatroomDataModel chatroomDataModel = new ChatroomDataModel().setId("chatroomId3");
ResponseResult result2 = chatroom.createV2(chatroomDataModel);
System.out.println("createV2: " + result2.toString());
ChatroomQueryResult queryResult = chatroom.query(new ChatroomModel().setId("chatroomId3"));
System.out.println("query: " + queryResult.toString());
/**
*
*
* Destroy a chatroom
*
* */
ChatroomModel chatroomModel = new ChatroomModel()
.setId("d7ec7a8b8d8546c98b0973417209a548");
//ResponseResult chatroomDestroyResult = chatroom.destroy(chatroomModel);
//System.out.println("destroy: " + chatroomDestroyResult.toString());
/**
*
*
* Query chatroom members demo
*
* */
chatroomModel = new ChatroomModel()
.setId("chatroomId1")
.setCount(500)
.setOrder(1);
ChatroomUserQueryResult chatroomQueryUserResult = chatroom.get(chatroomModel);
System.out.println("queryUser: " + chatroomQueryUserResult.toString());
/**
*
*
* Check if a chatroom member exists
*
* */
ChatroomMember member = new ChatroomMember()
.setId("76894")
.setChatroomId("76891");
CheckChatRoomUserResult checkMemberResult = chatroom.isExist(member);
System.out.println("checkChatroomUserResult: " + checkMemberResult.isInChrm);
/**
*
*
* Batch check if chatroom members exist
*
* */
ChatroomMember[] members = {
new ChatroomMember().setId("qawr34h"),new ChatroomMember().setId("qawr35h")
};
ChatroomModel exists = new ChatroomModel()
.setId("chrm01")
.setMembers(members);
CheckChatRoomUsersResult result1 = chatroom.isExists(exists);
System.out.println("checkChatroomUsersResult: " + result1);
}
}