Skip to content

Commit c2e6ce0

Browse files
committed
udpate demo chat page fix [email protected]
1 parent e80acbe commit c2e6ce0

File tree

1 file changed

+57
-98
lines changed

1 file changed

+57
-98
lines changed

example/app/routes/Chat/index.js

Lines changed: 57 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,11 @@
66

77
import React, { Component } from 'react';
88
import {
9-
AppRegistry,
109
StyleSheet,
11-
Text,
1210
View,
13-
TouchableHighlight,
14-
NativeModules,
15-
requireNativeComponent,
1611
Alert,
1712
Dimensions,
18-
DeviceEventEmitter,
1913
Platform,
20-
UIManager,
21-
findNodeHandle,
2214
} from 'react-native';
2315

2416
import IMUI from 'aurora-imui-react-native'
@@ -29,12 +21,6 @@ const window = Dimensions.get('window');
2921

3022
import JMessage from 'jmessage-react-plugin';
3123

32-
import Translations from '../../resource/Translations'
33-
34-
var themsgid = 1
35-
var from = 0;
36-
var limit = 10;
37-
3824
export default class Chat extends Component {
3925

4026
static navigationOptions = {
@@ -62,7 +48,7 @@ export default class Chat extends Component {
6248
this.onTouchMsgList = this.onTouchMsgList.bind(this);
6349
this.conversation = this.props.navigation.state.params.conversation
6450
console.log(JSON.stringify(this.conversation))
65-
// Alert.alert("the conversation ",JSON.stringify(this.conversation))
51+
6652
JMessage.getMyInfo((myInfo) => {
6753
this.myInfo = myInfo
6854
})
@@ -87,14 +73,17 @@ export default class Chat extends Component {
8773
}
8874

8975
if (jmessage.type === 'file') {
90-
auroraMsg.mediaPath = jmessage.path
91-
auroraMsg.duration = jmessage.duration
92-
auroraMsg.msgType = "video"
76+
if (jmessage.extras.fileType === 'video') {
77+
auroraMsg.mediaPath = jmessage.path
78+
auroraMsg.duration = jmessage.duration
79+
auroraMsg.msgType = "video"
80+
} else {
81+
console.log("cann't parse this file type ignore")
82+
return {}
83+
}
9384
}
9485

9586
if (jmessage.type === 'event') {
96-
// auroraMsg.mediaPath = jmessage.path
97-
// auroraMsg.duration = jmessage.duration
9887
Alert.alert('event' , jmessage.eventType)
9988
auroraMsg.text = jmessage.eventType
10089
}
@@ -167,8 +156,7 @@ export default class Chat extends Component {
167156
messages[i] = message;
168157
}
169158

170-
AuroraIController.appendMessages(messages);
171-
159+
AuroraIController.appendMessages(messages)
172160
}
173161

174162
componentDidMount() {
@@ -188,6 +176,8 @@ export default class Chat extends Component {
188176
this.messageListDidLoadCallback = () => {
189177

190178
JMessage.getHistoryMessages(parames, (messages) => {
179+
// Alert.alert('messages',JSON.stringify(messages))
180+
console.log(JSON.stringify(messages));
191181
this.setState({
192182
from: this.state.from + 10
193183
})
@@ -283,7 +273,7 @@ export default class Chat extends Component {
283273
}
284274

285275
onAvatarClick = (message) => {
286-
console.log(message)
276+
287277
}
288278

289279
onTouchMsgList() {
@@ -362,6 +352,18 @@ export default class Chat extends Component {
362352
})
363353
}
364354

355+
356+
setMessageTarget = (msg) => {
357+
if (this.conversation.type === 'single') {
358+
msg.username = this.conversation.username
359+
} else if (this.conversation.type === "group") {
360+
msg.groupId = this.conversation.groupId
361+
} else {
362+
msg.roomId = this.conversation.roomId
363+
}
364+
msg.type = this.conversation.type
365+
}
366+
365367
onSendText = (text) => {
366368

367369
var message = this.getNormalMessage()
@@ -370,64 +372,51 @@ export default class Chat extends Component {
370372

371373
JMessage.createSendMessage(message, (msg) => {
372374
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
375+
if (auroraMsg.msgType === undefined) {
376+
return
377+
}
378+
373379
auroraMsg.status = 'send_going'
374380
AuroraIController.appendMessages([auroraMsg])
375381
AuroraIController.scrollToBottom(true)
376-
377-
if (this.conversation.type === 'single') {
378-
msg.username = this.conversation.username
379-
} else if (this.conversation.type === "group") {
380-
msg.groupId = this.conversation.groupId
381-
} else {
382-
msg.roomId = this.conversation.roomId
383-
}
384-
msg.type = this.conversation.type
385-
382+
this.setMessageTarget(msg)
383+
Alert.alert('send text', JSON.stringify(msg))
384+
386385
JMessage.sendMessage(msg, (jmessage) => {
387-
388386
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
389387
AuroraIController.updateMessage(auroraMsg)
390388
}, (error) => {
391389
})
392390
})
393391
}
394392

395-
onTakePicture = (mediaPath) => {
396-
console.log("onTakePicture, path: " + mediaPath)
393+
onTakePicture = (media) => {
394+
console.log("onTakePicture, path: " + media)
397395
var message = this.getNormalMessage()
398396
message.messageType = "image"
399-
message.path = mediaPath
397+
message.path = media.mediaPath
400398

401399
JMessage.createSendMessage(message, (msg) => {
402400
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
403401
auroraMsg.status = 'send_going'
404402
AuroraIController.appendMessages([auroraMsg])
405403
AuroraIController.scrollToBottom(true)
406-
407-
if (this.conversation.type === 'single') {
408-
msg.username = this.conversation.username
409-
} else if (this.conversation.type === "group") {
410-
msg.groupId = this.conversation.groupId
411-
} else {
412-
msg.roomId = this.conversation.roomId
413-
}
414-
msg.type = this.conversation.type
415-
404+
this.setMessageTarget(msg)
416405
JMessage.sendMessage(msg, (jmessage) => {
417406
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
418407
AuroraIController.updateMessage(auroraMsg)
419408
}, (error) => {
420-
Alert.alert('send image fail')
409+
Alert.alert(`send image fail ${JSON.stringify(error)}`)
421410
})
422411
})
423-
424412
}
425413

426414
onStartRecordVoice = (e) => {
427415
console.log("on start record voice")
428416
}
429417

430-
onFinishRecordVoice = (mediaPath, duration) => {
418+
onFinishRecordVoice = (mediaPath) => {
419+
Alert.alert('onFinishRecordVoice', JSON.stringify(mediaPath))
431420
var message = this.getNormalMessage()
432421
message.messageType = "voice"
433422
message.path = mediaPath
@@ -437,21 +426,12 @@ export default class Chat extends Component {
437426
auroraMsg.status = 'send_going'
438427
AuroraIController.appendMessages([auroraMsg])
439428
AuroraIController.scrollToBottom(true)
440-
441-
if (this.conversation.type === 'single') {
442-
msg.username = this.conversation.username
443-
} else if (this.conversation.type === "group") {
444-
msg.groupId = this.conversation.groupId
445-
} else {
446-
msg.roomId = this.conversation.roomId
447-
}
448-
msg.type = this.conversation.type
449-
429+
this.setMessageTarget(msg)
450430
JMessage.sendMessage(msg, (jmessage) => {
451431
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
452432
AuroraIController.updateMessage(auroraMsg)
453433
}, (error) => {
454-
Alert.alert('send image fail')
434+
Alert.alert(`send image fail ${JSON.stringify(error)}`)
455435
})
456436
})
457437
}
@@ -464,31 +444,24 @@ export default class Chat extends Component {
464444
console.log("on start record video")
465445
}
466446

467-
onFinishRecordVideo = (mediaPath) => {
447+
onFinishRecordVideo = (video) => {
468448
var message = this.getNormalMessage()
469449
message.messageType = "file"
470-
message.path = mediaPath
450+
message.extras = {fileType: 'video'}
451+
message.path = video.mediaPath
471452

472453
JMessage.createSendMessage(message, (msg) => {
473454
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
474455
auroraMsg.status = 'send_going'
475456
AuroraIController.appendMessages([auroraMsg])
476457
AuroraIController.scrollToBottom(true)
477-
478-
if (this.conversation.type === 'single') {
479-
msg.username = this.conversation.username
480-
} else if (this.conversation.type === "group") {
481-
msg.groupId = this.conversation.groupId
482-
} else {
483-
msg.roomId = this.conversation.roomId
484-
}
485-
msg.type = this.conversation.type
458+
this.setMessageTarget(msg)
486459

487460
JMessage.sendMessage(msg, (jmessage) => {
488461
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
489462
AuroraIController.updateMessage(auroraMsg)
490463
}, (error) => {
491-
Alert.alert('send image fail')
464+
Alert.alert(`send image fail ${JSON.stringify(error)}`)
492465
})
493466
})
494467
}
@@ -499,34 +472,20 @@ export default class Chat extends Component {
499472
var message = this.getNormalMessage()
500473
message.messageType = "image"
501474
message.path = mediaFiles[index].mediaPath
502-
JMessage.sendImageMessage(message, (msg) => {
475+
476+
JMessage.createSendMessage(message, (msg) => {
503477
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
504478
auroraMsg.status = 'send_going'
505479
AuroraIController.appendMessages([auroraMsg])
506480
AuroraIController.scrollToBottom(true)
507-
}, () => {})
508-
// JMessage.createSendMessage(message, (msg) => {
509-
// var auroraMsg = this.convertJMessageToAuroraMsg(msg)
510-
// auroraMsg.status = 'send_going'
511-
// AuroraIController.appendMessages([auroraMsg])
512-
// AuroraIController.scrollToBottom(true)
513-
514-
// if (this.conversation.type === 'single') {
515-
// msg.username = this.conversation.username
516-
// } else if (this.conversation.type === "group") {
517-
// msg.groupId = this.conversation.groupId
518-
// } else {
519-
// msg.roomId = this.conversation.roomId
520-
// }
521-
// msg.type = this.conversation.type
522-
523-
// JMessage.sendMessage(msg, (jmessage) => {
524-
// var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
525-
// AuroraIController.updateMessage(auroraMsg)
526-
// }, (error) => {
527-
// Alert.alert('send image fail')
528-
// })
529-
// })
481+
this.setMessageTarget(msg)
482+
JMessage.sendMessage(msg, (jmessage) => {
483+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
484+
AuroraIController.updateMessage(auroraMsg)
485+
}, (error) => {
486+
Alert.alert(`send image fail ${JSON.stringify(error)}`)
487+
})
488+
})
530489
}
531490
}
532491

@@ -552,7 +511,7 @@ export default class Chat extends Component {
552511
}
553512

554513
onInitPress() {
555-
console.log('on click init push ');
514+
console.log('on click init push');
556515
this.updateAction();
557516
}
558517

0 commit comments

Comments
 (0)