33import React from 'react' ;
44import ReactNative , { ScrollView } from 'react-native' ;
55import JMessage from 'jmessage-react-plugin' ;
6- import { observer } from 'mobx-react/native' ;
7- import { observable } from 'mobx' ;
6+ import { observer } from 'mobx-react/native' ;
7+ import { observable } from 'mobx' ;
88
99import FormButton from '../../../views/FormButton' ;
1010import ConversationListStore from './ConversationListStore' ;
@@ -136,17 +136,17 @@ export default class ConversationList extends React.Component {
136136 } )
137137 }
138138
139- enterConversation ( conv ) {
139+ enterConversation ( item ) {
140140 this . reloadConversationList ( )
141- JMessage . enterConversation ( conv , ( status ) => { } , ( error ) => { } )
141+ JMessage . enterConversation ( item , ( status ) => { } , ( error ) => { } )
142142 this . props . navigation . navigate ( 'Chat' , {
143- conversation : { type : conv . conversationType , username : conv . target . username , groupId : conv . groupId }
143+ conversation : { type : item . type , username : item . username , groupId : item . groupId , appKey : item . appKey }
144144 } )
145145 }
146146
147147 createConversation ( params ) {
148148 JMessage . createConversation ( params , ( conv ) => {
149- this . enterConversation ( conv )
149+ this . enterConversation ( this . ConversationListStore . getListItem ( conv ) )
150150 } , ( error ) => {
151151 Alert . alert ( 'create conversation error !' , JSON . stringify ( error ) )
152152 } )
@@ -155,32 +155,42 @@ export default class ConversationList extends React.Component {
155155 enterChatRoom ( item ) {
156156 JMessage . enterChatRoom ( item , ( conversation ) => {
157157 this . props . navigation . navigate ( 'Chat' , {
158- conversation : { type : conversation . conversationType , roomId : conversation . target . roomId }
158+ conversation : { type : conversation . conversationType , roomId : conversation . target . roomId }
159159 } )
160160 } , ( error ) => {
161161 console . alert ( "error, code: " + error . code + ", description: " + error . description )
162162 } )
163163 }
164164
165+ onItemLongPress = ( key ) => {
166+ console . log ( "long press conversation, item key: " + key )
167+ this . ConversationListStore . deleteConversation ( key )
168+ }
169+
170+ keyExtractor = ( item , index ) => index ;
171+
172+
165173 render ( ) {
166174 this . listView = < FlatList
167175 data = { this . ConversationListStore . convList }
168176 extraData = { this . state }
177+ keyExtractor = { this . keyExtractor }
169178 renderItem = {
170179 ( {
171180 item
172181 } ) => (
173- < View >
182+ < View >
174183 < TouchableHighlight
175184 style = { [ styles . conversationContent ] }
176185 underlayColor = '#dddddd'
177186 onPress = { ( ) => {
178187 if ( item . type === "chatroom" ) {
179188 this . enterChatRoom ( item )
180189 } else {
181- this . enterConversation ( item . conversation )
190+ this . enterConversation ( item )
182191 }
183- } } >
192+ } }
193+ onLongPress = { this . onItemLongPress ( item . key ) } >
184194 < View style = { [ styles . conversationItem ] } >
185195 < Image
186196 source = { { uri : item . avatarThumbPath } }
@@ -194,11 +204,9 @@ export default class ConversationList extends React.Component {
194204 </ TouchableHighlight >
195205 </ View >
196206 )
197- } >
198-
207+ } >
199208 </ FlatList >
200209 return (
201-
202210 < View >
203211 < Modal
204212 transparent = { true }
0 commit comments