Skip to content

Commit 2fe8755

Browse files
guangyaoguangyao
authored andcommitted
2 parents 03f99bf + 0149401 commit 2fe8755

File tree

9 files changed

+128
-102
lines changed

9 files changed

+128
-102
lines changed

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,17 @@ public void onResult(int i, NimUserInfo userInfo, Throwable throwable) {
239239

240240
/**
241241
* 添加好友
242+
*
242243
* @param contactId
243244
* @param verifyType 1 直接添加
244-
* @param msg 备注
245+
* @param msg 备注
245246
* @param promise
246247
*/
247248
@ReactMethod
248249
public void addFriendWithType(final String contactId, String verifyType, String msg, final Promise promise) {
249250
VerifyType verifyTypeAdd = VerifyType.VERIFY_REQUEST;
250-
if("1".equals(verifyType)){
251-
verifyTypeAdd = VerifyType.DIRECT_ADD;
251+
if ("1".equals(verifyType)) {
252+
verifyTypeAdd = VerifyType.DIRECT_ADD;
252253
}
253254
LogUtil.i(TAG, "addFriend" + contactId);
254255
NIMClient.getService(FriendService.class).addFriend(new AddFriendData(contactId, verifyTypeAdd, msg))
@@ -265,6 +266,7 @@ public void onResult(int code, Void aVoid, Throwable throwable) {
265266
}
266267
});
267268
}
269+
268270
/**
269271
* 添加好友
270272
*
@@ -1474,8 +1476,12 @@ public void queryMessageListHistory(String sessionId, String sessionType, String
14741476
public void onResult(int code, List<IMMessage> result, Throwable exception) {
14751477
if (code == ResponseCode.RES_SUCCESS) {
14761478
if (result != null && result.size() > 0) {
1477-
promise.resolve(ReactCache.createMessageList(result));
1478-
return;
1479+
Object a = ReactCache.createMessageList(result);
1480+
if (a != null) {
1481+
promise.resolve(a);
1482+
return;
1483+
}
1484+
14791485
}
14801486
}
14811487
promise.reject("" + code, "");
@@ -1502,7 +1508,12 @@ public int onResult(int code, List<IMMessage> messageList, Set<String> timedItem
15021508
if (messageList == null || messageList.isEmpty()) {
15031509
promise.reject("" + code, "");
15041510
} else {
1505-
promise.resolve(ReactCache.createMessageList(messageList));
1511+
Object a = ReactCache.createMessageList(messageList);
1512+
if (a != null) {
1513+
promise.resolve(a);
1514+
} else {
1515+
promise.reject("" + code, "");
1516+
}
15061517
}
15071518
return 0;
15081519
}
@@ -1621,7 +1632,7 @@ public void play(String audioFile, Promise promise) {
16211632
*/
16221633
@ReactMethod
16231634
public void stopPlay(Promise promise) {
1624-
audioPlayService.stopPlay(handler,reactContext);
1635+
audioPlayService.stopPlay(handler, reactContext);
16251636
}
16261637

16271638
/**
@@ -1809,20 +1820,14 @@ public void onResult(int code, Void aVoid, Throwable throwable) {
18091820
/**
18101821
* 删除系统通知
18111822
*
1812-
* @param messageId
1823+
* @param fromAccount
18131824
* @param timestamp
18141825
* @param promise
18151826
*/
18161827
@ReactMethod
1817-
public void deleteSystemMessage(String messageId, String timestamp, final Promise promise) {
1818-
long messageIdLong = 0L;
1819-
try {
1820-
messageIdLong = Long.parseLong(messageId);
1821-
} catch (NumberFormatException e) {
1822-
e.printStackTrace();
1823-
}
1828+
public void deleteSystemMessage(String fromAccount, String timestamp, final Promise promise) {
18241829
if (sysMessageObserver != null)
1825-
sysMessageObserver.deleteSystemMessage(messageIdLong);
1830+
sysMessageObserver.deleteSystemMessageById(fromAccount);
18261831
}
18271832

18281833
/**

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

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ public static Object createRecentList(List<RecentContact> recents, int unreadNum
187187
if (attachment instanceof RedPacketOpenAttachement) {
188188
RedPacketOpenAttachement rpOpen = (RedPacketOpenAttachement) attachment;
189189
nickName = "";
190-
if (sessionType == SessionTypeEnum.Team && !rpOpen.isSelf()) {
191-
content = "";
192-
} else {
190+
// if (sessionType == SessionTypeEnum.Team && !rpOpen.isSelf()) {
191+
// content = "";
192+
// } else {
193193
content = rpOpen.getTipMsg(false);
194-
}
194+
// }
195195
}
196196
break;
197197
default:
@@ -541,28 +541,17 @@ public static Object createMessageList(List<IMMessage> messageList) {
541541
if (messageList != null) {
542542
int size = messageList.size();
543543
for (int i = 0; i < size; i++) {
544-
IMMessage item = messageList.get(i);
545-
if (item == null) {
546-
continue;
547-
}
548-
WritableMap itemMap = createMessage(item);
549544

550-
if (itemMap == null) {
551-
continue;
545+
IMMessage item = messageList.get(i);
546+
if (item != null) {
547+
WritableMap itemMap = createMessage(item);
548+
if (itemMap != null) {
549+
writableArray.pushMap(itemMap);
550+
}
552551
}
553-
// String timeStr = TimeUtil.getTimeShowString(item.getTime(), false);
554-
// if (timedItems != null && timedItems.contains(item.getUuid())) {//添加短时间处理,作为一条消息
555-
// itemMap = Arguments.createMap();
556-
// itemMap.putString("msgType", Integer.toString(MsgTypeEnum.tip.getValue() + 1));
557-
// itemMap.putString("time", timeStr);
558-
// writableArray.pushMap(itemMap);
559-
// }
560-
561-
562-
writableArray.pushMap(itemMap);
563552
}
564553
}
565-
return writableArray;
554+
return writableArray.size() > 0 ? writableArray : null;
566555
}
567556

568557
public static Object createTeamInfo(Team team) {
@@ -781,9 +770,9 @@ public static WritableMap createMessage(IMMessage item) {
781770
case CustomAttachmentType.RedPacketOpen:
782771
if (attachment instanceof RedPacketOpenAttachement) {
783772
RedPacketOpenAttachement rpOpen = (RedPacketOpenAttachement) attachment;
784-
if (!rpOpen.isSelf()) {
785-
return null;
786-
}
773+
// if (!rpOpen.isSelf()) {
774+
// return null;
775+
// }
787776
itemMap.putMap("redpacketOpenObj", rpOpen.toReactNative());
788777
}
789778
break;

android/src/main/java/com/netease/im/common/ImageLoaderKit.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private void init(ImageLoaderConfiguration config) {
7878

7979
public void clear() {
8080
ImageLoader.getInstance().clearMemoryCache();
81+
cacheLoad.clear();
8182
}
8283

8384
private ImageLoaderConfiguration getDefaultConfig() throws IOException {

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.netease.im.login;
22

33
import android.app.NotificationManager;
4-
import android.app.PendingIntent;
54
import android.content.Context;
6-
import android.content.Intent;
7-
import android.support.v4.app.NotificationCompat;
85

96
import com.netease.im.IMApplication;
10-
import com.netease.im.session.SessionUtil;
117
import com.netease.im.team.TeamListService;
128
import com.netease.im.uikit.LoginSyncDataStatusObserver;
139
import com.netease.im.uikit.cache.DataCacheManager;
@@ -18,13 +14,10 @@
1814
import com.netease.nimlib.sdk.auth.AuthService;
1915
import com.netease.nimlib.sdk.auth.LoginInfo;
2016
import com.netease.nimlib.sdk.friend.model.AddFriendNotify;
21-
import com.netease.nimlib.sdk.msg.MsgServiceObserve;
2217
import com.netease.nimlib.sdk.msg.constant.SystemMessageType;
2318
import com.netease.nimlib.sdk.msg.model.CustomNotification;
2419
import com.netease.nimlib.sdk.msg.model.SystemMessage;
2520

26-
import java.util.Map;
27-
2821
/**
2922
* Created by dowin on 2017/4/28.
3023
*/
@@ -122,29 +115,15 @@ synchronized void registerObserver(boolean register) {
122115
recentContactObserver.registerRecentContactObserver(register);
123116
// sysMessageObserver.registerSystemObserver(register);
124117
// NIMClient.getService(SystemMessageObserver.class).observeReceiveSystemMsg(systemMessageObserver, register);
125-
NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(notificationObserver, register);
118+
// NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(notificationObserver, register);
126119
}
127120

128121
private NotificationManager notificationManager;
129122
private Observer<CustomNotification> notificationObserver = new Observer<CustomNotification>() {
130123
@Override
131124
public void onEvent(CustomNotification customNotification) {
132125

133-
Map<String, Object> map = customNotification.getPushPayload();
134-
if (map != null && map.containsKey("type")) {
135-
String type = (String) map.get("type");
136-
if (SessionUtil.CUSTOM_Notification.equals(type)) {
137-
NotificationCompat.Builder builder = new NotificationCompat.Builder(IMApplication.getContext());
138-
builder.setContentTitle("请求加为好友");
139-
builder.setContentText(customNotification.getApnsText());
140-
builder.setAutoCancel(true);
141-
PendingIntent contentIntent = PendingIntent.getActivity(
142-
IMApplication.getContext(), 0, new Intent(IMApplication.getContext(), IMApplication.getMainActivityClass()), 0);
143-
builder.setContentIntent(contentIntent);
144-
builder.setSmallIcon(IMApplication.getNotify_msg_drawable_id());
145-
getNotificationManager().notify((int) System.currentTimeMillis(),builder.build());
146-
}
147-
}
126+
// SessionUtil.receiver(getNotificationManager(),customNotification);
148127
}
149128
};
150129

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ private boolean addFriendVerifyFilter(final SystemMessage msg) {
169169
return true; // 过滤
170170
}
171171

172-
if (attachData.getEvent() != AddFriendNotify.Event.RECV_ADD_FRIEND_VERIFY_REQUEST) {
173-
return false; // 不过滤
174-
}
172+
// if (attachData.getEvent() != AddFriendNotify.Event.RECV_ADD_FRIEND_VERIFY_REQUEST) {
173+
// return false; // 不过滤
174+
// }
175175

176176
if (addFriendVerifyRequestAccounts.contains(msg.getFromAccount())) {
177177
return true; // 过滤

android/src/main/java/com/netease/im/receiver/CustomNotificationReceiver.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.netease.im.receiver;
22

3+
import android.app.NotificationManager;
34
import android.content.BroadcastReceiver;
45
import android.content.Context;
56
import android.content.Intent;
67
import android.os.Bundle;
7-
import android.widget.Toast;
88

9-
import com.alibaba.fastjson.JSONException;
10-
import com.alibaba.fastjson.JSONObject;
9+
import com.netease.im.IMApplication;
10+
import com.netease.im.session.SessionUtil;
1111
import com.netease.im.uikit.common.util.log.LogUtil;
1212
import com.netease.nimlib.sdk.NimIntent;
1313
import com.netease.nimlib.sdk.msg.model.CustomNotification;
@@ -17,34 +17,29 @@
1717
*/
1818
public class CustomNotificationReceiver extends BroadcastReceiver {
1919

20+
private NotificationManager notificationManager;
2021
@Override
2122
public void onReceive(Context context, Intent intent) {
2223

2324
String action = context.getPackageName() + NimIntent.ACTION_RECEIVE_CUSTOM_NOTIFICATION;
24-
printIntent(intent);
25+
// printIntent(intent);
2526
if (action.equals(intent.getAction())) {
2627

2728
// 从intent中取出自定义通知
28-
CustomNotification notification = (CustomNotification) intent.getSerializableExtra(NimIntent.EXTRA_BROADCAST_MSG);
2929
try {
30-
JSONObject obj = JSONObject.parseObject(notification.getContent());
31-
if (obj != null && obj.getIntValue("id") == 2) {
32-
// 加入缓存中
33-
CustomNotificationCache.getInstance().addCustomNotification(notification);
34-
35-
// Toast
36-
String content = obj.getString("content");
37-
String tip = String.format("自定义消息[%s]:%s", notification.getFromAccount(), content);
38-
Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
39-
}
40-
} catch (JSONException e) {
30+
CustomNotification notification = (CustomNotification) intent.getSerializableExtra(NimIntent.EXTRA_BROADCAST_MSG);
31+
SessionUtil.receiver(getNotificationManager(), notification);
32+
} catch (Exception e) {
4133
LogUtil.e("CustomNotificationReceiver", e.getMessage());
4234
}
43-
44-
// 处理自定义通知消息
45-
LogUtil.i("CustomNotificationReceiver", "receive custom notification: " + notification.getContent() + " from :" + notification.getSessionId() + "/" + notification.getSessionType());
4635
}
4736
}
37+
public NotificationManager getNotificationManager() {
38+
if (notificationManager == null) {
39+
notificationManager = (NotificationManager) IMApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
40+
}
41+
return notificationManager;
42+
}
4843
void printIntent(Intent intent) {
4944
LogUtil.d("NimNetease", "--------------------------------------------");
5045
LogUtil.d("NimNetease", intent.getAction());

0 commit comments

Comments
 (0)