1.0.97 • Published 11 months ago

chatverse v1.0.97

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Firestore Chat

Introduction

The Firestore chat package includes components you need to build a functioning chat user experience in React js with support for one to one and group chat. It uses Firebase as the backend service.

The Package takes care of the basic functionality requirements for any chat application. In this project We have used the following Firebase services.

  • Firebase Authentication : For authentication user by email and password
  • Firebase Firestore Database : It is the db we used for Firestore chat
  • Firebase Storage : That's we used to store images and videos

Main features

- One to one chat
- Group chat
- Firebase authentication
- User listing
- User block - unblock
- User search
- Group create
- Group edit
- Group exit
- Message seen - unseen

Installation

To install Firestore chat on your project, follow below steps:

Step 1 - Install Firestore chat

Use the following command to install Firestore chat

$ npm install chatverse --save-exact

Step 2 - Firebase Registration

After a user is registered in the main project we need to register and add that user to firestore chat also, for that purpose, we can use firebaseSignUp function which can be imported from the firestore chat package and this function will return a Firebase uid which can be stored in the database of main project against the particular registered user.

import { RegisterToChat } from 'chatverse';
const [firebaseConfig, setFirebaseConfig] = useState({
    apiKey: ' ',

    authDomain: '',

    databaseURL: '',

    projectId: '',

    storageBucket: '',

    messagingSenderId: '',

    appId: '',

    measurementId: '',
  });

  const email = data.email;
  const password = data.password;
  const displayName = data.name.trim()

const firebaseData = await RegisterToChat(firebaseConfig, email, password ,displayName);

Here in the RegisterToChat function, we need to pass four arguments: firebaseConfig which is the firebase configurations, email, password and displayName which contains details of that person. The function returns the firebase uid of that particular person.

Step 3 - Firebase Login

After a user login into the main project, we need to log in that user to firestore chat also, for that purpose, we can use the LoginToChat function which can be imported from the chatverse package and this function will return a Firebase uid if the firebase login is successful.

import { LoginToChat } from 'chatverse';
const [firebaseConfig, setFirebaseConfig] = useState({
    apiKey: ' ',

    authDomain: '',

    databaseURL: '',

    projectId: '',

    storageBucket: '',

    messagingSenderId: '',

    appId: '',

    measurementId: '',
  });

const firebaseData = await LoginToChat( firebaseConfig, email, password );

Here in the LoginToChat function, we need to pass three arguments: email, password which is the email and password of the user we are trying to login and firebaseConfig which is the firebase configurations. The function returns the firebase uid of that particular person.

Step 4 - Package Loading

After the firebase authentication functions are implemented, finally we can load the chat component of firestore chat in our desired functional component in the main project, we can load the chat component by importing FirestoreChat from the firestore chat package and then render it.

import { FirestoreChat } from 'chatverse';
const [customStyle, setCustomStyle] = useState({
    primaryColor: '#6b5dd3',
    secondaryColor: '#9083e9',
  });
  const [condition, setCondition] = useState(false);
  const [firebaseConfig, setFirebaseConfig] = useState({
    apiKey: '',

    authDomain: '',

    databaseURL: '',

    projectId: '',

    storageBucket: '',

    messagingSenderId: '',

    appId: '',

    measurementId: '',
  });

    <FirestoreChat
        firebaseConfig={firebaseConfig} 
        condition={condition} 
        styles={customStyle}
       />

While loading the Chat component of the firestore chat, we also needed to pass some data as props like firebase configurations and some basic styles like primary color, secondary color.

propdescriptionrequireddefault
firebaseConfigFirebase configuration detailstrueNone
conditionConditional listing is used to decide whether the listing of users in firestore chat should conditional based or not.trueNone
stylesThe styles props can be used to set some basic styles of package like primary color, secondary colortrueNone

Styles

styledescriptionrequireddefault
primaryColorPrimary color of the firestore chattrueNone
secondaryColorSecondary color of the firestore chattrueNone

Conditional based user listing

If we want the user's list from which we can chat in firestore chat to be conditional based like we only want to chat with other users who are our followers or friends, then we can use a conditional-based user listing, to activate conditional-based user listing we need to do two things:

  • set conditional_listing to true while we load the chat component

    Example -

    const [condition, setCondition] = useState(true);
     <Chat
       firebaseConfig={firebaseConfig}
       condition={condition}
       styles={customStyle}
      />
    • While following or connecting to other users call the AddUserToChat and RemoveUserToChat functions in the firestore chat package and pass the firebase uid's of the following user and followed user.

      Example - Adding Friend or Follower

       import { AddUserToChat } from 'chatverse';
      const [firebaseConfig, setFirebaseConfig] = useState({
        apiKey: ' ',
      
        authDomain: '',
      
        databaseURL: '',
      
       projectId: '',
      
       storageBucket: '',
      
       messagingSenderId: '',
      
       appId: '',
      
       measurementId: '',
      });

    const firebaseData = await AddUserToChat(current_user, friend, firebaseConfig);

  • Removing Friend or Follower

    ```bash-session
     import { RemoveUserToChat } from 'chatverse';
    ```
    
    ```bash-session
    const [firebaseConfig, setFirebaseConfig] = useState({
      apiKey: ' ',
    
      authDomain: '',
    
      databaseURL: '',
    
     projectId: '',
    
     storageBucket: '',
    
     messagingSenderId: '',
    
     appId: '',
    
     measurementId: '',

    });

    const firebaseData = await RemoveUserToChat(current_user, friend, firebaseConfig);

    Here in the function AddUserToChat and  RemoveUserToChat we need to pass three arguments:
  • current_user : firebase uid of the following user

  • friend : firebase uid of the followed user
  • firebaseConfig : firebase configurations
1.0.95

11 months ago

1.0.97

11 months ago

1.0.96

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

11 months ago

1.0.77

11 months ago

1.0.76

11 months ago

1.0.75

11 months ago

1.0.74

11 months ago

1.0.79

11 months ago

1.0.78

11 months ago

1.0.39

12 months ago

1.0.38

12 months ago

1.0.40

12 months ago

1.0.44

12 months ago

1.0.43

12 months ago

1.0.42

12 months ago

1.0.41

12 months ago

1.0.48

11 months ago

1.0.47

12 months ago

1.0.46

12 months ago

1.0.45

12 months ago

1.0.49

11 months ago

1.0.51

11 months ago

1.0.50

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.59

11 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.37

12 months ago

1.0.36

12 months ago

1.0.80

11 months ago

1.0.84

11 months ago

1.0.83

11 months ago

1.0.82

11 months ago

1.0.81

11 months ago

1.0.88

11 months ago

1.0.87

11 months ago

1.0.86

11 months ago

1.0.85

11 months ago

1.0.89

11 months ago

1.0.91

11 months ago

1.0.90

11 months ago

1.0.94

11 months ago

1.0.93

11 months ago

1.0.92

11 months ago

1.0.35

12 months ago

1.0.34

12 months ago

1.0.33

12 months ago

1.0.32

12 months ago

1.0.31

12 months ago

1.0.30

12 months ago

1.0.29

12 months ago

1.0.28

12 months ago

1.0.27

12 months ago

1.0.26

12 months ago

1.0.25

12 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.22

12 months ago

1.0.21

12 months ago

1.0.20

12 months ago

1.0.19

12 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

0.1.0

12 months ago