6161import cn .jpush .im .android .api .event .GroupApprovedNotificationEvent ;
6262import cn .jpush .im .android .api .event .LoginStateChangeEvent ;
6363import cn .jpush .im .android .api .event .MessageEvent ;
64+ import cn .jpush .im .android .api .event .MessageReceiptStatusChangeEvent ;
6465import cn .jpush .im .android .api .event .MessageRetractEvent ;
6566import cn .jpush .im .android .api .event .NotificationClickEvent ;
6667import cn .jpush .im .android .api .event .OfflineMessageEvent ;
@@ -82,6 +83,7 @@ public class JMessageModule extends ReactContextBaseJavaModule {
8283
8384 private static final String TAG = "JMessageModule" ;
8485 private static final String RECEIVE_MSG_EVENT = "JMessage.ReceiveMsgEvent" ;
86+ private static final String RECEIPT_MSG_EVENT = "JMessage.ReceiptMsgEvent" ;
8587 private static final String LOGIN_STATE_CHANGE_EVENT = "JMessage.LoginStateChanged" ; //
8688 private static final String CLICK_NOTIFICATION_EVENT = "JMessage.ClickMessageNotification" ; // 点击推送 Android Only
8789 private static final String SYNC_OFFLINE_EVENT = "JMessage.SyncOfflineMessage" ; // 同步离线消息事件
@@ -377,17 +379,20 @@ public void sendMessage(ReadableMap map, final Callback success, final Callback
377379 if (map .hasKey (Constant .SENDING_OPTIONS )) {
378380 MessageSendingOptions options = new MessageSendingOptions ();
379381 ReadableMap optionMap = map .getMap (Constant .SENDING_OPTIONS );
380- options .setShowNotification (optionMap .getBoolean ("isShowNotification" ));
381- options .setRetainOffline (optionMap .getBoolean ("isRetainOffline" ));
382+ options .setShowNotification (optionMap .getBoolean (Constant . IS_SHOW_NOTIFICATION ));
383+ options .setRetainOffline (optionMap .getBoolean (Constant . IS_RETAIN_OFFLINE ));
382384
383- if (optionMap .hasKey ("isCustomNotificationEnabled" )) {
384- options .setCustomNotificationEnabled (optionMap .getBoolean ("isCustomNotificationEnabled" ));
385+ if (optionMap .hasKey (Constant . IS_CUSTOM_NOTIFICATION_ENABLED )) {
386+ options .setCustomNotificationEnabled (optionMap .getBoolean (Constant . IS_CUSTOM_NOTIFICATION_ENABLED ));
385387 }
386- if (optionMap .hasKey ("notificationTitle" )) {
387- options .setNotificationTitle (optionMap .getString ("notificationTitle" ));
388+ if (optionMap .hasKey (Constant . NOTIFICATION_TITLE )) {
389+ options .setNotificationTitle (optionMap .getString (Constant . NOTIFICATION_TITLE ));
388390 }
389- if (optionMap .hasKey ("notificationText" )) {
390- options .setNotificationText (optionMap .getString ("notificationText" ));
391+ if (optionMap .hasKey (Constant .NOTIFICATION_TEXT )) {
392+ options .setNotificationText (optionMap .getString (Constant .NOTIFICATION_TEXT ));
393+ }
394+ if (optionMap .hasKey (Constant .NEED_READ_RECEIPT )){
395+ options .setNeedReadReceipt (optionMap .getBoolean (Constant .NEED_READ_RECEIPT ));
391396 }
392397 JMessageClient .sendMessage (message , options );
393398 } else {
@@ -1517,17 +1522,20 @@ public void forwardMessage(ReadableMap map, final Callback success, final Callba
15171522 if (map .hasKey (Constant .SENDING_OPTIONS )) {
15181523 options = new MessageSendingOptions ();
15191524 ReadableMap optionMap = map .getMap (Constant .SENDING_OPTIONS );
1520- options .setShowNotification (optionMap .getBoolean ("isShowNotification" ));
1521- options .setRetainOffline (optionMap .getBoolean ("isRetainOffline" ));
1525+ options .setShowNotification (optionMap .getBoolean (Constant . IS_SHOW_NOTIFICATION ));
1526+ options .setRetainOffline (optionMap .getBoolean (Constant . IS_RETAIN_OFFLINE ));
15221527
1523- if (optionMap .hasKey ("isCustomNotificationEnabled" )) {
1524- options .setCustomNotificationEnabled (optionMap .getBoolean ("isCustomNotificationEnabled" ));
1528+ if (optionMap .hasKey (Constant .IS_CUSTOM_NOTIFICATION_ENABLED )) {
1529+ options .setCustomNotificationEnabled (optionMap .getBoolean (Constant .IS_CUSTOM_NOTIFICATION_ENABLED ));
1530+ }
1531+ if (optionMap .hasKey (Constant .NOTIFICATION_TITLE )) {
1532+ options .setNotificationTitle (optionMap .getString (Constant .NOTIFICATION_TITLE ));
15251533 }
1526- if (optionMap .hasKey ("notificationTitle" )) {
1527- options .setNotificationTitle (optionMap .getString ("notificationTitle" ));
1534+ if (optionMap .hasKey (Constant . NOTIFICATION_TEXT )) {
1535+ options .setNotificationText (optionMap .getString (Constant . NOTIFICATION_TEXT ));
15281536 }
1529- if (optionMap .hasKey ("notificationText" )) {
1530- options .setNotificationText (optionMap .getString ( "notificationText" ));
1537+ if (optionMap .hasKey (Constant . NEED_READ_RECEIPT )) {
1538+ options .setNeedReadReceipt (optionMap .getBoolean ( Constant . NEED_READ_RECEIPT ));
15311539 }
15321540 }
15331541 ReadableMap target = map .getMap (Constant .TARGET );
@@ -2076,6 +2084,53 @@ public void gotResult(int status, String desc) {
20762084 }
20772085 }
20782086
2087+ @ ReactMethod
2088+ public void setMsgHaveRead (ReadableMap map , final Callback callback ) {
2089+ String userName = map .getString (Constant .USERNAME );
2090+ String appKey = map .getString (Constant .APP_KEY );
2091+ String msgId = map .getString (Constant .ID );
2092+ String serverMsgId = map .getString (Constant .SERVER_ID );
2093+ WritableMap callbackMap = Arguments .createMap ();
2094+ if (TextUtils .isEmpty (userName )||
2095+ TextUtils .isEmpty (appKey )||
2096+ TextUtils .isEmpty (msgId )||
2097+ TextUtils .isEmpty (serverMsgId )){
2098+ callbackMap .putInt (Constant .CODE , ERR_CODE_CONVERSATION );
2099+ callbackMap .putString (Constant .DESCRIPTION , ERR_MSG_CONVERSATION );
2100+ callback .invoke (callbackMap );
2101+ return ;
2102+ }
2103+ Conversation conversation = JMessageClient .getSingleConversation (userName , appKey );
2104+ if (conversation ==null ){
2105+ callbackMap .putInt (Constant .CODE , ERR_CODE_CONVERSATION );
2106+ callbackMap .putString (Constant .DESCRIPTION , ERR_MSG_CONVERSATION );
2107+ callback .invoke (callbackMap );
2108+ return ;
2109+ }
2110+ //优先使用msgId获取conversation,获取不到再使用serverMsgId获取
2111+ Message message = conversation .getMessage (Integer .parseInt (msgId ));
2112+ if (message ==null ){
2113+ message = conversation .getMessage (Long .parseLong (serverMsgId ));
2114+ }
2115+ if (message == null ){
2116+ callbackMap .putInt (Constant .CODE , ERR_CODE_MESSAGE );
2117+ callbackMap .putString (Constant .DESCRIPTION , ERR_MSG_MESSAGE );
2118+ callback .invoke (callbackMap );
2119+ return ;
2120+ }
2121+ if (!message .haveRead ()) {
2122+ message .setHaveRead (new BasicCallback () {
2123+ @ Override
2124+ public void gotResult (int i , String s ) {
2125+ WritableMap map = Arguments .createMap ();
2126+ map .putInt (Constant .CODE , i );
2127+ map .putString (Constant .DESCRIPTION , s );
2128+ callback .invoke (map );
2129+ }
2130+ });
2131+ }
2132+ }
2133+
20792134 public void onEvent (LoginStateChangeEvent event ) {
20802135 Logger .d (TAG , "登录状态改变事件:event = " + event .toString ());
20812136 WritableMap map = Arguments .createMap ();
@@ -2091,6 +2146,23 @@ public void onEvent(MessageEvent event) {
20912146 .emit (RECEIVE_MSG_EVENT , ResultUtils .toJSObject (msg ));
20922147 }
20932148
2149+ /*
2150+ * 收到已读回执
2151+ * */
2152+ public void onEventMainThread (MessageReceiptStatusChangeEvent event ) {
2153+ WritableMap map = Arguments .createMap ();
2154+ Conversation conv = event .getConversation ();
2155+ for (MessageReceiptStatusChangeEvent .MessageReceiptMeta meta : event .getMessageReceiptMetas ()) {
2156+ WritableMap receiptMap = Arguments .createMap ();
2157+ receiptMap .putString (Constant .SERVER_ID , String .valueOf (meta .getServerMsgId ()));
2158+ receiptMap .putInt (Constant .UN_RECEIPT_COUNT , meta .getUnReceiptCnt ());
2159+ receiptMap .putString (Constant .UN_RECEIPT_M_TIME , String .valueOf (meta .getUnReceiptMtime ()));
2160+ map .putMap (Constant .RECEIPT_RESULT , receiptMap );
2161+ }
2162+ getReactApplicationContext ().getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
2163+ .emit (RECEIPT_MSG_EVENT , map );
2164+ }
2165+
20942166 /**
20952167 * 漫游消息同步事件。
20962168 *
0 commit comments