From 63892a0694e6dcd8bbbd7da111771c8cbb3ad4a9 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Tue, 16 Jan 2018 15:23:59 +0800 Subject: [PATCH 1/5] fix chatRoom name --- src/ios/Plugins/JMessagePlugin.h | 16 ++++++++-------- src/ios/Plugins/JMessagePlugin.m | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ios/Plugins/JMessagePlugin.h b/src/ios/Plugins/JMessagePlugin.h index 564c29e..41e7bc6 100644 --- a/src/ios/Plugins/JMessagePlugin.h +++ b/src/ios/Plugins/JMessagePlugin.h @@ -71,13 +71,13 @@ - (void)setConversationExtras:(CDVInvokedUrlCommand *)command; // 聊天室 API -- (void)getChatroomInfoListOfApp:(CDVInvokedUrlCommand *)command; -- (void)getChatroomInfoListOfUser:(CDVInvokedUrlCommand *)command; -- (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command; -- (void)enterChatroom:(CDVInvokedUrlCommand *)command; -- (void)exitChatroom:(CDVInvokedUrlCommand *)command; -- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command; -- (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command; -- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomInfoListOfApp:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomInfoListOfUser:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomInfoListById:(CDVInvokedUrlCommand *)command; +- (void)enterChatRoom:(CDVInvokedUrlCommand *)command; +- (void)exitChatRoom:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomConversation:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomConversationList:(CDVInvokedUrlCommand *)command; +- (void)getChatRoomOwner:(CDVInvokedUrlCommand *)command; @end diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 8624f29..9d3e3b0 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -112,7 +112,7 @@ -(void)initNotifications { name:kJJMessageReceiveMessage object:nil]; [defaultCenter addObserver:self - selector:@selector(didReceiveJMessageChatroomMessage:) + selector:@selector(didReceiveJMessageChatRoomMessage:) name:kJJMessageReceiveChatroomMessage object:nil]; @@ -451,8 +451,8 @@ - (void)didReceiveJMessageMessage:(NSNotification *)notification { [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId]; } -- (void)didReceiveJMessageChatroomMessage:(NSNotification *)notification { - CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"receiveChatroomMessage", @"value": notification.object}]; +- (void)didReceiveJMessageChatRoomMessage:(NSNotification *)notification { + CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"receiveChatRoomMessage", @"value": notification.object}]; [result setKeepCallback:@(true)]; [self.commandDelegate sendPluginResult:result callbackId:self.callBack.callbackId]; @@ -2156,7 +2156,7 @@ - (void)deleteMessageById:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomInfoListOfApp:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomInfoListOfApp:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; NSNumber *start = nil; NSNumber *count = nil; @@ -2194,7 +2194,7 @@ - (void)getChatroomInfoListOfApp:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomInfoListOfUser:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomInfoListOfUser:(CDVInvokedUrlCommand *)command { [JMSGChatRoom getMyChatRoomListCompletionHandler:^(id resultObject, NSError *error) { if (error) { [self handleResultWithDictionary: nil command: command error: error]; @@ -2211,7 +2211,7 @@ - (void)getChatroomInfoListOfUser:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomInfoListById:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomIds"]) { @@ -2235,7 +2235,7 @@ - (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command { }]; } -- (void)enterChatroom:(CDVInvokedUrlCommand *)command { +- (void)enterChatRoom:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2255,7 +2255,7 @@ - (void)enterChatroom:(CDVInvokedUrlCommand *)command { }]; } -- (void)exitChatroom:(CDVInvokedUrlCommand *)command { +- (void)exitChatRoom:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2272,7 +2272,7 @@ - (void)exitChatroom:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomConversation:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2291,7 +2291,7 @@ - (void)getChatroomConversation:(CDVInvokedUrlCommand *)command { [self handleResultWithDictionary:[chatRoomConversation conversationToDictionary] command:command error: error]; } -- (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomConversationList:(CDVInvokedUrlCommand *)command { [JMSGConversation allChatRoomConversation:^(id resultObject, NSError *error) { if (error) { @@ -2309,7 +2309,7 @@ - (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomOwner:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { From 3b901ff69d995c67afd4a59aa34e5d5256746449 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Tue, 16 Jan 2018 17:17:29 +0800 Subject: [PATCH 2/5] fix event message field --- src/ios/Plugins/JMessageHelper.m | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index d63c7ca..18dc66a 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -419,63 +419,63 @@ - (NSMutableDictionary *)messageToDictionary { switch (eventContent.eventType) { case kJMSGEventNotificationAcceptedFriendInvitation: { - dict[@"evenType"] = @"acceptedFriendInvitation"; + dict[@"eventType"] = @"acceptedFriendInvitation"; break; } case kJMSGEventNotificationAddGroupMembers: { - dict[@"evenType"] = @"group_member_added"; + dict[@"eventType"] = @"group_member_added"; break; } case kJMSGEventNotificationCreateGroup: { - dict[@"evenType"] = @"createGroup"; + dict[@"eventType"] = @"createGroup"; break; } case kJMSGEventNotificationCurrentUserInfoChange: { - dict[@"evenType"] = @"currentUserInfoChange"; + dict[@"eventType"] = @"currentUserInfoChange"; break; } case kJMSGEventNotificationDeclinedFriendInvitation: { - dict[@"evenType"] = @"declinedFriendInvitation"; + dict[@"eventType"] = @"declinedFriendInvitation"; break; } case kJMSGEventNotificationDeletedFriend: { - dict[@"evenType"] = @"deletedFriend"; + dict[@"eventType"] = @"deletedFriend"; break; } case kJMSGEventNotificationExitGroup: { - dict[@"evenType"] = @"group_member_exit"; + dict[@"eventType"] = @"group_member_exit"; break; } case kJMSGEventNotificationLoginKicked: { - dict[@"evenType"] = @"loginKicked"; + dict[@"eventType"] = @"loginKicked"; break; } case kJMSGEventNotificationMessageRetract: { - dict[@"evenType"] = @"messageRetract"; + dict[@"eventType"] = @"messageRetract"; break; } case kJMSGEventNotificationReceiveFriendInvitation: { - dict[@"evenType"] = @"receiveFriendInvitation"; + dict[@"eventType"] = @"receiveFriendInvitation"; break; } case kJMSGEventNotificationReceiveServerFriendUpdate: { - dict[@"evenType"] = @"receiveServerFriendUpdate"; + dict[@"eventType"] = @"receiveServerFriendUpdate"; break; } case kJMSGEventNotificationRemoveGroupMembers: { - dict[@"evenType"] = @"group_member_removed"; + dict[@"eventType"] = @"group_member_removed"; break; } case kJMSGEventNotificationServerAlterPassword: { - dict[@"evenType"] = @"serverAlterPassword"; + dict[@"eventType"] = @"serverAlterPassword"; break; } case kJMSGEventNotificationUpdateGroupInfo: { - dict[@"evenType"] = @"updateGroupInfo"; + dict[@"eventType"] = @"updateGroupInfo"; break; } case kJMSGEventNotificationUserLoginStatusUnexpected: { - dict[@"evenType"] = @"userLoginStatusUnexpected"; + dict[@"eventType"] = @"userLoginStatusUnexpected"; break; } default: From 6d8fd8f563f9ff3ffe63b63106dd284282b35c51 Mon Sep 17 00:00:00 2001 From: Hevin Date: Tue, 16 Jan 2018 18:33:56 +0800 Subject: [PATCH 3/5] build: v3.2.0 --- README.md | 4 +--- package.json | 2 +- plugin.xml | 2 +- www/JMessagePlugin.js | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5e58a40..1841e63 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JMessage PhoneGap / Cordova Plugin -[![release](https://img.shields.io/badge/release-3.1.7-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases) +[![release](https://img.shields.io/badge/release-3.2.0-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-green.svg)](https://github.com/jpush/jmessage-phonegap-plugin) [![Code Triagers Badge](https://www.codetriage.com/jpush/jmessage-phonegap-plugin/badges/users.svg)](https://www.codetriage.com/jpush/jmessage-phonegap-plugin) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) @@ -9,8 +9,6 @@ 若只需要简单的聊天功能,可优先考虑使用 [JMessage Web SDK](https://docs.jiguang.cn/jmessage/client/im_sdk_js_v2/)。 -**目前重构了 3.0.0+ 版本,Android, iOS 完全统一接口和对象字段,优化了 API 调用方式,不兼容老版本,升级时请注意。** - ## Full Documentation 完整文档请查阅 [wiki](https://github.com/jpush/jmessage-phonegap-plugin/wiki),包括[安装指南](https://github.com/jpush/jmessage-phonegap-plugin/wiki/Installation-Guide)、[API 说明](https://github.com/jpush/jmessage-phonegap-plugin/wiki/APIs)等。 diff --git a/package.json b/package.json index 2ca9acb..b24f034 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jmessage-phonegap-plugin", - "version": "3.1.7", + "version": "3.2.0", "description": "JMessage Cordova Plugin.", "cordova": { "id": "jmessage-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index 1e9c18a..0aa888e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.2.0"> JMessage 集成极光 IM 和推送功能 diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index e9d8edd..784a2d1 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -823,6 +823,7 @@ var JMessagePlugin = { ChatRoom: { /** * 获取当前应用所属聊天室的信息。 + * * @param {object} params = { * start: number, // 索引起始位置,从 0 开始。 * count: number // 查询个数。 From 8914d2b34d3012f16277ef9a12f4f01457516467 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Wed, 17 Jan 2018 10:53:20 +0800 Subject: [PATCH 4/5] add getChatRoomListByApp params judgement --- src/ios/Plugins/JMessagePlugin.m | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 9d3e3b0..375b33d 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -2160,18 +2160,19 @@ - (void)getChatRoomInfoListOfApp:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; NSNumber *start = nil; NSNumber *count = nil; - if (!param[@"start"]) { + if (param[@"start"]) { [self returnParamError:command]; - start = param[@"start"]; return; } - if (!param[@"count"]) { + if (param[@"count"]) { [self returnParamError:command]; - count = param[@"count"]; return; } + start = param[@"start"]; + count = param[@"count"]; + NSString *appKey = nil; if (param[@"appKey"]) { appKey = param[@"appKey"]; From 3461d70bfbfb2c38a762202486f20a7daf8d3ee6 Mon Sep 17 00:00:00 2001 From: Hevin Date: Mon, 22 Jan 2018 18:52:41 +0800 Subject: [PATCH 5/5] Optimize the method of message to json --- src/android/JsonUtils.java | 29 ++++++++++++++++------------- www/JMessagePlugin.js | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/android/JsonUtils.java b/src/android/JsonUtils.java index 755392a..53adc3e 100644 --- a/src/android/JsonUtils.java +++ b/src/android/JsonUtils.java @@ -127,20 +127,23 @@ static JSONObject toJson(Message msg) { result.put("from", toJson(msg.getFromUser())); // 消息发送者 result.put("isSend", msg.getDirect() == MessageDirect.send); // 消息是否是由当前用户发出 - if (msg.getDirect() == MessageDirect.send) { // 消息发送 - if (msg.getTargetType() == ConversationType.single) { // 消息发送对象的类型 - result.put("target", toJson((UserInfo) msg.getTargetInfo())); - } else if (msg.getTargetType() == ConversationType.group) { - result.put("target", toJson((GroupInfo) msg.getTargetInfo())); - } - - } else if (msg.getDirect() == MessageDirect.receive) { // 消息接收 - if (msg.getTargetType() == ConversationType.single) { - result.put("target", toJson(JMessageClient.getMyInfo())); - } else if (msg.getTargetType() == ConversationType.group) { - result.put("target", toJson((GroupInfo) msg.getTargetInfo())); - } + JSONObject targetJson = null; + switch (msg.getTargetType()) { + case single: + if (msg.getDirect() == MessageDirect.send) { // 消息发送 + targetJson = toJson((UserInfo) msg.getTargetInfo()); + } else { // 消息接收 + targetJson = toJson(JMessageClient.getMyInfo()); + } + break; + case group: + targetJson = toJson((GroupInfo) msg.getTargetInfo()); + break; + case chatroom: + targetJson = toJson((ChatRoomInfo) msg.getTargetInfo()); + break; } + result.put("target", targetJson); MessageContent content = msg.getContent(); if (content.getStringExtras() != null) { diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index 784a2d1..2b90e43 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -889,7 +889,7 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'exitChatRoom', [params]) }, /** - * 获取聊天室会话信息。如果无法返回 + * 获取聊天室会话信息。 * * @param {object} params = { roomId: String } * @param {function} success = function (conversation) {}