简体   繁体   English

创建群聊功能

[英]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 我注意到它摆脱了所有成员,只是添加了一个已定义的成员。

alternatively you could use a third party chat API to avoid a lot of headaches.或者,您可以使用第三方聊天 API 来避免很多麻烦。 I recommend trying out MinChat我建议试用MinChat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以使用 Twilio 会话 API 进行实时聊天功能吗 - Can I use Twilio conversations API for realtime chat feature 如何在聊天 flutter 应用程序中添加活跃用户功能 - how to add an active user feature in chat flutter app 带有群聊的聊天应用程序的架构设计。 我无法按时间顺序查询聊天室 - Schema design for chat app with group chat. I can't query chat room in chronological order 从 AWS Sagemaker 功能组中删除/编辑功能定义 - Remove/Edit feature definitions from AWS Sagemaker Feature Group 在预定义的时间内禁止特定 firebase firestore 群聊中的用户 - Ban a User in a particular firebase firestore group chat for predefined time 我在创建聊天应用程序时收到 ConcurrentModificationException - I am getting ConcurrentModificationException while creating a chat application 如何为 AWS DocumentDB 中的组替换 $$ROOT - 不支持的功能:$$ROOT - How to replace $$ROOT for group in AWS DocumentDB - Feature not supported: $$ROOT 未处理的异常:使用 Firebase 实时数据库聊天功能在 dispose() 之后调用 setState() - Unhandled Exception: setState() called after dispose() with Firebase Realtime Database chat feature terraform aws:创建安全组时的协议不正确 - terraform aws: Incorrect protocol in creating a security group 在 Oracle 到 BigQuery 之间创建 DataFusion 复制时缺少功能问题 - Missing Feature issue while creating DataFusion Replication between Oracle to BigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM