Skip to content

Commit 6942e9f

Browse files
authored
Merge pull request #68 from JoshLipan/dev
Dev
2 parents e6e5079 + ace8795 commit 6942e9f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
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 {

example/app/routes/Chat/index.js

100644100755
File mode changed.

0 commit comments

Comments
 (0)