Skip to content

Commit a8aec67

Browse files
Merge pull request #21 from jpush/dev
update example
2 parents 4600246 + 13053a0 commit a8aec67

File tree

2 files changed

+130
-81
lines changed

2 files changed

+130
-81
lines changed

example/app/routes/Chat/index.js

Lines changed: 124 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import Translations from '../../resource/Translations'
3535

3636
var themsgid = 1
3737

38-
3938
export default class Chat extends Component {
4039

4140
static navigationOptions = {
@@ -68,7 +67,6 @@ export default class Chat extends Component {
6867

6968
if (jmessage.type === 'text') {
7069
auroraMsg.text = jmessage.text
71-
// auroraMsg.text = "jmessage.text"
7270
}
7371

7472
if (jmessage.type === 'image') {
@@ -79,7 +77,13 @@ export default class Chat extends Component {
7977
auroraMsg.mediaPath = jmessage.path
8078
auroraMsg.duration = jmessage.duration
8179
}
82-
80+
81+
if (jmessage.type === 'file') {
82+
auroraMsg.mediaPath = jmessage.path
83+
auroraMsg.duration = jmessage.duration
84+
auroraMsg.msgType = "video"
85+
}
86+
8387
var user = {
8488
userId: "1",
8589
displayName: "",
@@ -96,7 +100,7 @@ export default class Chat extends Component {
96100
}
97101
auroraMsg.fromUser = user
98102
console.log("from user: " + JSON.stringify(auroraMsg.fromUser))
99-
auroraMsg.status = "send_going"
103+
auroraMsg.status = "send_succeed"
100104

101105
auroraMsg.isOutgoing = true
102106

@@ -125,14 +129,12 @@ export default class Chat extends Component {
125129
}
126130

127131
componentDidMount() {
128-
// Alert.alert(this.props.navigation.state.params.key)
129-
130132
var parames = {
131133

132134
'from': 0, // 开始的消息下标。
133135
'limit': 10 // 要获取的消息数。比如当 from = 0, limit = 10 时,是获取第 0 - 9 条历史消息。
134136
}
135-
// Alert.alert('conversation', this.conversation)
137+
136138
if (this.conversation.conversationType === 'single') {
137139
parames.type = 'single'
138140
parames.username = this.conversation.key
@@ -143,7 +145,6 @@ export default class Chat extends Component {
143145
this.messageListDidLoadCallback = () => {
144146

145147
JMessage.getHistoryMessages(parames, (messages) => {
146-
147148
var auroraMessages = messages.map((message) => {
148149
var normalMessage = this.convertJMessageToAuroraMsg(message)
149150
if (normalMessage.msgType === "unknow") {
@@ -155,7 +156,6 @@ export default class Chat extends Component {
155156
AuroraIController.insertMessagesToTop(auroraMessages)
156157
} else {
157158
AuroraIController.insertMessagesToTop(auroraMessages)
158-
// AuroraIController.scrollToBottom(true)
159159
}
160160
}, (error) => {
161161
Alert.alert('error!', JSON.stringify(error))
@@ -171,7 +171,6 @@ export default class Chat extends Component {
171171
}
172172
Alert.alert('message.target.username', message.target.username)
173173
Alert.alert('this.conversation.key', this.conversation.key)
174-
// Alert.alert("1111:", JSON.stringify(message))
175174
}
176175
} else {
177176
if (message.target.type === 'group') {
@@ -210,7 +209,7 @@ export default class Chat extends Component {
210209
isDismissMenuContainer: true,
211210
inputViewLayout: {
212211
width: Dimensions.get('window').width,
213-
height: 100
212+
height: 86
214213
},
215214
shouldExpandMenuContainer: false,
216215
});
@@ -260,58 +259,58 @@ export default class Chat extends Component {
260259
onSendText = (text) => {
261260

262261
var message = this.getNormalMessage()
263-
264262
message.text = text
265-
JMessage.sendTextMessage(message, (message) => {
266-
var auroraMsg = this.convertJMessageToAuroraMsg(message)
263+
message.messageType = "text"
264+
265+
JMessage.createSendMessage(message, (msg) => {
266+
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
267+
auroraMsg.status = 'send_going'
267268
AuroraIController.appendMessages([auroraMsg])
268269
AuroraIController.scrollToBottom(true)
269-
}, (error) => {
270-
Alert.alert(JSON.stringify(error))
271-
})
272-
}
273-
274-
onTakePicture = (mediaPath) => {
275-
var message = this.getNormalMessage()
276-
message.path = mediaPath
277-
message.messageType = "image"
278-
JMessage.createSendMessage(message, (message) => {
279-
Alert.alert("the message:", JSON.stringify(message))
280-
// {
281-
// * 'id': Number, // message id
282-
// * 'type': String, // 'single' / 'group'
283-
// * 'groupId': String, // 当 type = group 时,groupId 不能为空
284-
// * 'username': String, // 当 type = single 时,username 不能为空
285-
// * 'appKey': String, // 当 type = single 时,用于指定对象所属应用的 appKey。如果为空,默认为当前应用。
286-
// * 'messageSendingOptions': MessageSendingOptions // Optional. MessageSendingOptions 对象
287-
// * }
288-
var msg = {}
289-
msg.id = message.id
290-
console.log(JSON.stringify(message))
291-
// msg.type = message.target.type
292-
if (message.target.type === 'user') {
293-
msg.username = message.target.username
270+
271+
if (this.conversation.conversationType === 'single') {
294272
msg.type = 'single'
273+
msg.username = this.conversation.key
295274
} else {
296-
msg.groupId = message.target.id
297275
msg.type = 'group'
276+
msg.groupId = this.conversation.key
298277
}
299278

300-
JMessage.sendMessage(msg,(message) => {
301-
302-
},(error) => {
303-
304-
},(progress) => {
305-
// console.log("" + progress)
279+
JMessage.sendMessage(msg, (jmessage) => {
280+
281+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
282+
AuroraIController.updateMessage(auroraMsg)
283+
}, (error) => {
306284
})
307285
})
308-
// JMessage.sendImageMessage(message, (message) => {
309-
// var auroraMsg = this.convertJMessageToAuroraMsg(message)
310-
// AuroraIController.appendMessages([auroraMsg])
311-
// AuroraIController.scrollToBottom(true)
312-
// }, (error) => {
313-
// Alert.alert(JSON.stringify(error))
314-
// })
286+
}
287+
288+
onTakePicture = (mediaPath) => {
289+
var message = this.getNormalMessage()
290+
message.messageType = "image"
291+
message.path = mediaPath
292+
293+
JMessage.createSendMessage(message, (msg) => {
294+
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
295+
auroraMsg.status = 'send_going'
296+
AuroraIController.appendMessages([auroraMsg])
297+
AuroraIController.scrollToBottom(true)
298+
299+
if (this.conversation.conversationType === 'single') {
300+
msg.type = 'single'
301+
msg.username = this.conversation.key
302+
} else {
303+
msg.type = 'group'
304+
msg.groupId = this.conversation.key
305+
}
306+
307+
JMessage.sendMessage(msg, (jmessage) => {
308+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
309+
AuroraIController.updateMessage(auroraMsg)
310+
}, (error) => {
311+
Alert.alert('send image fail')
312+
})
313+
})
315314

316315
}
317316

@@ -320,16 +319,31 @@ export default class Chat extends Component {
320319
}
321320

322321
onFinishRecordVoice = (mediaPath, duration) => {
323-
324322
var message = this.getNormalMessage()
323+
message.messageType = "voice"
325324
message.path = mediaPath
326-
JMessage.sendVoiceMessage(message, (message) => {
327-
var auroraMsg = this.convertJMessageToAuroraMsg(message)
325+
326+
JMessage.createSendMessage(message, (msg) => {
327+
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
328+
auroraMsg.status = 'send_going'
328329
AuroraIController.appendMessages([auroraMsg])
329330
AuroraIController.scrollToBottom(true)
330-
}, (error) => {
331-
Alert.alert(JSON.stringify(error))
332-
})
331+
332+
if (this.conversation.conversationType === 'single') {
333+
msg.type = 'single'
334+
msg.username = this.conversation.key
335+
} else {
336+
msg.type = 'group'
337+
msg.groupId = this.conversation.key
338+
}
339+
340+
JMessage.sendMessage(msg, (jmessage) => {
341+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
342+
AuroraIController.updateMessage(auroraMsg)
343+
}, (error) => {
344+
Alert.alert('send image fail')
345+
})
346+
})
333347
}
334348

335349
onCancelRecordVoice = () => {
@@ -341,39 +355,59 @@ export default class Chat extends Component {
341355
}
342356

343357
onFinishRecordVideo = (mediaPath) => {
344-
345358
var message = this.getNormalMessage()
359+
message.messageType = "file"
346360
message.path = mediaPath
347-
message.extras = {type: "video"}
348-
message.fileName = "video"
349-
JMessage.sendFileMessage(message, (message) => {
350-
var auroraMsg = this.convertJMessageToAuroraMsg(message)
361+
362+
JMessage.createSendMessage(message, (msg) => {
363+
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
364+
auroraMsg.status = 'send_going'
351365
AuroraIController.appendMessages([auroraMsg])
352366
AuroraIController.scrollToBottom(true)
353-
}, (error) => {
354-
Alert.alert(JSON.stringify(error))
367+
368+
if (this.conversation.conversationType === 'single') {
369+
msg.type = 'single'
370+
msg.username = this.conversation.key
371+
} else {
372+
msg.type = 'group'
373+
msg.groupId = this.conversation.key
374+
}
375+
376+
JMessage.sendMessage(msg, (jmessage) => {
377+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
378+
AuroraIController.updateMessage(auroraMsg)
379+
}, (error) => {
380+
Alert.alert('send image fail')
381+
})
355382
})
356383
}
357384

358385
onSendGalleryFiles = (mediaFiles) => {
359-
360-
361-
/**
362-
* WARN: 这里返回的是原图,直接插入大会话列表会很大且耗内存.
363-
* 应该做裁剪操作后再插入到 messageListView 中,
364-
* 一般的 IM SDK 会提供裁剪操作,或者开发者手动进行裁剪。
365-
*
366-
* 代码用例不做裁剪操作。
367-
*/
368386
for(index in mediaFiles) {
369387
var message = this.getNormalMessage()
388+
message.messageType = "image"
370389
message.path = mediaFiles[index].mediaPath
371-
JMessage.sendImageMessage(message, (message) => {
372-
var auroraMsg = this.convertJMessageToAuroraMsg(message)
390+
391+
JMessage.createSendMessage(message, (msg) => {
392+
var auroraMsg = this.convertJMessageToAuroraMsg(msg)
393+
auroraMsg.status = 'send_going'
373394
AuroraIController.appendMessages([auroraMsg])
374395
AuroraIController.scrollToBottom(true)
375-
}, (error) => {
376-
Alert.alert(JSON.stringify(error))
396+
397+
if (this.conversation.conversationType === 'single') {
398+
msg.type = 'single'
399+
msg.username = this.conversation.key
400+
} else {
401+
msg.type = 'group'
402+
msg.groupId = this.conversation.key
403+
}
404+
405+
JMessage.sendMessage(msg, (jmessage) => {
406+
var auroraMsg = this.convertJMessageToAuroraMsg(jmessage)
407+
AuroraIController.updateMessage(auroraMsg)
408+
}, (error) => {
409+
Alert.alert('send image fail')
410+
})
377411
})
378412
}
379413
}
@@ -395,14 +429,23 @@ export default class Chat extends Component {
395429
} else {
396430
this.updateLayout({width:window.width, height:338,})
397431
}
398-
399432
}
400433

401434
onShowKeyboard = (keyboard_height) => {
402435
var inputViewHeight = keyboard_height + 86
403436
this.updateLayout({width:window.width, height:inputViewHeight,})
404437
}
405438

439+
onSwitchToEmojiMode = () => {
440+
if (Platform.OS == "android") {
441+
this.updateLayout({width:window.width, height: 338})
442+
this.setState({
443+
shouldExpandMenuContainer: true
444+
})
445+
} else {
446+
this.updateLayout({width:window.width, height:338,})
447+
}
448+
}
406449

407450
onInitPress() {
408451
console.log('on click init push ');
@@ -437,6 +480,7 @@ export default class Chat extends Component {
437480
onStartRecordVideo={this.onStartRecordVideo}
438481
onFinishRecordVideo={this.onFinishRecordVideo}
439482
onSendGalleryFiles={this.onSendGalleryFiles}
483+
onSwitchToEmojiMode={this.onSwitchToEmojiMode}
440484
onSwitchToMicrophoneMode={this.onSwitchToMicrophoneMode}
441485
onSwitchToGalleryMode={this.onSwitchToGalleryMode}
442486
onSwitchToCameraMode={this.onSwitchToCameraMode}

example/ios/JMessageDemo/Info.plist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>NSMicrophoneUsageDescription</key>
6+
<string></string>
7+
<key>NSCameraUsageDescription</key>
8+
<string></string>
9+
<key>NSPhotoLibraryUsageDescription</key>
10+
<string></string>
511
<key>CFBundleDevelopmentRegion</key>
612
<string>en</string>
713
<key>CFBundleDisplayName</key>
@@ -41,7 +47,6 @@
4147
<key>NSLocationWhenInUseUsageDescription</key>
4248
<string></string>
4349
<key>NSAppTransportSecurity</key>
44-
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
4550
<dict>
4651
<key>NSExceptionDomains</key>
4752
<dict>

0 commit comments

Comments
 (0)