[英]Creating Group Chat Feature
I have been stunned on this problem for a bit now, so I've come to ask for help.我现在对这个问题感到震惊,所以我来寻求帮助。 I am creating a private messaging app with a group chat feature.
我正在创建一个具有群聊功能的私人消息传递应用程序。 I am using firebase 7.14.0 (yes I know that's old) when you click on a contact in my app you can create a groupchat which will create another chat with just you in it (I know its not optimal I just want to get functionality working first) then in that chat you can add people to the chat.
我正在使用 firebase 7.14.0(是的,我知道那很旧)当您单击我的应用程序中的联系人时,您可以创建一个群聊,这将创建另一个与您聊天的群聊(我知道它不是最佳的,我只是想获得功能首先工作)然后在该聊天中您可以将人员添加到聊天中。
Here is the code I need help with.这是我需要帮助的代码。
import React, { useEffect, useState, useCallback } from 'react';
import firebase from "../firebase"
import { NavLink } from 'react-router-dom';
import { Avatar } from '@material-ui/core';
import './Gccontact.css';
const Gccontact = props => {
const [contact, setContact] = useState()
const [conversation, setConversation] = useState()
const getContact = useCallback(async () => {
const id = props.contact
const db = firebase.db
const unsubscribe = db.collection("users").doc(id).onSnapshot(snapshot => {
setContact(snapshot.data())
})
return unsubscribe
},[props.contact])
useEffect(() => {
getContact()
}, [props])
const addtogroup = useCallback(async uid => {
const members = [contact.uid];
await firebase.db.collection("conversations").doc('x8DGIeBhW96ziGh0MEGf').update({ members });
}, []);
/* db.collection("users").doc(currentUser.uid).update({
status
}) */
return (
<li className="contact">
{contact && <div className="wrap" onClick={addtogroup}>
<span className={`contact-status ${contact.status}`}></span>
<div className="img-container">
<Avatar src={contact.profilePicture} alt={contact.name + " Profile Picture"} />
</div>
<div style={{display: "inline-block"}} className="meta">
<p className="display-name">{contact.name}</p>
{props.recent && <p className="preview">
{props.recent?.sender === firebase?.auth?.currentUser?.uid && <span>You: </span>}
{props.recent?.attachments?.length === 0 ? props.recent?.body : "Picture"}
</p>}
</div>
</div>}
</li>
);
}
export default Gccontact;
This is the contact file, when you click on the contact I want it to add them to the groupchat.这是联系人文件,当您单击联系人时,我希望它将他们添加到群聊中。 When I try to add the members to group im getting an error saying contact.uid is undefined, so I tried contact.name and it still didn't work.
当我尝试将成员添加到组时,我收到一条错误消息,提示 contact.uid 未定义,因此我尝试了 contact.name,但仍然无效。 As far as the
至于
await firebase.db.collection("conversations").doc('x8DGIeBhW96ziGh0MEGf').update({ members });
goes I don't know how to get each individuals documents id, so I have a set one just to test.去 我不知道如何获取每个人的文档 ID,所以我有一套只是为了测试。 and with.update I noticed it gets rid of all the members and just adds that one that a defined.
和 with.update 我注意到它摆脱了所有成员,只是添加了一个已定义的成员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.