Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

receive msg from no-contacts #119

Merged
merged 5 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Screens/Auth/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class Auth extends Component {
...contactFromPhone,
contactName,
key: doc.id,
profile_img_url
contactPhoto: profile_img_url
})
}
}
Expand Down
32 changes: 27 additions & 5 deletions src/Screens/Chat/chat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
import React, { Component } from "react"

import { View, StyleSheet, StatusBar, BackHandler } from "react-native"
Expand Down Expand Up @@ -25,6 +26,7 @@ export default class Conversas extends Component {
messageText: "",
messages: [],
user: firebase.auth().currentUser.uid,
userData: null,
isValueNull: true,
destUser: navigation.getParam("item")
}
Expand All @@ -42,6 +44,22 @@ export default class Conversas extends Component {
.doc(destUser.key)
.collection("conversas")
.doc(user)

firebase
.firestore()
.collection("users")
.doc(user)
.get()
.then(us => {
const { phone, profile_img_url } = us.data()
this.setState({ userData: { phone, profile_img_url } })
})

TranslatorConfiguration.setConfig(
ProviderTypes.Google,
"AIzaSyC0j0BsAskqVIvaX2fcdvjsaw4fqGP5ut8",
"en"
)
}

componentDidMount() {
Expand Down Expand Up @@ -80,15 +98,19 @@ export default class Conversas extends Component {
}

sendMessage = () => {
const { destUser, user, messageText } = this.state
const { destUser, user, userData, messageText } = this.state

this.ref.set({
userKey: destUser.key
userKey: destUser.key,
contactName: destUser.contactName,
contactPhoto: destUser.contactPhoto
})
this.refDest.set({
userKey: user
userKey: user,
contactName: userData.phone,
contactPhoto: userData.profile_img_url
})

if (messageText === "") this.setState({ isValueNull: true })
const newMessage = {
content: messageText,
date: firebase.database().getServerTime(),
Expand Down Expand Up @@ -145,7 +167,7 @@ export default class Conversas extends Component {
<StatusBar backgroundColor="#fff" barStyle="dark-content" />
<ChatHeader
userName={destUser.contactName}
userPhoto={destUser.profile_img_url}
userPhoto={destUser.contactPhoto}
navigation={navigation}
/>
<View style={styles.chatContainer}>
Expand Down
6 changes: 3 additions & 3 deletions src/Screens/Contacts/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Contatos extends Component {
...contactFromPhone,
contactName,
key: doc.id,
profile_img_url
contactPhoto: profile_img_url
})
}
}
Expand Down Expand Up @@ -110,15 +110,15 @@ export default class Contatos extends Component {
: null
}
leftAvatar={
item.profile_img_url === "" ? (
item.contactPhoto === "" ? (
<Avatar
rounded
icon={{ name: "user", type: "font-awesome" }}
size="medium"
/>
) : (
{
source: { uri: item.profile_img_url },
source: { uri: item.contactPhoto },
size: "medium"
}
)
Expand Down
18 changes: 14 additions & 4 deletions src/Screens/Conversas/conversas.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,26 @@ export default class Conversas extends Component {
const contacts = JSON.parse(contactsResponse)
const conversas = []
querySnapshot.forEach(doc => {
let find = false
const { contactPhoto, contactName } = doc.data()
contacts.forEach(contact => {
if (contact.key === doc.id) {
conversas.push({
contact,
key: doc.id,
profileImage: contact.profile_img_url,
contactPhoto,
contactName: contact.contactName
})
find = true
}
})
if (find === false) {
conversas.push({
key: doc.id,
contactPhoto,
contactName
})
}
})
this.setState({ conversas })
})
Expand Down Expand Up @@ -148,10 +158,10 @@ export default class Conversas extends Component {
return (
<ListItem
onPress={() => {
this.goToChat(item.contact)
this.goToChat(item)
}}
onLongPress={() => {
this.confirmDelete(item.contact)
this.confirmDelete(item)
}}
style={styles.conversa}
subtitle={
Expand All @@ -170,7 +180,7 @@ export default class Conversas extends Component {
</View>
}
leftAvatar={{
source: { uri: item.profileImage },
source: { uri: item.contactPhoto },
size: "medium"
}}
/>
Expand Down