Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hevin committed Jan 22, 2018
2 parents 3f93923 + 3461d70 commit bb42ca4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 57 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)等。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="jmessage-phonegap-plugin"
version="3.1.7">
version="3.2.0">

<name>JMessage</name>
<description>集成极光 IM 和推送功能</description>
Expand Down
29 changes: 16 additions & 13 deletions src/android/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 15 additions & 15 deletions src/ios/Plugins/JMessageHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/ios/Plugins/JMessagePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 16 additions & 15 deletions src/ios/Plugins/JMessagePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ -(void)initNotifications {
name:kJJMessageReceiveMessage
object:nil];
[defaultCenter addObserver:self
selector:@selector(didReceiveJMessageChatroomMessage:)
selector:@selector(didReceiveJMessageChatRoomMessage:)
name:kJJMessageReceiveChatroomMessage
object:nil];

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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"];
Expand All @@ -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];
Expand All @@ -2211,7 +2212,7 @@ - (void)getChatroomInfoListOfUser:(CDVInvokedUrlCommand *)command {
}];
}

- (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command {
- (void)getChatRoomInfoListById:(CDVInvokedUrlCommand *)command {
NSDictionary * param = [command argumentAtIndex:0];

if (!param[@"roomIds"]) {
Expand All @@ -2235,7 +2236,7 @@ - (void)getChatroomInfoListById:(CDVInvokedUrlCommand *)command {
}];
}

- (void)enterChatroom:(CDVInvokedUrlCommand *)command {
- (void)enterChatRoom:(CDVInvokedUrlCommand *)command {
NSDictionary * param = [command argumentAtIndex:0];

if (!param[@"roomId"]) {
Expand All @@ -2255,7 +2256,7 @@ - (void)enterChatroom:(CDVInvokedUrlCommand *)command {
}];
}

- (void)exitChatroom:(CDVInvokedUrlCommand *)command {
- (void)exitChatRoom:(CDVInvokedUrlCommand *)command {
NSDictionary * param = [command argumentAtIndex:0];

if (!param[@"roomId"]) {
Expand All @@ -2272,7 +2273,7 @@ - (void)exitChatroom:(CDVInvokedUrlCommand *)command {
}];
}

- (void)getChatroomConversation:(CDVInvokedUrlCommand *)command {
- (void)getChatRoomConversation:(CDVInvokedUrlCommand *)command {
NSDictionary * param = [command argumentAtIndex:0];

if (!param[@"roomId"]) {
Expand All @@ -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) {
Expand All @@ -2309,7 +2310,7 @@ - (void)getChatroomConversationList:(CDVInvokedUrlCommand *)command {
}];
}

- (void)getChatroomOwner:(CDVInvokedUrlCommand *)command {
- (void)getChatRoomOwner:(CDVInvokedUrlCommand *)command {
NSDictionary * param = [command argumentAtIndex:0];

if (!param[@"roomId"]) {
Expand Down
3 changes: 2 additions & 1 deletion www/JMessagePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ var JMessagePlugin = {
ChatRoom: {
/**
* 获取当前应用所属聊天室的信息。
*
* @param {object} params = {
* start: number, // 索引起始位置,从 0 开始。
* count: number // 查询个数。
Expand Down Expand Up @@ -888,7 +889,7 @@ var JMessagePlugin = {
exec(success, error, PLUGIN_NAME, 'exitChatRoom', [params])
},
/**
* 获取聊天室会话信息。如果无法返回
* 获取聊天室会话信息。
*
* @param {object} params = { roomId: String }
* @param {function} success = function (conversation) {}
Expand Down

0 comments on commit bb42ca4

Please sign in to comment.