Browse Source

Mensajes directos funcionando

ErnestoOrtiz2 3 years ago
parent
commit
3f10c64a80
2 changed files with 7 additions and 58 deletions
  1. 7
    54
      screens/main/Home_page.js
  2. 0
    4
      screens/main/RoomScreen.js

+ 7
- 54
screens/main/Home_page.js View File

1
-
2
 import React, {useState, useEffect} from 'react'
1
 import React, {useState, useEffect} from 'react'
3
 import { Button, Text, View, StyleSheet} from 'react-native'
2
 import { Button, Text, View, StyleSheet} from 'react-native'
4
 import {FlatList, ListViewBase } from 'react-native'
3
 import {FlatList, ListViewBase } from 'react-native'
9
 import { styles } from "../../config/styles";
8
 import { styles } from "../../config/styles";
10
 import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
9
 import { TextInput, TouchableWithoutFeedback, Keyboard, ImageBackground} from "react-native";
11
 
10
 
12
-
13
 import { connect } from 'react-redux'
11
 import { connect } from 'react-redux'
14
 import { bindActionCreators } from 'redux' 
12
 import { bindActionCreators } from 'redux' 
15
 import { fetchUser } from '../../redux/actions/index'
13
 import { fetchUser } from '../../redux/actions/index'
19
   const [loading, setLoading] = useState(true);
17
   const [loading, setLoading] = useState(true);
20
   
18
   
21
   const [roomName, setRoomName] = useState('');
19
   const [roomName, setRoomName] = useState('');
22
-  //const navigation = useNavigation();
23
-  //const [roomName, setRoomName] = useState('');
24
 
20
 
25
   useEffect(() => {
21
   useEffect(() => {
26
 
22
 
27
     const fire = firebase.firestore()
23
     const fire = firebase.firestore()
28
-    .collection('Users')
29
-    .doc(firebase.auth().currentUser.uid)
30
     .collection('THREADS')
24
     .collection('THREADS')
31
-    
25
+    .where("members", "array-contains", firebase.auth().currentUser.uid)
32
     .onSnapshot(querySnapshot => {
26
     .onSnapshot(querySnapshot => {
33
       const threads = querySnapshot.docs.map(documentSnapshot => {
27
       const threads = querySnapshot.docs.map(documentSnapshot => {
34
         return{
28
         return{
55
   }
49
   }
56
 
50
 
57
 
51
 
58
-  function handleButtonPress() {
59
-    if (roomName.length > 0) {
60
-      firebase.firestore()
61
-        .collection('Users')
62
-        .doc(firebase.auth().currentUser.uid)
63
-        .collection('THREADS')
64
-        .add({
65
-          name: roomName
66
-        })
67
-        //.then(() => {
68
-          //navigation.navigate('allChats');
69
-         //});
70
-    }
71
-  }
72
-
73
-
74
   function handleButtonPress2() {
52
   function handleButtonPress2() {
75
       firebase.firestore()
53
       firebase.firestore()
76
-        .collection('Users')
77
-        .doc(firebase.auth().currentUser.uid)
78
         .collection('THREADS')
54
         .collection('THREADS')
79
         .add({
55
         .add({
80
-          name: 'citaFechaHora4'
56
+          name: 'NombreFecha',
57
+          members: [
58
+            firebase.auth().currentUser.uid,
59
+            'BhlrNDOqLOYSSlaEDK0nxZpQ2tD3'
60
+          ]
81
         })
61
         })
82
         //.then(() => {
62
         //.then(() => {
83
           //navigation.navigate('allChats');
63
           //navigation.navigate('allChats');
84
          //});
64
          //});
85
-
86
-         firebase.firestore()
87
-         .collection('Users')
88
-         .doc('HGGAJlcIfwdpUoYfcBKLZFcDude2')
89
-         .collection('THREADS')
90
-         .add({
91
-           name: 'citaFechaHora4'
92
-         })
93
-
94
-      /*firebase.database().ref('Users/' + 'HGGAJlcIfwdpUoYfcBKLZFcDude2' + '/THREADS/')
95
-        .push()
96
-        .set({
97
-          name: 'citaFechaHora3'
98
-        })*/
99
   }
65
   }
100
-
101
-
102
-
103
-
104
-
105
   
66
   
106
   return (
67
   return (
107
     <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
68
     <ImageBackground style={styles.stdcontainer} source={require('../../assets/yellow-white.jpg')}>
138
         onPress={() => handleButtonPress2()}
99
         onPress={() => handleButtonPress2()}
139
       />
100
       />
140
 
101
 
141
-      <Button
142
-        title='Provisional'
143
-        onPress={() => handleButtonPress()}
144
-      />
145
-
146
         <Button
102
         <Button
147
         title ='Hacer Busqueda'
103
         title ='Hacer Busqueda'
148
         onPress= {() => navigation.navigate('Room')}
104
         onPress= {() => navigation.navigate('Room')}
156
 })
112
 })
157
 const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
113
 const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
158
 
114
 
159
-export default connect(mapStateToProps, mapDispatchProps)(Home_page);
160
-
161
-
162
-
115
+export default connect(mapStateToProps, mapDispatchProps)(Home_page);

+ 0
- 4
screens/main/RoomScreen.js View File

40
   useEffect(() => {
40
   useEffect(() => {
41
     //readUser()
41
     //readUser()
42
     const unsubscribe = firebase.firestore() 
42
     const unsubscribe = firebase.firestore() 
43
-    .collection('Users')
44
-    .doc(firebase.auth().currentUser.uid)
45
     .collection('THREADS')
43
     .collection('THREADS')
46
     .doc(thread._id)
44
     .doc(thread._id)
47
     .collection('MESSAGES')
45
     .collection('MESSAGES')
66
 
64
 
67
   async function handleSend(messages) {
65
   async function handleSend(messages) {
68
     const writes = messages.map(m => firebase.firestore() 
66
     const writes = messages.map(m => firebase.firestore() 
69
-    .collection('Users')
70
-    .doc(firebase.auth().currentUser.uid)
71
     .collection('THREADS')
67
     .collection('THREADS')
72
     .doc(thread._id)
68
     .doc(thread._id)
73
     .collection('MESSAGES').add(m))
69
     .collection('MESSAGES').add(m))