From 34420ad4f539dfdf247a461c3d828cb98fa63cfb Mon Sep 17 00:00:00 2001 From: Tirath Date: Mon, 8 Nov 2021 15:31:02 +0530 Subject: [PATCH] v3.0.2-1 --- .DS_Store | Bin 8196 -> 8196 bytes README.md | 2 +- package-lock.json | 3796 ----------------- package.json | 6 +- .../Messages/CometChatMessageHeader/index.js | 14 +- .../Messages/CometChatMessages/index.js | 4 + .../CometChatStickerKeyboard/index.js | 107 +- .../CometChatStickerKeyboard/styles.js | 8 +- .../Users/CometChatUserDetails/controller.js | 26 + .../Users/CometChatUserDetails/index.js | 53 +- src/utils/actions.js | 1 + 11 files changed, 162 insertions(+), 3855 deletions(-) delete mode 100644 package-lock.json create mode 100644 src/components/Users/CometChatUserDetails/controller.js diff --git a/.DS_Store b/.DS_Store index 7e3ed36cd9151a40ec6e003ef1668655d6b56ec0..5117ec083ec154565e48bcfc240974bae286ed2e 100644 GIT binary patch delta 40 wcmZp1XmOa}&nUJrU^hRb*k&F97N*TXLR(oUHaKl&m-xoA* { - 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, @@ -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: diff --git a/src/components/Messages/CometChatMessages/index.js b/src/components/Messages/CometChatMessages/index.js index 837b636..a04ce1f 100644 --- a/src/components/Messages/CometChatMessages/index.js +++ b/src/components/Messages/CometChatMessages/index.js @@ -375,6 +375,10 @@ class CometChatMessages extends React.PureComponent { break; case enums.TRANSIENT_MESSAGE_RECEIVED: this.liveReactionReceived(messages); + break; + case actions.STATUS_UPDATED: + this.setState({ user: { ...this.state.user, status: messages } }); + break; default: break; diff --git a/src/components/Messages/CometChatStickerKeyboard/index.js b/src/components/Messages/CometChatStickerKeyboard/index.js index 4b09342..665a035 100644 --- a/src/components/Messages/CometChatStickerKeyboard/index.js +++ b/src/components/Messages/CometChatStickerKeyboard/index.js @@ -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'; @@ -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 ( - this.onStickerSetClicked(sectionItem)}> - {sectionItem} - - ); - }, + const sectionItems = ( + { + const stickerSetThumbnail = + this.state.stickerSet[sectionItem][0].stickerUrl; + + return ( + this.onStickerSetClicked(sectionItem)}> + + + ); + }} + /> ); let activeStickerList = []; if (this.state.activeStickerList.length) { const stickerList = [...this.state.activeStickerList]; - activeStickerList = stickerList.map((stickerItem, key) => { - return ( - this.sendStickerMessage(stickerItem)}> - {stickerItem.stickerName} - - ); - }); + activeStickerList = ( + { + return ( + this.sendStickerMessage(stickerItem)}> + + + ); + }} + /> + ); } stickers = ( <> - - {activeStickerList} - + {activeStickerList} - - {sectionItems} - + {sectionItems} ); diff --git a/src/components/Messages/CometChatStickerKeyboard/styles.js b/src/components/Messages/CometChatStickerKeyboard/styles.js index a066d1d..25d4ebf 100644 --- a/src/components/Messages/CometChatStickerKeyboard/styles.js +++ b/src/components/Messages/CometChatStickerKeyboard/styles.js @@ -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, @@ -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, diff --git a/src/components/Users/CometChatUserDetails/controller.js b/src/components/Users/CometChatUserDetails/controller.js new file mode 100644 index 0000000..ae5b5a2 --- /dev/null +++ b/src/components/Users/CometChatUserDetails/controller.js @@ -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); + } +} diff --git a/src/components/Users/CometChatUserDetails/index.js b/src/components/Users/CometChatUserDetails/index.js index fc9bc98..2458c5c 100644 --- a/src/components/Users/CometChatUserDetails/index.js +++ b/src/components/Users/CometChatUserDetails/index.js @@ -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 { @@ -30,10 +32,42 @@ 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 */ @@ -41,13 +75,20 @@ export default class CometChatUserDetails extends React.Component { 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, @@ -127,7 +168,7 @@ export default class CometChatUserDetails extends React.Component { this.props.item.blockedByMe && !this.state.restrictions?.isUserPresenceEnabled ? null : (