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 / AddGroupMembers.js
Created October 11, 2021 03:37
AddGroupMembers.js - Call CometChat Service to Add Members - React Native Gifted Chat App
...
const GUID = selectedConversation.guid;
const membersList = [
new cometChat.GroupMember(selectedUser.uid, cometChat.GROUP_MEMBER_SCOPE.PARTICIPANT),
];
cometChat.addMembersToGroup(GUID, membersList, []).then(
response => {
setIsLoading(false);
showMessage('Info', `${selectedUser.name} was added to the group successfully`);
searchUsers();
@hieptl
hieptl / RemoveGroupMembers.js
Created October 11, 2021 03:40
RemoveGroupMembers.js - Call CometChat Service to Remove Members - React Native Gifted Chat App
...
const GUID = selectedUser.guid;
const UID = selectedUser.uid;
cometChat.kickGroupMember(GUID, UID).then(
response => {
setIsLoading(false);
showMessage('Info', `${selectedUser.name} was removed from the group successfully`);
searchGroupMembers();
},
@hieptl
hieptl / App.js
Last active October 13, 2021 12:54
App.js - Logout - React Native Gifted Chat App
...
const handleLogout = (navigation) => {
cometChat.logout().then(
() => {
console.log("Logout completed successfully");
AsyncStorage.removeItem('auth');
setUser(null);
navigation.reset({
index: 0,
routes: [{ name: 'Login' }]
@hieptl
hieptl / context.js
Created October 13, 2021 01:54
Context.js - React Native Gifted Chat App
import React from 'react';
export default React.createContext(null);
@hieptl
hieptl / App.js
Created October 13, 2021 09:23
App.js - Get Permissions Android - React Native Gifted Chat App
...
useEffect(() => {
...
getPermissions();
}, []);
...
const getPermissions = async () => {
if (Platform.OS === 'android') {
let granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.CAMERA,
@hieptl
hieptl / Info.plist
Created October 13, 2021 09:28
Info.plist - Request Permissions - React Native Gifted Chat App
<key>NSCameraUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSMicrophoneUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
@hieptl
hieptl / Chat.js
Last active October 15, 2021 12:34
Chat.js - User Listener Event - React Native Gifted Chat App
...
const Chat = (props) => {
...
const userOnlineListenerId = useRef(uuidv4());
...
useEffect(() => {
if (selectedConversation) {
...
// listen for online users.
listenForOnlineUsers();
@hieptl
hieptl / App.tsx
Last active October 18, 2021 13:43
App.tsx - Initialize CometChat - Ionic Chat App
...
useEffect(() => {
initCometChat();
...
}, []);
...
const initCometChat = async () => {
const { CometChat } = await import('@cometchat-pro/cordova-ionic-chat');
const appID = `${process.env.REACT_APP_COMETCHAT_APP_ID}`;
const region = `${process.env.REACT_APP_COMETCHAT_REGION}`;
@hieptl
hieptl / App.tsx
Created October 18, 2021 13:46
App.tsx - Get Permissions - Ionic Chat App
...
useEffect(() => {
...
getPermissions();
...
}, []);
...
const getPermissions = () => {
AndroidPermissions.requestPermissions([AndroidPermissions.PERMISSION.CAMERA, AndroidPermissions.PERMISSION.RECORD_AUDIO, AndroidPermissions.PERMISSION.READ_EXTERNAL_STORAGE, AndroidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE]);
};
@hieptl
hieptl / firebase.ts
Created October 18, 2021 13:48
firebase.ts - Ionic Chat App
import firebase from "firebase";
import "firebase/storage";
const firebaseConfig = {
apiKey: `${process.env.REACT_APP_FIREBASE_API_KEY}`,
authDomain: `${process.env.REACT_APP_FIREBASE_AUTH_DOMAIN}`,
storageBucket: `${process.env.REACT_APP_FIREBASE_STORAGE_BUCKET}`
};
const app = !firebase.apps.length