Skip to content

Commit 0d2f694

Browse files
committed
add observeAccountNotice 账户变动通知
1 parent 1df3e8d commit 0d2f694

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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)