Skip to content

Commit a320d4a

Browse files
KenChoiKenChoi
authored andcommitted
fix bug and add localPath property
1 parent ea994cd commit a320d4a

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

android/src/io/jchat/android/Constant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class Constant {
6565
public static final String CUSTOM = "custom";
6666
public static final String EXTRAS = "extras";
6767
public static final String THUMB_PATH = "thumbPath";
68+
public static final String LOCAL_PATH = "localPath";
6869
public static final String PATH = "path";
6970
public static final String DURATION = "duration";
7071
public static final String LONGITUDE = "longitude";

android/src/io/jchat/android/utils/JMessageUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public Conversation getConversation(ReadableMap map) {
4444
String appKey = "";
4545
if (map.hasKey(Constant.APP_KEY)) {
4646
appKey = map.getString(Constant.APP_KEY);
47+
conversation = Conversation.createSingleConversation(username, appKey);
48+
} else {
49+
conversation = Conversation.createSingleConversation(username);
4750
}
48-
conversation = Conversation.createSingleConversation(username, appKey);
4951
} else {
5052
String groupId = map.getString(Constant.GROUP_ID);
5153
conversation = Conversation.createGroupConversation(Long.parseLong(groupId));
@@ -54,7 +56,7 @@ public Conversation getConversation(ReadableMap map) {
5456
}
5557

5658
public void sendMessage(ReadableMap map, MessageContent content,
57-
final Callback success, final Callback fail) {
59+
final Callback success, final Callback fail) {
5860
if (map.hasKey(Constant.EXTRAS)) {
5961
content.setExtras(ResultUtils.fromMap(map.getMap(Constant.EXTRAS)));
6062
}

android/src/io/jchat/android/utils/ResultUtils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44

5+
import android.graphics.Bitmap;
6+
import android.graphics.BitmapFactory;
57
import android.text.TextUtils;
68

79
import com.facebook.react.bridge.Arguments;
@@ -17,6 +19,10 @@
1719
import org.json.JSONException;
1820
import org.json.JSONObject;
1921

22+
import java.io.File;
23+
import java.io.FileInputStream;
24+
import java.io.FileNotFoundException;
25+
import java.io.FileOutputStream;
2026
import java.util.HashMap;
2127
import java.util.Iterator;
2228
import java.util.List;
@@ -152,7 +158,22 @@ public static WritableMap toJSObject(Message msg) {
152158
case image:
153159
result.putString(Constant.TYPE, Constant.IMAGE);
154160
ImageContent imageContent = (ImageContent) content;
155-
result.putString(Constant.THUMB_PATH, imageContent.getLocalThumbnailPath() + "." + imageContent.getFormat());
161+
// jmessage did not add file extension, so save to local.
162+
File file = new File(imageContent.getLocalThumbnailPath() + ".png");
163+
FileOutputStream fos = new FileOutputStream(file);
164+
BitmapFactory.Options opts = new BitmapFactory.Options();
165+
opts.inJustDecodeBounds = false;
166+
opts.inSampleSize = 1;
167+
Bitmap bitmap = BitmapFactory.decodeFile(imageContent.getLocalThumbnailPath(), opts);
168+
try {
169+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
170+
fos.flush();
171+
fos.close();
172+
} catch (Exception e) {
173+
e.printStackTrace();
174+
}
175+
result.putString(Constant.THUMB_PATH, file.getAbsolutePath());
176+
result.putString(Constant.LOCAL_PATH, imageContent.getLocalPath());
156177
break;
157178
case voice:
158179
result.putString(Constant.TYPE, Constant.VOICE);

document/Models.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ from: UserInfo, // 消息发送者对象
104104
target: UserInfo / GroupInfo, // 消息接收者对象
105105
extras: object, // 附带的键值对
106106
thumbPath: string // 图片的缩略图路径
107+
localPath: string // 图片本地路径
107108
```
108109

109110
### VoiceMessage

example/android/app/app.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,16 @@
101101
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
102102
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
103103
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
104-
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
105104
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
106105
</content>
107106
<orderEntry type="jdk" jdkName="Android API 25 Platform (1)" jdkType="Android SDK" />
108107
<orderEntry type="sourceFolder" forTests="false" />
109108
<orderEntry type="library" name="com.facebook.fresco:imagepipeline-okhttp3-1.3.0" level="project" />
110109
<orderEntry type="library" name="com.google.code.gson:gson:2.8.0@jar" level="project" />
111110
<orderEntry type="library" name="com.google.android:flexbox-0.2.5" level="project" />
112-
<orderEntry type="library" name="cn.jiguang.imui:chatinput-0.6.2" level="project" />
113111
<orderEntry type="library" name="javax.inject:javax.inject:1@jar" level="project" />
114112
<orderEntry type="library" name="com.android.support:support-core-ui-25.3.1" level="project" />
113+
<orderEntry type="library" name="cn.jiguang.imui:chatinput-0.6.3" level="project" />
115114
<orderEntry type="library" name="com.android.support:support-compat-25.3.1" level="project" />
116115
<orderEntry type="library" name="com.facebook.fresco:imagepipeline-base-1.3.0" level="project" />
117116
<orderEntry type="library" name="__local_aars__:/Users/caiyg/Desktop/github/jmessage-react-plugin/example/node_modules/jmessage-react-plugin/android/libs/jmessage-android_v2.4.1.jar:unspecified@jar" level="project" />

example/app/routes/Chat/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ export default class Chat extends Component {
231231
if (this.state.inputLayoutHeight != size.height) {
232232
this.setState({
233233
inputLayoutHeight: size.height,
234-
inputViewLayout: { width: size.width, height: size.height }
234+
inputViewLayout: { width: size.width, height: size.height },
235+
messageListLayout: { flex:1, width: window.width, margin: 0 }
235236
})
236237
}
237238
}
@@ -246,6 +247,9 @@ export default class Chat extends Component {
246247
resetMenu() {
247248
if (Platform.OS === "android") {
248249
this.refs["ChatInput"].showMenu(false)
250+
this.setState({
251+
messageListLayout: { flex: 1, width: window.width, margin: 0 },
252+
})
249253
} else {
250254
this.setState({
251255
inputViewLayout: { width: window.width, height: 86 }
@@ -267,8 +271,7 @@ export default class Chat extends Component {
267271

268272
onTouchEditText = () => {
269273
console.log("scroll to bottom")
270-
AuroraIController.scrollToBottom(true);
271-
// this.refs["ChatInput"].showMenu(false)
274+
this.refs["ChatInput"].showMenu(false)
272275
this.setState({
273276
inputViewLayout: { width: window.width, height: this.state.inputLayoutHeight }
274277
})
@@ -347,6 +350,7 @@ export default class Chat extends Component {
347350
}
348351

349352
onTakePicture = (mediaPath) => {
353+
console.log("onTakePicture, path: " + mediaPath)
350354
var message = this.getNormalMessage()
351355
message.messageType = "image"
352356
message.path = mediaPath
@@ -536,7 +540,7 @@ export default class Chat extends Component {
536540
onTouchEditText={this.onTouchEditText}
537541
onFullScreen={this.onFullScreen}
538542
onRecoverScreen={this.onRecoverScreen}
539-
onSizeChanged={this.onInputViewSizeChange}
543+
onSizeChange={this.onInputViewSizeChange}
540544
/>
541545
</View>
542546
);

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"start": "node node_modules/react-native/local-cli/cli.js start"
66
},
77
"dependencies": {
8-
"aurora-imui-react-native": "^0.6.0",
8+
"aurora-imui-react-native": "^0.6.9",
99
"jcore-react-native": "^1.2.3",
1010
"jmessage-react-plugin": "^2.1.3",
1111
"react": "^16.0.0",

0 commit comments

Comments
 (0)