Skip to content

Commit

Permalink
Merge pull request #26 from cometchat-pro/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
TirathBhuva authored Nov 8, 2021
2 parents 0e8a4a7 + 0b7746b commit dfe438b
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 3,853 deletions.
Binary file modified .DS_Store
Binary file not shown.
3,796 changes: 0 additions & 3,796 deletions package-lock.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cometchat-pro-react-native-ui-kit",
"version": "2.4.0-1",
"version": "2.4.0-2",
"description": "Chat UI Kit for React Native App",
"main": "./src/index.js",
"scripts": {
Expand Down Expand Up @@ -50,7 +50,7 @@
"prettier": "^2.1.2"
},
"dependencies": {
"@cometchat-pro/react-native-calls": "2.0.3-beta1",
"@cometchat-pro/react-native-calls": "2.1.1",
"@cometchat-pro/react-native-chat": "2.4.0",
"@react-native-async-storage/async-storage": "^1.13.4",
"lodash": "^4.17.20",
Expand Down
14 changes: 10 additions & 4 deletions src/components/Messages/CometChatMessageHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import { MessageHeaderManager } from './controller';
import { View, Text, TouchableOpacity, Image } from 'react-native';

import { CometChatUserPresence, CometChatAvatar } from '../../Shared';
import * as enums from '../../../utils/enums';
import * as actions from '../../../utils/actions';
Expand Down Expand Up @@ -37,10 +38,14 @@ class CometChatMessageHeader extends React.Component {
}

checkRestrictions = async () => {
let isGroupVideoCallEnabled = await this.context.FeatureRestriction.isGroupVideoCallEnabled();
let isOneOnOneAudioCallEnabled = await this.context.FeatureRestriction.isOneOnOneAudioCallEnabled();
let isTypingIndicatorsEnabled = await this.context.FeatureRestriction.isTypingIndicatorsEnabled();
let isOneOnOneVideoCallEnabled = await this.context.FeatureRestriction.isOneOnOneVideoCallEnabled();
let isGroupVideoCallEnabled =
await this.context.FeatureRestriction.isGroupVideoCallEnabled();
let isOneOnOneAudioCallEnabled =
await this.context.FeatureRestriction.isOneOnOneAudioCallEnabled();
let isTypingIndicatorsEnabled =
await this.context.FeatureRestriction.isTypingIndicatorsEnabled();
let isOneOnOneVideoCallEnabled =
await this.context.FeatureRestriction.isOneOnOneVideoCallEnabled();
this.setState({
restrictions: {
isGroupVideoCallEnabled,
Expand Down Expand Up @@ -172,6 +177,7 @@ class CometChatMessageHeader extends React.Component {
) {
this.setState({ status: item.status, presence: item.status });
}
this.props.actionGenerated(actions.STATUS_UPDATED, item.status);
break;
}
case enums.GROUP_MEMBER_KICKED:
Expand Down
4 changes: 4 additions & 0 deletions src/components/Messages/CometChatMessages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ class CometChatMessages extends React.PureComponent {
case actions.DIRECT_CALL_ENDED:
this.setState({ joinDirectCall: false, ongoingDirectCall: null });

break;
case actions.STATUS_UPDATED:
this.setState({ user: { ...this.state.user, status: messages } });

break;
default:
break;
Expand Down
107 changes: 65 additions & 42 deletions src/components/Messages/CometChatStickerKeyboard/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* eslint-disable react/jsx-fragments */
import React from 'react';
import { View, Text, TouchableOpacity, Image, ScrollView } from 'react-native';
import {
View,
Text,
TouchableOpacity,
ScrollView,
FlatList,
} from 'react-native';
import FastImage from 'react-native-fast-image';
import theme from '../../../resources/theme';
import Icon from 'react-native-vector-icons/MaterialIcons';
import style from './styles';
Expand Down Expand Up @@ -130,49 +137,71 @@ class CometChatStickerKeyboard extends React.PureComponent {

let stickers = null;
if (Object.keys(this.state.stickerSet).length) {
const sectionItems = Object.keys(this.state.stickerSet).map(
(sectionItem, key) => {
const stickerSetThumbnail = this.state.stickerSet[sectionItem][0]
.stickerUrl;
return (
<TouchableOpacity
key={key}
style={style.sectionListItemStyle}
onPress={() => this.onStickerSetClicked(sectionItem)}>
<Image
source={{ uri: stickerSetThumbnail }}
alt={sectionItem}
style={style.stickerHeaderImageStyle}
/>
</TouchableOpacity>
);
},
const sectionItems = (
<FlatList
style={{
width: '100%',
flexDirection: 'row',
backgroundColor: 'red',
}}
nestedScrollEnabled
style={{ paddingVertical: 10 }}
horizontal
bounces={false}
showsHorizontalScrollIndicator={false}
data={Object.keys(this.state.stickerSet)}
renderItem={({ item: sectionItem, index: key }) => {
const stickerSetThumbnail =
this.state.stickerSet[sectionItem][0].stickerUrl;

return (
<TouchableOpacity
key={sectionItem}
style={style.sectionListItemStyle}
onPress={() => this.onStickerSetClicked(sectionItem)}>
<FastImage
source={{ uri: stickerSetThumbnail }}
alt={sectionItem}
style={style.stickerHeaderImageStyle}
/>
</TouchableOpacity>
);
}}
/>
);

let activeStickerList = [];
if (this.state.activeStickerList.length) {
const stickerList = [...this.state.activeStickerList];
activeStickerList = stickerList.map((stickerItem, key) => {
return (
<TouchableOpacity
key={key}
style={style.stickerItemStyle}
onPress={() => this.sendStickerMessage(stickerItem)}>
<Image
source={{ uri: stickerItem.stickerUrl }}
alt={stickerItem.stickerName}
style={style.stickerImageStyle}
/>
</TouchableOpacity>
);
});
activeStickerList = (
<FlatList
numColumns={3}
style={{
width: '100%',
alignSelf: 'center',
}}
data={stickerList}
renderItem={({ item: stickerItem, index: key }) => {
return (
<TouchableOpacity
key={stickerItem.stickerName}
style={style.stickerItemStyle}
onPress={() => this.sendStickerMessage(stickerItem)}>
<FastImage
source={{ uri: stickerItem.stickerUrl }}
alt={stickerItem.stickerName}
style={style.stickerImageStyle}
/>
</TouchableOpacity>
);
}}
/>
);
}

stickers = (
<>
<ScrollView bounces={false}>
<View style={style.stickerListStyle}>{activeStickerList}</View>
</ScrollView>
<View style={style.stickerListStyle}>{activeStickerList}</View>

<View
style={[
Expand All @@ -182,13 +211,7 @@ class CometChatStickerKeyboard extends React.PureComponent {
backgroundColor: this.viewTheme.backgroundColor.silver,
},
]}>
<ScrollView
style={{ paddingVertical: 10 }}
horizontal
bounces={false}
showsHorizontalScrollIndicator={false}>
{sectionItems}
</ScrollView>
{sectionItems}
</View>
</>
);
Expand Down
8 changes: 5 additions & 3 deletions src/components/Messages/CometChatStickerKeyboard/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default StyleSheet.create({
marginHorizontal: 8,
},
stickerItemStyle: {
minWidth: 50,
width: '30%',
minHeight: 50,
maxWidth: 70,
marginLeft: '2.5%',
maxHeight: 70,
flexShrink: 0,
marginRight: 20,
Expand All @@ -37,8 +37,10 @@ export default StyleSheet.create({
flexWrap: 'wrap',
justifyContent: 'space-between',
alignItems: 'center',
paddingLeft: 20,
// paddingHorizontal: 20,
paddingRight: '2.5%',
paddingBottom: 10,
flex: 1,
},
stickerSectionListStyle: {
borderTopWidth: 1,
Expand Down
26 changes: 26 additions & 0 deletions src/components/Users/CometChatUserDetails/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CometChat } from '@cometchat-pro/react-native-chat';
import * as enums from '../../../utils/enums';

export class UserDetailManager {
userListenerId = 'user_detail_' + new Date().getTime();

attachListeners(callback) {
CometChat.addUserListener(
this.userListenerId,
new CometChat.UserListener({
onUserOnline: (onlineUser) => {
/* when someuser/friend comes online, user will be received here */
callback(enums.USER_ONLINE, onlineUser);
},
onUserOffline: (offlineUser) => {
/* when someuser/friend went offline, user will be received here */
callback(enums.USER_OFFLINE, offlineUser);
},
}),
);
}

removeListeners() {
CometChat.removeUserListener(this.userListenerId);
}
}
53 changes: 47 additions & 6 deletions src/components/Users/CometChatUserDetails/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import { View, Text, TouchableOpacity, Dimensions, Modal } from 'react-native';
import { UserDetailManager } from './controller';
import * as enums from '../../../utils/enums';
import theme from '../../../resources/theme';
import Icon from 'react-native-vector-icons/MaterialIcons';
import {
Expand Down Expand Up @@ -30,24 +32,63 @@ export default class CometChatUserDetails extends React.Component {
}

componentDidMount() {
this.setStatusForUser();
this.checkRestrictions();
this.setStatusForUser();
this.UserDetailManager = new UserDetailManager();
this.UserDetailManager.attachListeners(this.updateUser);
}

updateUser = (key, user) => {
console.log('updateUser', key, user);
switch (key) {
case enums.USER_ONLINE:
case enums.USER_OFFLINE: {
if (
this.props.type === CometChat.ACTION_TYPE.TYPE_USER &&
this.props.item.uid === user.uid
) {
//if user presence feature is disabled
if (this.state.isUserPresenceEnabled === false) {
return false;
}

let status = '';
if (user.status === CometChat.USER_STATUS.OFFLINE) {
status = 'OFFLINE';
} else if (user.status === CometChat.USER_STATUS.ONLINE) {
status = 'ONLINE';
}

this.setState({ status: status });
}
break;
}
default:
break;
}
};

/**
* Update bottom sheet to 0th snap point if prop received as open
*/
componentDidUpdate(prevProps) {
if (!prevProps.open && this.props.open) {
this.sheetRef.current.snapTo(0);
}
if (JSON.stringify(prevProps.item) !== JSON.stringify(this.props.item)) {
this.setStatusForUser();
}
}

checkRestrictions = async () => {
let isSharedMediaEnabled = await this.context.FeatureRestriction.isSharedMediaEnabled();
let isBlockUserEnabled = await this.context.FeatureRestriction.isBlockUserEnabled();
let isViewProfileEnabled = await this.context.FeatureRestriction.isViewProfileEnabled();
let isUserPresenceEnabled = await this.context.FeatureRestriction.isUserPresenceEnabled();
let isSharedMediaEnabled =
await this.context.FeatureRestriction.isSharedMediaEnabled();
let isBlockUserEnabled =
await this.context.FeatureRestriction.isBlockUserEnabled();
let isViewProfileEnabled =
await this.context.FeatureRestriction.isViewProfileEnabled();
let isUserPresenceEnabled =
await this.context.FeatureRestriction.isUserPresenceEnabled();
this.setState({
restrictions: {
isSharedMediaEnabled,
Expand Down Expand Up @@ -127,7 +168,7 @@ export default class CometChatUserDetails extends React.Component {
this.props.item.blockedByMe &&
!this.state.restrictions?.isUserPresenceEnabled ? null : (
<CometChatUserPresence
status={this.props.item.status}
status={this.state.status}
style={{ top: 35 }}
cornerRadius={9}
borderColor={theme.borderColor.white}
Expand Down
1 change: 1 addition & 0 deletions src/utils/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const CLOSE_DETAIL = 'closeDetail';
export const CLOSE_DETAIL_CLICKED = 'closeDetailClicked';
export const CLOSE_THREAD_CLICKED = 'closeThreadClicked';
export const MENU_CLICKED = 'menuClicked';
export const STATUS_UPDATED = 'statusUpdated';

export const GROUP_UPDATED = 'groupUpdated';
export const GROUP_DELETED = 'groupDeleted';
Expand Down

0 comments on commit dfe438b

Please sign in to comment.