Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mayur-bhandari committed Feb 1, 2021
1 parent fd9212d commit 7afe9f1
Show file tree
Hide file tree
Showing 50 changed files with 1,310 additions and 749 deletions.
69 changes: 65 additions & 4 deletions CometChatWorkspace/cometchat-app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,42 @@ import {Provider} from 'react-redux';
import {store, persistor} from './store/store';
import StackNavigator from './StackNavigator';
import {COMETCHAT_CONSTANTS} from './CONSTS';
import {LogBox} from 'react-native';
import {
LogBox,
PermissionsAndroid,
StyleSheet,
Text,
Platform,
} from 'react-native';
import {PersistGate} from 'redux-persist/integration/react';
import theme from './react-native-chat-ui-kit/src/resources/theme';

const styles = StyleSheet.create({
defaultFontFamily: {
fontFamily: theme.fontFamily,
},
});

const customProps = {style: styles.defaultFontFamily};

// To set default font family, avoiding issues with specific android fonts like OnePlus Slate
function setDefaultFontFamily() {
const TextRender = Text.render;
const initialDefaultProps = Text.defaultProps;
Text.defaultProps = {
...initialDefaultProps,
...customProps,
};
Text.render = function render(props) {
let oldProps = props;
props = {...props, style: [customProps.style, props.style]};
try {
return TextRender.apply(this, arguments);
} finally {
props = oldProps;
}
};
}

const App = () => {
LogBox.ignoreAllLogs();
Expand All @@ -15,9 +49,36 @@ const App = () => {
.setRegion(COMETCHAT_CONSTANTS.REGION)
.build();

CometChat.init(COMETCHAT_CONSTANTS.APP_ID, appSetting).catch(() => {
return null;
});
useEffect(() => {
console.log("init***")
CometChat.init(COMETCHAT_CONSTANTS.APP_ID, appSetting).catch(() => {
return null;
});

if (Platform.OS === 'android') {
setDefaultFontFamily();
}

const getPermissions = async () => {
if (Platform.OS === 'android') {
let granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.CAMERA,
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
]);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.CAMERA,
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
]);
}
}
};
getPermissions();
}, []);

return (
<Provider store={store}>
Expand Down
12 changes: 6 additions & 6 deletions CometChatWorkspace/cometchat-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions CometChatWorkspace/cometchat-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"lint": "eslint ."
},
"dependencies": {
"@cometchat-pro/react-native-calls": "1.0.3",
"@cometchat-pro/react-native-chat": "^2.1.6",
"@cometchat-pro/react-native-calls": "1.0.7",
"@cometchat-pro/react-native-chat": "2.1.7",
"@react-native-community/async-storage": "^1.12.1",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-picker/picker": "^1.9.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React, { useState, useEffect } from 'react';
import { View, TouchableOpacity, Image, Modal, SafeAreaView, Text } from 'react-native';
import {
View,
TouchableOpacity,
Image,
Modal,
SafeAreaView,
Text,
} from 'react-native';
import { CometChat } from '@cometchat-pro/react-native-chat';
import Sound from 'react-native-sound';

Expand Down Expand Up @@ -28,11 +35,13 @@ export default (props) => {
Object.prototype.hasOwnProperty.call(props, 'widgetsettings') &&
props.widgetsettings &&
Object.prototype.hasOwnProperty.call(props.widgetsettings, 'main') &&
(Object.prototype.hasOwnProperty.call(props.widgetsettings.main, 'enable_sound_for_calls') ===
false ||
(Object.prototype.hasOwnProperty.call(
props.widgetsettings.main,
'enable_sound_for_calls',
) === false ||
(Object.prototype.hasOwnProperty.call(
props.widgetsettings.main,
'enable_sound_for_calls'
'enable_sound_for_calls',
) &&
props.widgetsettings.main.enable_sound_for_calls === false))
) {
Expand All @@ -49,11 +58,13 @@ export default (props) => {
Object.prototype.hasOwnProperty.call(props, 'widgetsettings') &&
props.widgetsettings &&
Object.prototype.hasOwnProperty.call(props.widgetsettings, 'main') &&
(Object.prototype.hasOwnProperty.call(props.widgetsettings.main, 'enable_sound_for_calls') ===
false ||
(Object.prototype.hasOwnProperty.call(
props.widgetsettings.main,
'enable_sound_for_calls',
) === false ||
(Object.prototype.hasOwnProperty.call(
props.widgetsettings.main,
'enable_sound_for_calls'
'enable_sound_for_calls',
) &&
props.widgetsettings.main.enable_sound_for_calls === false))
) {
Expand All @@ -65,15 +76,19 @@ export default (props) => {

const markMessageAsRead = (message) => {
const { receiverType } = message;
const receiverId = receiverType === 'user' ? message.sender.uid : message.receiverId;
const receiverId =
receiverType === 'user' ? message.sender.uid : message.receiverId;

if (Object.prototype.hasOwnProperty.call(message, 'readAt') === false) {
CometChat.markAsRead(message.id, receiverId, receiverType);
}
};

const incomingCallReceived = (call) => {
if (props.loggedInUser && call.callInitiator.uid === props.loggedInUser.uid) {
if (
props.loggedInUser &&
call.callInitiator.uid === props.loggedInUser.uid
) {
return;
}

Expand Down Expand Up @@ -116,9 +131,16 @@ export default (props) => {
const rejectCall = () => {
pauseIncomingAlert();

CometChatManager.rejectCall(incomingCall.sessionId, CometChat.CALL_STATUS.REJECTED)
CometChatManager.rejectCall(
incomingCall.sessionId,
CometChat.CALL_STATUS.REJECTED,
)
.then((rejectedCall) => {
props.actionGenerated('rejectedIncomingCall', incomingCall, rejectedCall);
props.actionGenerated(
'rejectedIncomingCall',
incomingCall,
rejectedCall,
);
setIncomingCall(null);
})
.catch((error) => {
Expand All @@ -130,8 +152,8 @@ export default (props) => {
const acceptCall = () => {
pauseIncomingAlert();

setIncomingCall(null);
props.actionGenerated('acceptIncomingCall', incomingCall);
setIncomingCall(null);
};

useEffect(() => {
Expand All @@ -150,7 +172,8 @@ export default (props) => {
return (
<Modal transparent animated animationType="fade">
<SafeAreaView>
<View style={[style.callContainerStyle, { backgroundColor: '#444444' }]}>
<View
style={[style.callContainerStyle, { backgroundColor: '#444444' }]}>
<View style={style.senderDetailsContainer}>
<View>
<Text numberOfLines={1} style={style.nameStyle}>
Expand All @@ -177,19 +200,35 @@ export default (props) => {
)}
</View>
<View style={style.avatarStyle}>
<CometChatAvatar cornerRadius={1000} image={{ uri: incomingCall.sender.avatar }} />
<CometChatAvatar
cornerRadius={1000}
borderWidth={0}
textColor="white"
image={{ uri: incomingCall.sender.avatar }}
name={incomingCall.sender.name}
/>
</View>
</View>
<View style={style.headerButtonStyle}>
<TouchableOpacity
style={[style.buttonStyle, { backgroundColor: ViewTheme.backgroundColor.red }]}
style={[
style.buttonStyle,
{ backgroundColor: ViewTheme.backgroundColor.red },
]}
onPress={rejectCall}>
<Text style={{ color: 'white', textAlign: 'center' }}>Decline</Text>
<Text style={{ color: 'white', textAlign: 'center' }}>
Decline
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[style.buttonStyle, { backgroundColor: ViewTheme.backgroundColor.blue }]}
style={[
style.buttonStyle,
{ backgroundColor: ViewTheme.backgroundColor.blue },
]}
onPress={acceptCall}>
<Text style={{ color: 'white', textAlign: 'center' }}>Accept</Text>
<Text style={{ color: 'white', textAlign: 'center' }}>
Accept
</Text>
</TouchableOpacity>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default StyleSheet.create({
flexWrap: 'wrap',
width: 34,
height: 34,
borderRadius: 22,
backgroundColor: 'rgba(51,153,255,0.25)',
},
callTypeStyle: {
flexDirection: 'row',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class ConversationListManager {
},
})
);

CometChat.addGroupListener(
this.groupListenerId,
new CometChat.GroupListener({
Expand All @@ -58,10 +57,16 @@ export class ConversationListManager {
callback(enums.GROUP_MEMBER_UNBANNED, unbannedFrom, message, { user: unbannedUser });
},
onMemberAddedToGroup: (message, userAdded, userAddedBy, userAddedIn) => {
callback(enums.GROUP_MEMBER_ADDED, userAddedIn, message, {
user: userAdded,
hasJoined: true,
});
callback(
enums.GROUP_MEMBER_ADDED,
userAddedIn,
message,
{
user: userAdded,
hasJoined: true,
},
userAddedBy,
);
},
onGroupMemberLeft: (message, leavingUser, group) => {
callback(enums.GROUP_MEMBER_LEFT, group, message, { user: leavingUser });
Expand Down
Loading

0 comments on commit 7afe9f1

Please sign in to comment.