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/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/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: 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..375b33d 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,22 +2156,23 @@ - (void)deleteMessageById:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomInfoListOfApp:(CDVInvokedUrlCommand *)command { +- (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"]; @@ -2194,7 +2195,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 +2212,7 @@ - (void)getChatroomInfoListOfUser:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomInfoListById:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomIds"]) { @@ -2235,7 +2236,7 @@ - (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command { }]; } -- (void)enterChatroom:(CDVInvokedUrlCommand *)command { +- (void)enterChatRoom:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2255,7 +2256,7 @@ - (void)enterChatroom:(CDVInvokedUrlCommand *)command { }]; } -- (void)exitChatroom:(CDVInvokedUrlCommand *)command { +- (void)exitChatRoom:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2272,7 +2273,7 @@ - (void)exitChatroom:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomConversation:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { @@ -2291,7 +2292,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 +2310,7 @@ - (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command { }]; } -- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command { +- (void)getChatRoomOwner:(CDVInvokedUrlCommand *)command { NSDictionary * param = [command argumentAtIndex:0]; if (!param[@"roomId"]) { diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index e9d8edd..2b90e43 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -823,6 +823,7 @@ var JMessagePlugin = { ChatRoom: { /** * 获取当前应用所属聊天室的信息。 + * * @param {object} params = { * start: number, // 索引起始位置,从 0 开始。 * count: number // 查询个数。 @@ -888,7 +889,7 @@ var JMessagePlugin = { exec(success, error, PLUGIN_NAME, 'exitChatRoom', [params]) }, /** - * 获取聊天室会话信息。如果无法返回 + * 获取聊天室会话信息。 * * @param {object} params = { roomId: String } * @param {function} success = function (conversation) {}