Skip to content

Commit

Permalink
Merge pull request #113 from jpush/dev
Browse files Browse the repository at this point in the history
v0.6.3
  • Loading branch information
raoxudong authored Apr 8, 2020
2 parents edeb7c1 + 411103d commit 59d0dec
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.6.3
+ 新增:消息已读回执监听方法
## 0.6.2
+ 内部安全策略优化
## 0.6.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
//pub.dev 集成
dependencies:
jmessage_flutter: 0.6.2
jmessage_flutter: 0.6.3
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import cn.jpush.im.android.api.callback.GetReceiptDetailsCallback;
import cn.jpush.im.android.api.content.MessageContent;
import cn.jpush.im.android.api.enums.PlatformType;
import cn.jpush.im.android.api.event.MessageReceiptStatusChangeEvent;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand All @@ -31,6 +32,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;

Expand Down Expand Up @@ -182,6 +184,8 @@ public void onMethodCall(MethodCall call, Result result) {
retractMessage(call, result);
} else if (call.method.equals("getHistoryMessages")) {
getHistoryMessages(call, result);
} else if (call.method.equals("getMessageByServerMessageId")) {
getMessageByServerMessageId(call, result);
} else if (call.method.equals("getMessageById")) {
getMessageById(call, result);
} else if (call.method.equals("deleteMessageById")) {
Expand Down Expand Up @@ -1337,6 +1341,34 @@ private void getHistoryMessages(MethodCall call, Result result) {
result.success(messageJSONArr);
}

private void getMessageByServerMessageId(MethodCall call, Result result) {
HashMap<String, Object> map = call.arguments();

Conversation conversation;
String serverMessageId;
try {
JSONObject params = new JSONObject(map);
conversation = JMessageUtils.getConversation(params);

if (conversation == null) {
handleResult(ERR_CODE_CONVERSATION, "Can't get conversation", result);
return;
}

serverMessageId = params.getString("serverMessageId");
} catch (JSONException e) {
e.printStackTrace();
handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
return;
}
Message msg = conversation.getMessage(Long.parseLong(serverMessageId));
if (msg == null) {
result.success(null);
} else {
result.success(toJson(msg));
}
}

private void getMessageById(MethodCall call, Result result) {
HashMap<String, Object> map = call.arguments();

Expand Down Expand Up @@ -3150,6 +3182,24 @@ public void onEventMainThread(MessageRetractEvent event) throws JSONException {
JmessageFlutterPlugin.instance.channel.invokeMethod("onRetractMessage", json);
}

public void onEventMainThread(MessageReceiptStatusChangeEvent event) throws JSONException {
Log.d("Android","onEvent MessageReceiptStatusChangeEvent:");

Conversation conversation = event.getConversation();
List<MessageReceiptStatusChangeEvent.MessageReceiptMeta> list = event.getMessageReceiptMetas();
ArrayList<String> serverMessageIdList = new ArrayList();
for (MessageReceiptStatusChangeEvent.MessageReceiptMeta meta : list) {
String serverMsgId = String.valueOf(meta.getServerMsgId());
serverMessageIdList.add(serverMsgId);
}

HashMap json = new HashMap();
json.put("conversation", toJson(event.getConversation()));
json.put("serverMessageIdList", serverMessageIdList);

JmessageFlutterPlugin.instance.channel.invokeMethod("onReceiveMessageReceiptStatusChange",json);
}

/**
* 透传消息接收事件。
*
Expand Down Expand Up @@ -3298,6 +3348,5 @@ public void gotResult(int status, String desc, UserInfo userInfo) {

}


// Event Handler - end
}
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
#

Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.description = <<-DESC
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
DESC
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => '[email protected]' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.vendored_frameworks = 'Flutter.framework'
end
3 changes: 1 addition & 2 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Applications/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/raoxudong/JPush/jpush-github/jmessage-flutter-plugin/example"
export "FLUTTER_TARGET=/Users/raoxudong/JPush/jpush-github/jmessage-flutter-plugin/example/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Applications/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
10 changes: 8 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ class _MyHomePageState extends State<MyHomePage> {
}



void addListener() async {
print('add listener receive ReceiveMessage');

Expand Down Expand Up @@ -335,6 +334,14 @@ class _MyHomePageState extends State<MyHomePage> {
print('listener receive event - group admin approval');

});

jmessage.addReceiveMessageReceiptStatusChangelistener((JMConversationInfo conversation, List<String>serverMessageIdList){
print("listener receive event - message receipt status change");

//for (var serverMsgId in serverMessageIdList) {
// jmessage.getMessageByServerMessageId(type: conversation.target, serverMessageId: serverMsgId);
//}
});
}

// addReceiveMessageListener
Expand Down Expand Up @@ -1197,7 +1204,6 @@ void verifyMessage(dynamic msg) {
expect(msg.serverMessageId, isNotNull, reason: 'serverMessageId id is null');
expect(msg.isSend, isNotNull, reason: 'message isSend is null');
expect(msg.createTime, isNotNull, reason: 'message createTime is null');
expect(msg.extras, isNotNull, reason: 'message extras is null');
expect(msg.from, isNotNull, reason: 'message from is null');
verifyUser(msg.from);

Expand Down
31 changes: 30 additions & 1 deletion ios/Classes/JmessageFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[self getHistoryMessages:call result:result];
} else if([@"getMessageById" isEqualToString:call.method]) {
[self getMessageById:call result:result];
} else if ([@"getMessageByServerMessageId" isEqualToString:call.method]) {
[self getMessageByServerMessageId:call result:result];
} else if([@"deleteMessageById" isEqualToString:call.method]) {
[self deleteMessageById:call result:result];
} else if([@"sendInvitationRequest" isEqualToString:call.method]) {
Expand Down Expand Up @@ -1201,6 +1203,23 @@ - (void)getHistoryMessages:(FlutterMethodCall*)call result:(FlutterResult)result
}];
}

- (void)getMessageByServerMessageId:(FlutterMethodCall*)call result:(FlutterResult)result {
NSDictionary *param = call.arguments;
[self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) {
if (error) {
result([error flutterError]);
return;
}

JMSGMessage *msg = [conversation messageWithServerMessageId:param[@"serverMessageId"]];
if (msg) {
result([msg messageToDictionary]);
} else {
NSError *error = [NSError errorWithDomain:@"message id do not exit!" code: 1 userInfo: nil];
result([error flutterError]);
}
}];
}

- (void)getMessageById:(FlutterMethodCall*)call result:(FlutterResult)result {
NSDictionary *param = call.arguments;
Expand Down Expand Up @@ -2697,7 +2716,17 @@ - (void)onReceiveUserLoginStatusChangeEvent:(JMSGUserLoginStatusChangeEvent *)ev
*
*/
- (void)onReceiveMessageReceiptStatusChangeEvent:(JMSGMessageReceiptStatusChangeEvent *)receiptEvent {

JMSGConversation *conversation = receiptEvent.conversation;
NSArray *messageList = receiptEvent.messages;
NSMutableArray *serverMsgIdList = [NSMutableArray array];
for (JMSGMessage *message in messageList) {
[serverMsgIdList addObject:message.serverMessageId];
}
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:[conversation conversationToDictionary] forKey:@"conversation"];
[dic setObject:serverMsgIdList forKey:@"serverMessageIdList"];

[_channel invokeMethod:@"onReceiveMessageReceiptStatusChange" arguments:dic];
}


Expand Down
55 changes: 51 additions & 4 deletions lib/jmessage_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,39 @@ typedef JMReceiveChatRoomMessageListener = void Function(List<dynamic> messageLi
typedef JMReceiveApplyJoinGroupApprovalListener = void Function(JMReceiveApplyJoinGroupApprovalEvent event);
typedef JMReceiveGroupAdminRejectListener = void Function(JMReceiveGroupAdminRejectEvent event);
typedef JMReceiveGroupAdminApprovalListener = void Function(JMReceiveGroupAdminApprovalEvent event);
typedef JMMessageReceiptStatusChangeListener = void Function(JMConversationInfo conversation, List<String>serverMessageIdList);

class JMEventHandlers {

static final JMEventHandlers _instance = new JMEventHandlers._internal();
JMEventHandlers._internal();
factory JMEventHandlers() => _instance;

/// 收到:消息
List<JMMessageEventListener> receiveMessage = [];
/// 收到:离线消息
List<JMSyncOfflineMessageListener> syncOfflineMessage = [];
/// 收到:漫游消息
List<JMSyncRoamingMessageListener> syncRoamingMessage = [];
/// 收到:聊天室消息
List<JMReceiveChatRoomMessageListener> receiveChatRoomMessage = [];
/// 收到:登录状态发生变更
List<JMLoginStateChangedListener> loginStateChanged = [];
/// 收到:好友事件
List<JMContactNotifyListener> contactNotify = [];
/// 收到:触发通知栏点击事件
List<JMMessageEventListener> clickMessageNotification = [];
List<JMSyncRoamingMessageListener> syncRoamingMessage = [];
List<JMReceiveTransCommandListener> receiveTransCommand = []; // 透传命令
List<JMReceiveChatRoomMessageListener> receiveChatRoomMessage = []; // 聊天室消息
/// 收到:透传命令
List<JMReceiveTransCommandListener> receiveTransCommand = [];
/// 收到:申请入群请求
List<JMReceiveApplyJoinGroupApprovalListener> receiveApplyJoinGroupApproval = [];
/// 收到:管理员拒绝事件
List<JMReceiveGroupAdminRejectListener> receiveGroupAdminReject = [];
/// 收到:管理员审核事件
List<JMReceiveGroupAdminApprovalListener> receiveGroupAdminApproval = [];

/// 收到:消息已读回执事件
List<JMMessageReceiptStatusChangeListener> receiveReceiptStatusChangeEvents = [];
/// 收到:消息撤回事件
List<JMMessageRetractListener> retractMessage = [];
}

Expand Down Expand Up @@ -166,6 +180,12 @@ class JmessageFlutter {
removeReceiveGroupAdminApprovalListener(JMReceiveGroupAdminApprovalListener callback) {
_eventHanders.receiveGroupAdminApproval.removeWhere((cb) => cb == callback);
}
addReceiveMessageReceiptStatusChangelistener(JMMessageReceiptStatusChangeListener callback) {
_eventHanders.receiveReceiptStatusChangeEvents.add(callback);
}
removeMessageReceiptStatusChangelistener(JMMessageReceiptStatusChangeListener callback) {
_eventHanders.receiveReceiptStatusChangeEvents.removeWhere((cb) => cb == callback);
}

Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion');
Expand Down Expand Up @@ -260,6 +280,14 @@ class JmessageFlutter {
cb(JMReceiveGroupAdminApprovalEvent.fromJson(json));
}
break;
case 'onReceiveMessageReceiptStatusChange':
for (JMMessageReceiptStatusChangeListener cb in _eventHanders.receiveReceiptStatusChangeEvents) {
Map param = call.arguments.cast<dynamic, dynamic>();
List serverMessageIdList = param['serverMessageIdList'];
JMConversationInfo conversationInfo = JMConversationInfo.fromJson(param['conversation']);
cb(conversationInfo, serverMessageIdList);
}
break;
default:
throw new UnsupportedError("Unrecognized Event");
}
Expand Down Expand Up @@ -739,6 +767,25 @@ class JmessageFlutter {
return res;
}

/// 获取本地单条消息
/// @param target 聊天对象, JMSingle | JMGroup
/// @param serverMessageId 服务器返回的 serverMessageId,非本地数据库中的消息id,
Future<dynamic> getMessageByServerMessageId({
@required dynamic type, /// (JMSingle | JMGroup | JMChatRoom)
@required String serverMessageId,
}) async {
Map param = type.toJson();

param..addAll({
'serverMessageId': serverMessageId,
});

Map msgMap = await _channel.invokeMethod('getMessageByServerMessageId',
param..removeWhere((key,value) => value == null));

return JMNormalMessage.generateMessageFromJson(msgMap);
}

/**
* 获取本地单条消息
*
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: jmessage_flutter
description: JIGUANG officially supported JMessage Flutter plugin (Android & iOS). 极光推送官方支持的 Flutter 插件(Android & iOS)(https://www.jiguang.cn).
version: 0.6.2
version: 0.6.3
author: xudong.rao <[email protected]>
homepage: https://www.jiguang.cn

Expand Down

0 comments on commit 59d0dec

Please sign in to comment.