33import io .rong .CenterEnum ;
44import io .rong .RongCloud ;
55import io .rong .methods .conversation .Conversation ;
6+ import io .rong .models .conversation .ConversationAttrModel ;
67import io .rong .models .conversation .ConversationModel ;
78import 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 ;
812import io .rong .models .response .ConversationNotificationResult ;
913import io .rong .models .response .ResponseResult ;
14+ import io .rong .models .response .ResultData ;
1015import 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}
0 commit comments