Skip to content

Commit c2c16fb

Browse files
guangyaoguangyao
authored andcommitted
2 parents a1d5a04 + df185f4 commit c2c16fb

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ React Native的网易云信插件
44
[react-native-chat-demo](https://github.com/reactnativecomponent/react-native-chat-demo)
55

66
#### 注意: react-native版本需要0.47.0及以上NIMSDK版本4.0以上
7-
7+
```
8+
NIMSDK >=4.0 or react-native >=0.47 使用最新版
9+
NIMSDK <4.0 or react-native <0.47 请使用历史版本 <=1.0.7
10+
```
811
## 如何安装
912

1013
### 1.首先安装npm包

android/src/main/java/com/netease/im/ReactCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class ReactCache {
8181
public final static String observeBlackList = "observeBlackList";//'黑名单'
8282
public final static String observeAttachmentProgress = "observeAttachmentProgress";//'上传下载进度'
8383
public final static String observeOnKick = "observeOnKick";//'被踢出'
84+
public final static String observeAccountNotice = "observeAccountNotice";//'账户变动通知'
8485

8586
final static String TAG = "ReactCache";
8687
private static ReactContext reactContext;

android/src/main/java/com/netease/im/login/RecentContactObserver.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import com.facebook.react.bridge.WritableMap;
77
import com.netease.im.RNNeteaseImModule;
88
import com.netease.im.ReactCache;
9+
import com.netease.im.session.extension.AccountNoticeAttachment;
10+
import com.netease.im.session.extension.CustomAttachment;
11+
import com.netease.im.session.extension.CustomAttachmentType;
912
import com.netease.im.uikit.cache.SimpleCallback;
1013
import com.netease.im.uikit.cache.TeamDataCache;
1114
import com.netease.nimlib.sdk.NIMClient;
@@ -16,6 +19,7 @@
1619
import com.netease.nimlib.sdk.auth.constant.LoginSyncStatus;
1720
import com.netease.nimlib.sdk.msg.MsgService;
1821
import com.netease.nimlib.sdk.msg.MsgServiceObserve;
22+
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
1923
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
2024
import com.netease.nimlib.sdk.msg.model.IMMessage;
2125
import com.netease.nimlib.sdk.msg.model.RecentContact;
@@ -227,7 +231,29 @@ public int compare(RecentContact o1, RecentContact o2) {
227231

228232
@Override
229233
public void onEvent(List<IMMessage> imMessages) {
230-
234+
if (imMessages == null || imMessages.isEmpty()) {
235+
return;
236+
}
237+
for (IMMessage m : imMessages) {
238+
if (m.getMsgType() == MsgTypeEnum.custom) {
239+
CustomAttachment attachment = null;
240+
try {
241+
attachment = (CustomAttachment) m.getAttachment();
242+
} catch (Exception e) {
243+
e.printStackTrace();
244+
}
245+
if (attachment != null && attachment.getType() == CustomAttachmentType.AccountNotice) {
246+
AccountNoticeAttachment noticeAttachment = null;
247+
try {
248+
noticeAttachment = (AccountNoticeAttachment) attachment;
249+
} catch (Exception e) {
250+
e.printStackTrace();
251+
}
252+
ReactCache.emit(ReactCache.observeAccountNotice, noticeAttachment == null ? null : noticeAttachment.toReactNative());
253+
break;
254+
}
255+
}
256+
}
231257
}
232258
};
233259
Observer<List<RecentContact>> messageObserver = new Observer<List<RecentContact>>() {
@@ -301,7 +327,7 @@ public void onEvent(StatusCode code) {
301327
}
302328
WritableMap r = Arguments.createMap();
303329
String codeValue;
304-
switch (code){
330+
switch (code) {
305331
case PWD_ERROR:
306332
codeValue = "10";
307333
break;

0 commit comments

Comments
 (0)