Skip to content

Commit a6719ab

Browse files
rongljzrchht
authored andcommitted
feat:增加会话属性相关接口
1 parent 9db1e73 commit a6719ab

16 files changed

Lines changed: 680 additions & 59 deletions

README-CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ RongCloud IM Server SDK in Java.
1111
<dependency>
1212
<groupId>cn.rongcloud.im</groupId>
1313
<artifactId>server-sdk-java</artifactId>
14-
<version>4.0.6</version>
14+
<version>4.0.7</version>
1515
</dependency>
1616
```
1717
* Gradle
1818
```
19-
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.6'
19+
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.7'
2020
2121
```
2222
* 基于源码 Meavn 打包构建

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ RongCloud IM Server SDK in Java.
1010
<dependency>
1111
<groupId>cn.rongcloud.im</groupId>
1212
<artifactId>server-sdk-java</artifactId>
13-
<version>4.0.6</version>
13+
<version>4.0.7</version>
1414
</dependency>
1515
```
1616
* Gradle
1717
```
18-
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.6'
18+
compile group: 'cn.rongcloud.im', name: 'server-sdk-java', version: '4.0.7'
1919
```
2020
* Build from source
2121
```

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cn.rongcloud.im</groupId>
88
<artifactId>server-sdk-java</artifactId>
9-
<version>4.0.6</version>
9+
<version>4.0.7</version>
1010
<packaging>jar</packaging>
1111
<name>RongCloud IM Server SDK</name>
1212
<description>
@@ -174,9 +174,9 @@
174174
<source>1.7</source>
175175
<target>1.7</target>
176176
<encoding>UTF-8</encoding>
177-
<compilerArguments>
178-
<extdirs>${project.basedir}/lib</extdirs>
179-
</compilerArguments>
177+
<!-- <compilerArguments>-->
178+
<!-- <extdirs>${project.basedir}/lib</extdirs>-->
179+
<!-- </compilerArguments>-->
180180
</configuration>
181181
</plugin>
182182
</plugins>

src/main/java/io/rong/example/conversation/ConversationExample.java

Lines changed: 149 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
import io.rong.CenterEnum;
44
import io.rong.RongCloud;
55
import io.rong.methods.conversation.Conversation;
6+
import io.rong.models.conversation.ConversationAttrModel;
67
import io.rong.models.conversation.ConversationModel;
78
import io.rong.models.conversation.ConversationSetTopModel;
9+
import io.rong.models.conversation.ConversationTagModel;
10+
import io.rong.models.conversation.TagConversationsModel;
11+
import io.rong.models.conversation.UserConversationTagModel;
812
import io.rong.models.response.ConversationNotificationResult;
913
import io.rong.models.response.ResponseResult;
14+
import io.rong.models.response.ResultData;
1015
import io.rong.util.CodeUtil.ConversationType;
16+
import io.rong.util.GsonUtil;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
1120

1221
/**
1322
*
@@ -29,56 +38,158 @@ public class ConversationExample {
2938
public static void main(String[] args) throws Exception {
3039

3140
RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret, CenterEnum.BJ);
32-
// Custom API URL
33-
// RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret,api);
3441

35-
Conversation Conversation = rongCloud.conversation;
42+
Conversation conversation = rongCloud.conversation;
3643

37-
ConversationModel conversation = new ConversationModel()
38-
.setType(ConversationType.PRIVATE.getName())
39-
.setUserId("UgYzcDZSisNyYaZ83WXcEk11")
40-
.setTargetId("2iXiqVWUAWwaKA55FuZvY31");
41-
/**
42-
*
43-
*
44-
* Set Conversation Do Not Disturb
45-
*
46-
*/
47-
ResponseResult muteConversationResult = Conversation.mute(conversation);
4844

45+
// muteDemo(conversation);
46+
// unMuteDemo(conversation);
47+
// queryMuteDemo(conversation);
48+
// topDemo(conversation);
49+
50+
51+
// setUserConversationTagDemo(conversation);
52+
53+
// deleteUserConversationTagDemo(conversation);
54+
//
55+
// queryUserConversationTagsDemo(conversation);
56+
//
57+
// setConversationTagDemo(conversation);
58+
//
59+
// removeConversationTagDemo(conversation);
60+
//
61+
// queryTagConversationsDemo(conversation);
62+
//
63+
queryConversationAttributeDemo(conversation);
64+
65+
}
66+
67+
68+
public static void muteDemo(Conversation conversation) throws Exception {
69+
ConversationModel conversationModel = new ConversationModel()
70+
.setType(ConversationType.PRIVATE.getName())
71+
.setUserId("sdkTestU1")
72+
.setTargetId("sdkTestU2").setUnpushLevel(5);
73+
ResponseResult muteConversationResult = conversation.mute(conversationModel);
4974
System.out.println("muteConversationResult: " + muteConversationResult.toString());
75+
}
5076

51-
/**
52-
*
53-
*
54-
* Disable Conversation Do Not Disturb
55-
*
56-
* */
57-
ResponseResult unMuteConversationResult = Conversation.unMute(conversation);
58-
59-
System.out.println("unMuteConversationResult: " + unMuteConversationResult.toString());
60-
/**
61-
*
62-
*
63-
* Get Conversation Do Not Disturb Status
64-
*
65-
* */
66-
ConversationNotificationResult getMuteConversationResult = (ConversationNotificationResult)Conversation.get(conversation);
6777

68-
System.out.println("getMuteConversationResult: " + getMuteConversationResult.toString());
78+
public static void unMuteDemo(Conversation conversation) throws Exception {
79+
ConversationModel conversationModel = new ConversationModel()
80+
.setType(ConversationType.PRIVATE.getName())
81+
.setUserId("UgYzcDZSisNyYaZ83WXcEk11")
82+
.setTargetId("2iXiqVWUAWwaKA55FuZvY31");
83+
ResponseResult muteConversationResult = conversation.unMute(conversationModel);
84+
System.out.println("unMuteConversationResult: " + muteConversationResult.toString());
85+
}
6986

87+
public static void queryMuteDemo(Conversation conversation) throws Exception {
88+
ConversationModel conversationModel = new ConversationModel()
89+
.setType(ConversationType.PRIVATE.getName())
90+
.setUserId("UgYzcDZSisNyYaZ83WXcEk11")
91+
.setTargetId("2iXiqVWUAWwaKA55FuZvY31");
92+
ConversationNotificationResult getMuteConversationResult = (ConversationNotificationResult) conversation.get(conversationModel);
93+
System.out.println("getMuteConversationResult: " + getMuteConversationResult.toString());
94+
}
7095

7196

72-
/**
73-
*
74-
* Set conversation top.
75-
*/
97+
public static void topDemo(Conversation conversation) throws Exception {
7698
ConversationSetTopModel setTopModel = new ConversationSetTopModel()
7799
.setSetTop(true)
78100
.setConversationType(1)
79-
.setTargetId("tid")
80-
.setUserId("uid");
81-
ResponseResult result = Conversation.setTop(setTopModel);
101+
.setTargetId("sdkTestU2")
102+
.setUserId("sdkTestU1");
103+
ResponseResult result = conversation.setTop(setTopModel);
82104
System.out.println("setTop: " + result.toString());
83105
}
106+
107+
108+
private static void setUserConversationTagDemo(Conversation conversation) throws Exception {
109+
110+
111+
List<ConversationTagModel> tags = new ArrayList<>();
112+
tags.add(new ConversationTagModel("tag1","标签1"));
113+
tags.add(new ConversationTagModel("tag2","标签2"));
114+
tags.add(new ConversationTagModel("tag3","标签3"));
115+
tags.add(new ConversationTagModel("tag4","标签4"));
116+
117+
UserConversationTagModel userConversationTagModel = new UserConversationTagModel();
118+
userConversationTagModel.setUserId("sdkTestU1");
119+
userConversationTagModel.setTags(tags);
120+
121+
ResponseResult result = conversation.setUserConversationTag(userConversationTagModel);
122+
123+
System.out.println("setUserConversationTag result : " + result.toString());
124+
125+
}
126+
127+
128+
private static void deleteUserConversationTagDemo(Conversation conversation) throws Exception {
129+
String userId = "sdkTestU1";
130+
List<String> tagIds = new ArrayList<>();
131+
tagIds.add("tag1");
132+
tagIds.add("tag2");
133+
ResponseResult result = conversation.deleteUserConversationTag(userId, tagIds);
134+
System.out.println("deleteUserConversationTagDemo result : " + result.toString());
135+
}
136+
137+
private static void queryUserConversationTagsDemo(Conversation conversation) throws Exception {
138+
String userId = "sdkTestU1";
139+
ResultData<UserConversationTagModel> result = conversation.queryUserConversationTags(userId);
140+
System.out.println("queryUserConversationTagsDemo result : " + GsonUtil.toJson(result));
141+
}
142+
143+
144+
public static void setConversationTagDemo(Conversation conversation) throws Exception{
145+
146+
TagConversationsModel tagConversationsModel = new TagConversationsModel();
147+
tagConversationsModel.setUserId("sdkTestU1");
148+
tagConversationsModel.setTagId("tag3");
149+
TagConversationsModel.Conversation conversation1 = new TagConversationsModel.Conversation("sdkTestU2",1);
150+
TagConversationsModel.Conversation conversation2 = new TagConversationsModel.Conversation("sdkTestG1",3);
151+
List<TagConversationsModel.Conversation> conversationList= new ArrayList<>();
152+
conversationList.add(conversation1);
153+
conversationList.add(conversation2);
154+
tagConversationsModel.setConversations(conversationList);
155+
ResponseResult result = conversation.setConversationTag(tagConversationsModel);
156+
System.out.println("setConversationTagDemo result: " + GsonUtil.toJson(result));
157+
}
158+
159+
160+
public static void removeConversationTagDemo(Conversation conversation) throws Exception{
161+
162+
TagConversationsModel tagConversationsModel = new TagConversationsModel();
163+
tagConversationsModel.setUserId("sdkTestU1");
164+
tagConversationsModel.setTagId("tag3");
165+
TagConversationsModel.Conversation conversation1 = new TagConversationsModel.Conversation("sdkTestU2",1);
166+
TagConversationsModel.Conversation conversation2 = new TagConversationsModel.Conversation("sdkTestG2",3);
167+
List<TagConversationsModel.Conversation> conversationList= new ArrayList<>();
168+
conversationList.add(conversation1);
169+
conversationList.add(conversation2);
170+
tagConversationsModel.setConversations(conversationList);
171+
ResponseResult result = conversation.removeConversationTag(tagConversationsModel);
172+
System.out.println("removeConversationTagDemo result: " + GsonUtil.toJson(result));
173+
}
174+
175+
176+
177+
public static void queryTagConversationsDemo(Conversation conversation) throws Exception{
178+
String userId = "sdkTestU1";
179+
String tagId = "tag3";
180+
ResultData<TagConversationsModel> resultData = conversation.queryTagConversations(userId,tagId);
181+
System.out.println("queryTagConversationsDemo result: " + GsonUtil.toJson(resultData));
182+
}
183+
184+
185+
public static void queryConversationAttributeDemo(Conversation conversation) throws Exception{
186+
String userId = "sdkTestU1";
187+
String targetId = "sdkTestU2";
188+
Integer conversationType = 1;
189+
ResultData<ConversationAttrModel> resultData = conversation.queryConversationAttribute(userId, targetId, conversationType);
190+
System.out.println("queryConversationAttributeDemo result: " + GsonUtil.toJson(resultData));
191+
}
192+
193+
194+
84195
}

src/main/java/io/rong/methods/BaseMethod.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ protected <T extends ResponseResult> T doRequest(String uri, String body, String
9191
}
9292

9393

94+
protected <T extends ResponseResult> T doGetRequest(String uri, Class<T> respClass) {
95+
T result;
96+
String response = "";
97+
try {
98+
HttpURLConnection conn = HttpUtil.createGetHttpConnection(rongCloud.getConfig(), appKey, appSecret, uri);
99+
response = HttpUtil.returnResult(conn, rongCloud.getConfig());
100+
result = GsonUtil.fromJson(respClass, CommonUtil.getResponseByCode(path, "", response));
101+
if (result.getCode() == null) {
102+
throw new RuntimeException(response);
103+
}
104+
} catch (Exception e) {
105+
rongCloud.getConfig().errorCounter.incrementAndGet();
106+
result = GsonUtil.fromJson(respClass, new ResponseResult(500, "uri=" + uri + " response=" + response + " errorInfo=" + e.getClass().getSimpleName() + ":" + e.getMessage()).toString());
107+
}
108+
return result;
109+
}
110+
111+
94112
/**
95113
* Use LinkedHashSet to maintain the insertion order of elements and automatically remove duplicates
96114
*/

0 commit comments

Comments
 (0)