From 893ac49f01d074e12f6863e7263bcd13d6df2feb Mon Sep 17 00:00:00 2001 From: utopian-monkey Date: Tue, 4 Apr 2023 01:19:33 +0530 Subject: [PATCH] bfix: update firebase version from v8 to v9 --- .travis.yml | 2 +- .../org.eclipse.buildship.core.prefs | 4 +- app/screens/ChatListScreen/chatListScreen.js | 136 ++++---- .../forgotPasswordScreen.js | 14 +- app/screens/LoginScreen/loginScreen.js | 42 +-- app/screens/MessaginScreen/messaginScreen.js | 322 ++++++++---------- app/screens/NewPostScreen/NewPostScreen.js | 16 +- app/screens/ProfileScreen/profileScreen.js | 83 ++--- app/screens/SignupScreen/signupScreen.js | 30 +- config/config.example.js | 19 -- .../org.eclipse.buildship.core.prefs | 4 +- .../screens/ChatListScreen/chatListScreen.js | 131 ++++--- .../forgotPasswordScreen.js | 13 +- .../app/screens/LoginScreen/loginScreen.js | 32 +- .../screens/MessaginScreen/messaginScreen.js | 310 ++++++++--------- .../screens/NewPostScreen/NewPostScreen.js | 21 +- .../screens/ProfileScreen/profileScreen.js | 82 ++--- .../app/screens/SignupScreen/signupScreen.js | 30 +- package.json | 3 +- 19 files changed, 621 insertions(+), 673 deletions(-) delete mode 100644 config/config.example.js diff --git a/.travis.yml b/.travis.yml index 7fdeeaa..2486799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ cache: - node_modules before_install: -- mv config/config.example.js config/config.js +- mv config/config.js config/config.js install: - npm install diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index 3680d4b..34307ac 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments=--init-script C\:\\Users\\User\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\User\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\protobuf\\init.gradle +arguments=--init-script C\:\\Users\\naran\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\naran\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\protobuf\\init.gradle auto.sync=false build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home=C\:/Program Files/Java/jdk-17.0.5 +java.home=C\:/Program Files/Eclipse Adoptium/jdk-17.0.4.101-hotspot jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/app/screens/ChatListScreen/chatListScreen.js b/app/screens/ChatListScreen/chatListScreen.js index 842a1dd..73d109d 100644 --- a/app/screens/ChatListScreen/chatListScreen.js +++ b/app/screens/ChatListScreen/chatListScreen.js @@ -1,10 +1,15 @@ +// done + import React, { Component } from "react"; import { View, Text, Button, StatusBar, Image, ScrollView } from "react-native"; import styles from "./style"; import ConversationBanner from "../../components/ConversationBanner/conversationBanner"; import SuggestCardView from "../../components/SuggestionsCardView/suggestionsCardView"; import HeaderNavigationBar from "../../components/HeaderNavigationBar/HeaderNavigationBar"; -import { f, auth, storage, database } from "../../../config/config.js"; +import { auth, database } from "../../../config/config.js"; +import { ref, onValue, child } from "firebase/database"; +import { onAuthStateChanged } from "firebase/auth"; + export default class ChatListScreen extends Component { constructor(props) { super(props); @@ -19,33 +24,33 @@ export default class ChatListScreen extends Component { fetchUsers = () => { var that = this; var userId = auth.currentUser.uid; - database.ref("users").once( - "value", + var userRef = ref(database,"users"); + onValue( + userRef, function (snapshot) { - const exsist = snapshot.val() != null; - if (exsist) { - let data = snapshot.val(); - var userList = that.state.userList; - for (var user in data) { - let userObj = data[user]; - let uId = user; - if (uId != userId) { - userList.push({ - id: uId, - name: userObj.firstName, - avatar: userObj.avatar, - }); - } + const exsist = snapshot.val() != null; + if (exsist) { + let data = snapshot.val(); + var userList = that.state.userList; + for (var user in data) { + let userObj = data[user]; + let uId = user; + if (uId != userId) { + userList.push({ + id: uId, + name: userObj.firstName, + avatar: userObj.avatar, + }); } - that.setState({ - userList: userList, - }); } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); + that.setState({ + userList: userList, + }); } - ); + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + }) }; renderUserList = () => { if (this.state.loggedin == true) { @@ -66,51 +71,50 @@ export default class ChatListScreen extends Component { if (this.state.loggedin == true) { var that = this; var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .on( - "value", - function (snapshot) { - const exist = snapshot.exists(); - that.setState({ - chatList: [], - }); - if (exist) { - var data = snapshot.val(); - const exsist = snapshot.exists(); - if (exsist) { - data = snapshot.val(); - var chatList = that.state.chatList; - Object.keys(data).forEach(key => { - var tempdata = data[key]; - Object.keys(tempdata).forEach(key => { - chatList.push({ - posted: tempdata[key].posted, - lastMessage: tempdata[key].lastMessage, - name: tempdata[key].name, - avatar: tempdata[key].avatar, - id: tempdata[key].friend, - }); + var userRef = ref(database, "users"); + var chatRef = child(child(userRef, userId),"userChats"); + + onValue( + chatRef, + function (snapshot) { + const exist = snapshot.exists(); + that.setState({ + chatList: [], + }); + if (exist) { + var data = snapshot.val(); + const exsist = snapshot.exists(); + if (exsist) { + data = snapshot.val(); + var chatList = that.state.chatList; + Object.keys(data).forEach(key => { + var tempdata = data[key]; + Object.keys(tempdata).forEach(key => { + chatList.push({ + posted: tempdata[key].posted, + lastMessage: tempdata[key].lastMessage, + name: tempdata[key].name, + avatar: tempdata[key].avatar, + id: tempdata[key].friend, }); }); - console.log(chatList); - that.setState({ - loaded: true, - }); - } else { - that.setState({ - chatList: [], - loaded: true, - }); - } + }); + console.log(chatList); + that.setState({ + loaded: true, + }); + } else { + that.setState({ + chatList: [], + loaded: true, + }); } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); } - ); + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + } + ) } }; timePlural = s => { @@ -175,7 +179,7 @@ export default class ChatListScreen extends Component { }; componentDidMount = () => { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth, function (user) { if (user) { that.setState({ loggedin: true, diff --git a/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js b/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js index e3d848e..7e840bd 100644 --- a/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js +++ b/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js @@ -1,4 +1,5 @@ /* eslint-disable prettier/prettier */ +// done import React, { Component } from "react"; import { Platform, @@ -17,8 +18,9 @@ import { // import Btn from 'react-native-micro-animated-button'; import * as EmailValidator from "email-validator"; import styles from "./style"; -import { f, auth } from "../../../config/config.js"; +import { auth } from "../../../config/config.js"; import AsyncStorage from "@react-native-async-storage/async-storage"; +import { sendPasswordResetEmail } from "firebase/auth"; export default class ForgotPasswordScreen extends Component { constructor(props) { super(props); @@ -61,18 +63,18 @@ export default class ForgotPasswordScreen extends Component { resetPassword = () => { if (EmailValidator.validate(this.state.email) === true) { var that = this; - auth - .sendPasswordResetEmail(this.state.email) + + sendPasswordResetEmail(auth, this.state.email) .then(function () { - alert("Please Check Your Email To Reset Your Password"); + Alert("Please Check Your Email To Reset Your Password"); let { navigate } = that.props.navigation; navigate("Login"); }) .catch(function (error) { - alert(error); + Alert(error); }); } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; } diff --git a/app/screens/LoginScreen/loginScreen.js b/app/screens/LoginScreen/loginScreen.js index 319f953..0acd74d 100644 --- a/app/screens/LoginScreen/loginScreen.js +++ b/app/screens/LoginScreen/loginScreen.js @@ -1,3 +1,4 @@ +// done import React, { Component } from "react"; import { View, @@ -8,12 +9,16 @@ import { TouchableOpacity, KeyboardAvoidingView, ScrollView, + Alert, } from "react-native"; import { AccessToken, LoginManager } from "react-native-fbsdk"; -import { f, auth } from "../../../config/config.js"; +import { auth, database } from "../../../config/config.js"; +import { signInWithEmailAndPassword, FacebookAuthProvider, signInWithCredential } from "firebase/auth"; import * as EmailValidator from "email-validator"; import styles from "./style"; import { SocialIcon } from "react-native-elements"; +import { ref, child, update } from "firebase/database"; +import { onAuthStateChanged } from "firebase/auth"; export default class LoginScreen extends Component { constructor(props) { super(props); @@ -26,7 +31,8 @@ export default class LoginScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + + onAuthStateChanged(auth, function (user) { if (user) { that.redirectUser(); } @@ -39,14 +45,13 @@ export default class LoginScreen extends Component { let { navigate } = this.props.navigation; - auth - .signInWithEmailAndPassword(email, password) + signInWithEmailAndPassword(auth, email, password) .then(function (data) { navigate("App"); }) .catch(function (error) { var errorMessage = error.message; - alert(errorMessage.toString()); + Alert(errorMessage.toString()); }); } @@ -57,13 +62,13 @@ export default class LoginScreen extends Component { _signInAsync = async () => { if (EmailValidator.validate(this.state.email) === true) { - if (this.state.Pasword != "") { + if (this.state.Password != "") { this.login(); } else { - alert("Enter the password"); + Alert("Enter the password"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; @@ -71,7 +76,7 @@ export default class LoginScreen extends Component { LoginManager.logInWithReadPermissions(["public_profile", "email"]).then( result => this._handleCallBack(result), function (error) { - alert("Login fail with error: " + error); + Alert("Login fail with error: " + error); } ); } @@ -79,7 +84,7 @@ export default class LoginScreen extends Component { _handleCallBack(result) { let _this = this; if (result.isCancelled) { - alert("Login cancelled"); + Alert("Login cancelled"); } else { AccessToken.getCurrentAccessToken().then(data => { const token = data.accessToken; @@ -105,9 +110,8 @@ export default class LoginScreen extends Component { } authenticate = token => { - const provider = auth.FacebookAuthProvider; - const credential = provider.credential(token); - let ret = auth.signInWithCredential(credential); + const credential = FacebookAuthProvider.credential(token); + let ret = signInWithCredential(auth, credential); return ret; }; @@ -118,21 +122,19 @@ export default class LoginScreen extends Component { dp, ageRange: [20, 30], }; - f.database() - .ref("users") - .child(uid) - .update({ ...userData, ...defaults }); + var updates = { ...userData, ...defaults } + update(child(ref(database, "users"), uid), updates) }; _signInAsync = async () => { if (EmailValidator.validate(this.state.email) === true) { - if (this.state.Pasword != "") { + if (this.state.Password != "") { this.login(); } else { - alert("Enter the password"); + Alert("Enter the password"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; diff --git a/app/screens/MessaginScreen/messaginScreen.js b/app/screens/MessaginScreen/messaginScreen.js index a1d20c1..82ce3a8 100644 --- a/app/screens/MessaginScreen/messaginScreen.js +++ b/app/screens/MessaginScreen/messaginScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import FriendMessage from "../../components/MessageComponents/friendMessage"; import MyMessage from "../../components/MessageComponents/myMessage"; @@ -12,7 +13,10 @@ import { } from "react-native"; import styles from "./style"; import Ionicons from "react-native-vector-icons/FontAwesome"; -import { f, auth, storage, database } from "../../../config/config.js"; +import { auth, database } from "../../../config/config.js"; +import { onAuthStateChanged } from "firebase/auth"; +import { child, onValue, ref, set, update } from "firebase/database"; + export default class MessageScreen extends Component { constructor(props) { super(props); @@ -61,32 +65,29 @@ export default class MessageScreen extends Component { friendId: params.userId, }); var that = this; - database - .ref("users") - .child(params.userId) - .child("firstName") - .once("value") - .then(function (snapshot) { + var userCollectonRef = ref(database, "users"); + let userRef = child(userCollectonRef, params.userId) + let firstNameRef = child(userRef , "firstName") + onValue(firstNameRef, + function (snapshot) { const exist = snapshot.val() != null; if (exist) data = snapshot.val(); console.log(data); that.setState({ friendName: data, }); + }) + + let avatarRef = child(userRef,"avatar" ) + onValue(avatarRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + friendAvatar: data, }); - database - .ref("users") - .child(params.userId) - .child("avatar") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - friendAvatar: data, - }); - }); + }) + this.fetchMessages(params.userId); } @@ -136,60 +137,54 @@ export default class MessageScreen extends Component { fetchMessages = () => { var that = this; var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .child(this.state.friendId) - .on( - "value", - function (snapshot) { - const exist = snapshot.exists(); - if (exist) { + + var userCollectonRef = ref(database, "users"); + let userChatRef = child(child(child(userCollectonRef,userId),"userChats"),this.state.friendId); + onValue(userChatRef,function (snapshot) { + const exist = snapshot.exists(); + if (exist) { + var data = snapshot.val(); + var chatMessageRef= child(ref(database,"chatMessages"),Object.keys(data)[0]); + onValue(chatMessageRef,function (snapshot) { + const exsist = snapshot.exists(); + if (exsist) { + that.setState({ + messageList: [], + }); var data = snapshot.val(); - database - .ref("chatMessages") - .child(Object.keys(data)[0]) - .on( - "value", - function (snapshot) { - const exsist = snapshot.exists(); - if (exsist) { - that.setState({ - messageList: [], - }); - var data = snapshot.val(); - console.log(Object.keys(data)[0].message); - var messageList = that.state.messageList; - Object.keys(data).forEach(key => { - messageList.push({ - message: data[key].message, - posted: data[key].posted, - sendby: data[key].sendby, - }); - }); + console.log(Object.keys(data)[0].message); + var messageList = that.state.messageList; + Object.keys(data).forEach(key => { + messageList.push({ + message: data[key].message, + posted: data[key].posted, + sendby: data[key].sendby, + }); + }); - console.log(messageList); - that.setState({ - loaded: true, - }); - } else { - that.setState({ - messageList: [], - loaded: true, - }); - } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); - } - ); + console.log(messageList); + that.setState({ + loaded: true, + }); + } else { + that.setState({ + messageList: [], + loaded: true, + }); } }, function (errorObject) { console.log("The read failed: " + errorObject.code); - } - ); + }) + + + } + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + }) + + }; sendMessage = () => { @@ -202,122 +197,107 @@ export default class MessageScreen extends Component { var date = Date.now(); var posted = Math.floor(date / 1000); var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .child(this.state.friendId) - .once("value") - .then(function (snapshot) { - const exist = snapshot.exists(); - if (exist) { - data = snapshot.val(); - let cId = Object.keys(data)[0]; - var newMessage = { - sendby: userId, - message: that.state.newMessage, - status: 0, - posted: posted, - }; - that.setState({ - newMessageId: that.uniqueId(), - }); - database.ref("/chatMessages/" + cId + "/" + that.state.newMessageId).set(newMessage); - database - .ref("/users/" + userId + "/userChats/" + that.state.friendId + "/" + cId) - .update({ posted: posted, lastMessage: that.state.newMessage }); - database - .ref("/users/" + that.state.friendId + "/userChats/" + userId + "/" + cId) - .update({ posted: posted, lastMessage: that.state.newMessage }); - that.setState({ - newMessage: "", - }); - } else { - var chatUserf = { - lastMessage: that.state.newMessage, - posted: posted, - friend: that.state.friendId, - name: that.state.friendName, - avatar: that.state.friendAvatar, - }; - var chatUser = { - lastMessage: that.state.newMessage, - posted: posted, - friend: userId, - name: auth.currentUser.displayName, - avatar: that.state.avatar, - }; - var newMessage = { - sendby: userId, - message: that.state.newMessage, - status: 0, - posted: posted, - }; - database - .ref( - "/users/" + - userId + - "/userChats/" + - that.state.friendId + - "/" + - that.state.newChatId - ) - .set(chatUserf); - database - .ref( - "/users/" + - that.state.friendId + - "/userChats/" + - userId + - "/" + - that.state.newChatId - ) - .set(chatUser); - database - .ref("/chatMessages/" + that.state.newChatId + "/" + that.state.newMessageId) - .set(newMessage); - } - }) - .catch(); - that.textInput.clear(); + + onValue(child(child(child(ref(database,"users"),userId),"userChats"),this.state.friendId), + function (snapshot) { + const exist = snapshot.exists(); + if (exist) { + data = snapshot.val(); + let cId = Object.keys(data)[0]; + var newMessage = { + sendby: userId, + message: that.state.newMessage, + status: 0, + posted: posted, + }; + that.setState({ + newMessageId: that.uniqueId(), + }); + set(ref(database,"/chatMessages/" + cId + "/" + that.state.newMessageId),newMessage); + update(ref(database,"/users/" + userId + "/userChats/" + that.state.friendId + "/" + cId),{ posted: posted, lastMessage: that.state.newMessage }); + update(ref(database,"/users/" + that.state.friendId + "/userChats/" + userId + "/" + cId),{ posted: posted, lastMessage: that.state.newMessage }); + + that.setState({ + newMessage: "", + }); + } else { + var chatUserf = { + lastMessage: that.state.newMessage, + posted: posted, + friend: that.state.friendId, + name: that.state.friendName, + avatar: that.state.friendAvatar, + }; + var chatUser = { + lastMessage: that.state.newMessage, + posted: posted, + friend: userId, + name: auth.currentUser.displayName, + avatar: that.state.avatar, + }; + var newMessage = { + sendby: userId, + message: that.state.newMessage, + status: 0, + posted: posted, + }; + set(ref(database,"/users/" + + userId + + "/userChats/" + + that.state.friendId + + "/" + + that.state.newChatId),chatUserf); + set(ref(database,"/users/" + + that.state.friendId + + "/userChats/" + + userId + + "/" + + that.state.newChatId),chatUser); + set(ref(database,"/users/" + + userId + + "/userChats/" + + that.state.friendId + + "/" + + that.state.newChatId),chatUserf); + set(ref(database,"/chatMessages/" + that.state.newChatId + "/" + that.state.newMessageId),newMessage); + + } + }) + + // .catch(); + // that.textInput.clear(); } }; componentDidMount = () => { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.setState({ loggedin: true, }); that.check(); var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("name") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - name: data, - }); + var userNameRef = child(child(ref(database,"users"),userId),"name"); + onValue(userNameRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + name: data, }); - database - .ref("users") - .child(userId) - .child("avatar") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - avatar: data, - }); + }) + + var userIdRef= child(child(ref(database,"users"),userId),"avatar"); + onValue(userIdRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + avatar: data, }); + }) + } else { that.setState({ loggedin: false, diff --git a/app/screens/NewPostScreen/NewPostScreen.js b/app/screens/NewPostScreen/NewPostScreen.js index 631a67e..5c90b0c 100644 --- a/app/screens/NewPostScreen/NewPostScreen.js +++ b/app/screens/NewPostScreen/NewPostScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { ScrollView, @@ -16,8 +17,10 @@ import { Card, ListItem, Button } from "react-native-elements"; import { TextInput } from "react-native-gesture-handler"; import { launchImageLibrary } from "react-native-image-picker"; import Icon from "react-native-vector-icons/FontAwesome"; -import { f, auth, storage, database } from "../../../config/config.js"; +import { firebaseApp, auth, storage, database } from "../../../config/config.js"; import EvilIcons from "react-native-vector-icons/EvilIcons"; +import { getStorage } from "firebase/storage"; +import{ref,set,onValue,child} from "firebase/database" export default class NewPostScreen extends Component { constructor() { super(); @@ -122,10 +125,11 @@ export default class NewPostScreen extends Component { xhr.send(null); }); var filePath = postId + "." + ext; - var uploadTask = storage.ref("post/img").child(filePath).put(blob); + const storage = getStorage(); + var uploadTask = child(ref(storage,"post/img"),filePath).put(blob); - uploadTask.on( - "state_changed", + onValue( + uploadTask, function (snapshot) { let progress = ((snapshot.bytesTransferred / snapshot.totalBytes) * 100).toFixed(0); that.setState({ @@ -157,8 +161,8 @@ export default class NewPostScreen extends Component { image: imageURL, posted: posted, }; - database.ref("/post/" + postId).set(postObj); - alert("SuccessFully Published!!"); + set(ref(database,"/post/" + postId),postObj); + Alert("SuccessFully Published!!"); this.setState({ imageSelected: false, uploading: false, diff --git a/app/screens/ProfileScreen/profileScreen.js b/app/screens/ProfileScreen/profileScreen.js index a473a18..443b4c1 100644 --- a/app/screens/ProfileScreen/profileScreen.js +++ b/app/screens/ProfileScreen/profileScreen.js @@ -1,3 +1,4 @@ +//done /* eslint-disable prettier/prettier */ import React, { Component } from "react"; import { @@ -14,10 +15,12 @@ import { import { Info, DeatilView } from ".."; import HeaderNavigationBar from "../../components/HeaderNavigationBar/HeaderNavigationBar"; import styles from "./style"; -import { f, auth, storage, database } from "../../../config/config.js"; +import { firebaseApp, auth, storage, database } from "../../../config/config.js"; import { Avatar } from "react-native-elements"; import ImagePicker from "react-native-image-picker"; import AsyncStorage from "@react-native-async-storage/async-storage"; +import { set,ref,child,onValue, update } from "firebase/database"; +import { getStorage } from "firebase/storage"; // import { TouchableOpacity } from "react-native-gesture-handler"; export default class ProfileScreen extends Component { @@ -36,42 +39,42 @@ export default class ProfileScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.state.email = auth.currentUser.email; - database - .ref("users") - .child(auth.currentUser.uid) - .once("value", function (snapshot) { - if (snapshot.child("firstName").val() != null) { - that.setState({ - firstName: snapshot.child("firstName").val(), - }); - } - if (snapshot.child("lastName").val() != null) { - that.setState({ - lastName: snapshot.child("lastName").val(), - }); - } - if (snapshot.child("contact").val() != null) { - that.setState({ - contact: snapshot.child("contact").val(), - }); - } - if (snapshot.child("address").val() != null) { - that.setState({ - address: snapshot.child("address").val(), - }); - } - if (snapshot.child("avatar").val != null) { - that.setState({ - avatar: snapshot.child("avatar").val(), - }); - } + var userRef=child(ref(database,"users"),auth.currentUser.uid); + + onValue(userRef,function (snapshot) { + if (snapshot.child("firstName").val() != null) { that.setState({ - isLoading: false, + firstName: snapshot.child("firstName").val(), }); + } + if (snapshot.child("lastName").val() != null) { + that.setState({ + lastName: snapshot.child("lastName").val(), + }); + } + if (snapshot.child("contact").val() != null) { + that.setState({ + contact: snapshot.child("contact").val(), + }); + } + if (snapshot.child("address").val() != null) { + that.setState({ + address: snapshot.child("address").val(), + }); + } + if (snapshot.child("avatar").val != null) { + that.setState({ + avatar: snapshot.child("avatar").val(), + }); + } + that.setState({ + isLoading: false, }); + }) + } else { that.setState({ firstName: "John", @@ -147,11 +150,11 @@ export default class ProfileScreen extends Component { xhr.send(null); }); var filePath = userId + "." + that.state.currentFileType; + const storage = getStorage(); - var uploadTask = storage.ref("user/img").child(filePath).put(blob); + var uploadTask = child(ref(storage,"user/img"),filePath); - uploadTask.on( - "state_changed", + onValue(uploadTask, function (snapshot) { let progress = ((snapshot.bytesTransferred / snapshot.totalBytes) * 100).toFixed(0); that.setState({ @@ -166,21 +169,21 @@ export default class ProfileScreen extends Component { progress: 100, }); uploadTask.snapshot.ref.getDownloadURL().then(function (downloadURL) { - that.setDatabse(downloadURL); + that.setDatabase(downloadURL); }); } ); }; - setDatabse = imageURL => { + setDatabase = imageURL => { var user = auth.currentUser; var userID = auth.currentUser.uid; - database.ref("/users/" + userID).update({ avatar: imageURL }); + update(ref(database,"/users/"+ userID),{avatar:imageURL}); console.log("User: " + user); user.updateProfile({ photoURL: imageURL, }); - alert("SuccessFully Published!!"); + Alert("SuccessFully Published!!"); this.setState({ imageSelected: false, uploading: false, @@ -312,6 +315,6 @@ export default class ProfileScreen extends Component { }; console.log(user); - f.database().ref("users/").child(auth.currentUser.uid).set(user); + set(child(ref(database,"users/"),auth.currentUser.uid),user); }; } diff --git a/app/screens/SignupScreen/signupScreen.js b/app/screens/SignupScreen/signupScreen.js index e66cfee..30ea36c 100644 --- a/app/screens/SignupScreen/signupScreen.js +++ b/app/screens/SignupScreen/signupScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { View, @@ -12,8 +13,10 @@ import { import styles from "./style"; import * as EmailValidator from "email-validator"; import { AccessToken, LoginManager } from "react-native-fbsdk"; -import { f, auth } from "../../../config/config.js"; +import { firebaseApp, auth,database } from "../../../config/config.js"; +import{ ref,child,update,onValue, set} from "firebase/database"; import { SocialIcon } from "react-native-elements"; +import {onAuthStateChanged,signInWithCredential,createUserWithEmailAndPassword} from "firebase/auth"; export default class SignUpScreen extends Component { constructor(props) { @@ -28,7 +31,7 @@ export default class SignUpScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.redirectUser(); } @@ -44,7 +47,7 @@ export default class SignUpScreen extends Component { LoginManager.logInWithReadPermissions(["public_profile", "email"]).then( result => this._handleCallBack(result), function (error) { - alert("Login fail with error: " + error); + Alert("Login fail with error: " + error); } ); } @@ -52,7 +55,7 @@ export default class SignUpScreen extends Component { _handleCallBack(result) { let _this = this; if (result.isCancelled) { - alert("Login cancelled"); + Alert("Login cancelled"); } else { AccessToken.getCurrentAccessToken().then(data => { const token = data.accessToken; @@ -80,7 +83,7 @@ export default class SignUpScreen extends Component { authenticate = token => { const provider = auth.FacebookAuthProvider; const credential = provider.credential(token); - let ret = auth.signInWithCredential(credential); + let ret = signInWithCredential(auth,credential); return ret; }; @@ -91,10 +94,8 @@ export default class SignUpScreen extends Component { dp, ageRange: [20, 30], }; - f.database() - .ref("users") - .child(uid) - .update({ ...userData, ...defaults }); + update(child(ref(database,"users"),uid),{ ...userData, ...defaults }); + }; render() { @@ -173,8 +174,7 @@ export default class SignUpScreen extends Component { const { navigate } = this.props.navigation; - auth - .createUserWithEmailAndPassword(email, password) + createUserWithEmailAndPassword(auth,email, password) .then(function (data) { data.user .updateProfile({ @@ -188,13 +188,13 @@ export default class SignUpScreen extends Component { console.log("Error Updating User Data.." + error); } ); - alert("Welcome to Go Social!"); + Alert("Welcome to Go Social!"); navigate("App"); }) .catch(function (error) { var errorMessage = error.message; console.log("Error = " + errorMessage); - alert(errorMessage); + Alert(errorMessage); }); } @@ -203,10 +203,10 @@ export default class SignUpScreen extends Component { if (this.state.Password === this.state.ConfirmPassword) { this.register(); } else { - alert("password Missmatch"); + Alert("password Mismatch"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; } diff --git a/config/config.example.js b/config/config.example.js deleted file mode 100644 index b5b9722..0000000 --- a/config/config.example.js +++ /dev/null @@ -1,19 +0,0 @@ -import firebase from "firebase"; - -var config = { - apiKey: "", - authDomain: "", - databaseURL: "", - projectId: "", - storageBucket: "", - messagingSenderId: "", -}; -firebase.initializeApp(config); - -var MAP_API_KEY = ""; - -export const f = firebase; -export const database = firebase.database(); -export const auth = firebase.auth(); -export const storage = firebase.storage(); -export const MAP_API = MAP_API_KEY; diff --git a/docs/react-native/android/.settings/org.eclipse.buildship.core.prefs b/docs/react-native/android/.settings/org.eclipse.buildship.core.prefs index 3680d4b..34307ac 100644 --- a/docs/react-native/android/.settings/org.eclipse.buildship.core.prefs +++ b/docs/react-native/android/.settings/org.eclipse.buildship.core.prefs @@ -1,11 +1,11 @@ -arguments=--init-script C\:\\Users\\User\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\User\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\protobuf\\init.gradle +arguments=--init-script C\:\\Users\\naran\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\naran\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.15.0\\config_win\\org.eclipse.osgi\\54\\0\\.cp\\gradle\\protobuf\\init.gradle auto.sync=false build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home=C\:/Program Files/Java/jdk-17.0.5 +java.home=C\:/Program Files/Eclipse Adoptium/jdk-17.0.4.101-hotspot jvm.arguments= offline.mode=false override.workspace.settings=true diff --git a/docs/react-native/app/screens/ChatListScreen/chatListScreen.js b/docs/react-native/app/screens/ChatListScreen/chatListScreen.js index 0cbfbb9..dee6ad1 100644 --- a/docs/react-native/app/screens/ChatListScreen/chatListScreen.js +++ b/docs/react-native/app/screens/ChatListScreen/chatListScreen.js @@ -1,11 +1,15 @@ +//done import React, { Component } from "react"; import { View, Text, Button, StatusBar, Image, ScrollView } from "react-native"; import styles from "./style"; import ConversationBanner from "../../components/ConversationBanner/conversationBanner"; import SuggestCardView from "../../components/SuggestionsCardView/suggestionsCardView"; import HeaderNavigationBar from "../../components/HeaderNavigationBar/HeaderNavigationBar"; -import { fauthstorage, database } from "../../../config/config.js"; +import { fauthstorage,auth, database } from "../../../config/config.js"; +import {onAuthStateChanged} from "firebase/auth" +import {ref, onValue, set, child, update} from "firebase/database" import AsyncStorage from "@react-native-async-storage/async-storage"; + export default class ChatListScreen extends Component { constructor(props) { super(props); @@ -20,33 +24,31 @@ export default class ChatListScreen extends Component { fetchUsers = () => { var that = this; var userId = auth.currentUser.uid; - database.ref("users").once( - "value", - function (snapshot) { - const exsist = snapshot.val() != null; - if (exsist) { - data = snapshot.val(); - var userList = that.state.userList; - for (var user in data) { - let userObj = data[user]; - let uId = user; - if (uId != userId) { - userList.push({ - id: uId, - name: userObj.firstName, - avatar: userObj.avatar, - }); - } + onValue(ref(database,"users"), function (snapshot) { + const exsist = snapshot.val() != null; + if (exsist) { + data = snapshot.val(); + var userList = that.state.userList; + for (var user in data) { + let userObj = data[user]; + let uId = user; + if (uId != userId) { + userList.push({ + id: uId, + name: userObj.firstName, + avatar: userObj.avatar, + }); } - that.setState({ - userList: userList, - }); } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); + that.setState({ + userList: userList, + }); } - ); + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + }) + }; renderUserList = () => { if (this.state.loggedin) { @@ -67,51 +69,46 @@ export default class ChatListScreen extends Component { if (this.state.loggedin) { var that = this; var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .on( - "value", - function (snapshot) { - const exist = snapshot.exists(); + var userChatRef = child(child(ref(database,"users"),userId),"userChats"); + onValue(userChatRef,function (snapshot) { + const exist = snapshot.exists(); + that.setState({ + chatList: [], + }); + if (exist) { + var data = snapshot.val(); + const exsist = snapshot.exists(); + if (exsist) { + var data = snapshot.val(); + var chatList = that.state.chatList; + Object.keys(data).forEach(key => { + var tempdata = data[key]; + Object.keys(tempdata).forEach(key => { + chatList.push({ + posted: tempdata[key].posted, + lastMessage: tempdata[key].lastMessage, + name: tempdata[key].name, + avatar: tempdata[key].avatar, + id: tempdata[key].friend, + }); + }); + }); + console.log(chatList); + that.setState({ + loaded: true, + }); + } else { that.setState({ chatList: [], + loaded: true, }); - if (exist) { - var data = snapshot.val(); - const exsist = snapshot.exists(); - if (exsist) { - var data = snapshot.val(); - var chatList = that.state.chatList; - Object.keys(data).forEach(key => { - var tempdata = data[key]; - Object.keys(tempdata).forEach(key => { - chatList.push({ - posted: tempdata[key].posted, - lastMessage: tempdata[key].lastMessage, - name: tempdata[key].name, - avatar: tempdata[key].avatar, - id: tempdata[key].friend, - }); - }); - }); - console.log(chatList); - that.setState({ - loaded: true, - }); - } else { - that.setState({ - chatList: [], - loaded: true, - }); - } - } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); } - ); + } + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + }) + } }; timePlural = s => { @@ -176,7 +173,7 @@ export default class ChatListScreen extends Component { }; componentDidMount = () => { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.setState({ loggedin: true, diff --git a/docs/react-native/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js b/docs/react-native/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js index ee46bd7..8ac69e0 100644 --- a/docs/react-native/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js +++ b/docs/react-native/app/screens/ForgotPasswordScreen/forgotPasswordScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { Platform, @@ -16,7 +17,8 @@ import { // import Btn from 'react-native-micro-animated-button'; import * as EmailValidator from "email-validator"; import styles from "./style"; -import { f, auth } from "../../../config/config.js"; +import { firebaseApp, auth } from "../../../config/config.js"; +import {sendPasswordResetEmail} from "firebase/auth" import AsyncStorage from "@react-native-async-storage/async-storage"; export default class ForgotPasswordScreen extends Component { constructor(props) { @@ -60,18 +62,17 @@ export default class ForgotPasswordScreen extends Component { resetPassword = () => { if (EmailValidator.validate(this.state.email) === true) { var that = this; - auth - .sendPasswordResetEmail(this.state.email) + sendPasswordResetEmail(auth,this.state.email) .then(function () { - alert("Please Check Your Email To Reset Your Password"); + Alert("Please Check Your Email To Reset Your Password"); let { navigate } = that.props.navigation; navigate("Login"); }) .catch(function (error) { - alert(error); + Alert(error); }); } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; } diff --git a/docs/react-native/app/screens/LoginScreen/loginScreen.js b/docs/react-native/app/screens/LoginScreen/loginScreen.js index ba5ed5e..06c93a2 100644 --- a/docs/react-native/app/screens/LoginScreen/loginScreen.js +++ b/docs/react-native/app/screens/LoginScreen/loginScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { View, @@ -10,10 +11,12 @@ import { ScrollView, } from "react-native"; import { AccessToken, LoginManager } from "react-native-fbsdk"; -import { f, auth, database } from "../../../config/config.js"; +import { firebaseApp, auth, database } from "../../../config/config.js"; +import {onAuthStateChanged,signInWithEmailAndPassword,signInWithCredential} from "firebase/auth"; import * as EmailValidator from "email-validator"; import styles from "./style"; import { SocialIcon } from "react-native-elements"; +import { update, ref, child, onValue, set} from "firebase/database"; export default class LoginScreen extends Component { constructor(props) { super(props); @@ -25,7 +28,7 @@ export default class LoginScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.redirectUser(); } @@ -38,14 +41,13 @@ export default class LoginScreen extends Component { let { navigate } = this.props.navigation; - auth - .signInWithEmailAndPassword(email, password) + signInWithEmailAndPassword(auth,email, password) .then(function (data) { navigate("App"); }) .catch(function (error) { var errorMessage = error.message; - alert(errorMessage.toString()); + Alert(errorMessage.toString()); }); } @@ -59,10 +61,10 @@ export default class LoginScreen extends Component { if (this.state.Pasword != "") { this.login(); } else { - alert("Enter the password"); + Alert("Enter the password"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; @@ -70,7 +72,7 @@ export default class LoginScreen extends Component { LoginManager.logInWithReadPermissions(["public_profile", "email"]).then( result => this._handleCallBack(result), function (error) { - alert("Login fail with error: " + error); + Alert("Login fail with error: " + error); } ); } @@ -78,7 +80,7 @@ export default class LoginScreen extends Component { _handleCallBack(result) { let _this = this; if (result.isCancelled) { - alert("Login cancelled"); + Alert("Login cancelled"); } else { AccessToken.getCurrentAccessToken().then(data => { const token = data.accessToken; @@ -106,7 +108,7 @@ export default class LoginScreen extends Component { authenticate = token => { const provider = auth.FacebookAuthProvider; const credential = provider.credential(token); - let ret = auth.signInWithCredential(credential); + let ret = signInWithCredential(auth,credential); return ret; }; @@ -117,10 +119,8 @@ export default class LoginScreen extends Component { dp, ageRange: [20, 30], }; - database - .ref("users") - .child(uid) - .update({ ...userData, ...defaults }); + update(child(ref(database,"users"),uid),{ ...userData, ...defaults }); + }; _signInAsync = async () => { @@ -128,10 +128,10 @@ export default class LoginScreen extends Component { if (this.state.Pasword != "") { this.login(); } else { - alert("Enter the password"); + Alert("Enter the password"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; diff --git a/docs/react-native/app/screens/MessaginScreen/messaginScreen.js b/docs/react-native/app/screens/MessaginScreen/messaginScreen.js index aadeb53..5fb8d82 100644 --- a/docs/react-native/app/screens/MessaginScreen/messaginScreen.js +++ b/docs/react-native/app/screens/MessaginScreen/messaginScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import FriendMessage from "../../components/MessageComponents/friendMessage"; import MyMessage from "../../components/MessageComponents/myMessage"; @@ -12,7 +13,9 @@ import { } from "react-native"; import styles from "./style"; import Ionicons from "react-native-vector-icons/FontAwesome"; -import { fauthstorage, database } from "../../../config/config.js"; +import { fauthstorage, database,auth } from "../../../config/config.js"; +import{ onAuthStateChanged} from "firebase/auth" +import { onValue, set, update } from "firebase/database"; export default class messaginScreen extends Component { constructor(props) { super(props); @@ -61,32 +64,26 @@ export default class messaginScreen extends Component { friendId: params.userId, }); var that = this; - database - .ref("users") - .child(params.userId) - .child("firstName") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - friendName: data, - }); + var UserIdRef= child(ref(database,"users"),params.userId); + var firstNameRef= child(UserIdRef,"firstname"); + onValue(firstNameRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + friendName: data, }); - database - .ref("users") - .child(params.userId) - .child("avatar") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - friendAvatar: data, - }); + }); + var avatarRef = child( UserIdRef , "avatar" ); + onValue(avatarRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + friendAvatar: data, }); + }) + this.fetchMessages(params.userId); } @@ -136,60 +133,50 @@ export default class messaginScreen extends Component { fetchMessages = () => { var that = this; var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .child(this.state.friendId) - .on( - "value", + var userChatRef= child(child(child(ref(database, "users"),userId),"userChats"),this.state.friendId); + onValue(userChatRef,function (snapshot) { + const exist = snapshot.exists(); + if (exist) { + var data = snapshot.val(); + onValue(child(ref(database,"chatMessages"),Object.keys(data)[0]), function (snapshot) { - const exist = snapshot.exists(); - if (exist) { + const exsist = snapshot.exists(); + if (exsist) { + that.setState({ + messageList: [], + }); var data = snapshot.val(); - database - .ref("chatMessages") - .child(Object.keys(data)[0]) - .on( - "value", - function (snapshot) { - const exsist = snapshot.exists(); - if (exsist) { - that.setState({ - messageList: [], - }); - var data = snapshot.val(); - console.log(Object.keys(data)[0].message); - var messageList = that.state.messageList; - Object.keys(data).forEach(key => { - messageList.push({ - message: data[key].message, - posted: data[key].posted, - sendby: data[key].sendby, - }); - }); + console.log(Object.keys(data)[0].message); + var messageList = that.state.messageList; + Object.keys(data).forEach(key => { + messageList.push({ + message: data[key].message, + posted: data[key].posted, + sendby: data[key].sendby, + }); + }); - console.log(messageList); - that.setState({ - loaded: true, - }); - } else { - that.setState({ - messageList: [], - loaded: true, - }); - } - }, - function (errorObject) { - console.log("The read failed: " + errorObject.code); - } - ); + console.log(messageList); + that.setState({ + loaded: true, + }); + } else { + that.setState({ + messageList: [], + loaded: true, + }); } }, function (errorObject) { console.log("The read failed: " + errorObject.code); } - ); + ); + } + }, + function (errorObject) { + console.log("The read failed: " + errorObject.code); + }) + }; sendMessage = () => { @@ -202,122 +189,99 @@ export default class messaginScreen extends Component { var date = Date.now(); var posted = Math.floor(date / 1000); var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("userChats") - .child(this.state.friendId) - .once("value") - .then(function (snapshot) { - const exist = snapshot.exists(); - if (exist) { - data = snapshot.val(); - let cId = Object.keys(data)[0]; - var newMessage = { - sendby: userId, - message: that.state.newMessage, - status: 0, - posted: posted, - }; - that.setState({ - newMessageId: that.uniqueId(), - }); - database.ref("/chatMessages/" + cId + "/" + that.state.newMessageId).set(newMessage); - database - .ref("/users/" + userId + "/userChats/" + that.state.friendId + "/" + cId) - .update({ posted: posted, lastMessage: that.state.newMessage }); - database - .ref("/users/" + that.state.friendId + "/userChats/" + userId + "/" + cId) - .update({ posted: posted, lastMessage: that.state.newMessage }); - that.setState({ - newMessage: "", - }); - } else { - var chatUserf = { - lastMessage: that.state.newMessage, - posted: posted, - friend: that.state.friendId, - name: that.state.friendName, - avatar: that.state.friendAvatar, - }; - var chatUser = { - lastMessage: that.state.newMessage, - posted: posted, - friend: userId, - name: auth.currentUser.displayName, - avatar: that.state.avatar, - }; - var newMessage = { - sendby: userId, - message: that.state.newMessage, - status: 0, - posted: posted, - }; - database - .ref( - "/users/" + - userId + - "/userChats/" + - that.state.friendId + - "/" + - that.state.newChatId - ) - .set(chatUserf); - database - .ref( - "/users/" + - that.state.friendId + - "/userChats/" + - userId + - "/" + - that.state.newChatId - ) - .set(chatUser); - database - .ref("/chatMessages/" + that.state.newChatId + "/" + that.state.newMessageId) - .set(newMessage); - } - }) - .catch(); + var friendIdRef= child(child(child(ref(database,"users"),userId),"userChats"),this.state.friendId); + onValue(friendIdRef,function (snapshot) { + const exist = snapshot.exists(); + if (exist) { + data = snapshot.val(); + let cId = Object.keys(data)[0]; + var newMessage = { + sendby: userId, + message: that.state.newMessage, + status: 0, + posted: posted, + }; + that.setState({ + newMessageId: that.uniqueId(), + }); + set(ref(database,"/chatMessages/" + cId + "/" + that.state.newMessageId),newMessage); + update(ref(database,"/users/" + userId + "/userChats/" + that.state.friendId + "/" + cId),{ posted: posted, lastMessage: that.state.newMessage }) + update(ref(database,"/users/" + that.state.friendId + "/userChats/" + userId + "/" + cId),{ posted: posted, lastMessage: that.state.newMessage }) + + that.setState({ + newMessage: "", + }); + } else { + var chatUserf = { + lastMessage: that.state.newMessage, + posted: posted, + friend: that.state.friendId, + name: that.state.friendName, + avatar: that.state.friendAvatar, + }; + var chatUser = { + lastMessage: that.state.newMessage, + posted: posted, + friend: userId, + name: auth.currentUser.displayName, + avatar: that.state.avatar, + }; + var newMessage = { + sendby: userId, + message: that.state.newMessage, + status: 0, + posted: posted, + }; + set(ref(database,"/users/" + + userId + + "/userChats/" + + that.state.friendId + + "/" + + that.state.newChatId),chatUserf); + set(ref(database,"/users/" + + that.state.friendId + + "/userChats/" + + userId + + "/" + + that.state.newChatId),chatUser); + set(ref(database,"/chatMessages/" + that.state.newChatId + "/" + that.state.newMessageId),newMessage); + + } + }) + that.textInput.clear(); } }; componentDidMount = () => { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.setState({ loggedin: true, }); that.check(); var userId = auth.currentUser.uid; - database - .ref("users") - .child(userId) - .child("name") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - name: data, - }); + var userIdRef= child(ref(database,"users"),userId); + var nameRef= child(userIdRef,"name"); + onValue(nameRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + name: data, }); - database - .ref("users") - .child(userId) - .child("avatar") - .once("value") - .then(function (snapshot) { - const exist = snapshot.val() != null; - if (exist) data = snapshot.val(); - console.log(data); - that.setState({ - avatar: data, - }); + }); + var avatarRef= child(userIdRef,"avatar"); + onValue(avatarRef,function (snapshot) { + const exist = snapshot.val() != null; + if (exist) data = snapshot.val(); + console.log(data); + that.setState({ + avatar: data, }); + }); + } else { that.setState({ loggedin: false, diff --git a/docs/react-native/app/screens/NewPostScreen/NewPostScreen.js b/docs/react-native/app/screens/NewPostScreen/NewPostScreen.js index 33ddd13..44e7de6 100644 --- a/docs/react-native/app/screens/NewPostScreen/NewPostScreen.js +++ b/docs/react-native/app/screens/NewPostScreen/NewPostScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { ScrollView, @@ -16,7 +17,9 @@ import { Card, ListItem, Button } from "react-native-elements"; import { TextInput } from "react-native-gesture-handler"; import ImagePicker from "react-native-image-picker"; import Icon from "react-native-vector-icons/FontAwesome"; -import { f, auth, storage, database } from "../../../config/config.js"; +import { firebaseApp, auth, storage, database } from "../../../config/config.js"; +import {} from "firebase/auth"; +import { ref, set, onValue, update, child} from "firebase/database"; export default class NewPostScreen extends Component { constructor() { super(); @@ -121,11 +124,12 @@ export default class NewPostScreen extends Component { xhr.send(null); }); var filePath = postId + "." + that.state.currentFileType; + const storage= getStorage(); - var uploadTask = storage.ref("post/img").child(filePath).put(blob); + var uploadTask = child(ref(storage,"post/img"),filePath).put(blob); - uploadTask.on( - "state_changed", + onValue( + uploadTask, function (snapshot) { let progress = ((snapshot.bytesTransferred / snapshot.totalBytes) * 100).toFixed(0); that.setState({ @@ -140,13 +144,13 @@ export default class NewPostScreen extends Component { progress: 100, }); uploadTask.snapshot.ref.getDownloadURL().then(function (downloadURL) { - that.setDatabse(downloadURL); + that.setDatabase(downloadURL); }); } ); }; - setDatabse = imageURL => { + setDatabase = imageURL => { var date = Date.now(); var postId = this.state.postId; var userID = auth.currentUser.uid; @@ -157,8 +161,9 @@ export default class NewPostScreen extends Component { image: imageURL, posted: posted, }; - database.ref("/post/" + postId).set(postObj); - alert("SuccessFully Published!!"); + + set(ref(database, "/post/" + postId),postObj); + Alert("SuccessFully Published!!"); this.setState({ imageSelected: false, uploading: false, diff --git a/docs/react-native/app/screens/ProfileScreen/profileScreen.js b/docs/react-native/app/screens/ProfileScreen/profileScreen.js index 9640aab..0be3b8a 100644 --- a/docs/react-native/app/screens/ProfileScreen/profileScreen.js +++ b/docs/react-native/app/screens/ProfileScreen/profileScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { Text, @@ -12,10 +13,14 @@ import { import { Info, DeatilView } from ".."; import HeaderNavigationBar from "../../components/HeaderNavigationBar/HeaderNavigationBar"; import styles from "./style"; -import { fauthstorage, database } from "../../../config/config.js"; +import { fauthstorage, database,auth,storage} from "../../../config/config.js"; +import {getStorage,ref} from "firebase/storage"; import { Avatar } from "react-native-elements"; import ImagePicker from "react-native-image-picker"; import AsyncStorage from "@react-native-async-storage/async-storage"; +import {onAuthStateChanged} from "firebase/auth" +import { onValue, update,ref,child } from "firebase/database"; +import { getStorage } from "firebase/storage"; export default class ProfileScreen extends Component { constructor(props) { super(props); @@ -32,42 +37,41 @@ export default class ProfileScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.state.email = auth.currentUser.email; - database - .ref("users") - .child(auth.currentUser.uid) - .once("value", function (snapshot) { - if (snapshot.child("firstName").val() != null) { - that.setState({ - firstName: snapshot.child("firstName").val(), - }); - } - if (snapshot.child("lastName").val() != null) { - that.setState({ - lastName: snapshot.child("lastName").val(), - }); - } - if (snapshot.child("contact").val() != null) { - that.setState({ - contact: snapshot.child("contact").val(), - }); - } - if (snapshot.child("address").val() != null) { - that.setState({ - address: snapshot.child("address").val(), - }); - } - if (snapshot.child("avatar").val != null) { - that.setState({ - avatar: snapshot.child("avatar").val(), - }); - } + var userRef= child(ref(database,"users"),auth.currentUser.uid); + onValue(userRef,function (snapshot) { + if (snapshot.child("firstName").val() != null) { that.setState({ - isLoading: false, + firstName: snapshot.child("firstName").val(), }); + } + if (snapshot.child("lastName").val() != null) { + that.setState({ + lastName: snapshot.child("lastName").val(), + }); + } + if (snapshot.child("contact").val() != null) { + that.setState({ + contact: snapshot.child("contact").val(), + }); + } + if (snapshot.child("address").val() != null) { + that.setState({ + address: snapshot.child("address").val(), + }); + } + if (snapshot.child("avatar").val != null) { + that.setState({ + avatar: snapshot.child("avatar").val(), + }); + } + that.setState({ + isLoading: false, }); + }) + } else { that.setState({ firstName: "John", @@ -143,11 +147,10 @@ export default class ProfileScreen extends Component { xhr.send(null); }); var filePath = userId + "." + that.state.currentFileType; + const storage= getStorage(); + var uploadTask = child(ref(storage,"user/img"),filePath).put(blob); - var uploadTask = storage.ref("user/img").child(filePath).put(blob); - - uploadTask.on( - "state_changed", + onValue(uploadTask, function (snapshot) { let progress = ((snapshot.bytesTransferred / snapshot.totalBytes) * 100).toFixed(0); that.setState({ @@ -171,12 +174,12 @@ export default class ProfileScreen extends Component { setDatabse = imageURL => { var user = auth.currentUser; var userID = auth.currentUser.uid; - database.ref("/users/" + userID).update({ avatar: imageURL }); + update(ref(database,"/users/" + userID),{ avatar: imageURL }); console.log("User: " + user); user.updateProfile({ photoURL: imageURL, }); - alert("SuccessFully Published!!"); + Alert("SuccessFully Published!!"); this.setState({ imageSelected: false, uploading: false, @@ -280,6 +283,7 @@ export default class ProfileScreen extends Component { }; console.log(user); - f.database().ref("users/").child(auth.currentUser.uid).set(user); + set(child(ref(database,"users/"),auth.currentUser.uid),user); + }; } diff --git a/docs/react-native/app/screens/SignupScreen/signupScreen.js b/docs/react-native/app/screens/SignupScreen/signupScreen.js index 9eafa2d..8efac8f 100644 --- a/docs/react-native/app/screens/SignupScreen/signupScreen.js +++ b/docs/react-native/app/screens/SignupScreen/signupScreen.js @@ -1,3 +1,4 @@ +//done import React, { Component } from "react"; import { View, @@ -12,8 +13,10 @@ import { import styles from "./style"; import * as EmailValidator from "email-validator"; import { AccessToken, LoginManager } from "react-native-fbsdk"; -import { f, auth, database } from "../../../config/config.js"; +import { onAuthStateChanged,signInWithCredential,createUserWithEmailAndPassword } from "firebase/auth"; +import { firebaseApp, auth, database } from "../../../config/config.js"; import { SocialIcon } from "react-native-elements"; +import{ref,update,child,onValue} from "firebase/database"; export default class SignUpScreen extends Component { constructor(props) { @@ -28,7 +31,7 @@ export default class SignUpScreen extends Component { componentDidMount() { var that = this; - auth.onAuthStateChanged(function (user) { + onAuthStateChanged(auth,function (user) { if (user) { that.redirectUser(); } @@ -44,7 +47,7 @@ export default class SignUpScreen extends Component { LoginManager.logInWithReadPermissions(["public_profile", "email"]).then( result => this._handleCallBack(result), function (error) { - alert("Login fail with error: " + error); + Alert("Login fail with error: " + error); } ); } @@ -52,7 +55,7 @@ export default class SignUpScreen extends Component { _handleCallBack(result) { let _this = this; if (result.isCancelled) { - alert("Login cancelled"); + Alert("Login cancelled"); } else { AccessToken.getCurrentAccessToken().then(data => { const token = data.accessToken; @@ -80,7 +83,7 @@ export default class SignUpScreen extends Component { authenticate = token => { const provider = auth.FacebookAuthProvider; const credential = provider.credential(token); - let ret = auth.signInWithCredential(credential); + let ret = signInWithCredential(auth,credential); return ret; }; @@ -91,10 +94,8 @@ export default class SignUpScreen extends Component { dp, ageRange: [20, 30], }; - database - .ref("users") - .child(uid) - .update({ ...userData, ...defaults }); + update(child(ref(database,"users"),uid),{ ...userData, ...defaults }); + }; render() { @@ -173,8 +174,7 @@ export default class SignUpScreen extends Component { const { navigate } = this.props.navigation; - auth - .createUserWithEmailAndPassword(email, password) + createUserWithEmailAndPassword(auth,email, password) .then(function (data) { data.user .updateProfile({ @@ -188,13 +188,13 @@ export default class SignUpScreen extends Component { console.log("Error Updating User Data.." + error); } ); - alert("Welcome to Go Social!"); + Alert("Welcome to Go Social!"); navigate("App"); }) .catch(function (error) { var errorMessage = error.message; console.log("Error = " + errorMessage); - alert(errorMessage); + Alert(errorMessage); }); } @@ -203,10 +203,10 @@ export default class SignUpScreen extends Component { if (this.state.Password === this.state.ConfirmPassword) { this.register(); } else { - alert("password Missmatch"); + Alert("password Missmatch"); } } else { - alert("Please enter A Valid Email"); + Alert("Please enter A Valid Email"); } }; } diff --git a/package.json b/package.json index 4786d3f..6bfdb29 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@react-navigation/native": "^6.1.6", "@react-navigation/stack": "^6.3.16", "email-validator": "^2.0.4", - "firebase": "^9.17.2", + "firebase": "^9.19.1", "react": "18.2.0", "react-native": "0.71.3", "react-native-elements": "^3.4.3", @@ -39,6 +39,7 @@ "@tsconfig/react-native": "^2.0.3", "@types/jest": "^29.4.0", "@types/react": "^18.0.28", + "@types/react-native-fbsdk": "^3.0.2", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.4.3", "eslint": "^8.35.0",