77import io .rong .models .CheckMethod ;
88import io .rong .models .Result ;
99import io .rong .models .Templates ;
10+ import io .rong .models .message .ModifyPrivateMessage ;
1011import io .rong .models .message .PrivateMessage ;
1112import io .rong .models .message .PrivateStatusMessage ;
1213import io .rong .models .message .RecallMessage ;
1314import io .rong .models .message .TemplateMessage ;
1415import io .rong .models .response .MessageResult ;
1516import io .rong .models .response .ResponseResult ;
17+ import io .rong .messages .BaseMessage ;
1618import io .rong .util .CommonUtil ;
1719import io .rong .util .GsonUtil ;
1820import io .rong .util .HttpUtil ;
@@ -340,6 +342,7 @@ public MessageResult sendStatusMessage(PrivateStatusMessage message) throws Exce
340342 * @return MessageResult
341343 * @throws Exception
342344 */
345+ @ Deprecated
343346 public MessageResult sendTypingStatusMessage (PrivateMessage message ) throws Exception {
344347 String errMsg = CommonUtil .checkFiled (message , PATH , CheckMethod .SEND );
345348 if (null != errMsg ) {
@@ -382,4 +385,63 @@ public MessageResult sendTypingStatusMessage(PrivateMessage message) throws Exce
382385 result .setReqBody (body );
383386 return result ;
384387 }
388+
389+ /**
390+ * Modify a one-to-one chat message.
391+ *
392+ * @param message The one-to-one chat message modification request.
393+ * @return ResponseResult
394+ * @throws Exception
395+ */
396+ public Result modify (ModifyPrivateMessage message ) throws Exception {
397+ String errMsg = CommonUtil .checkFiled (message , PATH , CheckMethod .MODIFY );
398+ if (null != errMsg ) {
399+ return (ResponseResult ) GsonUtil .fromJson (errMsg , ResponseResult .class );
400+ }
401+
402+ StringBuilder sb = new StringBuilder ();
403+ sb .append ("&fromUserId=" ).append (URLEncoder .encode (message .getSenderId (), UTF8 ));
404+ sb .append ("&targetId=" ).append (URLEncoder .encode (message .getTargetId (), UTF8 ));
405+ sb .append ("&msgUID=" ).append (URLEncoder .encode (message .getMsgUID (), UTF8 ));
406+
407+ BaseMessage content = message .getContent ();
408+ String objectName = message .getObjectName ();
409+ if (StringUtils .isBlank (objectName )) {
410+ objectName = content .getType ();
411+ }
412+
413+ if (StringUtils .isNotBlank (objectName )) {
414+ sb .append ("&objectName=" ).append (URLEncoder .encode (objectName , UTF8 ));
415+ }
416+ sb .append ("&content=" ).append (URLEncoder .encode (content .toString (), UTF8 ));
417+
418+ String body = sb .toString ();
419+ if (body .indexOf ("&" ) == 0 ) {
420+ body = body .substring (1 , body .length ());
421+ }
422+
423+ HttpURLConnection conn = HttpUtil .CreatePostHttpConnection (
424+ rongCloud .getConfig (),
425+ appKey ,
426+ appSecret ,
427+ "/message/private/modify.json" ,
428+ "application/x-www-form-urlencoded"
429+ );
430+ HttpUtil .setBodyParameter (body , conn , rongCloud .getConfig ());
431+
432+ ResponseResult result = null ;
433+ String response = "" ;
434+ try {
435+ response = HttpUtil .returnResult (conn , rongCloud .getConfig ());
436+ result = (ResponseResult ) GsonUtil .fromJson (
437+ CommonUtil .getResponseByCode (PATH , CheckMethod .MODIFY , response ),
438+ ResponseResult .class
439+ );
440+ } catch (JSONException | JsonParseException | IllegalStateException e ) {
441+ rongCloud .getConfig ().errorCounter .incrementAndGet ();
442+ result = new ResponseResult (500 , "request:" + conn .getURL () + " ,response:" + response + " ,JSONException:" + e .getMessage ());
443+ }
444+ result .setReqBody (body );
445+ return result ;
446+ }
385447}
0 commit comments