Skip to content

Commit ffb6adc

Browse files
KenChoiKenChoi
authored andcommitted
modify demo
1 parent c9d95d1 commit ffb6adc

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

android/src/io/jchat/android/JMessageModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ public void updateMyInfo(ReadableMap map, final Callback success, final Callback
260260
}
261261
if (map.hasKey(Constant.BIRTHDAY)) {
262262
myInfo.setBirthday((long) map.getDouble(Constant.BIRTHDAY));
263+
} else {
264+
myInfo.setBirthday(0);
263265
}
264266
if (map.hasKey(Constant.SIGNATURE)) {
265267
myInfo.setSignature(map.getString(Constant.SIGNATURE));

example/app/routes/Home/ConversationList/ConversationListStore.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ class ConversationListStore {
77

88
convertToConvList = (list) => {
99
list.map((conversation, index) => {
10-
this.convList.push(this.getListItem(conversation))
10+
this.convList.push(this.getListItem(conversation, index))
1111
})
12-
return this.convList
12+
return this.convList.slice()
1313
}
1414

15-
getListItem(conversation) {
15+
getListItem(conversation, index) {
1616
var newItem = {}
17+
newItem.key = index
1718
newItem.conversation = conversation
1819
newItem.type = conversation.conversationType
1920
if (conversation.conversationType === "single") {
2021
newItem.appKey = conversation.target.appKey
21-
newItem.key = conversation.target.username
2222
newItem.username = conversation.target.username
2323
newItem.avatarThumbPath = conversation.target.avatarThumbPath
2424
newItem.displayName = conversation.target.nickname
@@ -37,7 +37,6 @@ class ConversationListStore {
3737
}
3838
} else if (conversation.conversationType === "group") {
3939
newItem.appKey = conversation.target.ownerAppKey
40-
newItem.key = conversation.target.id
4140
newItem.groupId = conversation.target.id
4241
newItem.displayName = conversation.target.name
4342
newItem.avatarThumbPath = conversation.target.avatarThumbPath
@@ -52,7 +51,6 @@ class ConversationListStore {
5251
}
5352
} else {
5453
newItem.appKey = conversation.target.appKey
55-
newItem.key = conversation.target.roomId
5654
newItem.roomId = conversation.target.roomId
5755
newItem.avatarThumbPath = "../../../resource/chat-icon.png"
5856
newItem.displayName = conversation.target.roomName
@@ -82,6 +80,16 @@ class ConversationListStore {
8280

8381
return newItem
8482
}
83+
84+
@action deleteConversation = (key) => {
85+
var item = this.convList[key]
86+
JMessage.deleteConversation(item, (code) => {
87+
this.convList.splice(key, 1)
88+
console.log("Delete succeed")
89+
}, (error) => {
90+
console.log("Delete failed, error: " + JSON.stringify(error))
91+
})
92+
}
8593
}
8694

8795
export default new ConversationListStore

example/app/routes/Home/ConversationList/index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import React from 'react';
44
import ReactNative, { ScrollView } from 'react-native';
55
import 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

99
import FormButton from '../../../views/FormButton';
1010
import 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

Comments
 (0)