Skip to content

Commit c7e9843

Browse files
authored
Merge pull request #69 from jpush/dev
Dev
2 parents 7a1ce2c + 6942e9f commit c7e9843

File tree

9 files changed

+144
-5
lines changed

9 files changed

+144
-5
lines changed

android/src/io/jchat/android/JMessageModule.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,44 @@ public void onComplete(int status, String desc, File file) {
10731073
}
10741074
}
10751075

1076+
@ReactMethod
1077+
public void downloadThumbImage(ReadableMap map, final Callback success, final Callback fail) {
1078+
try {
1079+
Conversation conversation = mJMessageUtils.getConversation(map);
1080+
if (null == conversation) {
1081+
mJMessageUtils.handleError(fail, ERR_CODE_CONVERSATION, ERR_MSG_CONVERSATION);
1082+
return;
1083+
}
1084+
final String messageId = map.getString(Constant.MESSAGE_ID);
1085+
Message msg = conversation.getMessage(Integer.parseInt(messageId));
1086+
if (null == msg) {
1087+
mJMessageUtils.handleError(fail, ERR_CODE_MESSAGE, ERR_MSG_MESSAGE);
1088+
return;
1089+
}
1090+
if (msg.getContentType() != ContentType.image) {
1091+
mJMessageUtils.handleError(fail, ERR_CODE_MESSAGE, "Wrong message type");
1092+
return;
1093+
}
1094+
ImageContent content = (ImageContent) msg.getContent();
1095+
content.downloadThumbnailImage(msg, new DownloadCompletionCallback() {
1096+
@Override
1097+
public void onComplete(int status, String desc, File file) {
1098+
if (status == 0) {
1099+
WritableMap result = Arguments.createMap();
1100+
result.putString(Constant.MESSAGE_ID, messageId);
1101+
result.putString(Constant.FILE_PATH, file.getAbsolutePath());
1102+
mJMessageUtils.handleCallbackWithObject(status, desc, success, fail, result);
1103+
} else {
1104+
mJMessageUtils.handleError(fail, status, desc);
1105+
}
1106+
}
1107+
});
1108+
} catch (Exception e) {
1109+
e.printStackTrace();
1110+
mJMessageUtils.handleError(fail, ERR_CODE_PARAMETER, ERR_MSG_PARAMETER);
1111+
}
1112+
}
1113+
10761114
@ReactMethod
10771115
public void downloadVoiceFile(ReadableMap map, final Callback success, final Callback fail) {
10781116
try {

document/API.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import JMessage from 'jmessage-react-plugin';
4545
- [retractMessage](#retractmessage)
4646
- [getHistoryMessages](#gethistorymessages)
4747
- [downloadOriginalImage](#downloadoriginalimage)
48+
- [downloadThumbImage](#downloadthumbimage)
4849
- [downloadVoiceFile](#downloadvoicefile)
4950
- [downloadFile](#downloadfile)
5051
- [会话](#会话)
@@ -107,7 +108,7 @@ import JMessage from 'jmessage-react-plugin';
107108

108109

109110

110-
- [点击消息通知事件(Android Only)](#addclickmessagenotificationlistener)
111+
- [点击消息通知事件(Android Only)](#addclickmessagenotificationlistener)
111112
- [addClickMessageNotificationListener](#addclickmessagenotificationlistener)
112113
- [removeClickMessageNotificationListener](#addclickmessagenotificationlistener)
113114

@@ -946,6 +947,33 @@ JMessage.downloadOriginalImage({ type: 'single', username: 'username',
946947
- groupId: 对象群组 id。当 `type` 为 'group' 时,`groupId` 为必填。
947948
- messageId: 图片消息 id。
948949

950+
### downloadThumbImage
951+
952+
下载图片消息缩略图。如果已经下载,会直接返回本地文件路径,不会重复下载。
953+
954+
#### 示例
955+
956+
```js
957+
JMessage.downloadThumbImage({ type: 'single', username: 'username',
958+
messageId: 'target_msg_id' },
959+
(result) => {
960+
var msgId = result.messageId
961+
var imgPath = result.filePath
962+
963+
}, (error) => {
964+
var code = error.code
965+
var desc = error.description
966+
})
967+
```
968+
969+
#### 参数说明
970+
971+
- type: 会话类型。可以为 'single' 或 'group' 。
972+
- username: 对方用户的用户名。当 `type` 为 'single' 时,`username` 为必填。
973+
- appKey: 对方用户所属应用的 AppKey。如果不填,默认为当前应用。
974+
- groupId: 对象群组 id。当 `type` 为 'group' 时,`groupId` 为必填。
975+
- messageId: 图片消息 id。
976+
949977
### downloadVoiceFile
950978

951979
下载语音文件。如果已经下载,会直接返回本地文件路径,不会重复下载。

example/app/routes/Chat/index.js

100644100755
File mode changed.

index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ export default class JMessage {
623623
}
624624

625625
/**
626-
* 下载指定图片消息的原图,如果已经下载,会直接返回本地文件路径,不会重复下载。
626+
* 下载指定图片消息的缩略图,如果已经下载,会直接返回本地文件路径,不会重复下载。
627627
*
628628
* @param {object} params = {
629629
* 'type': String, // 'single' / 'group'
@@ -639,6 +639,23 @@ export default class JMessage {
639639
JMessageModule.downloadOriginalImage(params, success, error)
640640
}
641641

642+
/**
643+
* 下载指定图片消息的原图,如果已经下载,会直接返回本地文件路径,不会重复下载。
644+
*
645+
* @param {object} params = {
646+
* 'type': String, // 'single' / 'group'
647+
* 'groupId': String, // 目标群组 id。
648+
* 'username': String, // 目标用户名。
649+
* 'appKey': String, // 目标用户所属 AppKey。
650+
* 'messageId': String // 指定消息 id。
651+
* }
652+
* @param {function} success = function ({'messageId': String, 'filePath': String}) {}
653+
* @param {function} error = function ({'code': '错误码', 'description': '错误信息'}) {}
654+
*/
655+
static downloadThumbImage(params, success, error) {
656+
JMessageModule.downloadThumbImage(params, success, error)
657+
}
658+
642659
/**
643660
* 下载语音消息文件,如果已经下载,会直接返回本地文件路径,不会重复下载。
644661
*

ios/RCTJMessageModule/JMessage.framework/Headers/JMessage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ extern NSString *const kJMSGServiceErrorNotification; // 错误
5555
@interface JMessage : NSObject
5656

5757
/*! JMessage SDK 版本号。用于展示 SDK 的版本信息 */
58-
#define JMESSAGE_VERSION @"3.6.1"
58+
#define JMESSAGE_VERSION @"3.6.2"
5959

6060
/*! JMessage SDK 构建ID. 每次构建都会增加 */
61-
#define JMESSAGE_BUILD 222
61+
#define JMESSAGE_BUILD 226
6262

6363
/*! API Version - int for program logic. SDK API 有变更时会增加 */
6464
extern NSInteger const JMESSAGE_API_VERSION;
0 Bytes
Binary file not shown.
-1.57 MB
Binary file not shown.

ios/RCTJMessageModule/RCTJMessageModule.m

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,62 @@ - (JMSGOptionalContent *)convertDicToJMSGOptionalContent:(NSDictionary *)dic {
16641664
}];
16651665
}
16661666

1667+
RCT_EXPORT_METHOD(downloadThumbImage:(NSDictionary *)param
1668+
successCallback:(RCTResponseSenderBlock)successCallback
1669+
failCallback:(RCTResponseSenderBlock)failCallback) {
1670+
if (param[@"messageId"] == nil ||
1671+
param[@"type"] == nil) {
1672+
failCallback(@[[self getParamError]]);
1673+
return;
1674+
}
1675+
1676+
NSString *appKey = nil;
1677+
if (param[@"appKey"]) {
1678+
appKey = param[@"appKey"];
1679+
} else {
1680+
appKey = [JMessageHelper shareInstance].JMessageAppKey;
1681+
}
1682+
1683+
if ([param[@"type"] isEqual: @"single"] && param[@"username"] != nil) {
1684+
1685+
} else {
1686+
if ([param[@"type"] isEqual: @"group"] && param[@"groupId"] != nil) {
1687+
} else {
1688+
failCallback(@[[self getParamError]]);
1689+
return;
1690+
}
1691+
}
1692+
[self getConversationWithDictionary:param callback:^(JMSGConversation *conversation, NSError *error) {
1693+
if (error) {
1694+
failCallback(@[[error errorToDictionary]]);
1695+
return;
1696+
}
1697+
1698+
JMSGMessage *message = [conversation messageWithMessageId:param[@"messageId"]];
1699+
if (message == nil) {
1700+
failCallback(@[[self getErrorWithLog:@"cann't find this message"]]);
1701+
return;
1702+
}
1703+
1704+
if (message.contentType != kJMSGContentTypeImage) {
1705+
failCallback(@[[self getErrorWithLog:@"It is not voice message"]]);
1706+
return;
1707+
} else {
1708+
JMSGImageContent *content = (JMSGImageContent *) message.content;
1709+
[content thumbImageData:^(NSData *data, NSString *objectId, NSError *error) {
1710+
if (error) {
1711+
failCallback(@[[error errorToDictionary]]);
1712+
return;
1713+
}
1714+
1715+
JMSGMediaAbstractContent *mediaContent = (JMSGMediaAbstractContent *) message.content;
1716+
successCallback(@[@{@"messageId": message.msgId,
1717+
@"filePath": [content thumbImageLocalPath]}]);
1718+
}];
1719+
}
1720+
}];
1721+
}
1722+
16671723
RCT_EXPORT_METHOD(downloadVoiceFile:(NSDictionary *)param
16681724
successCallback:(RCTResponseSenderBlock)successCallback
16691725
failCallback:(RCTResponseSenderBlock)failCallback) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jmessage-react-plugin",
3-
"version": "2.3.8",
3+
"version": "2.3.9",
44
"description": "a jmessage plugin for react native application",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)