From e2a6a8d0c07c987ac09ef334fa38ebafd25a8d38 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 27 Apr 2017 18:26:24 +0800 Subject: [PATCH 1/4] update add resourcePath property --- example/index.html | 84 ++++++++++++++++---------------- src/ios/Plugins/JMessageHelper.m | 11 +++-- src/ios/Plugins/JMessagePlugin.m | 38 ++++++++++++++- www/JMessagePlugin.js | 4 ++ 4 files changed, 89 insertions(+), 48 deletions(-) diff --git a/example/index.html b/example/index.html index 1e5906f..9ec7128 100755 --- a/example/index.html +++ b/example/index.html @@ -122,7 +122,14 @@ }); function gotoAddConversation() { - $.mobile.navigate("#addConversationPage", {transition: "slide"}); + window.JMessage.myGroupArray(function(response) { + console.log(response) + + }, function(response){ + + + }) + // $.mobile.navigate("#addConversationPage", {transition: "slide"}); } function updateConversationList() { @@ -216,9 +223,7 @@ }); // 在收到消息后将消息对象加入到消息数组的开头。 - function onReceiveMessage(message) { - console.log("onReceiveSingleMessage"); - alert("onReceiveSingleMessage") + function onReceiveMessage(message) {; if (device.platform == "Android") { message = window.JMessage.message; console.log(JSON.stringify(message)); @@ -238,6 +243,16 @@ messageArray = JSON.parse(response); refreshConversation(); } else { + + for(var i = 0; i< response.length ; i++) { + var msgContent = response[i].content + msgContent = JSON.parse(msgContent) + response[i].content = msgContent + } + for(var i = 0; i< response.length ; i++) { + console.log(response[i]) + } + messageArray = response; refreshConversation(); } @@ -271,7 +286,6 @@ } function insertMessage(message) { - console.log(message); var fromName; var createTime; @@ -297,51 +311,35 @@ } $('#messageList').append(insertString).listview('refresh'); } else { - if (message.msg_type == "voice") { - lastMessage = "[语音消息]" + message.msg_body.media_id; + if (message.content.msg_type == "voice") { + lastMessage = "[语音消息]" + message.resourcePath; } - if (message.msg_type == "image") { - lastMessage = "[图片消息]" + message.msg_body.media_id; + if (message.content.msg_type == "image") { + lastMessage = "[图片消息]" + message.resourcePath; } - if (message.from_name == undefined) { - var message = message.content; - if (message.msg_type == "text") { - lastMessage = message.msg_body.text; - } - fromName = message.from_name; - createTimeStr = message.create_time; - if(message.from_id == window.JMessage.username) { - insertString = '
  • ' - + createTimeStr - + "
    " - + fromName + ":" + lastMessage + '
  • '; - } else { - insertString = '
  • ' - + createTimeStr + "
    " + fromName + ":" - + lastMessage + '
  • '; - } + // var message = message.content; + if (message.content.msg_type == "text") { + console.log("haungmin999") + console.log(message) + lastMessage = message.content.msg_body.text; + } + + fromName = message.content.from_name; + createTimeStr = message.content.create_time; + if(message.content.from_id == window.JMessage.username) { + insertString = '
  • ' + + createTimeStr + + "
    " + + fromName + ":" + lastMessage + '
  • '; } else { + insertString = '
  • ' + + createTimeStr + "
    " + fromName + ":" + + lastMessage + '
  • '; + } - if (message.msg_type == "text") { - lastMessage = message.msg_body.text; - } - fromName = message.from_name; - createTimeStr = message.create_time; - console.log(window.JMessage.username); - if(message.from_id == window.JMessage.username) { - insertString = '
  • ' - + createTimeStr - + "
    " - + fromName + ":" + lastMessage + '
  • '; - } else { - insertString = '
  • ' - + createTimeStr + "
    " + fromName + ":" - + lastMessage + '
  • '; - } - } $('#messageList').append(insertString).listview('refresh'); } diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index 74dfb2c..36d1637 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -72,7 +72,7 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ Ivar ivar = class_getInstanceVariable([message.content class], "_resourcePath"); resourcePath = object_getIvar(message.content, ivar); [dict setValue:objectId forKey:@"objectId"]; - [dict setValue:resourcePath forKey:@"resourcePath"]; + [dict setValue:[self getFullPathWith: resourcePath] forKey:@"resourcePath"]; [[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveImageData object:dict]; } } @@ -87,7 +87,7 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ Ivar ivar = class_getInstanceVariable([message.content class], "_resourcePath"); resourcePath = object_getIvar(message.content, ivar); [dict setValue:objectId forKey:@"objectId"]; - [dict setValue:resourcePath forKey:@"resourcePath"]; + [dict setValue:[self getFullPathWith:resourcePath] forKey:@"resourcePath"]; [[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveVoiceData object:dict]; } } @@ -103,7 +103,7 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ Ivar ivar = class_getInstanceVariable([message.content class], "_resourcePath"); resourcePath = object_getIvar(message.content, ivar); [dict setValue:objectId forKey:@"objectId"]; - [dict setValue:resourcePath forKey:@"resourcePath"]; + [dict setValue:[self getFullPathWith: resourcePath] forKey:@"resourcePath"]; [[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveFileData object:dict]; } } @@ -122,6 +122,11 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ [[NSNotificationCenter defaultCenter] postNotificationName:kJJMessageReceiveMessage object:dict]; } +- (NSString *)getFullPathWith:(NSString *) path { + NSString * homeDir = NSHomeDirectory(); + return [NSString stringWithFormat:@"%@/Documents/%@", homeDir,path]; +} + - (void)onSendMessageResponse:(JMSGMessage *)message error:(NSError *)error { NSMutableDictionary * dict = [NSMutableDictionary new]; [dict setValue:message.msgId forKey:KEY_MSGID]; diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 72a634a..30f7575 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -14,11 +14,13 @@ #import "JMessagePlugin.h" #import #import +#import #import "JMessageHelper.h" #import "JMessageDefine.h" #import "AppDelegate+JMessage.h" + #pragma mark - Cordova #define ResultSuccess(method) [NSString stringWithFormat:@"success - %@",method] @@ -507,14 +509,46 @@ - (void)getSingleConversationHistoryMessage:(CDVInvokedUrlCommand *)command { JMSGConversation * conversation = resultObject; NSArray * messageList = [conversation messageArrayFromNewestWithOffset:from limit:limit]; for (JMSGMessage * msg in messageList) { - NSString * jsonString = [msg toJsonString]; - [resultArr addObject:[jsonString toDictionary]]; + + NSString *jsonString = [msg toJsonString]; + NSMutableDictionary *dict = [NSMutableDictionary new]; + [dict setValue:msg.msgId forKey:KEY_MSGID]; + [dict setValue:jsonString forKey:KEY_CONTENT]; + [dict setValue:[NSString stringWithFormat:@"%ld",(long)msg.contentType] forKey:KEY_CONTENTTYPE]; + NSString *resourcePath; + Ivar ivar = class_getInstanceVariable([msg.content class], "_resourcePath"); + + switch (msg.contentType) { + case kJMSGContentTypeVoice: + + resourcePath = object_getIvar(msg.content, ivar); + break; + case kJMSGContentTypeImage: + resourcePath = object_getIvar(msg.content, ivar); + break; + case kJMSGContentTypeFile: + resourcePath = object_getIvar(msg.content, ivar); + break; + + default: + break; + } + if (resourcePath != @"" && resourcePath != nil) { + [dict setValue:[self getFullPathWith:resourcePath] forKey:@"resourcePath"]; + } + + [resultArr addObject:dict]; } } [weakSelf handleResultWithValue:resultArr command:command error:error log:@"JMessagePlugin Get Single History Message"]; }]; } +- (NSString *)getFullPathWith:(NSString *) path { + NSString * homeDir = NSHomeDirectory(); + return [NSString stringWithFormat:@"%@/Documents/%@", homeDir,path]; +} + - (void)getAllSingleConversation:(CDVInvokedUrlCommand *)command { WEAK_SELF(weakSelf); [JMSGConversation allConversations:^(id resultObject, NSError *error) { diff --git a/www/JMessagePlugin.js b/www/JMessagePlugin.js index dd5a8a0..e2aa948 100644 --- a/www/JMessagePlugin.js +++ b/www/JMessagePlugin.js @@ -1,3 +1,4 @@ +cordova.define("jmessage-phonegap-plugin.JMessagePlugin", function(require, exports, module) { var exec = require('cordova/exec') var JMessagePlugin = function () { @@ -957,6 +958,7 @@ JMessagePlugin.prototype.onReceiveImageData = function (data) { JMessagePlugin.prototype.onReceiveVoiceData = function (data) { try { var bToObj = JSON.parse(data) + console.log(bToObj) } catch (exception) { console.log('onReceiveVoiceData ' + exception) } @@ -1000,3 +1002,5 @@ if (!window.plugins.jmessagePlugin) { } module.exports = new JMessagePlugin() + +}); From bea53ed3365b8b4bdd7bd2d7a4b8ae9690bbe5c7 Mon Sep 17 00:00:00 2001 From: huangminlinux <380108184@qq.com> Date: Thu, 27 Apr 2017 21:12:33 +0800 Subject: [PATCH 2/4] adjust message callback model --- example/index.html | 12 ++----- src/ios/Plugins/JMessageHelper.m | 10 ++++-- src/ios/Plugins/JMessagePlugin.m | 56 ++++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/example/index.html b/example/index.html index 9ec7128..300beec 100755 --- a/example/index.html +++ b/example/index.html @@ -139,11 +139,11 @@ function (response) { if (device.platform == "Android") { var conversations = JSON.parse(response); - for(var i = 0; i < conversations.length; i++) { + for (var i = 0; i < conversations.length; i++) { insertConversation(conversations[i]); } } else { - for(var i = 0; i < response.length; i++) { + for (var i = 0; i < response.length; i++) { insertConversation(response[i]); } } @@ -243,13 +243,7 @@ messageArray = JSON.parse(response); refreshConversation(); } else { - - for(var i = 0; i< response.length ; i++) { - var msgContent = response[i].content - msgContent = JSON.parse(msgContent) - response[i].content = msgContent - } - for(var i = 0; i< response.length ; i++) { + for (var i = 0; i< response.length ; i++) { console.log(response[i]) } diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index 36d1637..c8b0394 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -61,11 +61,17 @@ - (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{ NSString *jsonString = [message toJsonString]; NSMutableDictionary *dict = [NSMutableDictionary new]; [dict setValue:message.msgId forKey:KEY_MSGID]; - [dict setValue:jsonString forKey:KEY_CONTENT]; + NSError *decodeeError; + NSDictionary *msgBody = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; + + if (decodeeError == nil) { + [dict setValue:msgBody forKey:KEY_CONTENT]; + } + [dict setValue:[NSString stringWithFormat:@"%ld",(long)message.contentType] forKey:KEY_CONTENTTYPE]; if (message.contentType == kJMSGContentTypeImage) { - [(JMSGImageContent*)message.content thumbImageData:^(NSData *data, NSString *objectId, NSError *error) { + [(JMSGImageContent*)message.content thumbImageData:^(NSData *data, NSString *objectId, NSError *decodeeError) { if (!error) { if (data) { NSString *resourcePath; diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index 30f7575..b3c013d 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -512,8 +512,17 @@ - (void)getSingleConversationHistoryMessage:(CDVInvokedUrlCommand *)command { NSString *jsonString = [msg toJsonString]; NSMutableDictionary *dict = [NSMutableDictionary new]; + + NSError *decodeeError; + NSDictionary *msgBody = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; + + if (decodeeError == nil) { + [dict setValue:msgBody forKey:KEY_CONTENT]; + } + + [dict setValue:[NSString stringWithFormat:@"%ld",(long)msg.contentType] forKey:KEY_CONTENTTYPE]; + [dict setValue:msg.msgId forKey:KEY_MSGID]; - [dict setValue:jsonString forKey:KEY_CONTENT]; [dict setValue:[NSString stringWithFormat:@"%ld",(long)msg.contentType] forKey:KEY_CONTENTTYPE]; NSString *resourcePath; Ivar ivar = class_getInstanceVariable([msg.content class], "_resourcePath"); @@ -581,18 +590,59 @@ - (void)getGroupConversationHistoryMessage:(CDVInvokedUrlCommand *)command{ [JMSGConversation createGroupConversationWithGroupId:rid completionHandler:^(id resultObject, NSError *error) { NSMutableArray *resultArr = [NSMutableArray new]; if (error == nil) { + JMSGConversation * conversation = resultObject; NSArray * messageList = [conversation messageArrayFromNewestWithOffset:from limit:limit]; for (JMSGMessage * msg in messageList) { + NSString * jsonString = [msg toJsonString]; JMSGGroup *group = msg.target; NSDictionary *groupDict = [group groupToDictionary]; - NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[jsonString toDictionary]]; + + + NSMutableDictionary *dict = [NSMutableDictionary new]; + + NSError *decodeeError; + NSDictionary *msgBody = [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:0 error:&error]; + + if (decodeeError == nil) { + [dict setValue:msgBody forKey:KEY_CONTENT]; + } + + [dict setValue:[NSString stringWithFormat:@"%ld",(long)msg.contentType] forKey:KEY_CONTENTTYPE]; + [dict addEntriesFromDictionary:@{@"groupDict":groupDict}]; - dict[KEY_LASTMESSAGE] = conversation.latestMessageContentText; + + NSString *resourcePath; + Ivar ivar = class_getInstanceVariable([msg.content class], "_resourcePath"); + + switch (msg.contentType) { + case kJMSGContentTypeVoice: + + resourcePath = object_getIvar(msg.content, ivar); + break; + case kJMSGContentTypeImage: + resourcePath = object_getIvar(msg.content, ivar); + break; + case kJMSGContentTypeFile: + resourcePath = object_getIvar(msg.content, ivar); + break; + + default: + break; + } + if (resourcePath != @"" && resourcePath != nil) { + [dict setValue:[self getFullPathWith:resourcePath] forKey:@"resourcePath"]; + } + + [dict setValue:msg.msgId forKey:KEY_MSGID]; [resultArr addObject:dict]; + } } + + + [weakSelf handleResultWithValue:resultArr command:command error:error log:@"JMessagePlugin Get Group History Message"]; }]; } From bbb9b318dc22db012b0e757797d0a49eed9a74b6 Mon Sep 17 00:00:00 2001 From: Hevin Date: Fri, 28 Apr 2017 09:55:42 +0800 Subject: [PATCH 3/4] Update doc. updateMyInfo --- doc/Android_detail_api.md | 3 ++- doc/iOS_API.md | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/doc/Android_detail_api.md b/doc/Android_detail_api.md index 5a074d5..4f8e674 100644 --- a/doc/Android_detail_api.md +++ b/doc/Android_detail_api.md @@ -203,7 +203,8 @@ - signature:个性签名。 - gender:性别。 - region:地区。 -- value:更新的值。 + - avatar : 头像。 +- value:更新的值,当更新头像时,为图片路径。 - successCallback:获取成功的回调函数,无返回值。 - errorCallback:更新失败的回调函数,以参数形式返回错误信息。如果为 null,默认打印失败信息日志。 diff --git a/doc/iOS_API.md b/doc/iOS_API.md index c81d59a..fc734d5 100644 --- a/doc/iOS_API.md +++ b/doc/iOS_API.md @@ -71,26 +71,22 @@ API 统一说明: window.JMessage.updateMyPassword(oldPwd, newPwd, errorCallback); -### API - updateMyInfo +### API - updateMyInfo(与 Android 通用) 获取我的信息(当前登录用户) #### 接口定义 window.JMessage.updateMyInfo(field, value, successCallback, errorCallback); #### 参数说明 -- field:数字、或纯数字字符串 - - /// 用户信息字段: 用户名 - kJMSGUserFieldsNickname = 0, - /// 用户信息字段: 生日 - kJMSGUserFieldsBirthday = 1, - /// 用户信息字段: 签名 - kJMSGUserFieldsSignature = 2, - /// 用户信息字段: 性别 - kJMSGUserFieldsGender = 3, - /// 用户信息字段: 区域 - kJMSGUserFieldsRegion = 4, - /// 用户信息字段: 头像 (内部定义的 media_id) - kJMSGUserFieldsAvatar = 5, +- userInfoField:需要更新的用户信息字段。包括: + - nickname:昵称。 + - birthday:生日。 + - signature:个性签名。 + - gender:性别。 + - region:地区。 + - avatar : 头像。 +- value:更新的值,当更新头像时,为图片路径。 +- successCallback:获取成功的回调函数,无返回值。 +- errorCallback:更新失败的回调函数,以参数形式返回错误信息。如果为 null,默认打印失败信息日志。 ### API - updateNoteName From 3450faa6d379ece311f4152992ba21c45788f3b1 Mon Sep 17 00:00:00 2001 From: Hevin Date: Fri, 28 Apr 2017 10:17:43 +0800 Subject: [PATCH 4/4] Update npm version. --- README.md | 2 +- package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c6b9b1..95bc498 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JMessage PhoneGap / Cordova Plugin -[![release](https://img.shields.io/badge/release-2.3.4-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases) +[![release](https://img.shields.io/badge/release-2.3.5-blue.svg)](https://github.com/jpush/jmessage-phonegap-plugin/releases) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jmessage-phonegap-plugin) [![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)](https://github.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) diff --git a/package.json b/package.json index 0528a4d..0a152ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jmessage-phonegap-plugin", - "version": "2.3.4", + "version": "2.3.5", "description": "JMessage Cordova Plugin.", "cordova": { "id": "jmessage-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index 3fff596..c3b061c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="2.3.5"> JMessage 集成极光 IM 和推送功能