This repository has been archived by the owner on Jan 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (65 loc) · 2.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, {Component} from 'react'
import {GiftedChat} from 'react-native-gifted-chat'
import PropTypes from 'prop-types';
class XMPPMessenger extends Component {
constructor(props) {
super(props)
}
componentDidMount() {
const {xmpp} = this.props
// xmpp.xmppObject.on('message', this.onReceiveMessage.bind(this))
}
onReceiveMessage(text) {
// this.props.onReceiveMessage(text)
}
onSend(messages = []) {
const { xmpp } = this.props
const { settings } = this.props.xmpp
const { chattingWith } = this.props
this.props.onSend(messages[0])
// xmpp.sendMessage(messages[0].text, `${chattingWith}@${settings.domain}`) // change this
if(this.props.isLoggedIn && messages[0].text !=''){
xmpp.sendMessage(messages[0].text, `${chattingWith}@${settings.domain}`)
}
else{
if(this.props.cacheAction && messages[0].text !='')
this.props.cacheAction({message:messages[0],to:`${chattingWith}@${settings.domain}`})
}
// ^^ gifted chat push an array of message. we require the first
// one. thus sending only one
}
render() {
let {chat, chattingWith} = this.props,
key = `${chat.jid}:${chattingWith}`,
{user, parsePatterns,systemMessageParsePatterns, ...rest} = this.props
return (
<GiftedChat
{...rest}
messages={chat.messages[key] || []}
onSend={(messages) => this.onSend(messages)}
user={this.props.user}
parsePatterns={this.props.parsePatterns}
systemMessageParsePatterns={this.props.systemMessageParsePatterns}
/>
)
}
}
XMPPMessenger.defaultProps = {
onReceiveMessage: () => {},
}
XMPPMessenger.propTypes = {
xmpp: PropTypes.object.isRequired,
chat: PropTypes.object.isRequired,
chattingWith: PropTypes.string.isRequired,
onSend: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
parsePatterns: PropTypes.func.isRequired,
systemMessageParsePatterns: PropTypes.func.isRequired,
}
export default XMPPMessenger
/*
* props
* chat: chat object that contains usually a redux reducer
* chattingWith: xmpp id of the person chatting with
*
* */