@@ -54,6 +54,8 @@ export default class Chat extends Component {
5454 messageListLayout : { } ,
5555 inputViewLayout : { width : window . width , height : initHeight , } ,
5656 menuContainerHeight : 625 ,
57+ from : 0 ,
58+ limit : 10 ,
5759 } ;
5860
5961 this . updateLayout = this . updateLayout . bind ( this ) ;
@@ -176,8 +178,8 @@ export default class Chat extends Component {
176178 } )
177179 var parames = {
178180
179- from : 0 , // 开始的消息下标。
180- limit : 10 , // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
181+ from : this . state . from , // 开始的消息下标。
182+ limit : this . state . limit , // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
181183 type : this . conversation . type ,
182184 username : this . conversation . username ,
183185 groupId : this . conversation . groupId ,
@@ -186,6 +188,9 @@ export default class Chat extends Component {
186188 this . messageListDidLoadCallback = ( ) => {
187189
188190 JMessage . getHistoryMessages ( parames , ( messages ) => {
191+ this . setState ( {
192+ from : this . state . from + 10
193+ } )
189194 var auroraMessages = messages . map ( ( message ) => {
190195 var normalMessage = this . convertJMessageToAuroraMsg ( message )
191196 if ( normalMessage . msgType === "unknow" ) {
@@ -310,7 +315,8 @@ export default class Chat extends Component {
310315
311316 onMsgClick = ( message ) => {
312317 console . log ( message )
313- alert ( JSON . stringify ( message ) )
318+ // alert(JSON.stringify(message))
319+ Alert . alert ( 'onSendGalleryFiles' , JSON . stringify ( message ) )
314320 }
315321
316322 onStatusViewClick = ( message ) => {
@@ -327,13 +333,33 @@ export default class Chat extends Component {
327333
328334 onPullToRefresh = ( ) => {
329335 console . log ( "on pull to refresh" )
330- // After loading history messages
331- if ( Platform . OS === "android" ) {
332- this . timer = setTimeout ( ( ) => {
333- console . log ( "send refresh complete event" )
334- this . refs [ "MessageList" ] . refreshComplete ( )
335- } , 2000 ) ;
336+ var parames = {
337+
338+ from : this . state . from , // 开始的消息下标。
339+ limit : this . state . limit , // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
340+ type : this . conversation . type ,
341+ username : this . conversation . username ,
342+ groupId : this . conversation . groupId ,
343+ roomId : this . conversation . roomId
336344 }
345+ JMessage . getHistoryMessages ( parames , ( messages ) => {
346+ if ( Platform . OS == "android" ) {
347+ this . refs [ "MessageList" ] . refreshComplete ( )
348+ }
349+ this . setState ( {
350+ from : this . state . from + 10
351+ } )
352+ var auroraMessages = messages . map ( ( message ) => {
353+ var normalMessage = this . convertJMessageToAuroraMsg ( message )
354+ if ( normalMessage . msgType === "unknow" ) {
355+ return
356+ }
357+ return normalMessage
358+ } )
359+ AuroraIController . insertMessagesToTop ( auroraMessages )
360+ } , ( error ) => {
361+ Alert . alert ( 'error!' , JSON . stringify ( error ) )
362+ } )
337363 }
338364
339365 onSendText = ( text ) => {
@@ -469,32 +495,38 @@ export default class Chat extends Component {
469495
470496 onSendGalleryFiles = ( mediaFiles ) => {
471497 for ( index in mediaFiles ) {
498+ Alert . alert ( 'onSendGalleryFiles' , JSON . stringify ( mediaFiles [ index ] [ 'mediaPath' ] ) )
472499 var message = this . getNormalMessage ( )
473500 message . messageType = "image"
474501 message . path = mediaFiles [ index ] . mediaPath
475-
476- JMessage . createSendMessage ( message , ( msg ) => {
502+ JMessage . sendImageMessage ( message , ( msg ) => {
477503 var auroraMsg = this . convertJMessageToAuroraMsg ( msg )
478504 auroraMsg . status = 'send_going'
479505 AuroraIController . appendMessages ( [ auroraMsg ] )
480506 AuroraIController . scrollToBottom ( true )
481-
482- if ( this . conversation . type === 'single' ) {
483- msg . username = this . conversation . username
484- } else if ( this . conversation . type === "group" ) {
485- msg . groupId = this . conversation . groupId
486- } else {
487- msg . roomId = this . conversation . roomId
488- }
489- msg . type = this . conversation . type
490-
491- JMessage . sendMessage ( msg , ( jmessage ) => {
492- var auroraMsg = this . convertJMessageToAuroraMsg ( jmessage )
493- AuroraIController . updateMessage ( auroraMsg )
494- } , ( error ) => {
495- Alert . alert ( 'send image fail' )
496- } )
497- } )
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+ // })
498530 }
499531 }
500532
0 commit comments