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 / Home.js
Created October 10, 2021 16:41
Home.js - Search Data - React Native Gifted Chat App
...
const searchUsers = () => {
if (cometChat) {
const limit = 30;
const usersRequestBuilder = new cometChat.UsersRequestBuilder().setLimit(limit);
const usersRequest = keyword ? usersRequestBuilder.setSearchKeyword(keyword).build() : usersRequestBuilder.build();
usersRequest.fetchNext().then(
userList => {
/* userList will be the list of User class. */
/* retrived list can be used to display contact list. */
@hieptl
hieptl / CreateGroup.js
Created October 10, 2021 16:50
CreateGroup.js - React Native Gifted Chat App
import React, { useState, useContext } from 'react';
import { StyleSheet, View, TextInput, TouchableOpacity, Text, ActivityIndicator, Alert } from 'react-native';
// import Context to get shared data from React context.
import Context from "../context";
// import validator to validate user's credentials.
import validator from "validator";
// import uuid to generate id for users.
import 'react-native-get-random-values';
import { v4 as uuidv4 } from "uuid";
@hieptl
hieptl / CreateGroup.js
Created October 10, 2021 16:55
CreateGroup.js - Create Group - React Native Gifted Chat App
...
const createGroup = () => {
if (isGroupValid(groupName)) {
setIsLoading(true);
const GUID = uuidv4();
const groupType = cometChat.GROUP_TYPE.PUBLIC;
const groupIcon = generateAvatar();
const password = "";
const group = new cometChat.Group(GUID, groupName, groupType, password);
@hieptl
hieptl / Home.js
Last active October 11, 2021 02:01
Home.js - Select Item - React Native Gifted Chat App
...
const joinGroup = (item) => {
if (item && item.guid && !item.hasJoined) {
const GUID = item.guid;
const password = "";
const groupType = cometChat.GROUP_TYPE.PUBLIC;
cometChat.joinGroup(GUID, groupType, password).then(
group => {
},
@hieptl
hieptl / Chat.js
Last active October 15, 2021 12:29
Chat.js - Load Messages - React Native Gifted Chat App
...
const Chat = () => {
...
const { cometChat, selectedConversation, user } = useContext(Context);
const [messages, setMessages] = useState([]);
...
useEffect(() => {
if (selectedConversation) {
// get list of messages.
@hieptl
hieptl / Chat.js
Last active October 15, 2021 12:30
Chat.js - Send Message - React Native Gifted Chat App
...
const Chat = () => {
...
const { cometChat, selectedConversation, user} = useContext(Context);
const [messages, setMessages] = useState([]);
...
const getReceiverId = () => {
if (selectedConversation && selectedConversation.guid) {
return selectedConversation.guid;
@hieptl
hieptl / Chat.js
Last active October 15, 2021 12:33
Chat.js - Sending Media Message - React Native Gifted Chat App
...
const Chat = () => {
...
const { cometChat, selectedConversation, user } = useContext(Context);
const [messages, setMessages] = useState([]);
const [selectedFile, setSelectedFile] = useState(null);
...
useEffect(() => {
if (selectedFile && selectedFile.name && selectedFile.uri) {
@hieptl
hieptl / Chat.js
Last active October 15, 2021 12:34
Chat.js - Listen to Real-Time Messages - React Native Gifted Chat App
...
const Chat = () => {
...
const { cometChat, selectedConversation, user } = useContext(Context);
const [messages, setMessages] = useState([]);
...
useEffect(() => {
if (selectedConversation) {
...
@hieptl
hieptl / App.js
Last active October 15, 2021 07:56
App.js - Audio & Video Call - React Native Gifted Chat App
...
const App = () => {
const callListenerId = useRef(uuidv4());
...
const [callType, setCallType] = useState(null);
const [callSettings, setCallSettings] = useState(null);
const [call, setCall] = useState(null);
const [isSomeoneCalling, setIsSomeoneCalling] = useState(false);
useEffect(() => {
@hieptl
hieptl / ManageGroup.js
Created October 11, 2021 03:21
ManageGroup.js - React Native Gifted Chat App
import React, { useState, useContext } from 'react';
import { StyleSheet, View, TouchableOpacity, Text, Image, Alert, ActivityIndicator } from 'react-native';
import Context from '../context';
const ManageGroup = (props) => {
const { navigation } = props;
const { cometChat, selectedConversation } = useContext(Context);