|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
|
2
|
import React, { useState, useEffect, useCallback } from 'react';
|
2
|
3
|
import { GiftedChat } from 'react-native-gifted-chat';
|
3
|
4
|
import firebase from 'firebase';
|
|
@@ -6,39 +7,10 @@ import { bindActionCreators } from 'redux'
|
6
|
7
|
import { fetchUser } from '../../redux/actions/index'
|
7
|
8
|
|
8
|
9
|
export function RoomScreen({ route }) {
|
9
|
|
- //const { currentUser } = props;
|
10
|
10
|
const { thread } = route.params;
|
11
|
|
- /*const [messages, setMessages] = useState([
|
12
|
|
- /**
|
13
|
|
- * Mock message data
|
14
|
|
- */
|
15
|
|
- // example of system message
|
16
|
|
- /* {
|
17
|
|
- _id: 0,
|
18
|
|
- text: 'New room created.',
|
19
|
|
- createdAt: new Date().getTime(),
|
20
|
|
- system: true
|
21
|
|
- },
|
22
|
|
- // example of chat message
|
23
|
|
- {
|
24
|
|
- _id: 1,
|
25
|
|
- text: 'Henlo!',
|
26
|
|
- createdAt: new Date().getTime(),
|
27
|
|
- user: {
|
28
|
|
- _id: 2,
|
29
|
|
- name: 'Test User'
|
30
|
|
- }
|
31
|
|
- }
|
32
|
|
- ]);*/
|
33
|
|
-
|
34
|
11
|
const [messages, setMessages] = useState([])
|
35
|
12
|
|
36
|
|
-
|
37
|
|
- /** the useEffect is used when we first render the component
|
38
|
|
- * solo va a corrar al principio.
|
39
|
|
- */
|
40
|
13
|
useEffect(() => {
|
41
|
|
- //readUser()
|
42
|
14
|
const unsubscribe = firebase.firestore()
|
43
|
15
|
.collection('THREADS')
|
44
|
16
|
.doc(thread._id)
|
|
@@ -70,52 +42,9 @@ export function RoomScreen({ route }) {
|
70
|
42
|
await Promise.all(writes)
|
71
|
43
|
}
|
72
|
44
|
|
73
|
|
- /*async function handleSend(messages, newMessage = []) {
|
74
|
|
- const text = messages[0].text;
|
75
|
|
- setMessages(GiftedChat.append(messages, newMessage));
|
76
|
|
-
|
77
|
|
- //aqui podemos usar current user que no lo hemos usado, ya tenemos conectado redux
|
78
|
|
- firebase.firestore()
|
79
|
|
- .collection('Users')
|
80
|
|
- .doc(firebase.auth().currentUser.uid)
|
81
|
|
- .collection('THREADS')
|
82
|
|
- .doc(thread._id)
|
83
|
|
- .collection('MESSAGES')
|
84
|
|
- .add({
|
85
|
|
- text,
|
86
|
|
- createdAt: new Date().getTime(),
|
87
|
|
- });
|
88
|
|
-
|
89
|
|
- //Esto se ve, pero no genraliza, solo funciona desde currentUser y se graba en la otra cuenta,
|
90
|
|
- //pero la otra cuenta no puede responder porque pasa a ser current user.
|
91
|
|
- //Ademas no guarda que usuario dijo que.
|
92
|
|
- firebase.firestore()
|
93
|
|
- .collection('Users')
|
94
|
|
- .doc('HGGAJlcIfwdpUoYfcBKLZFcDude2')
|
95
|
|
- .collection('THREADS')
|
96
|
|
- .doc(thread._id)
|
97
|
|
- .collection('MESSAGES')
|
98
|
|
- .add({
|
99
|
|
- text,
|
100
|
|
- createdAt: new Date().getTime(),
|
101
|
|
- });
|
102
|
|
- }*/
|
103
|
|
-
|
104
|
|
- // helper method that is sends a message
|
105
|
|
- /*function handleSend(newMessage = []) {
|
106
|
|
- setMessages(GiftedChat.append(messages, newMessage));
|
107
|
|
- }*/
|
|
45
|
+
|
108
|
46
|
|
109
|
47
|
return (
|
110
|
|
- /*<GiftedChat
|
111
|
|
- messages={messages}
|
112
|
|
- onSend={newMessage => handleSend(messages, newMessage)}
|
113
|
|
- user={{ _id: 1 }}
|
114
|
|
- showUserAvatar
|
115
|
|
- alwaysShowSend
|
116
|
|
- scrollToBottom
|
117
|
|
- />*/
|
118
|
|
-
|
119
|
48
|
<GiftedChat messages={messages} user={{ _id: 1 }} onSend={handleSend} />
|
120
|
49
|
);
|
121
|
50
|
}
|