Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hevin committed Apr 3, 2018
2 parents 71fd135 + 35a4057 commit c2ca5c6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
6 changes: 4 additions & 2 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.4.0-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-3.4.4-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,7 +9,9 @@

若只需要简单的聊天功能,可优先考虑使用 [JMessage Web SDK](https://docs.jiguang.cn/jmessage/client/im_sdk_js_v2/)

注意:从 v3.4.0 开始支持 cordova-android 7.0.0,因 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。如果需要安装之前版本的插件,请先安装 v1.2.0 以下版本的 cordova-plugin-jcore,再安装插件。
>注意:从 v3.4.0 开始支持 cordova-android 7.0.0,因 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。
>
>如果需要安装之前版本的插件,请先自行安装 v1.2.0 以下版本(建议安装 v1.1.12,cordova-plugin-jcore 向下兼容)的 cordova-plugin-jcore,再安装插件,否则运行会报错。
## Full Documentation

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.4.0",
"version": "3.4.4",
"description": "JMessage Cordova Plugin.",
"cordova": {
"id": "jmessage-phonegap-plugin",
Expand Down
3 changes: 2 additions & 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.4.0">
version="3.4.4">

<name>JMessage</name>
<description>集成极光 IM 和推送功能</description>
Expand Down Expand Up @@ -158,6 +158,7 @@
</config-file>

<lib-file src="src/android/libs/jmessage-android_v2.4.1.jar" />

<source-file src="src/android/JMessagePlugin.java" target-dir="app/src/main/java/cn/jiguang/cordova/im"/>
<source-file src="src/android/JMessageUtils.java" target-dir="app/src/main/java/cn/jiguang/cordova/im"/>
<source-file src="src/android/JsonUtils.java" target-dir="app/src/main/java/cn/jiguang/cordova/im"/>
Expand Down
13 changes: 10 additions & 3 deletions src/android/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ static JSONObject toJson(Message msg) {
result.put("id", String.valueOf(msg.getId())); // 本地数据库 id
result.put("serverMessageId", String.valueOf(msg.getServerMessageId())); // 服务器端 id
result.put("from", toJson(msg.getFromUser())); // 消息发送者
result.put("isSend", msg.getDirect() == MessageDirect.send); // 消息是否是由当前用户发出

boolean isSend = msg.getDirect().equals(MessageDirect.send);
result.put("isSend", isSend); // 消息是否是由当前用户发出

JSONObject targetJson = null;
switch (msg.getTargetType()) {
case single:
if (msg.getDirect() == MessageDirect.send) { // 消息发送
if (isSend) { // 消息发送
targetJson = toJson((UserInfo) msg.getTargetInfo());
} else { // 消息接收
targetJson = toJson(JMessageClient.getMyInfo());
Expand All @@ -141,6 +143,7 @@ static JSONObject toJson(Message msg) {
case chatroom:
targetJson = toJson((ChatRoomInfo) msg.getTargetInfo());
break;
default:
}
result.put("target", targetJson);

Expand Down Expand Up @@ -186,7 +189,9 @@ static JSONObject toJson(Message msg) {
case eventNotification:
result.put("type", "event");
List usernameList = ((EventNotificationContent) content).getUserNames();
result.put("usernames", toJson(usernameList));
if (usernameList != null) {
result.put("usernames", toJson(usernameList));
}
switch (((EventNotificationContent) content).getEventNotificationType()) {
case group_member_added:
//群成员加群事件
Expand All @@ -200,7 +205,9 @@ static JSONObject toJson(Message msg) {
//群成员退群事件
result.put("eventType", "group_member_exit");
break;
default:
}
default:
}
} catch (JSONException e) {
e.printStackTrace();
Expand Down
4 changes: 0 additions & 4 deletions src/ios/Plugins/JMessageHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ - (void)onSyncOfflineMessageConversation:(JMSGConversation *)conversation

#pragma mark - Group 回调

- (void)onGroupInfoChanged:(JMSGGroup *)group{
[[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageGroupInfoChanged object:[group groupToDictionary]];
}

@end


Expand Down
22 changes: 13 additions & 9 deletions src/ios/Plugins/JMessagePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ -(void)initNotifications {
selector:@selector(didReceiveRetractMessage:)
name:kJJMessageRetractMessage
object:nil];

[defaultCenter addObserver:self
selector:@selector(groupInfoChanged:)
name:kJJMessageGroupInfoChanged
object:nil];


[defaultCenter addObserver:self
selector:@selector(onSyncOfflineMessage:)
Expand Down Expand Up @@ -422,10 +418,6 @@ - (void)unreadChanged:(NSNotification *)notification{
[self evalFuntionName:@"onUnreadChanged" jsonParm:[notification.object toJsonString]];
}

- (void)groupInfoChanged:(NSNotification *)notification{
[self evalFuntionName:@"onGroupInfoChanged" jsonParm:[notification.object toJsonString]];
}

- (void)loginStateChanged:(NSNotification *)notification{
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"eventName": @"loginStateChanged", @"value": notification.object}];

Expand Down Expand Up @@ -987,12 +979,24 @@ - (void)getHistoryMessages:(CDVInvokedUrlCommand *)command {
if ([limit isEqualToNumber:@(-1)]) {
limit = nil;
}

BOOL isDescend = false;
if (param[@"isDescend"]) {
NSNumber *number = param[@"isDescend"];
isDescend = [number boolValue];
}

NSArray *messageList = [conversation messageArrayFromNewestWithOffset:param[@"from"] limit:limit];

NSArray *messageDicArr = [messageList mapObjectsUsingBlock:^id(id obj, NSUInteger idx) {
JMSGMessage *message = obj;
return [message messageToDictionary];
}];

if (isDescend) {
messageDicArr = [[messageDicArr reverseObjectEnumerator] allObjects];
}

[self handleResultWithArray:messageDicArr command:command error:error];
}];
}
Expand Down
6 changes: 3 additions & 3 deletions www/JMessagePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ var JMessagePlugin = {
* 是否开启了自定义接收方通知栏功能。
* @type {?boolean}
*/
isCustomNotificationEnabled: null,
isCustomNotificationEnabled: undefined,
/**
* 设置此条消息在接收方通知栏所展示通知的标题。
* @type {?string}
*/
notificationTitle: null,
notificationTitle: undefined,
/**
* 设置此条消息在接收方通知栏所展示通知的内容。
* @type {?string}
*/
notificationText: null
notificationText: undefined
},
/**
* @param {object} params = {
Expand Down

0 comments on commit c2ca5c6

Please sign in to comment.