nice clean up and see that group chat is easy
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
limit,
|
limit,
|
||||||
startAt,
|
startAt,
|
||||||
endAt,
|
endAt,
|
||||||
|
addDoc,
|
||||||
} from 'firebase/firestore';
|
} from 'firebase/firestore';
|
||||||
|
|
||||||
import { User as FirebaseUser } from 'firebase/auth';
|
import { User as FirebaseUser } from 'firebase/auth';
|
||||||
@@ -115,36 +116,29 @@ export const searchUsers = async (searchQuery: string): Promise<User[] | undefin
|
|||||||
export const createOneOnOneConversation = async (
|
export const createOneOnOneConversation = async (
|
||||||
otherUserId: string,
|
otherUserId: string,
|
||||||
myUserId: string,
|
myUserId: string,
|
||||||
): Promise<string> => {
|
): Promise<void> => {
|
||||||
const conversation = new Conversation(myUserId, [myUserId, otherUserId]);
|
const newConversation = new Conversation(myUserId, [myUserId, otherUserId]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await setDoc(
|
await addDoc(db.conversations, newConversation);
|
||||||
db.conversations(user.uid),
|
} catch (e) {
|
||||||
new User(
|
console.error('Error creating user: ', e);
|
||||||
user.uid,
|
|
||||||
user.providerId,
|
throw new Error('Error creating user');
|
||||||
user.email,
|
}
|
||||||
user.displayName,
|
};
|
||||||
user.photoURL,
|
|
||||||
user.phoneNumber,
|
export const createGroupConversation = async (
|
||||||
),
|
otherUserIds: string[],
|
||||||
{ merge: true },
|
myUserId: string,
|
||||||
);
|
): Promise<void> => {
|
||||||
|
const newConversation = new Conversation(myUserId, [myUserId, ...otherUserIds]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await addDoc(db.conversations, newConversation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating user: ', e);
|
console.error('Error creating user: ', e);
|
||||||
|
|
||||||
throw new Error('Error creating user');
|
throw new Error('Error creating user');
|
||||||
}
|
}
|
||||||
return '';
|
|
||||||
|
|
||||||
// const docRef =
|
|
||||||
// const docSnap = await getDoc(docRef);
|
|
||||||
|
|
||||||
// if (docSnap.exists()) {
|
|
||||||
// console.log("Document data:", docSnap.data());
|
|
||||||
// } else {
|
|
||||||
// // doc.data() will be undefined in this case
|
|
||||||
// console.log("No such document!");
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user