This repository has been archived by the owner on Jul 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoipMSSMS.js
134 lines (113 loc) · 3.14 KB
/
VoipMSSMS.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, { Component } from 'react';
import { AppRegistry, Navigator, BackAndroid, Text } from 'react-native';
import ChatScene from './scenes/ChatScene';
import SetupScene from './scenes/SetupScene';
import ThreadsScene from './scenes/ThreadsScene';
import Notification from './models/Notification'
import Contact from './models/Contact';
import DB from './DB'
var navigator;
var currentContact = '';
export default class VoipMSSMS extends Component {
constructor(props) {
super(props);
db = new DB();
contact = new Contact();
notification = new Notification();
this.state = {
loading: false,
isConfigured: db.isConfigured()
};
contact.loadContacts(()=> {});
notification.configure(this._handleNotification.bind(this));
}
componentWillMount(){
BackAndroid.addEventListener('hardwareBackPress', () => { return this.handleBackPress(); } );
}
componentWillUnmount(){
BackAndroid.removeEventListener('hardwareBackPress', () => { return this.handleBackPress();} );
}
handleBackPress() {
if (navigator && navigator.getCurrentRoutes().length > 1) {
navigator.pop();
return true;
}
return false;
}
backHandler (route, navigator) {
if (route.index > 0) {
navigator.pop();
}
}
_handleNotification(notification) {
db = new DB();
if (notification.foreground) {
db.fetchNewMessages();
}
else if (notification.userInteraction) {
navigator.push({
title: 'Contacts',
index: 0,
});
}
else {
var notification = new Notification();
var db = new DB();
db.fetchNewMessages().then((messages) => {
notification.sendMessage(messages.slice(-1)[0])
});
}
}
_configureScene(route, routeStack) {
return Navigator.SceneConfigs.HorizontalSwipeJump
}
_renderScene (route, navigator) {
switch(route.index) {
case 0:
return <ThreadsScene
title={route.title}
onSetup={() => {
navigator.push({
title: 'Setup',
index: 1,
});
}}
onGotoChat={(contact) => {
currentContact = contact;
navigator.push({
title: 'Chat',
index: 2
});
}}
onBack={() => { this.backHandler (route, navigator)}}/>
case 1:
return <SetupScene
title={route.title}
// Function to call when a new scene should be displayed
onSave={() => {
navigator.push({
title: 'Contacts',
index: 0,
});
}}
onBack={() => { this.backHandler (route, navigator)}}/>
case 2:
return <ChatScene
title={route.title}
currentContact={currentContact}
onBack={() => { this.backHandler (route, navigator)}}/>
}
}
render() {
if (this.state.loading == true)
return <Text>Loading contacts...</Text>
else
return (
<Navigator
ref={(nav) => { navigator = nav; }}
initialRoute={this.state.isConfigured ? { title: 'Contacts', index: 0 } : { title: 'Setup', index: 1 }}
renderScene={this._renderScene.bind(this)}
configureScene={this._configureScene.bind(this)}
/>
)}
}