Skip to content

Instantly share code, notes, and snippets.

View hieptl's full-sized avatar
🎯
Focusing

Hiep Le hieptl

🎯
Focusing
View GitHub Profile
@hieptl
hieptl / signup.js
Created October 27, 2021 07:03
signup.js - Encrypted Chat App
import { useRef, useContext } from "react";
import Context from "../context";
import validator from "validator";
import { auth, realTimeDb } from "../firebase";
import { v4 as uuidv4 } from "uuid";
const SignUp = (props) => {
const { toggleModal } = props;
const emailRef = useRef(null);
@hieptl
hieptl / signup.js
Created October 27, 2021 07:04
signup.js - Register New CometChat Account - Encrypted Chat App
...
const authKey = `${process.env.REACT_APP_COMETCHAT_AUTH_KEY}`;
const user = new cometChat.User(userUuid);
user.setName(fullname);
user.setAvatar(userAvatar);
cometChat.createUser(user, authKey).then(
user => {
setIsLoading(false);
},error => {
@hieptl
hieptl / modal.js
Created October 27, 2021 07:08
modal.js - Encrypted Chat App
import { useState } from 'react';
const withModal = ModalComponent => WrapperComponent => {
return function () {
const [isModalShown, setIsModalShown] = useState(false);
return (
<>
<WrapperComponent toggleModal={setIsModalShown}/>
{isModalShown && <ModalComponent toggleModal={setIsModalShown} />}
@hieptl
hieptl / home.js
Last active November 8, 2021 08:03
home.js - Encrypted Chat App
import { useContext } from 'react';
import { CometChatUI } from '../cometchat-pro-react-ui-kit/CometChatWorkspace/src';
import Header from './Header';
import Context from '../context';
const Home = () => {
@hieptl
hieptl / index.js
Last active November 5, 2021 09:04
index.js - CometChatMessageComposer
...
buildTextMessage = (receiverId, messageInput, receiverType) => {
const textMessage = new CometChat.TextMessage(receiverId, messageInput, receiverType);
if (this.props.parentMessageId) {
textMessage.setParentMessageId(this.props.parentMessageId);
}
textMessage.setSender(this.loggedInUser);
textMessage.setReceiver(this.context.type);
textMessage.setText(messageInput);
textMessage._composedAt = getUnixTimestamp();
@hieptl
hieptl / login.js
Last active November 2, 2021 16:14
login.js - init EThree - Encrypted Chat App
...
const registerEThree = async (eThree, user) => {
if (eThree) {
try {
await eThree.register();
// generate the backup key.
if (user && user.keyPassword) {
await eThree.backupPrivateKey(user.keyPassword);
}
} catch (err) {
@hieptl
hieptl / index.js
Created October 27, 2021 13:26
index.js - Encrypted Chat App Server
require("dotenv").config();
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
const path = require("path");
const { JwtGenerator } = require('virgil-sdk');
const { initCrypto, VirgilCrypto, VirgilAccessTokenSigner } = require('virgil-crypto');
const PORT = process.env.PORT || 8080;
@hieptl
hieptl / index.js
Last active November 5, 2021 12:55
index.js - CometChatMessageList - Decrypt After Receiving the Message - Encrypted Chat App
...
async componentDidMount() {
...
if (this.context.item && this.context.item.guid) {
await this.startVirgilGroupChat();
}
...
}
async componentDidUpdate(prevProps, prevState) {
...
@hieptl
hieptl / index.js
Last active November 5, 2021 11:17
index.js - Decrypt the List of Messages - CometChatMessageList
...
getVirgilGroupInstance = async guid => {
try {
if (guid) {
const eThree = this.context.eThree;
let group = await eThree.getGroup(guid);
if (group) {
return group;
}
const ownerCard = await eThree.findUsers(this.context.item.owner);
@hieptl
hieptl / index.js
Last active November 3, 2021 15:22
index.js - CometChatConversationListItem - Encrypted Chat App
...
async componentDidMount() {
const message = await this.getLastMessage();
...
}
async componentDidUpdate(prevProps) {
...
if (previousItem !== currentItem) {
const message = await this.getLastMessage();