From adbd7a250e31109d7a58829e3a7c666742ab453c Mon Sep 17 00:00:00 2001 From: "Tirath.CometChat" Date: Fri, 11 Jun 2021 15:29:26 +0530 Subject: [PATCH 1/2] optimistic UI --- src/components/.DS_Store | Bin 6148 -> 0 bytes src/components/Messages/.DS_Store | Bin 10244 -> 0 bytes .../Messages/CometChatMessageHeader/.DS_Store | Bin 6148 -> 0 bytes .../CometChatMessageHeader/resources/.DS_Store | Bin 6148 -> 0 bytes 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/components/.DS_Store delete mode 100644 src/components/Messages/.DS_Store delete mode 100644 src/components/Messages/CometChatMessageHeader/.DS_Store delete mode 100644 src/components/Messages/CometChatMessageHeader/resources/.DS_Store diff --git a/src/components/.DS_Store b/src/components/.DS_Store deleted file mode 100644 index a396720d10086dede0c63ae13f0a418f626210cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK-A)rh6g~r0w?$<6N21Bb#>50JAP@)_gtcH4jiIs)wgQ&jb|@Q{oo07Sg<8`m z@Lrz52k^=}FMI+MZ+rnSyz<&JKb4>AtueBvnfcD1pP8O-Gc!8?Kr*%RG=L5O8a9rJ z6n4K6?&qyTx|F3Gk%%#Dr~rk~sfX2$=-3c55Hs+vF~HZZ29Now#owv*>v+sT-zTT) zxnVRl^_g^aCoWySqG>5D)tlP3_E_DD?5GxI>|m2WW$kFsQF@Ls@0V^n8!oLE^`T|v zN4D$JKqR|miXmH1UBArg8CLVlp%}-K4oypH$)Y~iXv|G7Od2z@3(ZNRF+V>wY0S>d zHJeFo^!D`P>dyY*QR7wf^;^j-!Hq~rpTagAqta2RTRN!9Ldl1ApHSNml0Qr`oOuk zby|LYV#*y>F=pt*AjY~MQ0i}10=K-jyBpFdU)1};QouYf%R)DDnO`{NEo_Cz{c1$_ zSN&avGaew>#lH3e6mDd$vQpH9y0mi0$)8J{lI14JaQ;%w$#V zlIvH}OW!4%X*1ha?np(4v{V4n=C)Kdo#cGx(_}JjK2lx{Cg3hS1Pk_{4sYNX-obnL z2w&hE{2&Q3LT-@>GD{Z85_v$LkadzH1@eq+%KWbO+r8PIO(H2HcD&sKEATz$SJ2na zJDYaFpA;!t&jsfpE4)Ll&M5rF^Eh@yP@Jtg)NCP9f-Po5H&MVHxwdf$MFpj4#bog_b~%817{iF-~K2% zKmYIj`Tj40;x1+&X5jy1fFxF|l?>LV&eo19`B`gV+rh?#$F(Gi6ztS-EEIkek6{yn aK7%WWroxs)w4lTv0)mFPiy8Q<4EzN7iP50| diff --git a/src/components/Messages/.DS_Store b/src/components/Messages/.DS_Store deleted file mode 100644 index e2350f846e6f944f54036a94b43e68095b772361..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHM;ZD;~6g~yiGBsjCgdZkWj0r!8fj}U{n2a%uL`{q%XrczXb%E(cSL05n$8@NMMNel%dty1 z#1y{IwWkaPEmM#N#uGJYm3GO7TraZz!aLUW7Y1_9+gAu_Y$ru zXm{x`?)doGw1cx8HK~YSmCEZ?uT-phMPTr2cNcZ~rzkj!$ISx)BY|B`jQb^mJ0A1A z>v(?oe4BXcGPO|a;pa0ZPKr}(`L)2#uf@M7mxdz<8A;6ERp} z!ma!P?MDP{av++ddJV+(dnqC){86EBoTcHXdm!v}Vz8LDC&oIhluPB%2<_tN8V&}N z(5FU(a{S(_fw(%5Byprw5e8eafql@rq(UD20!oEyQLC7$hN)2X zR*Y4QBggZrS;wwylN_LVX>xB!%gqE@^3cGxa}roZGN|I$ch=yn9MUkAK*N1#;8`Rb z{r)IERW0`~;G z5>Zz*+=z*~sv#YxINmC{H2^&=pE%Mg{viLP=8}l>cO}k)EJ({EOiqT1KgfdA91;;$ zHN;KL1@VnpqBr1DogU(Nh%ZYIIipTaByVy|RlK;jOUb&xaw2aPXTuuu#-U(C6YP!7 z6dYGoM_g_`_C((=O^)8sb0vC-aZc;BpV$GBDL+GNB0X}d@x{ai872mS${}Z)=qD4? z0o|e3(f&-#P=CzFx@ZraJr4{^lP%u=U+e$>|Jielwpe@M40*s9$rtiD82o#$C~7p?CWk|PH)9e3#vi|=CJm&Aw diff --git a/src/components/Messages/CometChatMessageHeader/.DS_Store b/src/components/Messages/CometChatMessageHeader/.DS_Store deleted file mode 100644 index f1e9d24078fcbc089db9a04ae2fc209949a76cdf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKL2uJA6n^f?mK06&fV3TbLE=!MR+~0WXj0UT!){1HZ~(L=O~isiJS8b*l%ibt z5%3TADf|L{4t&oxgOVa{2!UVq{5?OvXE&c?J0>DAo+cxrJ`s6P#*U9-g>XA-OFGuG z4ivhNk`(3mrBt?}o#St0fah+LCYZN^YRuaA`MX2UsXEEkB+gZgD1JrmLT`W30*haZ z40#FW`xUK<|M*k9j}cO;Fv=9xgze=K#MbXK;#qZJ|I?@VBG0ONIQ%R+Yu#(>8=lwm zdYiqc;klZHbyQEQaa2C$+Wn|LkFEVcsr<^0;)hu}JMG^*QbiqQMOy0QEJ+dabLs3^)eb z4A{-cyWVbc9>;)V;6G=8_Xi1O3@kPV_11wxUjcw!xV6CM4@J(A76XfoL9{@GNd=lz zVXqj%q{A<5Twt*=Xwpg8%ZIQd3wuKmdUW(JbvTK@per2%j)7$c)=ag}=l{K5-~X4B zT+K1y82G0c5Z&YOc#KD~XKU->_^g%CGbjtkH3qLzVCbV5v3wM7L$$y!*#HI>8-wsb P+=qas!4-~yKgz&Y$E1pw diff --git a/src/components/Messages/CometChatMessageHeader/resources/.DS_Store b/src/components/Messages/CometChatMessageHeader/resources/.DS_Store deleted file mode 100644 index df5813e37d48f2220efd1c104d0f25aa2130bb53..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}&BV5S~F|P{eT4V~?Ipe1nGIfwM251vDfLB_N)A@f~~xpU(%-Z+=1wZR5=l zGec&--RXRt?zc^sB_bYeXLm$HBI>~fJ7;JbOsH_}$jBBXEog z$l49CW?P!kf~xDcq9wgd@?x6hMTRWAB76n>_*T=&oP+rWe}%8H<_#SBMCMI}bBRiG zWi0TXtiW7i+|I4m>(d5LDg3OxBEKJ0yuj=>;H+taTF;neV>SLd;0-W0tM;2NQnC7+ z7>0!cp+G2b#0p@~7VGs5qYVW@fly$lfP5bkxM1p78tSJ5jUEAjU4+%pm$QU$635iB zG{hAc8x?3&_9F%x9r48TQpeKJ=)`{bV6V)6LSe0r`zM-CoEkndu;-Lgo{aDX}F`Hqgyd@Wh=ght0A692bemR ShKRu8kATV$O(^iE3j6>UA7*&~ From 41da68e962c685705317a2bd08f06e192563b597 Mon Sep 17 00:00:00 2001 From: "Tirath.CometChat" Date: Fri, 11 Jun 2021 15:31:05 +0530 Subject: [PATCH 2/2] v2.3.4 --- README.md | 4 +- package.json | 9 +- .../Calls/CometChatIncomingCall/index.js | 18 +- .../CometChatIncomingDirectCall/index.js | 48 +- .../Calls/CometChatOutgoingCall/index.js | 3 +- .../CometChatOutgoingDirectCall/index.js | 9 +- .../CometChatConversationList/controller.js | 27 +- .../Chats/CometChatConversationList/index.js | 211 +++- .../resources/delete.png | Bin 0 -> 1586 bytes .../Chats/CometChatConversationList/styles.js | 1 + .../CometChatConversationListItem/index.js | 48 +- .../CometChatConversationListItem/styles.js | 3 +- .../index.js | 139 ++- src/components/CometChatUI/index.js | 141 ++- .../CometChatAddGroupMemberList/controller.js | 56 +- .../CometChatAddGroupMemberList/index.js | 16 +- .../CometChatAddGroupMemberListItem/index.js | 4 +- .../CometChatBanGroupMemberList/index.js | 3 +- .../CometChatBanGroupMemberListItem/index.js | 3 +- .../Groups/CometChatCreateGroup/index.js | 56 +- .../Groups/CometChatGroupDetails/index.js | 55 +- .../Groups/CometChatGroupList/index.js | 181 +-- .../Groups/CometChatGroupListItem/index.js | 2 +- .../CometChatGroupListWithMessages/index.js | 83 +- .../CometChatViewGroupMemberList/index.js | 3 +- .../CometChatViewGroupMemberListItem/index.js | 32 +- .../CometChatViewGroupMemberListItem/style.js | 6 +- .../CometChatMessageActions/actions.js | 54 +- .../composerActions.js | 50 +- .../CometChatMessageComposer/index.js | 42 +- .../Messages/CometChatMessageHeader/index.js | 42 +- .../Messages/CometChatMessageHeader/styles.js | 2 - .../CometChatMessageList/MessageFilter.js | 31 +- .../CometChatMessageList/controller.js | 26 +- .../Messages/CometChatMessageList/index.js | 58 +- .../Messages/CometChatMessageThread/index.js | 43 +- .../Messages/CometChatMessages/index.js | 273 +++-- .../Messages/CometChatReadReceipt/index.js | 20 +- .../index.js | 4 +- .../index.js | 22 +- .../index.js | 4 +- .../index.js | 4 +- .../index.js | 21 +- .../index.js | 4 +- .../CometChatSenderDirectCallBubble/index.js | 20 +- .../CometChatSenderTextMessageBubble/index.js | 17 +- .../Messages/CometChatVideoViewer/.DS_Store | Bin 6148 -> 0 bytes .../Extensions/CometChatCreatePoll/index.js | 3 +- .../CometChatMessageReactions/index.js | 13 + .../CometChatMessageReactions/styles.js | 2 - .../index.js | 11 +- .../index.js | 11 +- .../CometChatSenderPollMessageBubble/index.js | 9 +- .../index.js | 9 +- .../Shared/CometChatSharedMedia/controller.js | 17 +- .../Shared/CometChatSharedMedia/index.js | 26 +- .../Shared/CometChatUserPresence/index.js | 15 +- .../Users/CometChatUserDetails/index.js | 59 +- .../Users/CometChatUserList/controller.js | 56 +- .../Users/CometChatUserList/index.js | 149 ++- .../Users/CometChatUserListItem/index.js | 1 + .../CometChatUserListWithMessages/index.js | 72 +- src/utils/CometChatContext.js | 31 + src/utils/FeatureRestriction/index.js | 1003 +++++++++++++++++ src/utils/UIKitSettings.js | 488 ++++++++ src/utils/settings.js | 1 - 66 files changed, 3110 insertions(+), 764 deletions(-) create mode 100644 src/components/Chats/CometChatConversationList/resources/delete.png delete mode 100644 src/components/Messages/CometChatVideoViewer/.DS_Store create mode 100644 src/utils/CometChatContext.js create mode 100644 src/utils/FeatureRestriction/index.js create mode 100644 src/utils/UIKitSettings.js delete mode 100644 src/utils/settings.js diff --git a/README.md b/README.md index a536483..cdf7dc8 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ To install React-Native UI Kit, you need to first register on CometChat Dashboar ### ii. Add the CometChat Dependency ```javascript - npm install @cometchat-pro/react-native-chat@2.3.3 --save + npm install @cometchat-pro/react-native-chat@2.3.4 --save ``` ### iii. Other required DEPENDENCIES @@ -90,7 +90,7 @@ These packages help make the ui-kit smooth and functioning [emoji-mart-native](https://www.npmjs.com/package/emoji-mart-native)
[react-native-keep-awake](https://www.npmjs.com/package/react-native-keep-awake)
[react-native-webview](https://www.npmjs.com/package/react-native-webview)
- +[react-native-swipe-list-view](https://www.npmjs.com/package/react-native-swipe-list-view)

diff --git a/package.json b/package.json index 5eff8a6..f3ed270 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,6 @@ { "name": "cometchat-pro-react-native-ui-kit", - - "version": "2.3.3-1", - + "version": "2.3.4-1", "description": "Chat UI Kit for React Native App", "main": "./src/index.js", "scripts": { @@ -31,7 +29,8 @@ "@react-navigation/bottom-tabs": "^5.11.2", "@react-navigation/native": "^5.8.10", "@react-navigation/stack": "^5.12.8", - "react-native-video-controls": "^2.7.1" + "react-native-video-controls": "^2.7.1", + "react-native-swipe-list-view": "^3.2.8" }, "author": "Inscripts", "license": "ISC", @@ -52,7 +51,7 @@ }, "dependencies": { "@cometchat-pro/react-native-calls": "2.0.3-beta1", - "@cometchat-pro/react-native-chat": "2.3.3", + "@cometchat-pro/react-native-chat": "2.3.4", "@react-native-async-storage/async-storage": "^1.13.4", "lodash": "^4.17.20", "react-native-autolink": "^3.0.0", diff --git a/src/components/Calls/CometChatIncomingCall/index.js b/src/components/Calls/CometChatIncomingCall/index.js index e5b08c7..126a8df 100644 --- a/src/components/Calls/CometChatIncomingCall/index.js +++ b/src/components/Calls/CometChatIncomingCall/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useContext } from 'react'; import { View, TouchableOpacity, @@ -14,7 +14,7 @@ import { CometChatManager } from '../../../utils/controller'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import theme from '../../../resources/theme'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import { CallAlertManager } from './controller'; @@ -25,6 +25,7 @@ import videoCallIcon from './resources/incomingvideocall.png'; import { incomingCallAlert } from '../../../resources/audio'; import { logger } from '../../../utils/common'; import DropDownAlert from '../../Shared/DropDownAlert'; +import { CometChatContext } from '../../../utils/CometChatContext'; export default (props) => { let callAlertManager = null; @@ -32,12 +33,23 @@ export default (props) => { const incomingAlert = new Sound(incomingCallAlert); const [incomingCall, setIncomingCall] = useState(null); - + const [isMessagesSoundEnabled, setIsMessagesSoundEnabled] = useState(null); + const context = useContext(CometChatContext); + useEffect(() => { + checkRestrictions(); + }, []); + const checkRestrictions = async () => { + let isEnabled = await context.FeatureRestriction.isCallsSoundEnabled(); + setIsMessagesSoundEnabled(isEnabled); + }; /** * Play call alerts * @param */ const playIncomingAlert = () => { + if (!isMessagesSoundEnabled) { + return false; + } try { incomingAlert.setCurrentTime(0); incomingAlert.setNumberOfLoops(-1); diff --git a/src/components/Calls/CometChatIncomingDirectCall/index.js b/src/components/Calls/CometChatIncomingDirectCall/index.js index 830c5aa..6e6071d 100644 --- a/src/components/Calls/CometChatIncomingDirectCall/index.js +++ b/src/components/Calls/CometChatIncomingDirectCall/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect, useContext } from 'react'; import { View, TouchableOpacity, @@ -14,7 +14,7 @@ import { CometChatManager } from '../../../utils/controller'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import theme from '../../../resources/theme'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import { messageAlertManager } from './controller'; @@ -24,18 +24,30 @@ import audioCallIcon from './resources/incomingaudiocall.png'; import videoCallIcon from './resources/incomingvideocall.png'; import { incomingCallAlert } from '../../../resources/audio'; import { logger } from '../../../utils/common'; +import { CometChatContext } from '../../../utils/CometChatContext'; export default (props) => { let callAlertManager = null; const viewTheme = { ...theme, ...props.theme }; const incomingAlert = new Sound(incomingCallAlert); + const [isMessagesSoundEnabled, setIsMessagesSoundEnabled] = useState(null); const [incomingCall, setIncomingCall] = useState(null); - + const context = useContext(CometChatContext); + useEffect(() => { + checkRestrictions(); + }, []); + const checkRestrictions = async () => { + let isEnabled = await context.FeatureRestriction.isCallsSoundEnabled(); + setIsMessagesSoundEnabled(isEnabled); + }; /** * Play call alerts * @param */ const playIncomingAlert = () => { + if (!isMessagesSoundEnabled) { + return false; + } try { incomingAlert.setCurrentTime(0); incomingAlert.setNumberOfLoops(-1); @@ -217,29 +229,15 @@ export default (props) => { {incomingCall.sender.name} - {incomingCall.type === 'video' ? ( - - Incoming video call - - - Incoming video call - - - - ) : ( - - Incoming audio call - - - Incoming audio call - - + + + Incoming video call + + + Incoming video call + - )} + { - this.props.actionGenerated(actions.DIRECT_CALL_ENDED, call); - this.setState({ - outgoingCallScreen: false, - callInProgress: null, - callSettings: null, - }); + this.props.close(); }, onError: (error) => { console.log('Call Error: ', error); diff --git a/src/components/Chats/CometChatConversationList/controller.js b/src/components/Chats/CometChatConversationList/controller.js index d60a91b..9e62127 100644 --- a/src/components/Chats/CometChatConversationList/controller.js +++ b/src/components/Chats/CometChatConversationList/controller.js @@ -1,7 +1,7 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; import * as enums from '../../../utils/enums'; - +import { UIKitSettings } from '../../../utils/UIKitSettings'; export class ConversationListManager { conversationRequest = null; @@ -14,9 +14,28 @@ export class ConversationListManager { callListenerId = `chatlist_call_${new Date().getTime()}`; constructor() { - this.conversationRequest = new CometChat.ConversationsRequestBuilder() - .setLimit(30) - .build(); + let UIKitSettingsBuilder = new UIKitSettings(); + const chatListMode = UIKitSettingsBuilder.chatListMode; + const chatListFilterOptions = UIKitSettings.chatListFilterOptions; + switch (chatListMode) { + case chatListFilterOptions['USERS']: + this.conversationRequest = new CometChat.ConversationsRequestBuilder() + .setConversationType(CometChat.ACTION_TYPE.TYPE_USER) + .setLimit(30) + .build(); + break; + case chatListFilterOptions['GROUPS']: + this.conversationRequest = new CometChat.ConversationsRequestBuilder() + .setConversationType(CometChat.ACTION_TYPE.TYPE_GROUP) + .setLimit(30) + .build(); + break; + default: + this.conversationRequest = new CometChat.ConversationsRequestBuilder() + .setLimit(30) + .build(); + break; + } } fetchNextConversation() { diff --git a/src/components/Chats/CometChatConversationList/index.js b/src/components/Chats/CometChatConversationList/index.js index 5879148..53589fc 100644 --- a/src/components/Chats/CometChatConversationList/index.js +++ b/src/components/Chats/CometChatConversationList/index.js @@ -6,11 +6,16 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; import { CometChatManager } from '../../../utils/controller'; import { ConversationListManager } from './controller'; import * as enums from '../../../utils/enums'; -import { CometChatConversationListItem } from '../index'; +import CometChatConversationListItem from '../CometChatConversationListItem'; import theme from '../../../resources/theme'; import styles from './styles'; import Sound from 'react-native-sound'; import DropDownAlert from '../../Shared/DropDownAlert'; +import { UIKitSettings } from '../../../utils/UIKitSettings'; +import { + CometChatContextProvider, + CometChatContext, +} from '../../../utils/CometChatContext'; import { incomingOtherMessageAlert } from '../../../resources/audio'; import { View, @@ -18,15 +23,16 @@ import { SafeAreaView, KeyboardAvoidingView, Platform, - FlatList, + Image, + TouchableOpacity, } from 'react-native'; import { logger } from '../../../utils/common'; - +import { SwipeListView } from 'react-native-swipe-list-view'; class CometChatConversationList extends React.Component { loggedInUser = null; decoratorMessage = 'Loading...'; - + static contextType = CometChatContext; constructor(props) { super(props); @@ -34,13 +40,24 @@ class CometChatConversationList extends React.Component { conversationList: [], selectedConversation: undefined, showSmallHeader: false, + isMessagesSoundEnabled: true, }; this.chatListRef = React.createRef(); this.theme = { ...theme, ...this.props.theme }; this.audio = new Sound(incomingOtherMessageAlert); + this.UIKitSettingsBuilder = new UIKitSettings(); } componentDidMount() { + this.decoratorMessage = 'Loading...'; + if (this.ConversationListManager) { + this.ConversationListManager.removeListeners(); + } + this.setState({ conversationList: [] }); + this.ConversationListManager = new ConversationListManager(); + this.getConversations(); + this.ConversationListManager.attachListeners(this.conversationUpdated); + this.checkRestrictions(); try { this.navListener = this.props.navigation.addListener('focus', () => { this.decoratorMessage = 'Loading...'; @@ -51,12 +68,18 @@ class CometChatConversationList extends React.Component { this.ConversationListManager = new ConversationListManager(); this.getConversations(); this.ConversationListManager.attachListeners(this.conversationUpdated); + this.checkRestrictions(); }); } catch (error) { logger(error); } } + checkRestrictions = async () => { + let isMessagesSoundEnabled = await this.context.FeatureRestriction.isMessagesSoundEnabled(); + this.setState({ isMessagesSoundEnabled }); + }; + componentDidUpdate(prevProps) { try { const previousItem = JSON.stringify(prevProps.item); @@ -210,6 +233,45 @@ class CometChatConversationList extends React.Component { conversationList.splice(conversationKey, 1); conversationList.unshift(newConversationObj); this.setState({ conversationList: conversationList }); + } else { + // TODO: dont know what to do here + const chatListMode = this.UIKitSettingsBuilder.chatListMode; + const chatListFilterOptions = UIKitSettings.chatListFilterOptions; + if (chatListMode !== chatListFilterOptions['USERS_AND_GROUPS']) { + if ( + (chatListMode === chatListFilterOptions['USERS'] && + lastMessage.receiverType === CometChat.RECEIVER_TYPE.GROUP) || + (chatListMode === chatListFilterOptions['GROUPS'] && + lastMessage.receiverType === CometChat.RECEIVER_TYPE.USER) + ) { + return false; + } + } + + const getConversationId = () => { + let conversationId = null; + if (this.getContext().type === CometChat.RECEIVER_TYPE.USER) { + const users = [this.loggedInUser.uid, this.getContext().item.uid]; + conversationId = users.sort().join('_user_'); + } else if ( + this.getContext().type === CometChat.RECEIVER_TYPE.GROUP + ) { + conversationId = `group_${this.getContext().item.guid}`; + } + + return conversationId; + }; + + let newConversation = new CometChat.Conversation(); + newConversation.setConversationId(getConversationId()); + newConversation.setConversationType(this.getContext().type); + newConversation.setConversationWith(this.getContext().item); + newConversation.setLastMessage(lastMessage); + newConversation.setUnreadMessageCount(0); + + conversationList.unshift(newConversation); + this.setState({ conversationList: conversationList }); + // this.getContext().setLastMessage({}); } } @@ -256,6 +318,19 @@ class CometChatConversationList extends React.Component { * @param actionBy: user object of action taker */ conversationUpdated = (key, item, message, options, actionBy) => { + const chatListMode = this.UIKitSettingsBuilder.chatListMode; + const chatListFilterOptions = UIKitSettings.chatListFilterOptions; + + if (chatListMode !== chatListFilterOptions['USERS_AND_GROUPS']) { + if ( + (chatListMode === chatListFilterOptions['USERS'] && + message.receiverType === CometChat.RECEIVER_TYPE.GROUP) || + (chatListMode === chatListFilterOptions['GROUPS'] && + message.receiverType === CometChat.RECEIVER_TYPE.USER) + ) { + return false; + } + } try { switch (key) { case enums.USER_ONLINE: @@ -339,9 +414,10 @@ class CometChatConversationList extends React.Component { */ playAudio = () => { try { - if (this.state.playingAudio) { + if (this.state.playingAudio || !this.state.isMessagesSoundEnabled) { return false; } + this.setState({ playingAudio: true }, () => { this.audio.setCurrentTime(0); this.audio.play(() => { @@ -849,39 +925,102 @@ class CometChatConversationList extends React.Component { this.getConversations(); }; + deleteConversations = (conversation) => { + let conversationWith = + conversation.conversationType === CometChat.RECEIVER_TYPE.GROUP + ? conversation?.conversationWith?.guid + : conversation?.conversationWith?.uid; + CometChat.deleteConversation( + conversationWith, + conversation.conversationType, + ) + .then((deletedConversation) => { + const newConversationList = [...this.state.conversationList]; + const conversationKey = newConversationList.findIndex( + (c) => c.conversationId === conversation.conversationId, + ); + + newConversationList.splice(conversationKey, 1); + this.setState({ conversationList: newConversationList }); + }) + .catch((error) => { + logger(error); + }); + }; + render() { return ( - - - - {this.listHeaderComponent()} - { - return ( - - ); - }} - ListEmptyComponent={this.listEmptyContainer} - onScroll={this.handleScroll} - onEndReached={this.endReached} - onEndReachedThreshold={0.3} - showsVerticalScrollIndicator={false} - scrollEnabled - /> - - (this.dropDownAlertRef = ref)} /> - + (this.contextProviderRef = el)}> + + + + {this.listHeaderComponent()} + item?.conversationId + '_' + index} + renderHiddenItem={(data, rowMap) => ( + + this.deleteConversations(data.item)}> + + Delete + + + )} + leftOpenValue={0} + rightOpenValue={-75} + previewRowKey={'0'} + previewOpenValue={-40} + previewOpenDelay={3000} + renderItem={({ item }) => { + return ( + + ); + }} + ListEmptyComponent={this.listEmptyContainer} + onScroll={this.handleScroll} + onEndReached={this.endReached} + onEndReachedThreshold={0.3} + showsVerticalScrollIndicator={false} + scrollEnabled + /> + + (this.dropDownAlertRef = ref)} /> + + ); } } diff --git a/src/components/Chats/CometChatConversationList/resources/delete.png b/src/components/Chats/CometChatConversationList/resources/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..76d3b448683dda237f98c6e14da6fa958750ecc5 GIT binary patch literal 1586 zcmV-22F>}2P)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91HlPCl1ONa40RR91KL7v#0RB@<)c^nmoJmAMRA>e5T05v6RTO&m2#Nu*vQflF8yf{hFolJUg@QI>p%Nt6TL>0uUL^#HRV*TYP$UXQ zjfkK4dC%mz)@9DHXU#e@_cJs1zTknKIcJ~!S?ipA&fJ^(Mk^h(&CShKgn1NlV7NX0P*6yY>fXA=(aWG z?R5^xZ-=ZKU|pyV%nN>!b6|4-{UJ;|ZYIBi?l|OMGpDM(P}~7g96vy}2WM_m9eN*w z*r#S|UWaa~GJ^eskh3P%^}UmD2>|4j0dtMBZPOvnF%#>~HovC%sa974ohM@sPZ`}L zD(C0oPZDcvGY_$elPtpUoFz8iZq)Zatm>_h?NhAo1;+Lf#G2$bRM*|A!1#W|y3Xix zs*{-b5I5-=8jRrl9G5 zw2}P68o>OdfH2P94Y@PM3q{*bRSY~<5JH z3iZ*Ly%TfqF$FP8DXNdg?39>0n64ZYgs#5Xpqfg3w7luyE{|T{V+uk+)>s&Y`siZO z#Vu;D#1w>b^Rv#`*w1hwFWUHoFFWmP6>=%`Px zJ4PH@!|njnE&|cA;(S|EpBOLsy4;E{*^Zxf#|jH|+=dUV>BDRc5`pOIN4s2Kee^=2 zU#(i8Q+$>9(-5PhdzVEZ3bK+cGf}cujkG zxRr}Q6l4O{^whJt}=zHTuGAr^rs$Tm`( zSDzS<^Mep`@39C(K@wP7)AEh+=-WB5S>9tj6VsB5_PiAMIW;!DI5;;*DaJF#q!B2` zZ7tgCZqc{%9doPVk|-E0tu|uOUSlm4vA6?mq&Oe#b@y|`+%c)->iW7@pp|5qK_s?R zJNByp*2Di-nCIMj7_%FH3es4dcjfPn32n>P#g4s)XeWz^Yj}QB^wZ;AbP~CDaO-Kg zah~Kz`fZ4|nTTnSa*S(x6{79)(jatTv;(pi;(ky_zmM$+E|o6)uBKF!#Q^$OAljaC zwo%vghgfdA-3xjJyTG&YT?`!im}e{(Z)}En{(hEgE@w7Y3X(0wqGSj-w%u5|E23h6 z{yvk#oke4oQGvwAS_2rr1+gWU2{W@AdG3SokD#^P&=#~2Afmm208g7B{4?^8AbP_Y z)0tGnMeq+m^bgm5L^av-IB_Nr+pkNt1mlAf6KFC7kwZ&BCPDZX9rtr^69qqqK$k(* zQsf0bPayZ*9_1Wb1brBC6!IHnsJ4MbpFv)RxUVl+Mva$8&I?KS_wuW``HuAbgz_~m kioPzWj$r;DrkfS`56kLt_0tMAumAu607*qoM6N<$g0G3*Z~y=R literal 0 HcmV?d00001 diff --git a/src/components/Chats/CometChatConversationList/styles.js b/src/components/Chats/CometChatConversationList/styles.js index 96125c1..63aace0 100644 --- a/src/components/Chats/CometChatConversationList/styles.js +++ b/src/components/Chats/CometChatConversationList/styles.js @@ -57,4 +57,5 @@ export default StyleSheet.create({ justifyContent: 'center', }, flexGrow1: { flexGrow: 1 }, + deleteText: { color: '#fff' }, }); diff --git a/src/components/Chats/CometChatConversationListItem/index.js b/src/components/Chats/CometChatConversationListItem/index.js index 6040c8d..05b5b37 100644 --- a/src/components/Chats/CometChatConversationListItem/index.js +++ b/src/components/Chats/CometChatConversationListItem/index.js @@ -12,6 +12,7 @@ import styles from './styles'; import { View, TouchableOpacity, Text } from 'react-native'; import { Platform } from 'react-native'; import { logger } from '../../../utils/common'; +import { CometChatContext } from '../../../utils/CometChatContext'; const conversation = 'conversation'; const lastMessage = 'lastMessage'; @@ -19,6 +20,7 @@ const deletedAt = 'deletedAt'; const sentAt = 'sentAt'; class CometChatConversationListItem extends React.Component { + static contextType = CometChatContext; constructor(props) { super(props); @@ -26,19 +28,35 @@ class CometChatConversationListItem extends React.Component { lastMessage: '', lastMessageTimestamp: '', isThreaded: false, + restrictions: null, }; } componentDidMount() { - const message = this.getLastMessage(); const timestamp = this.getLastMessageTimestamp(); this.setState({ - lastMessage: message || '', lastMessageTimestamp: timestamp, }); + + this.checkRestrictions(); } + checkRestrictions = async () => { + let isUnreadCountEnabled = await this.context.FeatureRestriction.isUnreadCountEnabled(); + let isHideDeletedMessagesEnabled = await this.context.FeatureRestriction.isHideDeletedMessagesEnabled(); + + this.setState( + { + restrictions: { isUnreadCountEnabled, isHideDeletedMessagesEnabled }, + }, + () => { + const message = this.getLastMessage(); + this.setState({ lastMessage: message || '' }); + }, + ); + }; + componentDidUpdate(prevProps) { try { const previousItem = JSON.stringify(prevProps.conversation); @@ -83,10 +101,14 @@ class CometChatConversationListItem extends React.Component { const { lastMessage: lastMessageObject } = this.props.conversation; if (Object.prototype.hasOwnProperty.call(lastMessageObject, deletedAt)) { - message = - this.props.loggedInUser.uid === lastMessageObject.sender.uid - ? '⚠ You deleted this message.' - : '⚠ This message was deleted.'; + if (this.state?.restrictions?.isHideDeletedMessagesEnabled) { + message = ''; + } else { + message = + this.props.loggedInUser.uid === lastMessageObject.sender.uid + ? '⚠ You deleted this message.' + : '⚠ This message was deleted.'; + } } else { switch (lastMessageObject.category) { case 'message': @@ -334,6 +356,7 @@ class CometChatConversationListItem extends React.Component { return ( @@ -379,15 +402,16 @@ class CometChatConversationListItem extends React.Component { alignItems: 'center', }}> - {`${this.state.isThreaded ? 'In a thread : ' : ''}` + this.state.lastMessage} - - + + {this.state.restrictions?.isUnreadCountEnabled ? ( + + ) : null} diff --git a/src/components/Chats/CometChatConversationListItem/styles.js b/src/components/Chats/CometChatConversationListItem/styles.js index 68fcc15..75d2d93 100644 --- a/src/components/Chats/CometChatConversationListItem/styles.js +++ b/src/components/Chats/CometChatConversationListItem/styles.js @@ -7,10 +7,11 @@ export default StyleSheet.create({ flexDirection: 'row', alignItems: 'center', width: '100%', - maxHeight: 64, + height: 64, paddingHorizontal: 16, justifyContent: 'center', marginBottom: 8, + backgroundColor: '#fff', }, avatarStyle: { flexWrap: 'wrap', diff --git a/src/components/Chats/CometChatConversationListWithMessages/index.js b/src/components/Chats/CometChatConversationListWithMessages/index.js index c3c954f..b825fa0 100644 --- a/src/components/Chats/CometChatConversationListWithMessages/index.js +++ b/src/components/Chats/CometChatConversationListWithMessages/index.js @@ -6,13 +6,14 @@ import { CometChatManager } from '../../../utils/controller'; import * as enums from '../../../utils/enums'; import DropDownAlert from '../../Shared/DropDownAlert'; import * as actions from '../../../utils/actions'; -import { CometChatConversationList } from '../index'; +import CometChatConversationList from '../CometChatConversationList'; import { CometChatIncomingCall, CometChatOutgoingCall, CometChatOutgoingDirectCall, CometChatIncomingDirectCall, } from '../../Calls'; +import { CometChatContextProvider } from '../../../utils/CometChatContext'; import { CometChatImageViewer } from '../../Messages'; import theme from '../../../resources/theme'; import { View } from 'react-native'; @@ -44,10 +45,12 @@ class CometChatConversationListWithMessages extends React.Component { groupMessage: {}, lastMessage: {}, }; + this.theme = { ...theme, ...this.props.theme }; } componentDidMount() { + this.checkRestrictions(); if (!Object.keys(this.state.item).length) { this.toggleSideBar(); } @@ -65,6 +68,12 @@ class CometChatConversationListWithMessages extends React.Component { }); } + checkRestrictions = async () => { + let context = this.contextProviderRef.state; + let isCallActionMessagesEnabled = await context.FeatureRestriction.isCallActionMessagesEnabled(); + this.setState({ isCallActionMessagesEnabled }); + }; + changeTheme = () => { const theme = this.state.darkTheme; this.setState({ darkTheme: !theme }); @@ -114,8 +123,9 @@ class CometChatConversationListWithMessages extends React.Component { break; case actions.VIDEO_CALL: this.setState({ joinDirectCall: false }, () => { - this.videoCall(true); + this.videoCall(null); }); + break; case actions.VIEW_DETAIL: case actions.CLOSE_DETAIL_CLICKED: @@ -185,9 +195,16 @@ class CometChatConversationListWithMessages extends React.Component { break; case actions.ACCEPT_DIRECT_CALL: - this.setState({ joinDirectCall: true }, () => { - this.videoCall(true); - }); + this.setState( + { + joinDirectCall: true, + item: item.receiver, + type: item.receiverType, + }, + () => { + this.videoCall(true); + }, + ); default: break; } @@ -294,6 +311,7 @@ class CometChatConversationListWithMessages extends React.Component { return; } + receiverId = this.state.item.uid; receiverType = CometChat.RECEIVER_TYPE.USER; @@ -571,65 +589,72 @@ class CometChatConversationListWithMessages extends React.Component { } return ( - + (this.contextProviderRef = el)}> - + + + {imageView} + {this.state.isCallActionMessagesEnabled ? ( + { + this.dropDownAlertRef?.showMessage(type, message); + }} + theme={this.theme} + loggedInUser={this.loggedInUser} + actionGenerated={this.actionHandler} + outgoingCall={this.state.outgoingCall} + /> + ) : null} + - - {imageView} - { - this.dropDownAlertRef?.showMessage(type, message); - }} - theme={this.theme} - loggedInUser={this.loggedInUser} - actionGenerated={this.actionHandler} - outgoingCall={this.state.outgoingCall} - /> - - - (this.dropDownAlertRef = ref)} /> - - - {this.state.ongoingDirectCall ? ( - this.actionHandler(actions.DIRECT_CALL_ENDED)} - theme={this.props.theme} - item={this.state.item} - type={this.state.type} - lang={this.state.lang} - callType={CometChat.CALL_TYPE.VIDEO} - joinDirectCall={this.state.joinDirectCall} + incomingCall={this.state.incomingCall} + outgoingCall={this.state.outgoingCall} loggedInUser={this.loggedInUser} actionGenerated={this.actionHandler} /> - ) : null} - + + (this.dropDownAlertRef = ref)} /> + + {this.state.isCallActionMessagesEnabled ? ( + + ) : null} + {this.state.ongoingDirectCall ? ( + this.actionHandler(actions.DIRECT_CALL_ENDED)} + theme={this.props.theme} + item={this.state.item} + type={this.state.type} + lang={this.state.lang} + callType={CometChat.CALL_TYPE.VIDEO} + joinDirectCall={this.state.joinDirectCall} + loggedInUser={this.loggedInUser} + actionGenerated={this.actionHandler} + /> + ) : null} + + ); } } diff --git a/src/components/CometChatUI/index.js b/src/components/CometChatUI/index.js index f701e53..fbe47d3 100644 --- a/src/components/CometChatUI/index.js +++ b/src/components/CometChatUI/index.js @@ -1,10 +1,11 @@ /* eslint-disable import/no-duplicates */ -import * as React from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; - +import { View, Text } from 'react-native'; import { CometChatGroupListWithMessages } from '../Groups'; import { CometChatUserListWithMessages } from '../Users'; import { CometChatConversationListWithMessages } from '../Chats'; +import { CometChatContextProvider } from '../../utils/CometChatContext'; import { CometChatUserProfile } from '../UserProfile'; import Ionicons from 'react-native-vector-icons/Ionicons'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; @@ -14,53 +15,97 @@ import { heightRatio } from '../../utils/consts'; const Tab = createBottomTabNavigator(); -export default () => { +function CometChatUI() { + const [tabs, setTabs] = useState(null); + const contextRef = useRef(null); + + useEffect(() => { + checkRestrictions(); + }, []); + const checkRestrictions = async () => { + let isChatEnabled = await contextRef.current.state.FeatureRestriction.isRecentChatListEnabled(); + let isGroupListEnabled = await contextRef.current.state.FeatureRestriction.isGroupListEnabled(); + let isUserSettingsEnabled = await contextRef.current.state.FeatureRestriction.isUserSettingsEnabled(); + let isUserListEnabled = await contextRef.current.state.FeatureRestriction.isUserListEnabled(); + let isCallListEnabled = await contextRef.current.state.FeatureRestriction.isCallListEnabled(); + setTabs({ + isChatEnabled, + isGroupListEnabled, + isUserSettingsEnabled, + isUserListEnabled, + isCallListEnabled, + }); + }; return ( - ({ - tabBarIcon: ({ color }) => { - let iconName; + + {tabs ? ( + ({ + tabBarIcon: ({ color }) => { + let iconName; - if (route.name === 'Chats') { - return ( - - ); - } - if (route.name === 'More') { - return ( - - ); - } - if (route.name === 'Users') { - iconName = 'ios-person-circle-sharp'; - } else if (route.name === 'Groups') { - iconName = 'people'; - } + if (route.name === 'Chats') { + return ( + + ); + } + if (route.name === 'More') { + return ( + + ); + } + if (route.name === 'Users') { + iconName = 'ios-person-circle-sharp'; + } else if (route.name === 'Groups') { + iconName = 'people'; + } - // You can return any component that you like here! - return ( - - ); - }, - })} - tabBarOptions={{ - activeTintColor: theme.color.blue, - inactiveTintColor: 'rgba(0,0,0,0.5)', - activeBackgroundColor: theme.color.white, - inactiveBackgroundColor: theme.color.white, - labelStyle: { fontSize: 12 }, - }}> - - - - - + // You can return any component that you like here! + return ( + + ); + }, + })} + tabBarOptions={{ + activeTintColor: theme.color.blue, + inactiveTintColor: 'rgba(0,0,0,0.5)', + activeBackgroundColor: theme.color.white, + inactiveBackgroundColor: theme.color.white, + labelStyle: { fontSize: 12 }, + }}> + {tabs.isChatEnabled && ( + + )} + {tabs.isUserListEnabled && ( + + )} + {tabs.isGroupListEnabled && ( + + )} + {tabs.isUserSettingsEnabled && ( + + )} + + ) : null} + ); -}; +} + +export default CometChatUI; diff --git a/src/components/Groups/CometChatAddGroupMemberList/controller.js b/src/components/Groups/CometChatAddGroupMemberList/controller.js index 225ef3b..d10cb7e 100644 --- a/src/components/Groups/CometChatAddGroupMemberList/controller.js +++ b/src/components/Groups/CometChatAddGroupMemberList/controller.js @@ -1,24 +1,52 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; - +import { UIKitSettings } from '../../../utils/UIKitSettings'; export class AddMembersManager { membersRequest = null; userListenerId = `add_member_user_${new Date().getTime()}`; - constructor(friendsOnly, searchKey) { - if (searchKey) { - this.membersRequest = new CometChat.UsersRequestBuilder() - .setLimit(30) - .friendsOnly(friendsOnly) - .setSearchKeyword(searchKey) - .build(); - } else { - this.membersRequest = new CometChat.UsersRequestBuilder() - .setLimit(30) - .friendsOnly(friendsOnly) - .build(); - } + constructor(searchKey) { + this.searchKey = searchKey; } + initializeMembersRequest = () => { + let UIKitSettingsBuilder = new UIKitSettings(); + const userListMode = UIKitSettingsBuilder.userListMode; + const userListModeOptions = UIKitSettings.userListFilterOptions; + + return new Promise((resolve, reject) => { + if (userListMode === userListModeOptions['ALL']) { + if (this.searchKey) { + this.membersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .setSearchKeyword(this.searchKey) + .build(); + } else { + this.membersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .build(); + } + + return resolve(this.membersRequest); + } else if (userListMode === userListModeOptions['FRIENDS']) { + if (this.searchKey) { + this.membersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .friendsOnly(true) + .setSearchKeyword(this.searchKey) + .build(); + } else { + this.membersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .friendsOnly(true) + .build(); + } + + return resolve(this.membersRequest); + } else { + return reject({ message: 'Invalid filter for userlist' }); + } + }); + }; fetchNextUsers() { return this.membersRequest.fetchNext(); diff --git a/src/components/Groups/CometChatAddGroupMemberList/index.js b/src/components/Groups/CometChatAddGroupMemberList/index.js index 76fbdf4..b99ce2f 100644 --- a/src/components/Groups/CometChatAddGroupMemberList/index.js +++ b/src/components/Groups/CometChatAddGroupMemberList/index.js @@ -21,7 +21,7 @@ import Icon from 'react-native-vector-icons/Ionicons'; import { CometChatManager } from '../../../utils/controller'; import { AddMembersManager } from './controller'; -import { CometChatAddGroupMemberListItem } from '../index'; +import CometChatAddGroupMemberListItem from '../CometChatAddGroupMemberListItem'; import GroupDetailContext from '../CometChatGroupDetails/context'; import theme from '../../../resources/theme'; import style from './styles'; @@ -51,9 +51,11 @@ class CometChatAddGroupMemberList extends React.Component { this.friendsOnly = this.props.friendsOnly; } - this.AddMembersManager = new AddMembersManager(this.friendsOnly); - this.getUsers(); - this.AddMembersManager.attachListeners(this.userUpdated); + this.AddMembersManager = new AddMembersManager(); + this.AddMembersManager.initializeMembersRequest().then(() => { + this.getUsers(); + this.AddMembersManager.attachListeners(this.userUpdated); + }); } componentDidUpdate() { @@ -135,10 +137,7 @@ class CometChatAddGroupMemberList extends React.Component { } this.timeout = setTimeout(() => { - this.AddMembersManager = new AddMembersManager( - this.friendsOnly, - val, - ); + this.AddMembersManager = new AddMembersManager(val); this.setState( { userList: [], @@ -427,6 +426,7 @@ class CometChatAddGroupMemberList extends React.Component { item.uid + '_' + index} data={filteredUserList} renderItem={({ item }) => { const chr = item.name[0].toUpperCase(); diff --git a/src/components/Groups/CometChatAddGroupMemberListItem/index.js b/src/components/Groups/CometChatAddGroupMemberListItem/index.js index e30b865..f2afdaf 100644 --- a/src/components/Groups/CometChatAddGroupMemberListItem/index.js +++ b/src/components/Groups/CometChatAddGroupMemberListItem/index.js @@ -1,6 +1,8 @@ import React, { useState } from 'react'; import theme from '../../../resources/theme'; -import { CometChatUserPresence, CometChatAvatar } from '../../Shared'; +import CometChatUserPresence from '../../Shared/CometChatUserPresence'; +import CometChatAvatar from '../../Shared/CometChatUserPresence'; + import { Text, View, Image, TouchableOpacity } from 'react-native'; import style from './styles'; import checkboxActive from './resources/checkbox-blue-active.png'; diff --git a/src/components/Groups/CometChatBanGroupMemberList/index.js b/src/components/Groups/CometChatBanGroupMemberList/index.js index 2dd3f61..3cd8a42 100644 --- a/src/components/Groups/CometChatBanGroupMemberList/index.js +++ b/src/components/Groups/CometChatBanGroupMemberList/index.js @@ -6,7 +6,7 @@ import { View, Text, FlatList, Modal, TouchableOpacity } from 'react-native'; import BottomSheet from 'reanimated-bottom-sheet'; import DropDownAlert from '../../Shared/DropDownAlert'; -import { CometChatBanGroupMemberListItem } from '../index'; +import CometChatBanGroupMemberListItem from '../CometChatBanGroupMemberListItem'; import GroupDetailContext from '../CometChatGroupDetails/context'; import style from './styles'; @@ -202,6 +202,7 @@ export default class CometChatBanGroupMemberList extends React.Component { item.uid + '_' + index} renderItem={({ item, index }) => { return ( ; class CometChatCreateGroup extends React.Component { + static contextType = CometChatContext; constructor(props) { super(props); this.state = { @@ -29,11 +31,29 @@ class CometChatCreateGroup extends React.Component { name: '', type: 'Select group type', password: '', + restrictions: null, }; this.sheetRef = React.createRef(null); } + componentDidMount() { + this.checkRestrictions(); + } + + checkRestrictions = async () => { + let isPublicGroupEnabled = await this.context.FeatureRestriction.isPublicGroupEnabled(); + let isPasswordGroupEnabled = await this.context.FeatureRestriction.isPasswordGroupEnabled(); + let isPrivateGroupEnabled = await this.context.FeatureRestriction.isPrivateGroupEnabled(); + this.setState({ + restrictions: { + isPublicGroupEnabled, + isPasswordGroupEnabled, + isPrivateGroupEnabled, + }, + }); + }; + componentDidUpdate(prevProps, prevState) { if (!prevState.open && this.state.open) { this.sheetRef.current.snapTo(0); @@ -253,21 +273,27 @@ class CometChatCreateGroup extends React.Component { label="Select group type" value="Select group type" /> - - - + {this.state.restrictions?.isPublicGroupEnabled ? ( + + ) : null} + {this.state.restrictions?.isPrivateGroupEnabled ? ( + + ) : null} + {this.state.restrictions?.isPasswordGroupEnabled ? ( + + ) : null} {password} diff --git a/src/components/Groups/CometChatGroupDetails/index.js b/src/components/Groups/CometChatGroupDetails/index.js index 199ddcc..a23c324 100644 --- a/src/components/Groups/CometChatGroupDetails/index.js +++ b/src/components/Groups/CometChatGroupDetails/index.js @@ -4,7 +4,8 @@ import React from 'react'; import { View, Text, TouchableOpacity, Dimensions, Modal } from 'react-native'; import theme from '../../../resources/theme'; import Icon from 'react-native-vector-icons/MaterialIcons'; -import { CometChatSharedMedia, CometChatAvatar } from '../../Shared'; +import CometChatSharedMedia from '../../Shared/CometChatSharedMedia'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import style from './styles'; import BottomSheet from 'reanimated-bottom-sheet'; import { CometChat } from '@cometchat-pro/react-native-chat'; @@ -13,21 +14,21 @@ import { GroupDetailManager } from './controller'; import { CometChatManager } from '../../../utils/controller'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; -import { - CometChatAddGroupMemberList, - CometChatViewGroupMemberList, - CometChatBanGroupMemberList, -} from '../index'; +import CometChatAddGroupMemberList from '../CometChatAddGroupMemberList'; +import CometChatViewGroupMemberList from '../CometChatViewGroupMemberList'; +import CometChatBanGroupMemberList from '../CometChatBanGroupMemberList'; import { deviceHeight } from '../../../utils/consts'; import { logger } from '../../../utils/common'; import DropDownAlert from '../../Shared/DropDownAlert'; import styles from '../../Shared/CometChatAvatar/styles'; +import { CometChatContext } from '../../../utils/CometChatContext'; const ADD_MEMBER = 'addMember'; const VIEW_MEMBER = 'viewMember'; const BAN_MEMBER = 'banMember'; export default class CometChatGroupDetails extends React.Component { + static contextType = CometChatContext; constructor(props) { super(props); this.state = { @@ -41,6 +42,8 @@ export default class CometChatGroupDetails extends React.Component { banMember: false, addAdministrator: false, addModerator: false, + enableLeaveGroup: false, + restrictions: null, }; this.viewTheme = { ...theme, ...this.props.theme }; @@ -60,6 +63,7 @@ export default class CometChatGroupDetails extends React.Component { this.getGroupMembers(); this.getBannedGroupMembers(); this.GroupDetailManager.attachListeners(this.groupUpdated); + this.checkRestrictions(); } componentDidUpdate(prevProps) { @@ -84,6 +88,24 @@ export default class CometChatGroupDetails extends React.Component { } } + checkRestrictions = async () => { + let isJoinLeaveGroupsEnabled = await this.context.FeatureRestriction.isJoinLeaveGroupsEnabled(); + let isAddingGroupMembersEnabled = await this.context.FeatureRestriction.isAddingGroupMembersEnabled(); + + let isViewingGroupMembersEnabled = await this.context.FeatureRestriction.isViewingGroupMembersEnabled(); + let isSharedMediaEnabled = await this.context.FeatureRestriction.isSharedMediaEnabled(); + let isGroupDeletionEnabled = await this.context.FeatureRestriction.isGroupDeletionEnabled(); + this.setState({ + restrictions: { + isJoinLeaveGroupsEnabled, + isAddingGroupMembersEnabled, + isViewingGroupMembersEnabled, + isSharedMediaEnabled, + isGroupDeletionEnabled, + }, + }); + }; + componentWillUnmount() { this.GroupDetailManager.removeListeners(); this.GroupDetailManager = null; @@ -584,10 +606,16 @@ export default class CometChatGroupDetails extends React.Component { ); + if (!this.state.restrictions?.isViewingGroupMembersEnabled) { + viewMembersBtn = null; + } let addMembersBtn = null; let deleteGroupBtn = null; let bannedMembersBtn = null; - if (this.props.item.scope === CometChat.GROUP_MEMBER_SCOPE.ADMIN) { + if ( + this.props.item.scope === CometChat.GROUP_MEMBER_SCOPE.ADMIN && + this.state.restrictions?.isAddingGroupMembersEnabled + ) { addMembersBtn = ( { @@ -633,7 +661,10 @@ export default class CometChatGroupDetails extends React.Component { ); } let leaveGroupBtn = null; - if (this.props.item.scope !== CometChat.GROUP_MEMBER_SCOPE.ADMIN) { + if ( + this.props.item.scope !== CometChat.GROUP_MEMBER_SCOPE.ADMIN && + this.state.restrictions?.isJoinLeaveGroupsEnabled + ) { leaveGroupBtn = ( { @@ -663,6 +694,14 @@ export default class CometChatGroupDetails extends React.Component { /> ); + if (!this.state.restrictions?.isSharedMediaEnabled) { + sharedMediaView = null; + } + + if (!this.state.restrictions?.isGroupDeletionEnabled) { + deleteGroupBtn = null; + } + let members = ( Members diff --git a/src/components/Groups/CometChatGroupList/index.js b/src/components/Groups/CometChatGroupList/index.js index f9d391d..b804f0a 100644 --- a/src/components/Groups/CometChatGroupList/index.js +++ b/src/components/Groups/CometChatGroupList/index.js @@ -8,8 +8,13 @@ import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import DropDownAlert from '../../Shared/DropDownAlert'; import { GroupListManager } from './controller'; +import { + CometChatContextProvider, + CometChatContext, +} from '../../../utils/CometChatContext'; -import { CometChatCreateGroup, CometChatGroupListItem } from '../index'; +import CometChatCreateGroup from '../CometChatCreateGroup'; +import CometChatGroupListItem from '../CometChatGroupListItem'; import theme from '../../../resources/theme'; @@ -37,7 +42,7 @@ import { logger } from '../../../utils/common'; class CometChatGroupList extends React.Component { timeout; - + static contextType = CometChatContext; passwordScreen = null; loggedInUser = null; @@ -79,11 +84,25 @@ class CometChatGroupList extends React.Component { this.GroupListManager = new GroupListManager(); this.getGroups(); //you are getting groups here. this.GroupListManager.attachListeners(this.groupUpdated); + this.checkRestrictions(); }); } catch (error) { logger(error); } } + checkRestrictions = async () => { + let context = this.contextProviderRef.state; + let isGroupSearchEnabled = await context.FeatureRestriction.isGroupSearchEnabled(); + let isGroupCreationEnabled = await context.FeatureRestriction.isGroupCreationEnabled(); + let isJoinLeaveGroupsEnabled = await context.FeatureRestriction.isJoinLeaveGroupsEnabled(); + this.setState({ + restrictions: { + isGroupSearchEnabled, + isGroupCreationEnabled, + isJoinLeaveGroupsEnabled, + }, + }); + }; componentDidUpdate(prevProps, prevState) { try { @@ -398,7 +417,11 @@ class CometChatGroupList extends React.Component { handleClick = (group) => { //handle click here if (!this.props.onItemClick) return; + if (group.hasJoined === false) { + if (this.state.restrictions?.isJoinLeaveGroupsEnabled === false) { + return false; + } if (group.type === CometChat.GROUP_TYPE.PASSWORD) { this.setState({ showPasswordScreen: true, @@ -659,40 +682,45 @@ class CometChatGroupList extends React.Component { Groups - this.createGroupHandler(true)} - style={{ borderRadius: 20 }}> - {this.createGroup} - + {this.state.restrictions?.isGroupCreationEnabled ? ( + this.createGroupHandler(true)} + style={{ borderRadius: 20 }}> + {this.createGroup} + + ) : null} - this.textInputRef.current.focus()}> - - - this.textInputRef.current.focus()}> + - - + ]}> + + + + + ) : null} ); }; @@ -817,51 +845,54 @@ class CometChatGroupList extends React.Component { } return ( - - - - - (this.contextProviderRef = el)}> + + + + + + + {this.ListHeaderComponent()} + item.uid + '_' + index} + renderItem={({ item }) => { + return ( + + ); }} + ListEmptyComponent={this.listEmptyContainer} + onScroll={this.handleScroll} + onEndReached={this.endReached} + onEndReachedThreshold={0.3} + showsVerticalScrollIndicator={false} /> - - {this.ListHeaderComponent()} - { - return ( - - ); - }} - ListEmptyComponent={this.listEmptyContainer} - onScroll={this.handleScroll} - onEndReached={this.endReached} - onEndReachedThreshold={0.3} - showsVerticalScrollIndicator={false} - /> - this.createGroupHandler(false)} - actionGenerated={this.createGroupActionHandler} - /> - {passwordScreen} - - (this.dropDownAlertRef = ref)} /> - - + this.createGroupHandler(false)} + actionGenerated={this.createGroupActionHandler} + /> + {passwordScreen} + + (this.dropDownAlertRef = ref)} /> + + + ); } } diff --git a/src/components/Groups/CometChatGroupListItem/index.js b/src/components/Groups/CometChatGroupListItem/index.js index 796ec9f..c3cfc1f 100644 --- a/src/components/Groups/CometChatGroupListItem/index.js +++ b/src/components/Groups/CometChatGroupListItem/index.js @@ -1,6 +1,6 @@ import React from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import style from './styles'; import theme from '../../../resources/theme'; import Icon from 'react-native-vector-icons/SimpleLineIcons'; diff --git a/src/components/Groups/CometChatGroupListWithMessages/index.js b/src/components/Groups/CometChatGroupListWithMessages/index.js index 13a3424..f77bba8 100644 --- a/src/components/Groups/CometChatGroupListWithMessages/index.js +++ b/src/components/Groups/CometChatGroupListWithMessages/index.js @@ -12,13 +12,14 @@ import { CometChatOutgoingDirectCall, CometChatIncomingDirectCall, } from '../../Calls'; -import { CometChatGroupList } from '../index'; -import { CometChatImageViewer } from '../../Messages'; +import CometChatGroupList from '../CometChatGroupList'; +import CometChatImageViewer from '../../Messages/CometChatImageViewer'; import DropDownAlert from '../../Shared/DropDownAlert'; import theme from '../../../resources/theme'; import style from './styles'; import { logger } from '../../../utils/common'; +import { CometChatContextProvider } from '../../../utils/CometChatContext'; class CometChatGroupListWithMessages extends React.Component { loggedInUser = null; @@ -696,27 +697,28 @@ class CometChatGroupListWithMessages extends React.Component { ); } return ( - - - {imageView} - { - this.dropDownAlertRef?.showMessage(type, message); - }} - theme={this.props.theme} - loggedInUser={this.loggedInUser} - outgoingCall={this.state.outgoingCall} - actionGenerated={this.actionHandler} - /> - {/* (this.contextProviderRef = el)}> + + + {imageView} + { + this.dropDownAlertRef?.showMessage(type, message); + }} + theme={this.props.theme} + loggedInUser={this.loggedInUser} + outgoingCall={this.state.outgoingCall} + actionGenerated={this.actionHandler} + /> + {/* */} - - (this.dropDownAlertRef = ref)} /> - {this.state.ongoingDirectCall ? ( - this.actionHandler(actions.DIRECT_CALL_ENDED)} + - ) : null} - + (this.dropDownAlertRef = ref)} /> + {this.state.ongoingDirectCall ? ( + this.actionHandler(actions.DIRECT_CALL_ENDED)} + theme={this.props.theme} + item={this.state.item} + type={this.state.type} + lang={this.state.lang} + callType={CometChat.CALL_TYPE.VIDEO} + joinDirectCall={this.state.joinDirectCall} + loggedInUser={this.loggedInUser} + actionGenerated={this.actionHandler} + /> + ) : null} + + ); } } diff --git a/src/components/Groups/CometChatViewGroupMemberList/index.js b/src/components/Groups/CometChatViewGroupMemberList/index.js index 859d354..c92bda0 100644 --- a/src/components/Groups/CometChatViewGroupMemberList/index.js +++ b/src/components/Groups/CometChatViewGroupMemberList/index.js @@ -7,7 +7,7 @@ import DropDownAlert from '../../Shared/DropDownAlert'; import { View, Text, FlatList, Modal, TouchableOpacity } from 'react-native'; import BottomSheet from 'reanimated-bottom-sheet'; -import { CometChatViewGroupMemberListItem } from '../index'; +import CometChatViewGroupMemberListItem from '../CometChatViewGroupMemberListItem'; import GroupDetailContext from '../CometChatGroupDetails/context'; import _ from 'lodash'; import style from './styles'; @@ -276,6 +276,7 @@ export default class CometChatViewGroupMemberList extends React.Component { item.uid + '_' + index} renderItem={({ item, index }) => { return ( { + const context = useContext(CometChatContext); const [showChangeScope, toggleChange] = useState(false); + const [restrictions, setRestrictions] = useState(false); const [scope, setScope] = useState(props.member.scope); + useEffect(() => { + checkRestrictions(); + }, []); + + const checkRestrictions = async () => { + let isChangingGroupMemberScopeEnabled = await context.FeatureRestriction.isChangingGroupMemberScopeEnabled(); + let isKickingGroupMembersEnabled = await context.FeatureRestriction.isKickingGroupMembersEnabled(); + let isBanningGroupMembersEnabled = await context.FeatureRestriction.isBanningGroupMembersEnabled(); + setRestrictions({ + isChangingGroupMemberScopeEnabled, + isKickingGroupMembersEnabled, + isBanningGroupMembersEnabled, + }); + }; + /** * Update member scope * @param @@ -158,6 +177,15 @@ export default (props) => { } let editAccess = null; + if (!restrictions.isChangingGroupMemberScopeEnabled) { + changeScope = receivedScope; + } + if (!restrictions.isKickingGroupMembersEnabled) { + kick = null; + } + if (!restrictions.isBanningGroupMembersEnabled) { + ban = null; + } // if the logged in user is participant, don't show change scope, ban, kick group members if (props.item.scope === CometChat.GROUP_MEMBER_SCOPE.PARTICIPANT) { editAccess = null; diff --git a/src/components/Groups/CometChatViewGroupMemberListItem/style.js b/src/components/Groups/CometChatViewGroupMemberListItem/style.js index 6462920..81b2e11 100644 --- a/src/components/Groups/CometChatViewGroupMemberListItem/style.js +++ b/src/components/Groups/CometChatViewGroupMemberListItem/style.js @@ -11,7 +11,11 @@ export default StyleSheet.create({ overflow: 'hidden', paddingHorizontal: 10, }, - memberScopeText: { flex: 1, paddingLeft: 15 * widthRatio }, + memberScopeText: { + flex: 1, + paddingLeft: 15 * widthRatio, + alignSelf: 'center', + }, changeScopeContainer: { flex: 1, flexDirection: 'row', diff --git a/src/components/Messages/CometChatMessageActions/actions.js b/src/components/Messages/CometChatMessageActions/actions.js index cef7ebd..0f59a56 100644 --- a/src/components/Messages/CometChatMessageActions/actions.js +++ b/src/components/Messages/CometChatMessageActions/actions.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useContext, useEffect } from 'react'; import { Text, View, @@ -12,14 +12,47 @@ import styles from './styles'; import * as actions from '../../../utils/actions'; import * as enums from '../../../utils/enums'; import { CometChat } from '@cometchat-pro/react-native-chat'; +import { CometChatContext } from '../../../utils/CometChatContext'; const actionIconSize = 26; export default (props) => { + const [restrictions, setRestrictions] = useState(null); + const context = useContext(CometChatContext); + useEffect(() => { + checkRestrictions(); + }, []); + + const checkRestrictions = async () => { + let enableEditMessage = await context.FeatureRestriction.isEditMessageEnabled(); + let enableThreadedChats = await context.FeatureRestriction.isThreadedMessagesEnabled(); + let enableDeleteMessage = await context.FeatureRestriction.isDeleteMessageEnabled(); + let enableDeleteMessageForModerator = await context.FeatureRestriction.isDeleteMemberMessageEnabled(); + let enableMessageInPrivate = await context.FeatureRestriction.isMessageInPrivateEnabled(); + + if ( + !enableEditMessage && + !enableThreadedChats && + !enableDeleteMessage && + !enableDeleteMessageForModerator && + !enableMessageInPrivate + ) { + props.actionGenerated(actions.CLOSE_MESSAGE_ACTIONS); + } + setRestrictions({ + enableEditMessage, + enableThreadedChats, + enableDeleteMessage, + enableDeleteMessageForModerator, + enableMessageInPrivate, + }); + }; + let sendMessage = null; if ( props.message.messageFrom === enums.MESSAGE_FROM_RECEIVER && - props.message.receiverType === CometChat.RECEIVER_TYPE.GROUP + props.message.receiverType === CometChat.RECEIVER_TYPE.GROUP && + restrictions?.enableMessageInPrivate ) { sendMessage = ( { // if threaded messages need to be disabled if ( props.message.category === CometChat.CATEGORY_CUSTOM || - props.message.parentMessageId + props.message.parentMessageId || + !restrictions?.enableThreadedChats ) { threadedChats = null; } @@ -63,10 +97,13 @@ export default (props) => { ); // if deleting messages need to be disabled + if ( props.message.messageFrom === enums.MESSAGE_FROM_RECEIVER && - props.item.scope !== CometChat.GROUP_MEMBER_SCOPE.ADMIN && - props.item.scope !== CometChat.GROUP_MEMBER_SCOPE.MODERATOR + (props.item.scope == CometChat.GROUP_MEMBER_SCOPE.MODERATOR || + props.item.scope == CometChat.GROUP_MEMBER_SCOPE.ADMIN + ? !restrictions?.enableDeleteMessageForModerator + : !restrictions?.enableDeleteMessage) ) { deleteMessage = null; } @@ -84,14 +121,11 @@ export default (props) => { // if editing messages need to be disabled if ( props.message.messageFrom === enums.MESSAGE_FROM_RECEIVER || - props.message.type !== CometChat.MESSAGE_TYPE.TEXT + props.message.type !== CometChat.MESSAGE_TYPE.TEXT || + !restrictions?.enableEditMessage ) { editMessage = null; } - if (!threadedChats && !editMessage && !deleteMessage) { - props.actionGenerated(actions.CLOSE_MESSAGE_ACTIONS); - return null; - } return ( {}}> diff --git a/src/components/Messages/CometChatMessageComposer/composerActions.js b/src/components/Messages/CometChatMessageComposer/composerActions.js index a2e168d..ab15ef5 100644 --- a/src/components/Messages/CometChatMessageComposer/composerActions.js +++ b/src/components/Messages/CometChatMessageComposer/composerActions.js @@ -18,16 +18,41 @@ import { launchCamera, launchImageLibrary } from 'react-native-image-picker'; import DocumentPicker from 'react-native-document-picker'; import { CometChat } from '@cometchat-pro/react-native-chat'; import { heightRatio } from '../../../utils/consts'; +import { CometChatContext } from '../../../utils/CometChatContext'; export default class ComposerActions extends Component { sheetRef = React.createRef(null); - + static contextType = CometChatContext; + constructor(props) { + super(props); + this.state = { + restrictions: null, + }; + } componentDidUpdate(prevProps) { if (!prevProps.visible && this.props.visible) { this.sheetRef.current.snapTo(0); } } + componentDidMount() { + this.checkRestrictions(); + } + checkRestrictions = async () => { + let isPollsEnabled = await this.context.FeatureRestriction.isPollsEnabled(); + let isStickersEnabled = await this.context.FeatureRestriction.isStickersEnabled(); + let isFilesEnabled = await this.context.FeatureRestriction.isFilesEnabled(); + let isPhotosVideosEnabled = await this.context.FeatureRestriction.isPhotosVideosEnabled(); + this.setState({ + restrictions: { + isPollsEnabled, + isStickersEnabled, + isFilesEnabled, + isPhotosVideosEnabled, + }, + }); + }; + takePhoto = async (mediaType = 'photo') => { try { let granted = null; @@ -42,8 +67,7 @@ export default class ComposerActions extends Component { }, ); } - this.sheetRef.current.snapTo(1); - this.props.close(); + if ( Platform.OS === 'ios' || granted === PermissionsAndroid.RESULTS.GRANTED @@ -55,6 +79,8 @@ export default class ComposerActions extends Component { cameraType: 'back', }, (response) => { + this.sheetRef.current.snapTo(1); + this.props.close(); if (response.didCancel) { return null; } @@ -62,6 +88,7 @@ export default class ComposerActions extends Component { let name = null; if (Platform.OS === 'ios' && response.fileName !== undefined) { name = response.fileName; + type = response.type; } else { type = response.type; name = 'Camera_001.jpeg'; @@ -84,6 +111,7 @@ export default class ComposerActions extends Component { ? response.uri : response.uri.replace('file://', ''), }; + console.log('file', file); this.props.sendMediaMessage( file, mediaType === 'photo' @@ -248,7 +276,21 @@ export default class ComposerActions extends Component { ); - + if (!this.state.restrictions?.isPollsEnabled) { + createPollBtn = null; + } + if (!this.state.restrictions?.isStickersEnabled) { + stickerBtn = null; + } + if (!this.state.restrictions?.isFilesEnabled) { + docs = null; + } + if (!this.state.restrictions?.isPhotosVideosEnabled) { + takeVideoBtn = null; + avp = null; + takePhotoBtn = null; + vp = null; + } return ( {takePhotoBtn} diff --git a/src/components/Messages/CometChatMessageComposer/index.js b/src/components/Messages/CometChatMessageComposer/index.js index 46880d2..de7f6f4 100644 --- a/src/components/Messages/CometChatMessageComposer/index.js +++ b/src/components/Messages/CometChatMessageComposer/index.js @@ -31,8 +31,10 @@ import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import { heightRatio } from '../../../utils/consts'; import { logger } from '../../../utils/common'; +import { CometChatContext } from '../../../utils/CometChatContext'; export default class CometChatMessageComposer extends React.PureComponent { + static contextType = CometChatContext; constructor(props) { super(props); @@ -58,6 +60,7 @@ export default class CometChatMessageComposer extends React.PureComponent { composerActionsVisible: false, user: null, keyboardActivity: false, + restrictions: null, }; this.audio = new Sound(outgoingMessageAlert); @@ -78,8 +81,22 @@ export default class CometChatMessageComposer extends React.PureComponent { 'keyboardDidHide', this._keyboardDidHide, ); + this.checkRestrictions(); } + checkRestrictions = async () => { + let isLiveReactionsEnabled = await this.context.FeatureRestriction.isLiveReactionsEnabled(); + let isTypingIndicatorsEnabled = await this.context.FeatureRestriction.isTypingIndicatorsEnabled(); + let isSmartRepliesEnabled = await this.context.FeatureRestriction.isSmartRepliesEnabled(); + this.setState({ + restrictions: { + isLiveReactionsEnabled, + isTypingIndicatorsEnabled, + isSmartRepliesEnabled, + }, + }); + }; + componentWillUnmount() { this.keyboardDidShowListener.remove(); this.keyboardDidHideListener.remove(); @@ -179,7 +196,6 @@ export default class CometChatMessageComposer extends React.PureComponent { const { receiverId, receiverType } = this.getReceiverDetails(); const conversationId = this.props.getConversationId(); - const mediaMessage = new CometChat.MediaMessage( receiverId, messageInput, @@ -211,25 +227,21 @@ export default class CometChatMessageComposer extends React.PureComponent { this.messageSending = false; this.playAudio(); - const newMessageObj = { ...response, _id: mediaMessage._id, localFile: messageInput, }; this.props.actionGenerated(actions.MESSAGE_SENT, newMessageObj); - }) .catch((error) => { const newMessageObj = { ...mediaMessage, error: error }; const errorCode = error?.message || 'ERROR'; - this.props.actionGenerated( actions.ERROR_IN_SEND_MESSAGE, newMessageObj, ); - this.props?.showMessage('error', errorCode); this.messageSending = false; logger('Message sending failed with error: ', error); @@ -282,9 +294,7 @@ export default class CometChatMessageComposer extends React.PureComponent { textMessage.setReceiver(receiverType); textMessage.setText(messageInput); textMessage.setConversationId(conversationId); - textMessage._composedAt = Date.now(); - textMessage._id = '_' + Math.random().toString(36).substr(2, 9); this.props.actionGenerated(actions.MESSAGE_COMPOSED, [textMessage]); this.setState({ messageInput: '', replyPreview: false }); @@ -298,7 +308,6 @@ export default class CometChatMessageComposer extends React.PureComponent { this.messageSending = false; this.messageInputRef.current.textContent = ''; // this.playAudio(); - this.props.actionGenerated(actions.MESSAGE_SENT, newMessageObj); }) .catch((error) => { @@ -307,7 +316,6 @@ export default class CometChatMessageComposer extends React.PureComponent { actions.ERROR_IN_SEND_MESSAGE, newMessageObj, ); - logger('Message sending failed with error:', error); const errorCode = error?.message || 'ERROR'; this.props?.showMessage('error', errorCode); @@ -377,6 +385,9 @@ export default class CometChatMessageComposer extends React.PureComponent { startTyping = (timer, metadata) => { try { const typingInterval = timer || 5000; + if (!this.state.restrictions?.isTypingIndicatorsEnabled) { + return false; + } if (this.isTyping) { return false; } @@ -508,9 +519,7 @@ export default class CometChatMessageComposer extends React.PureComponent { customMessage.setSender(this.loggedInUser); customMessage.setReceiver(receiverType); customMessage.setConversationId(conversationId); - customMessage._composedAt = Date.now(); - customMessage._id = '_' + Math.random().toString(36).substr(2, 9); this.props.actionGenerated(actions.MESSAGE_COMPOSED, [customMessage]); CometChat.sendCustomMessage(customMessage) @@ -519,7 +528,6 @@ export default class CometChatMessageComposer extends React.PureComponent { this.playAudio(); const newMessageObj = { ...message, _id: customMessage._id }; - this.props.actionGenerated(actions.MESSAGE_SENT, newMessageObj); }) .catch((error) => { @@ -528,7 +536,6 @@ export default class CometChatMessageComposer extends React.PureComponent { actions.ERROR_IN_SEND_MESSAGE, newMessageObj, ); - const errorCode = error?.message || 'ERROR'; this.props?.showMessage('error', errorCode); @@ -627,7 +634,10 @@ export default class CometChatMessageComposer extends React.PureComponent { ); - if (!this.state.messageInput.length) { + if ( + !this.state.messageInput.length && + this.state.restrictions?.isLiveReactionsEnabled + ) { sendBtn = null; } else { liveReactionBtn = null; @@ -754,6 +764,10 @@ export default class CometChatMessageComposer extends React.PureComponent { } } + if (!this.state.restrictions?.isSmartRepliesEnabled) { + smartReplyPreview: false; + } + let stickerViewer = null; if (this.state.stickerViewer) { stickerViewer = ( diff --git a/src/components/Messages/CometChatMessageHeader/index.js b/src/components/Messages/CometChatMessageHeader/index.js index fc70450..79aeb8e 100644 --- a/src/components/Messages/CometChatMessageHeader/index.js +++ b/src/components/Messages/CometChatMessageHeader/index.js @@ -12,7 +12,9 @@ import videoCallIcon from './resources/videoCall.png'; import detailPaneIcon from './resources/detailpane.png'; import { logger } from '../../../utils/common'; import { CometChat } from '@cometchat-pro/react-native-chat'; +import { CometChatContext } from '../../../utils/CometChatContext'; class CometChatMessageHeader extends React.Component { + static contextType = CometChatContext; constructor(props) { super(props); @@ -31,8 +33,24 @@ class CometChatMessageHeader extends React.Component { } else { this.setStatusForGroup(); } + this.checkRestrictions(); } + 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(); + this.setState({ + restrictions: { + isGroupVideoCallEnabled, + isOneOnOneAudioCallEnabled, + isTypingIndicatorsEnabled, + isOneOnOneVideoCallEnabled, + }, + }); + }; + componentDidUpdate(prevProps) { try { this.MessageHeaderManager.removeListeners(); @@ -195,8 +213,10 @@ class CometChatMessageHeader extends React.Component { this.props.type === item.receiverType && this.props.item.guid === item.receiverId ) { - this.setState({ status: `${item.sender.name} is typing...` }); - this.props.actionGenerated(actions.SHOW_REACTION, item); + if (this.state.restrictions?.isTypingIndicatorsEnabled) { + this.setState({ status: `${item.sender.name} is typing...` }); + this.props.actionGenerated(actions.SHOW_REACTION, item); + } } else if ( this.props.type === CometChat.RECEIVER_TYPE.USER && this.props.type === item.receiverType && @@ -248,9 +268,7 @@ class CometChatMessageHeader extends React.Component { presence = ( ); - return ( { - return Object.keys(this.categories); + const categories = { ...this.categories }; + return new Promise((resolve) => { + this.context.FeatureRestriction.isGroupActionMessagesEnabled() + .then((response) => { + if (response === false) { + delete categories[CometChat.CATEGORY_ACTION]; + } + return categories; + }) + .catch((error) => { + delete categories[CometChat.CATEGORY_ACTION]; + return categories; + }) + .then((categories) => { + this.context.FeatureRestriction.isCallActionMessagesEnabled() + .then((response) => { + if (response === false) { + delete categories[CometChat.CATEGORY_CALL]; + } + resolve(Object.keys(categories)); + }) + .catch((error) => { + delete categories[CometChat.CATEGORY_CALL]; + resolve(Object.keys(categories)); + }); + }); + }); }; getTypes = () => { diff --git a/src/components/Messages/CometChatMessageList/controller.js b/src/components/Messages/CometChatMessageList/controller.js index 94f24b9..8138c7a 100644 --- a/src/components/Messages/CometChatMessageList/controller.js +++ b/src/components/Messages/CometChatMessageList/controller.js @@ -1,7 +1,7 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; import * as enums from '../../../utils/enums'; -import { HIDE_DELETED_MSG } from '../../../utils/settings'; + import MessageFilter from './MessageFilter'; export class MessageListManager { @@ -41,19 +41,27 @@ export class MessageListManager { callListenerId = `call_${new Date().getTime()}`; - constructor(item, type, parentMessageId) { + constructor(item, type, parentMessageId, context) { this.item = item; this.type = type; this.parentMessageId = parentMessageId; + this.checkRestrictions(item, type, parentMessageId, context); + } - const messageFilterManager = new MessageFilter(); - const categories = messageFilterManager.getCategories(); + checkRestrictions = async (item, type, parentMessageId, context) => { + this.hideDeletedMessages = await context.FeatureRestriction.isHideDeletedMessagesEnabled(); + this.buildRequestBuilder(item, type, parentMessageId, context); + }; + + buildRequestBuilder = async (item, type, parentMessageId, context) => { + const messageFilterManager = new MessageFilter(context); + const categories = await messageFilterManager.getCategories(); const types = messageFilterManager.getTypes(); if (type === CometChat.RECEIVER_TYPE.USER) { if (this.parentMessageId) { this.messageRequest = new CometChat.MessagesRequestBuilder() .setUID(item.uid) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .setParentMessageId(this.parentMessageId) .setCategories(categories) .setTypes(types) @@ -63,7 +71,7 @@ export class MessageListManager { this.messageRequest = new CometChat.MessagesRequestBuilder() .setUID(item.uid) .setCategories(categories) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .setTypes(types) .hideReplies(true) .setLimit(this.limit) @@ -74,7 +82,7 @@ export class MessageListManager { this.messageRequest = new CometChat.MessagesRequestBuilder() .setGUID(item.guid) .setParentMessageId(this.parentMessageId) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .setCategories(categories) .setTypes(types) .setLimit(this.limit) @@ -85,12 +93,12 @@ export class MessageListManager { .setCategories(categories) .setTypes(types) .hideReplies(true) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .setLimit(this.limit) .build(); } } - } + }; fetchPreviousMessages() { return this.messageRequest.fetchPrevious(); diff --git a/src/components/Messages/CometChatMessageList/index.js b/src/components/Messages/CometChatMessageList/index.js index b8c00a2..9bfd175 100644 --- a/src/components/Messages/CometChatMessageList/index.js +++ b/src/components/Messages/CometChatMessageList/index.js @@ -9,32 +9,30 @@ import { MessageListManager } from './controller'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; -import { - CometChatSenderPollMessageBubble, - CometChatSenderStickerMessageBubble, - CometChatReceiverPollMessageBubble, - CometChatReceiverStickerMessageBubble, -} from '../../Messages/Extensions'; -import { - CometChatActionMessageBubble, - CometChatDeleteMessageBubble, - CometChatReceiverVideoMessageBubble, - CometChatSenderVideoMessageBubble, - CometChatSenderFileMessageBubble, - CometChatReceiverFileMessageBubble, - CometChatSenderAudioMessageBubble, - CometChatReceiverAudioMessageBubble, - CometChatSenderImageMessageBubble, - CometChatReceiverImageMessageBubble, - CometChatSenderTextMessageBubble, - CometChatReceiverTextMessageBubble, - CometChatReceiverDirectCallBubble, - CometChatSenderDirectCallBubble, -} from '../index'; +import CometChatSenderPollMessageBubble from '../../Messages/Extensions/CometChatSenderPollMessageBubble'; +import CometChatSenderStickerMessageBubble from '../../Messages/Extensions/CometChatSenderStickerMessageBubble'; +import CometChatReceiverPollMessageBubble from '../../Messages/Extensions/CometChatReceiverPollMessageBubble'; +import CometChatReceiverStickerMessageBubble from '../../Messages/Extensions/CometChatReceiverStickerMessageBubble'; +import CometChatActionMessageBubble from '../CometChatActionMessageBubble'; +import CometChatDeleteMessageBubble from '../CometChatDeleteMessageBubble'; +import CometChatReceiverVideoMessageBubble from '../CometChatReceiverVideoMessageBubble'; +import CometChatSenderVideoMessageBubble from '../CometChatSenderVideoMessageBubble'; +import CometChatSenderFileMessageBubble from '../CometChatSenderFileMessageBubble'; +import CometChatReceiverFileMessageBubble from '../CometChatReceiverFileMessageBubble'; +import CometChatSenderAudioMessageBubble from '../CometChatSenderAudioMessageBubble'; +import CometChatReceiverAudioMessageBubble from '../CometChatReceiverAudioMessageBubble'; +import CometChatReceiverImageMessageBubble from '../CometChatReceiverImageMessageBubble'; +import CometChatSenderTextMessageBubble from '../CometChatSenderTextMessageBubble'; +import CometChatSenderImageMessageBubble from '../CometChatSenderImageMessageBubble'; +import CometChatReceiverTextMessageBubble from '../CometChatReceiverTextMessageBubble'; +import CometChatReceiverDirectCallBubble from '../CometChatReceiverDirectCallBubble'; +import CometChatSenderDirectCallBubble from '../CometChatSenderDirectCallBubble'; + import styles from './styles'; import { logger } from '../../../utils/common'; import { TouchableOpacity } from 'react-native-gesture-handler'; import Icon from 'react-native-vector-icons/Ionicons'; +import { CometChatContext } from '../../../utils/CometChatContext'; let cDate = null; @@ -46,6 +44,7 @@ class CometChatMessageList extends React.PureComponent { times = 0; decoratorMessage = 'Loading...'; + static contextType = CometChatContext; constructor(props) { super(props); @@ -63,11 +62,14 @@ class CometChatMessageList extends React.PureComponent { this.props.item, this.props.type, this.props.parentMessageId, + this.context, ); } else { this.MessageListManager = new MessageListManager( this.props.item, this.props.type, + null, + this.context, ); } @@ -85,18 +87,21 @@ class CometChatMessageList extends React.PureComponent { prevProps.item.uid !== this.props.item.uid ) { this.decoratorMessage = 'Loading...'; - this.MessageListManager.removeListeners(); + this.MessageListManager?.removeListeners(); if (this.props.parentMessageId) { this.MessageListManager = new MessageListManager( this.props.item, this.props.type, this.props.parentMessageId, + this.context, ); } else { this.MessageListManager = new MessageListManager( this.props.item, this.props.type, + null, + this.context, ); } @@ -107,7 +112,7 @@ class CometChatMessageList extends React.PureComponent { prevProps.item.guid !== this.props.item.guid ) { this.decoratorMessage = 'Loading...'; - this.MessageListManager.removeListeners(); + this.MessageListManager?.removeListeners(); if (this.props.parentMessageId) { this.MessageListManager = new MessageListManager( @@ -126,7 +131,7 @@ class CometChatMessageList extends React.PureComponent { this.MessageListManager.attachListeners(this.messageUpdated); } else if (prevProps.parentMessageId !== this.props.parentMessageId) { this.decoratorMessage = 'Loading...'; - this.MessageListManager.removeListeners(); + this.MessageListManager?.removeListeners(); this.MessageListManager = new MessageListManager( this.props.item, this.props.type, @@ -141,7 +146,7 @@ class CometChatMessageList extends React.PureComponent { } componentWillUnmount() { - this.MessageListManager.removeListeners(); + this.MessageListManager?.removeListeners(); this.MessageListManager = null; } @@ -1195,6 +1200,7 @@ class CometChatMessageList extends React.PureComponent { : null } data={messages} + keyExtractor={(item, index) => item.messageId + '_' + index} renderItem={this.renderItem} /> {this.state.showNewMsg ? newMsgPopUp : null} diff --git a/src/components/Messages/CometChatMessageThread/index.js b/src/components/Messages/CometChatMessageThread/index.js index 10fbe95..d53cc8c 100644 --- a/src/components/Messages/CometChatMessageThread/index.js +++ b/src/components/Messages/CometChatMessageThread/index.js @@ -4,23 +4,21 @@ import React from 'react'; import { CometChat } from '@cometchat-pro/react-native-chat'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; -import { HIDE_DELETED_MSG } from '../../../utils/settings'; import { MessageThreadManager } from './controller'; -import { - CometChatMessageActions, - CometChatMessageComposer, - CometChatMessageList, - CometChatSenderTextMessageBubble, - CometChatReceiverTextMessageBubble, - CometChatSenderImageMessageBubble, - CometChatReceiverImageMessageBubble, - CometChatSenderFileMessageBubble, - CometChatReceiverFileMessageBubble, - CometChatSenderAudioMessageBubble, - CometChatReceiverAudioMessageBubble, - CometChatSenderVideoMessageBubble, - CometChatReceiverVideoMessageBubble, -} from '../index'; +import CometChatMessageActions from '../CometChatMessageActions'; +import CometChatMessageComposer from '../CometChatMessageComposer'; +import CometChatMessageList from '../CometChatMessageList'; +import CometChatSenderTextMessageBubble from '../CometChatSenderTextMessageBubble'; +import CometChatReceiverTextMessageBubble from '../CometChatReceiverTextMessageBubble'; +import CometChatSenderImageMessageBubble from '../CometChatSenderImageMessageBubble'; +import CometChatReceiverImageMessageBubble from '../CometChatReceiverImageMessageBubble'; +import CometChatSenderFileMessageBubble from '../CometChatSenderFileMessageBubble'; +import CometChatReceiverFileMessageBubble from '../CometChatReceiverFileMessageBubble'; +import CometChatSenderAudioMessageBubble from '../CometChatSenderAudioMessageBubble'; +import CometChatReceiverAudioMessageBubble from '../CometChatReceiverAudioMessageBubble'; +import CometChatSenderVideoMessageBubble from '../CometChatSenderVideoMessageBubble'; +import CometChatReceiverVideoMessageBubble from '../CometChatReceiverVideoMessageBubble'; + import styles from './style'; import { View, @@ -35,8 +33,10 @@ import _ from 'lodash'; import Icon from 'react-native-vector-icons/Ionicons'; import { heightRatio, widthRatio } from '../../../utils/consts'; import { logger } from '../../../utils/common'; +import { CometChatContext } from '../../../utils/CometChatContext'; class CometChatMessageThread extends React.PureComponent { + static contextType = CometChatContext; constructor(props) { super(props); @@ -54,6 +54,7 @@ class CometChatMessageThread extends React.PureComponent { messageToBeEdited: null, parentMessage: props.parentMessage, keyboardActivity: false, + hideDeletedEnabled: false, }; } @@ -66,8 +67,14 @@ class CometChatMessageThread extends React.PureComponent { 'keyboardDidHide', this._keyboardDidHide, ); + this.checkIsHideDeletedEnabled(); } + checkIsHideDeletedEnabled = async () => { + let hideDeletedEnabled = this.context.FeatureRestriction.isHideDeletedMessagesEnabled(); + this.setState({ hideDeletedEnabled }); + }; + componentWillUnmount() { this.keyboardDidShowListener.remove(); this.keyboardDidHideListener.remove(); @@ -191,10 +198,8 @@ class CometChatMessageThread extends React.PureComponent { ); } break; - case actions.MESSAGE_SENT: case actions.ERROR_IN_SEND_MESSAGE: - this.messageSent(messages); break; case actions.MESSAGE_UPDATED: @@ -396,7 +401,7 @@ class CometChatMessageThread extends React.PureComponent { if (messageKey > -1) { const messageObj = { ...messageList[messageKey] }; const newMessageObj = { ...messageObj, ...deletedMessage }; - if (HIDE_DELETED_MSG) { + if (this.state.hideDeletedEnabled) { messageList.splice(messageKey, 1); } else { messageList.splice(messageKey, 1, newMessageObj); diff --git a/src/components/Messages/CometChatMessages/index.js b/src/components/Messages/CometChatMessages/index.js index 87ea963..a1d0597 100644 --- a/src/components/Messages/CometChatMessages/index.js +++ b/src/components/Messages/CometChatMessages/index.js @@ -11,17 +11,24 @@ import { import { CometChat } from '@cometchat-pro/react-native-chat'; import * as actions from '../../../utils/actions'; import _ from 'lodash'; -import { HIDE_DELETED_MSG } from '../../../utils/settings'; -import { CometChatUserDetails } from '../../Users'; import { - CometChatLiveReactions, - CometChatMessageHeader, - CometChatMessageList, - CometChatMessageComposer, - CometChatMessageActions, - CometChatMessageThread, -} from '../index'; -import { CometChatGroupDetails } from '../../Groups'; + CometChatContextProvider, + CometChatContext, +} from '../../../utils/CometChatContext'; +import CometChatUserDetails from '../../Users/CometChatUserDetails'; +import CometChatLiveReactions from '../CometChatLiveReactions'; +import CometChatMessageHeader from '../CometChatMessageHeader'; +import CometChatMessageList from '../CometChatMessageList'; +import CometChatMessageComposer from '../CometChatMessageComposer'; +import CometChatMessageActions from '../CometChatMessageActions'; +import CometChatMessageThread from '../CometChatMessageThread'; +import { + CometChatIncomingCall, + CometChatOutgoingCall, + CometChatOutgoingDirectCall, + CometChatIncomingDirectCall, +} from '../../Calls'; +import CometChatGroupDetails from '../../Groups/CometChatGroupDetails'; import CometChatVideoViewer from '../CometChatVideoViewer'; import theme from '../../../resources/theme'; import { CometChatManager } from '../../../utils/controller'; @@ -33,6 +40,8 @@ import style from './styles'; import CometChatUserProfile from '../../Users/CometChatUserProfile'; class CometChatMessages extends React.PureComponent { + static contextType = CometChatContext; + loggedInUser = null; constructor(props) { super(props); @@ -55,6 +64,7 @@ class CometChatMessages extends React.PureComponent { groupDetailVisible: false, user: params.type === 'user' ? params.item : null, showProfile: false, + ongoingDirectCall: false, }; this.composerRef = React.createRef(); @@ -65,6 +75,7 @@ class CometChatMessages extends React.PureComponent { } componentDidMount() { + this.checkRestrictions(); new CometChatManager() .getLoggedInUser() .then((user) => { @@ -74,6 +85,23 @@ class CometChatMessages extends React.PureComponent { // console.log('[CometChatMessages] getLoggedInUser error', error); }); } + checkRestrictions = async () => { + let context = this.contextProviderRef.state; + let isGroupActionMessagesEnabled = await context.FeatureRestriction.isGroupActionMessagesEnabled(); + let isCallActionMessagesEnabled = await context.FeatureRestriction.isCallActionMessagesEnabled(); + let isOneOnOneChatEnabled = await context.FeatureRestriction.isOneOnOneChatEnabled(); + let isGroupChatEnabled = await context.FeatureRestriction.isGroupChatEnabled(); + let isHideDeletedMessagesEnabled = await context.FeatureRestriction.isHideDeletedMessagesEnabled(); + this.setState({ + restrictions: { + isGroupActionMessagesEnabled, + isCallActionMessagesEnabled, + isOneOnOneChatEnabled, + isGroupChatEnabled, + isHideDeletedMessagesEnabled, + }, + }); + }; componentDidUpdate(prevProps, prevState) { const { route: prevRoute } = prevProps; @@ -187,12 +215,10 @@ class CometChatMessages extends React.PureComponent { case actions.MESSAGE_READ: params.actionGenerated(action, messages); break; - case actions.MESSAGE_SENT: case actions.ERROR_IN_SEND_MESSAGE: this.messageSent(messages); case actions.MESSAGE_COMPOSED: { - this.appendMessage(messages); break; } @@ -255,8 +281,13 @@ class CometChatMessages extends React.PureComponent { break; case actions.AUDIO_CALL: case actions.VIDEO_CALL: + if (params.type === CometChat.RECEIVER_TYPE.GROUP) { + this.setState({ joinDirectCall: false, ongoingDirectCall: true }); + } else { + params.actionGenerated(action, { ...params.item, type: params.type }); + } case actions.MENU_CLICKED: - case actions.JOIN_DIRECT_CALL: + // case actions.JOIN_DIRECT_CALL: params.actionGenerated(action); break; case actions.SEND_REACTION: @@ -325,12 +356,21 @@ class CometChatMessages extends React.PureComponent { break; case actions.SHOW_PROFILE: this.showProfile(); + break; + case actions.JOIN_DIRECT_CALL: + this.setState({ joinDirectCall: true }, () => { + this.setState({ ongoingDirectCall: true }); + }); + break; + case actions.DIRECT_CALL_ENDED: + this.setState({ joinDirectCall: false, ongoingDirectCall: null }); + + break; default: break; } }; - sendMessage = (message) => { const { route } = this.props; @@ -353,7 +393,6 @@ class CometChatMessages extends React.PureComponent { }); }; - messageSent = (message) => { const messageList = [...this.state.messageList]; @@ -369,6 +408,9 @@ class CometChatMessages extends React.PureComponent { }; memberUnbanned = (members) => { + if (!this.state.restrictions?.isGroupActionMessagesEnabled) { + return false; + } const messageList = [...this.state.messageList]; let filteredMembers = _.uniqBy(members, 'id'); filteredMembers.forEach((eachMember) => { @@ -387,6 +429,9 @@ class CometChatMessages extends React.PureComponent { }; membersAdded = (members) => { + if (!this.state.restrictions?.isGroupActionMessagesEnabled) { + return false; + } const messageList = [...this.state.messageList]; members.forEach((eachMember) => { const message = `${this.loggedInUser.name} added ${eachMember.name}`; @@ -404,6 +449,9 @@ class CometChatMessages extends React.PureComponent { }; membersRemoved = (members) => { + if (!this.state.restrictions?.isGroupActionMessagesEnabled) { + return false; + } const messageList = [...this.state.messageList]; let filteredMembers = _.uniqBy(members, 'id'); filteredMembers.forEach((eachMember) => { @@ -422,6 +470,9 @@ class CometChatMessages extends React.PureComponent { }; memberScopeChanged = (members) => { + if (!this.state.restrictions?.isGroupActionMessagesEnabled) { + return false; + } const messageList = [...this.state.messageList]; let filteredMembers = _.uniqBy(members, 'id'); filteredMembers.forEach((eachMember) => { @@ -440,6 +491,9 @@ class CometChatMessages extends React.PureComponent { }; memberBanned = (members) => { + if (!this.state.restrictions?.isGroupActionMessagesEnabled) { + return false; + } const messageList = [...this.state.messageList]; members.forEach((eachMember) => { const message = `${this.loggedInUser.name} banned ${eachMember.name}`; @@ -659,7 +713,7 @@ class CometChatMessages extends React.PureComponent { if (messageKey > -1) { const messageObj = { ...messageList[messageKey] }; const newMessageObj = { ...messageObj, ...deletedMessage }; - if (HIDE_DELETED_MSG) { + if (this.state.restrictions?.isHideDeletedMessagesEnabled) { messageList.splice(messageKey, 1); } else { messageList.splice(messageKey, 1, newMessageObj); @@ -842,6 +896,15 @@ class CometChatMessages extends React.PureComponent { /> ); + if ( + (params.type === CometChat.RECEIVER_TYPE.USER && + this.state.restrictions?.isOneOnOneChatEnabled === false) || + (params.type === CometChat.RECEIVER_TYPE.GROUP && + this.state.restrictions?.isGroupChatEnabled === false) + ) { + messageComposer = null; + } + let liveReactionView = null; if (this.state.liveReaction) { liveReactionView = ( @@ -898,102 +961,120 @@ class CometChatMessages extends React.PureComponent { ); return ( - - - {this.state.showProfile ? ( - this.setState({ showProfile: null })} - url={this.state.user?.link} + (this.contextProviderRef = el)}> + + + {this.state.showProfile ? ( + this.setState({ showProfile: null })} + url={this.state.user?.link} + /> + ) : null} + {this.state.videoMessage ? ( + this.setState({ videoMessage: null })} + message={this.state.videoMessage} + /> + ) : null} + {this.state.userDetailVisible ? ( + + ) : null} + {threadMessageView} + {this.state.groupDetailVisible ? ( + + ) : null} + { + this.actionHandler('closeMessageActions'); + }} /> - ) : null} - {this.state.videoMessage ? ( - this.setState({ videoMessage: null })} - message={this.state.videoMessage} + - ) : null} - {this.state.userDetailVisible ? ( - { + this.DropDownAlertRef?.showMessage(type, message); + }} + // widgetsettings={route.params.widgetsettings} + // widgetconfig={route.params.widgetconfig} + loggedInUser={params.loggedInUser} actionGenerated={this.actionHandler} /> - ) : null} - {threadMessageView} - {this.state.groupDetailVisible ? ( - + (this.DropDownAlertRef = ref)} /> + + {this.state.ongoingDirectCall ? ( + <> + this.actionHandler(actions.DIRECT_CALL_ENDED)} theme={this.theme} - open={this.state.groupDetailVisible} item={this.state.item} type={params.type} + lang={this.state.lang} + callType={CometChat.CALL_TYPE.VIDEO} + joinDirectCall={this.state.joinDirectCall} + loggedInUser={params.loggedInUser} actionGenerated={this.actionHandler} - loggedInUser={this.loggedInUser} /> - ) : null} - { - this.actionHandler('closeMessageActions'); - }} - /> - - { - this.DropDownAlertRef?.showMessage(type, message); - }} - // widgetsettings={route.params.widgetsettings} - // widgetconfig={route.params.widgetconfig} - loggedInUser={params.loggedInUser} - actionGenerated={this.actionHandler} - /> - {liveReactionView} - {messageComposer} - - (this.DropDownAlertRef = ref)} /> - + + ) : null} + ); } } diff --git a/src/components/Messages/CometChatReadReceipt/index.js b/src/components/Messages/CometChatReadReceipt/index.js index ed7b0c5..1c89b06 100644 --- a/src/components/Messages/CometChatReadReceipt/index.js +++ b/src/components/Messages/CometChatReadReceipt/index.js @@ -1,6 +1,6 @@ -import React from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Text, View, Image, Platform } from 'react-native'; -import { get as _get } from 'lodash'; +import { get as _get, identity } from 'lodash'; import blueDoubleTick from './resources/blue-double-tick-icon.png'; import greyDoubleTick from './resources/grey-double-tick-icon.png'; @@ -9,7 +9,19 @@ import sendingTick from './resources/sending.png'; import errorTick from './resources/error.png'; import styles from './styles'; import { CometChat } from '@cometchat-pro/react-native-chat'; +import { CometChatContext } from '../../../utils/CometChatContext'; const CometChatReadReceipt = (props) => { + const context = useContext(CometChatContext); + const [isDeliveryReceiptsEnabled, setIsDeliveryReceiptsEnabled] = useState( + true, + ); + useEffect(() => { + checkRestrictions(); + }); + const checkRestrictions = async () => { + let isEnabled = await context.FeatureRestriction.isDeliveryReceiptsEnabled(); + setIsDeliveryReceiptsEnabled(isEnabled); + }; let ticks = blueDoubleTick; if (props.message.messageFrom === 'sender') { if (props.message.receiverType === CometChat.RECEIVER_TYPE.GROUP) { @@ -76,7 +88,9 @@ const CometChatReadReceipt = (props) => { timeValue += hours >= 12 ? ' PM' : ' AM'; // get AM/PM timestamp = timeValue; } - + if (!isDeliveryReceiptsEnabled) { + ticks = null; + } return ( {timestamp} diff --git a/src/components/Messages/CometChatReceiverAudioMessageBubble/index.js b/src/components/Messages/CometChatReceiverAudioMessageBubble/index.js index e0c726d..9f5daaa 100644 --- a/src/components/Messages/CometChatReceiverAudioMessageBubble/index.js +++ b/src/components/Messages/CometChatReceiverAudioMessageBubble/index.js @@ -5,8 +5,8 @@ import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; import CometChatReadReceipt from '../CometChatReadReceipt'; -import { CometChatMessageReactions } from '../../Messages/Extensions'; -import { CometChatAvatar } from '../../Shared'; +import CometChatMessageReactions from '../../Messages/Extensions/CometChatMessageReactions'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import style from './styles'; import AudioControls from './audioControls'; import { CometChat } from '@cometchat-pro/react-native-chat'; diff --git a/src/components/Messages/CometChatReceiverDirectCallBubble/index.js b/src/components/Messages/CometChatReceiverDirectCallBubble/index.js index 9ea3674..32a97aa 100644 --- a/src/components/Messages/CometChatReceiverDirectCallBubble/index.js +++ b/src/components/Messages/CometChatReceiverDirectCallBubble/index.js @@ -1,19 +1,15 @@ -import React from 'react'; -import { - CometChatMessageActions, - CometChatThreadedMessageReplyCount, - CometChatReadReceipt, -} from '../'; import { CometChat } from '@cometchat-pro/react-native-chat'; -import { View, Text, Image, TouchableOpacity } from 'react-native'; -import { CometChatMessageReactions } from '../Extensions'; -import { CometChatAvatar } from '../../Shared'; -import Styles from './style'; -import { checkMessageForExtensionsData } from '../../../utils/common'; -import * as actions from '../../../utils/actions'; +import React from 'react'; +import { Image, Text, TouchableOpacity, View } from 'react-native'; import theme from '../../../resources/theme'; - +import * as actions from '../../../utils/actions'; +import { checkMessageForExtensionsData } from '../../../utils/common'; +import CometChatAvatar from '../..//Shared/CometChatAvatar'; +import CometChatReadReceipt from '../CometChatReadReceipt'; +import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; +import CometChatMessageReactions from '../Extensions/CometChatMessageReactions'; import callIcon from './resources/receivervideocall.png'; +import Styles from './style'; class CometChatReceiverDirectCallBubble extends React.Component { messageFrom = 'receiver'; diff --git a/src/components/Messages/CometChatReceiverFileMessageBubble/index.js b/src/components/Messages/CometChatReceiverFileMessageBubble/index.js index 50be699..0d93f85 100644 --- a/src/components/Messages/CometChatReceiverFileMessageBubble/index.js +++ b/src/components/Messages/CometChatReceiverFileMessageBubble/index.js @@ -3,11 +3,11 @@ import React from 'react'; import { View, Text, TouchableWithoutFeedback, Alert } from 'react-native'; import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; import CometChatReadReceipt from '../CometChatReadReceipt'; -import { CometChatMessageReactions } from '../../Messages/Extensions'; +import CometChatMessageReactions from '../../Messages/Extensions/CometChatMessageReactions'; import style from './styles'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import RNFetchBlob from 'rn-fetch-blob'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import { CometChat } from '@cometchat-pro/react-native-chat'; diff --git a/src/components/Messages/CometChatReceiverImageMessageBubble/index.js b/src/components/Messages/CometChatReceiverImageMessageBubble/index.js index a58666c..c453103 100644 --- a/src/components/Messages/CometChatReceiverImageMessageBubble/index.js +++ b/src/components/Messages/CometChatReceiverImageMessageBubble/index.js @@ -1,10 +1,10 @@ import React, { useState, useRef, useEffect } from 'react'; import { View, TouchableOpacity, Text } from 'react-native'; import FastImage from 'react-native-fast-image'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; import CometChatReadReceipt from '../CometChatReadReceipt'; -import { CometChatMessageReactions } from '../../Messages/Extensions'; +import CometChatMessageReactions from '../../Messages/Extensions/CometChatMessageReactions'; import style from './styles'; import theme from '../../../resources/theme'; import * as enums from '../../../utils/enums'; diff --git a/src/components/Messages/CometChatReceiverTextMessageBubble/index.js b/src/components/Messages/CometChatReceiverTextMessageBubble/index.js index 2cf160c..ff14fb2 100644 --- a/src/components/Messages/CometChatReceiverTextMessageBubble/index.js +++ b/src/components/Messages/CometChatReceiverTextMessageBubble/index.js @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; import { View, Text, @@ -11,12 +11,13 @@ import theme from '../../../resources/theme'; import Autolink from 'react-native-autolink'; import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; import CometChatReadReceipt from '../CometChatReadReceipt'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import style from './styles'; -import { CometChatMessageReactions } from '../../Messages/Extensions'; +import CometChatMessageReactions from '../../Messages/Extensions/CometChatMessageReactions'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; import { CometChat } from '@cometchat-pro/react-native-chat'; +import { CometChatContext } from '../../../utils/CometChatContext'; function usePrevious(value) { const ref = useRef(); @@ -36,6 +37,17 @@ const CometChatReceiverTextMessageBubble = (props) => { if (message.receiverType === CometChat.RECEIVER_TYPE.GROUP) { senderAvatar = { uri: message.sender.avatar }; } + const context = useContext(CometChatContext); + const [restrictions, setRestrictions] = useState(null); + + useEffect(() => { + checkRestrictions(); + }, []); + + const checkRestrictions = async () => { + let isLinkPreviewEnabled = context.FeatureRestriction.isLinkPreviewEnabled(); + setRestrictions({ isLinkPreviewEnabled }); + }; /** * Handler that parses text and wraps URLs, phone numbers, emails, social handles, hashtags, and more with Text nodes and onPress handlers. @@ -81,7 +93,8 @@ const CometChatReceiverTextMessageBubble = (props) => { if ( linkPreviewObject && Object.prototype.hasOwnProperty.call(linkPreviewObject, 'links') && - linkPreviewObject.links.length + linkPreviewObject.links.length && + !restrictions?.isLinkPreviewEnabled ) { const linkObject = linkPreviewObject.links[0]; const pattern = /(http:|https:)?\/\/(www\.)?(youtube.com|youtu.be)(\S+)?/; diff --git a/src/components/Messages/CometChatReceiverVideoMessageBubble/index.js b/src/components/Messages/CometChatReceiverVideoMessageBubble/index.js index 3a75a41..ba23a87 100644 --- a/src/components/Messages/CometChatReceiverVideoMessageBubble/index.js +++ b/src/components/Messages/CometChatReceiverVideoMessageBubble/index.js @@ -5,10 +5,10 @@ import { TouchableOpacity } from 'react-native-gesture-handler'; import VideoPlayer from 'react-native-video-controls'; import theme from '../../../resources/theme'; import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; -import { CometChatMessageReactions } from '../../Messages/Extensions'; +import CometChatMessageReactions from '../../Messages/Extensions/CometChatMessageReactions'; import CometChatReadReceipt from '../CometChatReadReceipt'; import style from './styles'; -import { CometChatAvatar } from '../../Shared'; +import CometChatAvatar from '../../Shared/CometChatAvatar'; import * as actions from '../../../utils/actions'; import * as enums from '../../../utils/enums'; import { CometChat } from '@cometchat-pro/react-native-chat'; diff --git a/src/components/Messages/CometChatSenderDirectCallBubble/index.js b/src/components/Messages/CometChatSenderDirectCallBubble/index.js index b3bbb30..f188fba 100644 --- a/src/components/Messages/CometChatSenderDirectCallBubble/index.js +++ b/src/components/Messages/CometChatSenderDirectCallBubble/index.js @@ -1,18 +1,18 @@ import React from 'react'; import { - CometChatMessageActions, - CometChatThreadedMessageReplyCount, - CometChatReadReceipt, -} from '../'; -import Styles from './style'; + Image, + Text, + TouchableOpacity, + TouchableWithoutFeedback, + View, +} from 'react-native'; +import CometChatReadReceipt from '../CometChatReadReceipt'; +import CometChatThreadedMessageReplyCount from '../CometChatThreadedMessageReplyCount'; import * as actions from '../../../utils/actions'; -import { CometChatMessageReactions } from '../Extensions'; import { checkMessageForExtensionsData } from '../../../utils/common'; -import * as enums from '../../../utils/enums'; -import theme from '../../../resources/theme'; +import { CometChatMessageReactions } from '../Extensions'; import callIcon from './resources/sendervideocall.png'; -import { View, Text, Image, TouchableOpacity } from 'react-native'; -import { TouchableWithoutFeedback } from 'react-native'; +import Styles from './style'; class CometChatSenderDirectCallBubble extends React.Component { messageFrom = 'sender'; diff --git a/src/components/Messages/CometChatSenderTextMessageBubble/index.js b/src/components/Messages/CometChatSenderTextMessageBubble/index.js index 293af99..2fc2eec 100644 --- a/src/components/Messages/CometChatSenderTextMessageBubble/index.js +++ b/src/components/Messages/CometChatSenderTextMessageBubble/index.js @@ -1,4 +1,4 @@ -import React, { useEffect, useRef, useState } from 'react'; +import React, { useEffect, useRef, useState, useContext } from 'react'; import { View, Text, @@ -15,6 +15,7 @@ import style from './styles'; import { CometChatMessageReactions } from '../../Messages/Extensions'; import * as enums from '../../../utils/enums'; import * as actions from '../../../utils/actions'; +import { CometChatContext } from '../../../utils/CometChatContext'; function usePrevious(value) { const ref = useRef(); @@ -31,6 +32,17 @@ const CometChatSenderTextMessageBubble = (props) => { }); const prevMessage = usePrevious(message); const viewTheme = { ...theme, ...props.theme }; + const context = useContext(CometChatContext); + const [restrictions, setRestrictions] = useState(null); + + useEffect(() => { + checkRestrictions(); + }, []); + + const checkRestrictions = async () => { + let isLinkPreviewEnabled = context.FeatureRestriction.isLinkPreviewEnabled(); + setRestrictions({ isLinkPreviewEnabled }); + }; /** * Handler that parses text and wraps URLs, phone numbers, emails, social handles, hashtags, and more with Text nodes and onPress handlers. @@ -77,7 +89,8 @@ const CometChatSenderTextMessageBubble = (props) => { if ( linkPreviewObject && Object.prototype.hasOwnProperty.call(linkPreviewObject, 'links') && - linkPreviewObject.links.length + linkPreviewObject.links.length && + restrictions?.isLinkPreviewEnabled ) { const linkObject = linkPreviewObject.links[0]; diff --git a/src/components/Messages/CometChatVideoViewer/.DS_Store b/src/components/Messages/CometChatVideoViewer/.DS_Store deleted file mode 100644 index ff4edbd2eba077a421c7c587c4ff397bd49fa739..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKF-`+95S)b+hiKA4>5>YGA6QW+sQCa&LIFB)5=SKHuHiAf5@yyWB;;BULc5YZ z8}E*N9x1jLfX&vc3t$SMVH2915!3K!=%6Ma63yp$#yRfMU$xzGWTL+~q;GF>cpwB3R+3G>Ew_U=XxIKm@ydvsXSTgumtzZiD1$LR5d7qrgXXtc$6{l?HbVWB`M z5DJ6>p}9}=4|R~!oZ(ZSA30OEwhZuIqJ7AIBA6^DY1 z(5z62g=)3LutMi}s(HEMP_WQpwfL~Q@@Mg4zB=bmo({_eqYni_fn5bu`_iVm|1bHM z87=ZXCAv@`6!@ { props.actionGenerated(actions.POLL_CREATED, message); }) .catch((err) => { - console.log('err', err); const errorCode = err?.details?.message || err?.message || 'ERROR'; dropDownAlertRef?.current?.showMessage('error', errorCode); setError(err); diff --git a/src/components/Messages/Extensions/CometChatMessageReactions/index.js b/src/components/Messages/Extensions/CometChatMessageReactions/index.js index 88f8d91..71351f7 100644 --- a/src/components/Messages/Extensions/CometChatMessageReactions/index.js +++ b/src/components/Messages/Extensions/CometChatMessageReactions/index.js @@ -19,16 +19,26 @@ import * as enums from '../../../../utils/enums'; import { ModalPicker, Emoji } from 'emoji-mart-native'; import ReactionDetails from './reactionDetails'; import DropDownAlert from '../../../Shared/DropDownAlert'; +import { CometChatContext } from '../../../../utils/CometChatContext'; class CometChatMessageReactions extends Component { + static contextType = CometChatContext; constructor(props) { super(props); this.state = { message: props.message, pickerVisible: false, reactionsDetailContainer: false, + restrictions: null, }; } + componentDidMount() { + this.checkRestrictions(); + } + checkRestrictions = async () => { + let isReactionsEnabled = await this.context.FeatureRestriction.isReactionsEnabled(); + this.setState({ restrictions: { isReactionsEnabled } }); + }; componentDidUpdate(prevProps) { if ( @@ -131,6 +141,9 @@ class CometChatMessageReactions extends Component { }; render() { + if (!this.state.restrictions?.isReactionsEnabled) { + return null; + } const { pickerVisible, message, reactionsDetailContainer } = this.state; const reaction = checkMessageForExtensionsData(message, 'reactions'); const messageReactions = this.getMessageReactions(reaction); diff --git a/src/components/Messages/Extensions/CometChatMessageReactions/styles.js b/src/components/Messages/Extensions/CometChatMessageReactions/styles.js index b7668a8..b987e34 100644 --- a/src/components/Messages/Extensions/CometChatMessageReactions/styles.js +++ b/src/components/Messages/Extensions/CometChatMessageReactions/styles.js @@ -21,12 +21,10 @@ export default StyleSheet.create({ alignItems: 'center', justifyContent: 'center', elevation: 1, - shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.2, shadowRadius: 2, - backgroundColor: '#fff', margin: 2, }, diff --git a/src/components/Messages/Extensions/CometChatReceiverPollMessageBubble/index.js b/src/components/Messages/Extensions/CometChatReceiverPollMessageBubble/index.js index eaa0f5d..9b62caf 100644 --- a/src/components/Messages/Extensions/CometChatReceiverPollMessageBubble/index.js +++ b/src/components/Messages/Extensions/CometChatReceiverPollMessageBubble/index.js @@ -3,13 +3,12 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; import { View, Text, FlatList, TouchableOpacity } from 'react-native'; import DropDownAlert from '../../../Shared/DropDownAlert'; import theme from '../../../../resources/theme'; -import { - CometChatReadReceipt, - CometChatThreadedMessageReplyCount, -} from '../../'; +import CometChatReadReceipt from '../../CometChatReadReceipt'; +import CometChatThreadedMessageReplyCount from '../../CometChatThreadedMessageReplyCount'; + import style from './styles'; -import { CometChatAvatar } from '../../../Shared'; -import { CometChatMessageReactions } from '../index'; +import CometChatAvatar from '../../../Shared/CometChatAvatar'; +import CometChatMessageReactions from '../CometChatMessageReactions'; import Icon from 'react-native-vector-icons/MaterialIcons'; import * as actions from '../../../../utils/actions'; import * as enums from '../../../../utils/enums'; diff --git a/src/components/Messages/Extensions/CometChatReceiverStickerMessageBubble/index.js b/src/components/Messages/Extensions/CometChatReceiverStickerMessageBubble/index.js index b8aca34..72c6eb8 100644 --- a/src/components/Messages/Extensions/CometChatReceiverStickerMessageBubble/index.js +++ b/src/components/Messages/Extensions/CometChatReceiverStickerMessageBubble/index.js @@ -3,13 +3,12 @@ import { View, Text } from 'react-native'; import FastImage from 'react-native-fast-image'; import theme from '../../../../resources/theme'; -import { - CometChatThreadedMessageReplyCount, - CometChatReadReceipt, -} from '../../'; +import CometChatThreadedMessageReplyCount from '../../CometChatThreadedMessageReplyCount'; +import CometChatReadReceipt from '../../CometChatReadReceipt'; + import style from './styles'; -import { CometChatAvatar } from '../../../Shared'; -import { CometChatMessageReactions } from '../index'; +import CometChatAvatar from '../../../Shared/CometChatAvatar'; +import CometChatMessageReactions from '../CometChatMessageReactions'; import * as enums from '../../../../utils/enums'; import { CometChat } from '@cometchat-pro/react-native-chat'; diff --git a/src/components/Messages/Extensions/CometChatSenderPollMessageBubble/index.js b/src/components/Messages/Extensions/CometChatSenderPollMessageBubble/index.js index ddfbf97..86560cf 100644 --- a/src/components/Messages/Extensions/CometChatSenderPollMessageBubble/index.js +++ b/src/components/Messages/Extensions/CometChatSenderPollMessageBubble/index.js @@ -1,11 +1,10 @@ import React, { useEffect } from 'react'; import { View, Text, FlatList, TouchableWithoutFeedback } from 'react-native'; import theme from '../../../../resources/theme'; -import { - CometChatReadReceipt, - CometChatThreadedMessageReplyCount, -} from '../../'; -import { CometChatMessageReactions } from '../index'; +import CometChatReadReceipt from '../../CometChatReadReceipt'; +import CometChatThreadedMessageReplyCount from '../../CometChatThreadedMessageReplyCount'; + +import CometChatMessageReactions from '../CometChatMessageReactions'; import style from './styles'; import * as enums from '../../../../utils/enums'; diff --git a/src/components/Messages/Extensions/CometChatSenderStickerMessageBubble/index.js b/src/components/Messages/Extensions/CometChatSenderStickerMessageBubble/index.js index 0764be1..b5e3e3c 100644 --- a/src/components/Messages/Extensions/CometChatSenderStickerMessageBubble/index.js +++ b/src/components/Messages/Extensions/CometChatSenderStickerMessageBubble/index.js @@ -1,11 +1,10 @@ import React, { useState } from 'react'; import { View, TouchableWithoutFeedback } from 'react-native'; import FastImage from 'react-native-fast-image'; -import { - CometChatReadReceipt, - CometChatThreadedMessageReplyCount, -} from '../../'; -import { CometChatMessageReactions } from '../index'; +import CometChatReadReceipt from '../../CometChatReadReceipt'; +import CometChatThreadedMessageReplyCount from '../../CometChatThreadedMessageReplyCount'; + +import CometChatMessageReactions from '../CometChatMessageReactions'; import style from './styles'; import * as enums from '../../../../utils/enums'; diff --git a/src/components/Shared/CometChatSharedMedia/controller.js b/src/components/Shared/CometChatSharedMedia/controller.js index 4c2b03b..628484f 100644 --- a/src/components/Shared/CometChatSharedMedia/controller.js +++ b/src/components/Shared/CometChatSharedMedia/controller.js @@ -1,20 +1,27 @@ import { CometChat } from '@cometchat-pro/react-native-chat'; import * as enums from '../../../utils/enums'; -import { HIDE_DELETED_MSG } from '../../../utils/settings'; export class SharedMediaManager { mediaMessageListenerId = `shared_media_${new Date().getTime()}`; mediaMessageRequest = null; - constructor(item, type, messageType) { + constructor(item, type, messageType, context) { + this.checkRestrictions(item, type, messageType, context); + } + checkRestrictions = async (item, type, messageType, context) => { + this.hideDeletedMessages = await context.FeatureRestriction.isHideDeletedMessagesEnabled(); + this.createBuilder(item, type, messageType); + }; + + createBuilder = (item, type, messageType) => { if (type === CometChat.RECEIVER_TYPE.USER) { this.mediaMessageRequest = new CometChat.MessagesRequestBuilder() .setUID(item.uid) .setLimit(10) .setCategory(CometChat.CATEGORY_MESSAGE) .setType(messageType) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .build(); } else { this.mediaMessageRequest = new CometChat.MessagesRequestBuilder() @@ -22,10 +29,10 @@ export class SharedMediaManager { .setLimit(10) .setCategory(CometChat.CATEGORY_MESSAGE) .setType(messageType) - .hideDeletedMessages(HIDE_DELETED_MSG) + .hideDeletedMessages(this.hideDeletedMessages) .build(); } - } + }; fetchPreviousMessages() { return this.mediaMessageRequest.fetchPrevious(); diff --git a/src/components/Shared/CometChatSharedMedia/index.js b/src/components/Shared/CometChatSharedMedia/index.js index dd1635b..16b3cf9 100644 --- a/src/components/Shared/CometChatSharedMedia/index.js +++ b/src/components/Shared/CometChatSharedMedia/index.js @@ -1,22 +1,23 @@ +import { CometChat } from '@cometchat-pro/react-native-chat'; +import _ from 'lodash'; import React from 'react'; -import { View, Text, Linking, TouchableOpacity, FlatList } from 'react-native'; +import { FlatList, Linking, Text, TouchableOpacity, View } from 'react-native'; import FastImage from 'react-native-fast-image'; -import { CometChatManager } from '../../../utils/controller'; -import { SharedMediaManager } from './controller'; -import { CometChatImageViewer } from '../../Messages'; +import Icon from 'react-native-vector-icons/FontAwesome5'; +import VideoPlayer from 'react-native-video-controls'; import theme from '../../../resources/theme'; -import _ from 'lodash'; +import { CometChatContext } from '../../../utils/CometChatContext'; +import { logger } from '../../../utils/common'; +import { deviceHeight, heightRatio } from '../../../utils/consts'; +import { CometChatManager } from '../../../utils/controller'; import * as enums from '../../../utils/enums'; -import styles from './styles'; -import VideoPlayer from 'react-native-video-controls'; +import CometChatImageViewer from '../../Messages/CometChatImageViewer'; import DropDownAlert from '../../Shared/DropDownAlert'; - -import Icon from 'react-native-vector-icons/FontAwesome5'; -import { CometChat } from '@cometchat-pro/react-native-chat'; -import { deviceHeight, heightRatio } from '../../../utils/consts'; -import { logger } from '../../../utils/common'; +import { SharedMediaManager } from './controller'; +import styles from './styles'; export default class CometChatSharedMedia extends React.Component { + static contextType = CometChatContext; constructor(props) { super(props); @@ -35,6 +36,7 @@ export default class CometChatSharedMedia extends React.Component { this.props.item, this.props.type, this.state.messageType, + this.context, ); this.getMessages(); this.SharedMediaManager.attachListeners(this.messageUpdated); diff --git a/src/components/Shared/CometChatUserPresence/index.js b/src/components/Shared/CometChatUserPresence/index.js index 3f2aaf5..7532bf4 100644 --- a/src/components/Shared/CometChatUserPresence/index.js +++ b/src/components/Shared/CometChatUserPresence/index.js @@ -1,10 +1,20 @@ -import React from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { View } from 'react-native'; import styles from './styles'; import * as enums from '../../../utils/enums'; import { CometChat } from '@cometchat-pro/react-native-chat'; +import { CometChatContext } from '../../../utils/CometChatContext'; const CometChatUserPresence = (props) => { + const context = useContext(CometChatContext); + const [isPresenceEnabled, setIsPresenceEnabled] = useState(true); + useEffect(() => { + checkRestrictions(); + }, []); + const checkRestrictions = async () => { + let isEnabled = await context.FeatureRestriction.isUserPresenceEnabled(); + setIsPresenceEnabled(isEnabled); + }; let presenceStatus = { backgroundColor: 'rgb(85, 85, 85)', }; @@ -28,6 +38,9 @@ const CometChatUserPresence = (props) => { borderColor, borderRadius: cornerRadius, }; + if (!isPresenceEnabled) { + return null; + } return ( { + 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, + isBlockUserEnabled, + isViewProfileEnabled, + isUserPresenceEnabled, + }, + }); + }; + setStatusForUser = () => { try { let { status } = this.props.item; @@ -104,7 +123,9 @@ export default class CometChatUserDetails extends React.Component { image={{ uri: this.props.item.avatar }} name={this.props.item.name} /> - {this.props.item && this.props.item.blockedByMe ? null : ( + {this.props.item && + this.props.item.blockedByMe && + !this.state.restrictions?.isUserPresenceEnabled ? null : ( ); + if (!this.state.restrictions?.isViewProfileEnabled) { + showProfile = null; + } + let blockUserView = ( ); - let action = this.props.item?.link ? ( - - - ACTIONS - + if (!this.state.restrictions?.isBlockUserEnabled) { + blockUserView = null; + } - {showProfile} - - ) : null; + let action = + this.props.item?.link && this.state.restrictions?.isViewProfileEnabled ? ( + + + ACTIONS + + + {showProfile} + + ) : null; let sharedMediaView = ( ); + if (!this.state.restrictions?.isSharedMediaEnabled) { + sharedMediaView = null; + } return ( { + let UIKitSettingsBuilder = new UIKitSettings(); + const userListMode = UIKitSettingsBuilder.userListMode; + const userListModeOptions = UIKitSettings.userListFilterOptions; + + return new Promise((resolve, reject) => { + if (userListMode === userListModeOptions['ALL']) { + if (this.searchKey) { + this.usersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .setSearchKeyword(this.searchKey) + .build(); + } else { + this.usersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .build(); + } + + return resolve(this.usersRequest); + } else if (userListMode === userListModeOptions['FRIENDS']) { + if (this.searchKey) { + this.usersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .friendsOnly(true) + .setSearchKeyword(this.searchKey) + .build(); + } else { + this.usersRequest = new CometChat.UsersRequestBuilder() + .setLimit(30) + .friendsOnly(true) + .build(); + } + + return resolve(this.usersRequest); + } else { + return reject({ message: 'Invalid filter for userlist' }); + } + }); + }; + fetchNextUsers() { return this.usersRequest.fetchNext(); } diff --git a/src/components/Users/CometChatUserList/index.js b/src/components/Users/CometChatUserList/index.js index bcf901f..8e6c37b 100644 --- a/src/components/Users/CometChatUserList/index.js +++ b/src/components/Users/CometChatUserList/index.js @@ -11,12 +11,16 @@ import { KeyboardAvoidingView, Keyboard, } from 'react-native'; +import { + CometChatContextProvider, + CometChatContext, +} from '../../../utils/CometChatContext'; import Icon from 'react-native-vector-icons/Ionicons'; import { CometChatManager } from '../../../utils/controller'; import { UserListManager } from './controller'; -import { CometChatUserListItem } from '../index'; +import CometChatUserListItem from '../CometChatUserListItem'; import style from './styles'; import theme from '../../../resources/theme'; import { logger } from '../../../utils/common'; @@ -24,6 +28,8 @@ import * as enums from '../../../utils/enums'; import { CometChat } from '@cometchat-pro/react-native-chat'; import DropDownAlert from '../../Shared/DropDownAlert'; class CometChatUserList extends React.PureComponent { + static contextType = CometChatContext; + timeout; friendsOnly = false; @@ -39,6 +45,7 @@ class CometChatUserList extends React.PureComponent { textInputValue: '', textInputFocused: false, showSmallHeader: false, + restrictions: null, }; this.userListRef = React.createRef(); this.textInputRef = React.createRef(null); @@ -47,6 +54,7 @@ class CometChatUserList extends React.PureComponent { } componentDidMount() { + this.checkRestrictions(); try { if (Object.prototype.hasOwnProperty.call(this.props, 'friendsOnly')) { this.friendsOnly = this.props.friendsOnly; @@ -58,15 +66,27 @@ class CometChatUserList extends React.PureComponent { this.UserListManager.removeListeners(); } this.setState({ userList: [] }); - this.UserListManager = new UserListManager(this.friendsOnly); - this.getUsers(); - this.UserListManager.attachListeners(this.userUpdated); + this.UserListManager = new UserListManager(); + this.UserListManager.initializeUsersRequest() + .then((response) => { + this.getUsers(); + this.UserListManager.attachListeners(this.userUpdated); + }) + .catch((error) => { + console.log(error); + }); }); } catch (error) { logger(error); } } + checkRestrictions = async () => { + let context = this.contextProviderRef.state; + let isUserSearchEnabled = await context.FeatureRestriction.isUserSearchEnabled(); + this.setState({ restrictions: { isUserSearchEnabled } }); + }; + componentDidUpdate(prevProps) { try { if (this.state.textInputFocused) { @@ -186,7 +206,7 @@ class CometChatUserList extends React.PureComponent { } this.timeout = setTimeout(() => { - this.UserListManager = new UserListManager(this.friendsOnly, val); + this.UserListManager = new UserListManager(val); this.setState({ userList: [] }, () => this.getUsers()); }, 500); }, @@ -300,40 +320,42 @@ class CometChatUserList extends React.PureComponent { return ( Users - this.textInputRef.current.focus()}> - - - { - this.setState({ textInputFocused: true }); - }} - onBlur={() => { - this.setState({ textInputFocused: false }); - }} - clearButtonMode="always" - numberOfLines={1} + {this.state.restrictions?.isUserSearchEnabled ? ( + this.textInputRef.current.focus()}> + - - + ]}> + + { + this.setState({ textInputFocused: true }); + }} + onBlur={() => { + this.setState({ textInputFocused: false }); + }} + clearButtonMode="always" + numberOfLines={1} + style={[ + style.contactSearchInputStyle, + { + color: `${this.theme.color.primary}`, + }, + ]} + /> + + + ) : null} ); }; @@ -380,32 +402,35 @@ class CometChatUserList extends React.PureComponent { } return ( - { - Keyboard.dismiss(); - }}> - - - {this.listHeaderComponent()} - - (this.dropDownAlertRef = ref)} /> - - + (this.contextProviderRef = el)}> + { + Keyboard.dismiss(); + }}> + + + {this.listHeaderComponent()} + item.uid + '_' + index} + stickyHeaderIndices={ + Platform.OS === 'android' ? null : headerIndices + } + onScroll={this.handleScroll} + onEndReached={this.endReached} + onEndReachedThreshold={0.3} + showsVerticalScrollIndicator={false} + /> + (this.dropDownAlertRef = ref)} /> + + + ); } } diff --git a/src/components/Users/CometChatUserListItem/index.js b/src/components/Users/CometChatUserListItem/index.js index 2119402..b11c332 100644 --- a/src/components/Users/CometChatUserListItem/index.js +++ b/src/components/Users/CometChatUserListItem/index.js @@ -10,6 +10,7 @@ const CometChatUserListItem = (props) => { return ( props.clickHandler(props.user)} underlayColor={viewTheme.backgroundColor.listUnderlayColor}> diff --git a/src/components/Users/CometChatUserListWithMessages/index.js b/src/components/Users/CometChatUserListWithMessages/index.js index db58795..2292a83 100644 --- a/src/components/Users/CometChatUserListWithMessages/index.js +++ b/src/components/Users/CometChatUserListWithMessages/index.js @@ -3,11 +3,13 @@ import React from 'react'; import { SafeAreaView, View } from 'react-native'; import { CometChat } from '@cometchat-pro/react-native-chat'; -import { CometChatOutgoingCall, CometChatIncomingCall } from '../../Calls'; -import { CometChatUserList } from '../index'; +import CometChatOutgoingCall from '../../Calls/CometChatOutgoingCall'; +import CometChatIncomingCall from '../../Calls/CometChatIncomingCall'; +import CometChatUserList from '../CometChatUserList'; import { CometChatManager } from '../../../utils/controller'; -import { CometChatImageViewer } from '../../Messages'; +import CometChatImageViewer from '../../Messages/CometChatImageViewer'; import theme from '../../../resources/theme'; +import { CometChatContextProvider } from '../../../utils/CometChatContext'; import * as actions from '../../../utils/actions'; import * as enums from '../../../utils/enums'; import { logger } from '../../../utils/common'; @@ -378,37 +380,39 @@ class CometChatUserListWithMessages extends React.Component { ); } return ( - - - {imageView} - { - this.dropDownAlertRef?.showMessage(type, message); - }} - theme={this.props.theme} - loggedInUser={this.loggedInUser} - outgoingCall={this.state.outgoingCall} - actionGenerated={this.actionHandler} - /> - - (this.dropDownAlertRef = ref)} /> - + (this.contextProviderRef = el)}> + + + {imageView} + { + this.dropDownAlertRef?.showMessage(type, message); + }} + theme={this.props.theme} + loggedInUser={this.loggedInUser} + outgoingCall={this.state.outgoingCall} + actionGenerated={this.actionHandler} + /> + + (this.dropDownAlertRef = ref)} /> + + ); } } diff --git a/src/utils/CometChatContext.js b/src/utils/CometChatContext.js new file mode 100644 index 0000000..63dfc58 --- /dev/null +++ b/src/utils/CometChatContext.js @@ -0,0 +1,31 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { UIKitSettings } from './UIKitSettings'; +import { FeatureRestriction } from './FeatureRestriction'; +import { theme } from '../resources/theme'; + +export const CometChatContext = React.createContext({}); + +export class CometChatContextProvider extends React.Component { + constructor(props) { + super(props); + + const settings = new UIKitSettings(); + const featureRestriction = new FeatureRestriction(settings); + + this.state = { + UIKitSettings: settings, + FeatureRestriction: featureRestriction, + theme: theme, + }; + } + + render() { + return ( + + {this.props.children} + + ); + } +} diff --git a/src/utils/FeatureRestriction/index.js b/src/utils/FeatureRestriction/index.js new file mode 100644 index 0000000..f6241cb --- /dev/null +++ b/src/utils/FeatureRestriction/index.js @@ -0,0 +1,1003 @@ +import { CometChat } from '@cometchat-pro/react-native-chat'; + +export class FeatureRestriction { + /** + * Core Chat + */ + static chat_users_list_enabled = 'core.chat.users.list.enabled'; + static chat_users_presence_enabled = 'core.chat.users.presence.enabled'; + static chat_users_search_enabled = 'core.chat.users.search.enabled'; + + static chat_groups_enabled = 'core.chat.groups.enabled'; + static chat_groups_public_enabled = 'core.chat.groups.public.enabled'; + static chat_groups_private_enabled = 'core.chat.groups.private.enabled'; + static chat_groups_password_enabled = 'core.chat.groups.password.enabled'; + static chat_groups_search_enabled = 'core.chat.groups.search.enabled'; + + static chat_messages_media_enabled = 'core.chat.messages.media.enabled'; + static chat_messages_threads_enabled = 'core.chat.messages.threads.enabled'; + static chat_messages_replies_enabled = 'core.chat.messages.replies.enabled'; + static chat_messages_receipts_enabled = 'core.chat.messages.receipts.enabled'; + static chat_messages_unread_count_enabled = + 'core.chat.messages.unread-count.enabled'; + static chat_messages_search_enabled = 'core.chat.messages.search.enabled'; + static chat_messages_history_enabled = 'core.chat.messages.history.enabled'; + static chat_messages_custom_enabled = 'core.chat.messages.custom.enabled'; + + static chat_one_on_one_enabled = 'core.chat.one-on-one.enabled'; + static chat_voice_notes_enabled = 'core.chat.voice-notes.enabled'; + static chat_typing_indicator_enabled = 'core.chat.typing-indicator.enabled'; + + /** + * Voice & Video Calling/Conferencing + */ + static calls_enabled = 'core.call.enabled'; + static call_one_on_one_video_enabled = 'core.call.one-on-one.video.enabled'; + static call_groups_video_enabled = 'core.call.groups.video.enabled'; + static call_one_on_one_audio_enabled = 'core.call.one-on-one.audio.enabled'; + static call_groups_audio_enabled = 'core.call.groups.audio.enabled'; + static call_recording_enabled = 'core.call.recording.enabled'; + static call_live_streaming_enabled = 'core.call.live-streaming.enabled'; + static call_transcript_enabled = 'core.call.transcript.enabled'; + + /** + * Collaboration + */ + static collaboration_whiteboard_enabled = + 'features.collaboration.whiteboard.enabled'; + static collaboration_document_enabled = + 'features.collaboration.document.enabled'; + + /** + * Moderation + */ + static moderation_groups_moderators_enabled = + 'features.moderation.groups.moderators.enabled'; + static moderation_users_block_enabled = + 'features.moderation.users.block.enabled'; + static moderation_groups_kick_enabled = + 'features.moderation.groups.kick.enabled'; + static moderation_groups_ban_enabled = + 'features.moderation.groups.ban.enabled'; + static moderation_xss_filter_enabled = + 'features.moderation.xss-filter.enabled'; + static moderation_profanity_filter_enabled = + 'features.moderation.profanity-filter.enabled'; + static moderation_image_moderation_enabled = + 'features.moderation.image-moderation.enabled'; + static moderation_data_masking_enabled = + 'features.moderation.data-masking.enabled'; + static moderation_malware_scanner_enabled = + 'features.moderation.malware-scanner.enabled'; + static moderation_sentiment_analysis_enabled = + 'features.moderation.sentiment-analysis.enabled'; + static moderation_inflight_message_moderation_enabled = + 'features.moderation.inflight-message-moderation.enabled'; + + /** + * User Engagement + */ + static reactions_enabled = 'features.ue.reactions.enabled'; + static emojis_enabled = 'features.ue.emojis.enabled'; + static stickers_enabled = 'features.ue.stickers.enabled'; + static message_translation_enabled = + 'features.ue.message-translation.enabled'; + static email_replies_enabled = 'features.ue.email-replies.enabled'; + static polls_enabled = 'features.ue.polls.enabled'; + static live_reactions_enabled = 'features.ue.live-reactions.enabled'; + static smart_replies_enabled = 'features.ue.smart-replies.enabled'; + static mentions_enabled = 'features.ue.mentions.enabled'; + + /** + * User Experience + */ + static thumbnail_generation_enabled = + 'features.ux.thumbnail-generation.enabled'; + static link_preview_enabled = 'features.ux.link-preview.enabled'; + static messages_saved_enabled = 'features.ux.messages.saved.enabled'; + static messages_pinned_enabled = 'features.ux.messages.pinned.enabled'; + static rich_media_preview_enabled = 'features.ux.rich-media-preview.enabled'; + static voice_transcription_enabled = + 'features.ux.voice-transcription.enabled'; + + /** + * Extensions slug + */ + static dataMasking = 'data-masking'; + static profanityFilter = 'profanity-filter'; + static thumbnailGeneration = 'thumbnail-generator'; + static linkPreview = 'link-preview'; + static richMediaPreview = 'rich-media'; + static sticker = 'stickers'; + static reactions = 'reactions'; + static messageTranslation = 'message-translation'; + static smartReplies = 'smart-reply'; + static collaborationWhiteboard = 'whiteboard'; + static collaborationDocument = 'document'; + static pinMessages = 'pin-message'; + static saveMessages = 'save-message'; + static voiceTranscription = 'voice-transcription'; + static polls = 'polls'; + static xssFilter = 'xss-filter'; + static imageModeration = 'image-moderation'; + static malwareScanner = 'virus-malware-scanner'; + static sentimentAnalysis = 'sentiment-analysis'; + static emailReplies = 'email-replies'; + static emojis = 'emojis'; + static mentions = 'mentions'; + + static UIKitSettings; + + static isExtensionEnabled = (extensionKey) => { + return new Promise((resolve) => + CometChat.isExtensionEnabled(extensionKey) + .then((response) => resolve(response)) + .catch((error) => resolve(false)), + ); + }; + + constructor(UIKitSettings) { + FeatureRestriction.UIKitSettings = UIKitSettings; + } + + isRecentChatListEnabled = () => + new Promise((resolve) => resolve(FeatureRestriction.UIKitSettings.chats)); + isGroupListEnabled = () => + new Promise((resolve) => resolve(FeatureRestriction.UIKitSettings.groups)); + isUserSettingsEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.userSettings), + ); + isEditMessageEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.editMessage), + ); + isQNAModeEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.setGroupInQnaModeByModerators), + ); + isHighlightMessagesEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.highlightMessageFromModerators), + ); + isJoinLeaveGroupsEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.joinOrLeaveGroup), + ); + isLargerSizeEmojisEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.sendEmojisInLargerSize), + ); + isGifsEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.sendGifs), + ); + isShareCopyForwardMessageEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.shareCopyForwardMessage), + ); + isSharedMediaEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.viewShareMedia), + ); + isMessagesSoundEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.enableSoundForMessages), + ); + isCallsSoundEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.enableSoundForCalls), + ); + isViewingGroupMembersEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.viewGroupMembers), + ); + isCallActionMessagesEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.callNotifications), + ); + isGroupDeletionEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.allowDeleteGroup), + ); + isChangingGroupMemberScopeEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.allowPromoteDemoteMembers), + ); + isAddingGroupMembersEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.allowAddMembers), + ); + isLocationSharingEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.shareLocation), + ); + isGroupActionMessagesEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.joinLeaveNotifications), + ); + isGroupCreationEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.groupCreation), + ); + isDeleteMessageEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.deleteMessage), + ); + isHideDeletedMessagesEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.hideDeletedMessages), + ); + isViewProfileEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.viewProfile), + ); + isMessageInPrivateEnabled = () => + new Promise((resolve) => + resolve(FeatureRestriction.UIKitSettings.messageInPrivate), + ); + + isCallListEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.calls_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.calls), + ) + .catch((error) => resolve(false)); + }); + }; + + isUserListEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_users_list_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.users), + ) + .catch((error) => resolve(false)); + }); + }; + + isOneOnOneVideoCallEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.call_one_on_one_video_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.userVideoCall), + ) + .catch((error) => resolve(false)); + }); + }; + + isGroupVideoCallEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.call_groups_video_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.groupVideoCall), + ) + .catch((error) => resolve(false)); + }); + }; + + isOneOnOneAudioCallEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.call_one_on_one_audio_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.userAudioCall), + ) + .catch((error) => resolve(false)); + }); + }; + + isGroupAudioCallEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.call_groups_audio_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.groupAudioCall), + ) + .catch((error) => resolve(false)); + }); + }; + + isOneOnOneChatEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_one_on_one_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sendMessageInOneOnOne, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isGroupChatEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_groups_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sendMessageInGroup, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isDeleteMemberMessageEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_groups_moderators_enabled, + ) + .then((response) => + resolve( + response && + FeatureRestriction.UIKitSettings + .allowModeratorToDeleteMemberMessages, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isBlockUserEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_users_block_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.blockUser), + ) + .catch((error) => resolve(false)); + }); + }; + + isEmojisEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.emojis_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.sendEmojis), + ) + .catch((error) => resolve(false)); + }); + }; + + isFilesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_messages_media_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.sendFiles), + ) + .catch((error) => resolve(false)); + }); + }; + + isPhotosVideosEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_messages_media_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.sendPhotoVideos), + ) + .catch((error) => resolve(false)); + }); + }; + + isKickingGroupMembersEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_groups_kick_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.kickMember), + ) + .catch((error) => resolve(false)); + }); + }; + + isBanningGroupMembersEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_groups_ban_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.banMember), + ) + .catch((error) => resolve(false)); + }); + }; + + isVoiceNotesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_voice_notes_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.sendVoiceNotes), + ) + .catch((error) => resolve(false)); + }); + }; + + isTypingIndicatorsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_typing_indicator_enabled, + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sendTypingIndicator, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isUserPresenceEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_users_presence_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.showUserPresence, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isThreadedMessagesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_threads_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.threadedChats), + ) + .catch((error) => resolve(false)); + }); + }; + + isMessageRepliesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_replies_enabled, + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.replyingToMessage, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isDeliveryReceiptsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_receipts_enabled, + ) + .then((response) => + resolve( + response && + FeatureRestriction.UIKitSettings.showReadDeliveryReceipts, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isLiveReactionsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.live_reactions_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sendLiveReaction, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isPublicGroupEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_groups_public_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.publicGroup), + ) + .catch((error) => resolve(false)); + }); + }; + + isPrivateGroupEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_groups_private_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.privateGroup), + ) + .catch((error) => resolve(false)); + }); + }; + + isPasswordGroupEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_groups_password_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.passwordGroup), + ) + .catch((error) => resolve(false)); + }); + }; + + isUnreadCountEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_unread_count_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.unreadCount), + ) + .catch((error) => resolve(false)); + }); + }; + + isUserSearchEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_users_search_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.searchUsers), + ) + .catch((error) => resolve(false)); + }); + }; + + isGroupSearchEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.chat_groups_search_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.searchGroups), + ) + .catch((error) => resolve(false)); + }); + }; + isGroupSearchEnabled; + + isMessageSearchEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_search_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.searchMessages), + ) + .catch((error) => resolve(false)); + }); + }; + + isCallRecordingEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.call_recording_enabled) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.callRecording), + ) + .catch((error) => resolve(false)); + }); + }; + + isCallLiveStreamingEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.call_live_streaming_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.callLiveStreaming, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isCallTranscriptEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.call_transcript_enabled) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.callTranscription, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isMessageHistoryEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.chat_messages_history_enabled, + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.messageHistory), + ) + .catch((error) => resolve(false)); + }); + }; + + isMessageTranslationEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.message_translation_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.messageTranslation, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.messageTranslation, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isReactionsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.reactions_enabled) + .then((response) => { + return ( + response && + FeatureRestriction.isExtensionEnabled(FeatureRestriction.reactions) + ); + }) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sendMessageReaction, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isCollaborativeWhiteBoardEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.collaboration_whiteboard_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.collaborationWhiteboard, + ), + ) + .then((response) => + resolve( + response && + FeatureRestriction.UIKitSettings.collaborativeWhiteboard, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isCollaborativeDocumentEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.collaboration_document_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.collaborationDocument, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.collaborativeDocument, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isStickersEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.stickers_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled(FeatureRestriction.sticker), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.sendStickers), + ) + .catch((error) => resolve(false)); + }); + }; + + isEmailRepliesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.email_replies_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.emailReplies, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.emailReplies), + ) + .catch((error) => resolve(false)); + }); + }; + + isPollsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.polls_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled(FeatureRestriction.polls), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.polls), + ) + .catch((error) => resolve(false)); + }); + }; + + isSmartRepliesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.smart_replies_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.smartReplies, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.smartReplies), + ) + .catch((error) => resolve(false)); + }); + }; + + isThumbnailGenerationEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.thumbnail_generation_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.thumbnailGeneration, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.thumbnailGeneration, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isLinkPreviewEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.link_preview_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.linkPreview, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.linkPreview), + ) + .catch((error) => resolve(false)); + }); + }; + + isSaveMessagesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.messages_saved_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.saveMessages, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.saveMessages), + ) + .catch((error) => resolve(false)); + }); + }; + + isPinMessagesEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.messages_pinned_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.pinMessages, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.pinMessages), + ) + .catch((error) => resolve(false)); + }); + }; + + isRichMediaPreviewEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.rich_media_preview_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.richMediaPreview, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.richMediaPreview, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isVoiceTranscriptionEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.voice_transcription_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.voiceTranscription, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.voiceTranscription, + ), + ) + .catch((error) => resolve(false)); + }); + }; + + isMentionsEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled(FeatureRestriction.mentions_enabled) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled(FeatureRestriction.mentions), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.mentions), + ) + .catch((error) => resolve(false)); + }); + }; + isXssFilterEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_xss_filter_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled(FeatureRestriction.xssFilter), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.xssFilter), + ) + .catch((error) => resolve(false)); + }); + }; + + isProfanityFilterEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_profanity_filter_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.profanityFilter, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.profanityFilter), + ) + .catch((error) => resolve(false)); + }); + }; + + isImageModerationEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_image_moderation_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.imageModeration, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.imageModeration), + ) + .catch((error) => resolve(false)); + }); + }; + + isDataMaskingEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_data_masking_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.dataMasking, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.dataMasking), + ) + .catch((error) => resolve(false)); + }); + }; + + isMalwareScannerEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_malware_scanner_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.malwareScanner, + ), + ) + .then((response) => + resolve(response && FeatureRestriction.UIKitSettings.malwareScanner), + ) + .catch((error) => resolve(false)); + }); + }; + + isSentimentAnalysisEnabled = () => { + return new Promise((resolve) => { + CometChat.isFeatureEnabled( + FeatureRestriction.moderation_sentiment_analysis_enabled, + ) + .then( + (response) => + response && + FeatureRestriction.isExtensionEnabled( + FeatureRestriction.sentimentAnalysis, + ), + ) + .then((response) => + resolve( + response && FeatureRestriction.UIKitSettings.sentimentAnalysis, + ), + ) + .catch((error) => resolve(false)); + }); + }; +} diff --git a/src/utils/UIKitSettings.js b/src/utils/UIKitSettings.js new file mode 100644 index 0000000..57fa9a6 --- /dev/null +++ b/src/utils/UIKitSettings.js @@ -0,0 +1,488 @@ +export class UIKitSettings { + static userListFilterOptions = { + ALL: 'all_users', + // NONE: 'none', + FRIENDS: 'friends', + }; + + static groupListFilterOptions = { + PUBLIC: 'public_groups', + PASSWORD: 'password_protected_groups', + PUBLIC_AND_PASSWORD: 'public_and_password_protected_groups', + }; + + static chatListFilterOptions = { + USERS: 'users', + GROUPS: 'groups', + USERS_AND_GROUPS: 'all_chats', + }; + + constructor() { + this.backgroundColor = ''; + this.primaryColor = ''; + this.foregroundColor = ''; + this.overrideSystemBackgroundColor = ''; + + this.userListMode = UIKitSettings.userListFilterOptions['ALL']; + this.groupInMode = + UIKitSettings.groupListFilterOptions['PUBLIC_AND_PASSWORD']; //left + this.chatListMode = UIKitSettings.chatListFilterOptions['USERS_AND_GROUPS']; + + this.chats = true; + this.calls = false; + this.users = true; + this.groups = true; + this.userSettings = true; + + this.searchUsers = true; + this.searchGroups = true; + this.searchMessages = true; + this.searchChats = true; + + this.unreadCount = true; + + this.publicGroup = true; + this.privateGroup = true; + this.passwordGroup = true; + + this.blockUser = true; + this.viewShareMedia = true; + + this.groupCreation = true; + this.allowDeleteGroup = true; + this.joinOrLeaveGroup = true; + this.viewGroupMembers = true; + this.kickMember = true; + this.banMember = true; + this.allowPromoteDemoteMembers = true; + this.allowAddMembers = true; + + this.callNotifications = true; + this.joinLeaveNotifications = true; + + this.enableSoundForMessages = true; + this.enableSoundForCalls = false; + + this.userVideoCall = true; + this.groupVideoCall = true; + this.userAudioCall = true; + this.groupAudioCall = true; + + this.sendTypingIndicator = true; + this.showUserPresence = true; + this.showReadDeliveryReceipts = true; + + this.threadedChats = true; + this.hideDeletedMessages = true; + + this.sendMessageInOneOnOne = true; + this.sendMessageInGroup = true; + this.editMessage = true; + this.deleteMessage = true; + this.replyingToMessage = true; + + this.sendEmojis = true; + this.sendEmojisInLargerSize = true; + this.sendGifs = false; + this.shareCopyForwardMessage = false; + this.sendFiles = true; + this.sendPhotoVideos = true; + this.sendVoiceNotes = true; + this.sendLiveReaction = true; + + this.sendMessageReaction = true; + this.collaborativeWhiteboard = true; + this.collaborativeDocument = true; + this.sendStickers = false; + this.shareLocation = false; + this.polls = false; + this.messageTranslation = true; + + this.allowModeratorToDeleteMemberMessages = false; + this.setGroupInQnaModeByModerators = false; + this.highlightMessageFromModerators = false; + this.emailReplies = true; + this.smartReplies = true; + this.callRecording = true; + this.callLiveStreaming = true; + this.callTranscription = true; + this.thumbnailGeneration = true; + this.linkPreview = true; + this.saveMessages = true; + this.pinMessages = true; + this.richMediaPreview = true; + this.voiceTranscription = true; + this.mentions = true; + this.xssFilter = true; + this.profanityFilter = true; + this.imageModeration = true; + this.dataMasking = true; + this.malwareScanner = true; + this.sentimentAnalysis = true; + this.inflightMessageModeration = true; + this.messageHistory = true; + + this.viewProfile = true; + this.messageInPrivate = true; + } + + setUserSettings = (userSettings) => { + this.userSettings = userSettings; + }; + + setCalls = (calls) => { + this.calls = calls; + }; + + setUsers = (users) => { + this.users = users; + }; + + setChats = (chats) => { + this.chats = chats; + }; + + setGroups = (groups) => { + this.groups = groups; + }; + + setChatListMode = (option) => { + if (!option.trim().length) { + return false; + } + + const chatListFilterKey = this.returnMatchedKey( + UIKitSettings.chatListFilterOptions, + option, + ); + if (chatListFilterKey) { + this.chatListMode = + UIKitSettings.chatListFilterOptions[chatListFilterKey]; + } + }; + + setUserListMode = (option) => { + if (!option.trim().length) { + return false; + } + + const userListFilterKey = this.returnMatchedKey( + UIKitSettings.userListFilterOptions, + option, + ); + if (userListFilterKey) { + this.userListMode = + UIKitSettings.userListFilterOptions[userListFilterKey]; + } + }; + + setGroupListMode = () => {}; + + setUserVideoCall = (userVideoCall) => { + this.userVideoCall = userVideoCall; + }; + + setGroupVideoCall = (groupVideoCall) => { + this.groupVideoCall = groupVideoCall; + }; + + setUserAudioCall = (userAudioCall) => { + this.userAudioCall = userAudioCall; + }; + + setGroupAudioCall = (groupAudioCall) => { + this.groupAudioCall = groupAudioCall; + }; + + setEditMessage = (editMessage) => { + this.editMessage = editMessage; + }; + + setSendMessageInOneOnOne = (sendMessageInOneOnOne) => { + this.sendMessageInOneOnOne = sendMessageInOneOnOne; + }; + + setSendMessageInGroup = (sendMessageInGroup) => { + this.sendMessageInGroup = sendMessageInGroup; + }; + + setJoinOrLeaveGroup = (joinOrLeaveGroup) => { + this.joinOrLeaveGroup = joinOrLeaveGroup; + }; + + setBlockUser = (blockUser) => { + this.blockUser = blockUser; + }; + + setSendEmojis = (sendEmojis) => { + this.sendEmojis = sendEmojis; + }; + + setSendEmojisInLargerSize = (sendEmojisInLargerSize) => { + this.sendEmojisInLargerSize = sendEmojisInLargerSize; + }; + + setSendGifs = (sendGifs) => { + this.sendGifs = sendGifs; + }; + + setShareCopyForwardMessage = (shareCopyForwardMessage) => { + this.shareCopyForwardMessage = shareCopyForwardMessage; + }; + + setSendFiles = (sendFiles) => { + this.sendFiles = sendFiles; + }; + + setSendPhotoVideos = (sendPhotoVideos) => { + this.sendPhotoVideos = sendPhotoVideos; + }; + + setViewShareMedia = (viewShareMedia) => { + this.viewShareMedia = viewShareMedia; + }; + + setEnableSoundForMessages = (enableSoundForMessages) => { + this.enableSoundForMessages = enableSoundForMessages; + }; + + setEnableSoundForCalls = (enableSoundForCalls) => { + this.enableSoundForCalls = enableSoundForCalls; + }; + + setSendStickers = (sendStickers) => { + this.sendStickers = sendStickers; + }; + + setViewGroupMembers = (viewGroupMembers) => { + this.viewGroupMembers = viewGroupMembers; + }; + + setCallNotifications = (callNotifications) => { + this.callNotifications = callNotifications; + }; + + setAllowDeleteGroup = (allowDeleteGroup) => { + this.allowDeleteGroup = allowDeleteGroup; + }; + + setKickMember = (kickMember) => { + this.kickMember = kickMember; + }; + + setBanMember = (banMember) => { + this.banMember = banMember; + }; + + setAllowPromoteDemoteMembers = (allowPromoteDemoteMembers) => { + this.allowPromoteDemoteMembers = allowPromoteDemoteMembers; + }; + + setAllowAddMembers = (allowAddMembers) => { + this.allowAddMembers = allowAddMembers; + }; + + setShareLocation = (shareLocation) => { + this.shareLocation = shareLocation; + }; + + setJoinLeaveNotifications = (joinLeaveNotifications) => { + this.joinLeaveNotifications = joinLeaveNotifications; + }; + + setSendVoiceNotes = (sendVoiceNotes) => { + this.sendVoiceNotes = sendVoiceNotes; + }; + + setMessageTranslation = (messageTranslation) => { + this.messageTranslation = messageTranslation; + }; + + setGroupCreation = (groupCreation) => { + this.groupCreation = groupCreation; + }; + + setSendTypingIndicator = (sendTypingIndicator) => { + this.sendTypingIndicator = sendTypingIndicator; + }; + + setShowUserPresence = (showUserPresence) => { + this.showUserPresence = showUserPresence; + }; + + setDeleteMessage = (deleteMessage) => { + this.deleteMessage = deleteMessage; + }; + + setThreadedChats = (threadedChats) => { + this.threadedChats = threadedChats; + }; + + setReplyingToMessage = (replyingToMessage) => { + this.replyingToMessage = replyingToMessage; + }; + + setShowReadDeliveryReceipts = (showReadDeliveryReceipts) => { + this.showReadDeliveryReceipts = showReadDeliveryReceipts; + }; + + setHideDeletedMessages = (hideDeletedMessages) => { + this.hideDeletedMessages = hideDeletedMessages; + }; + + setEmailReplies = (emailReplies) => { + this.emailReplies = emailReplies; + }; + + setSendMessageReaction = (sendMessageReaction) => { + this.sendMessageReaction = sendMessageReaction; + }; + + setCollaborativeWhiteboard = (collaborativeWhiteboard) => { + this.collaborativeWhiteboard = collaborativeWhiteboard; + }; + + setCollaborativeDocument = (collaborativeDocument) => { + this.collaborativeDocument = collaborativeDocument; + }; + + setPolls = (polls) => { + this.polls = polls; + }; + + setSendLiveReaction = (sendLiveReaction) => { + this.sendLiveReaction = sendLiveReaction; + }; + + setPublicGroup = (publicGroup) => { + this.publicGroup = publicGroup; + }; + + setPrivateGroup = (privateGroup) => { + this.privateGroup = privateGroup; + }; + + setPasswordGroup = (passwordGroup) => { + this.passwordGroup = passwordGroup; + }; + + setAllowModeratorToDeleteMemberMessages = ( + allowModeratorToDeleteMemberMessages, + ) => { + this.allowModeratorToDeleteMemberMessages = allowModeratorToDeleteMemberMessages; + }; + + setUnreadCount = (unreadCount) => { + this.unreadCount = unreadCount; + }; + + setSmartReplies = (smartReplies) => { + this.smartReplies = smartReplies; + }; + + setSearchUsers = (searchUsers) => { + this.searchUsers = searchUsers; + }; + + setSearchGroups = (searchGroups) => { + this.searchGroups = searchGroups; + }; + + setSearchMessages = (searchMessages) => { + this.searchMessages = searchMessages; + }; + + setCallRecording = (callRecording) => { + this.callRecording = callRecording; + }; + + setCallLiveStreaming = (callLiveStreaming) => { + this.callLiveStreaming = callLiveStreaming; + }; + + setCallTranscription = (callTranscription) => { + this.callTranscription = callTranscription; + }; + + setThumbnailGeneration = (thumbnailGeneration) => { + this.thumbnailGeneration = thumbnailGeneration; + }; + + setLinkPreview = (linkPreview) => { + this.linkPreview = linkPreview; + }; + + setSaveMessages = (saveMessages) => { + this.saveMessages = saveMessages; + }; + + setPinMessages = (pinMessages) => { + this.pinMessages = pinMessages; + }; + + setRichMediaPreview = (richMediaPreview) => { + this.richMediaPreview = richMediaPreview; + }; + + setVoiceTranscription = (voiceTranscription) => { + this.voiceTranscription = voiceTranscription; + }; + + setMentions = (mentions) => { + this.mentions = mentions; + }; + + setXssFilter = (xssFilter) => { + this.xssFilter = xssFilter; + }; + + setProfanityFilter = (profanityFilter) => { + this.profanityFilter = profanityFilter; + }; + + setImageModeration = (imageModeration) => { + this.imageModeration = imageModeration; + }; + + setDataMasking = (dataMasking) => { + this.dataMasking = dataMasking; + }; + + setMalwareScanner = (malwareScanner) => { + this.malwareScanner = malwareScanner; + }; + + setSentimentAnalysis = (sentimentAnalysis) => { + this.sentimentAnalysis = sentimentAnalysis; + }; + + setInflightMessageModeration = (inflightMessageModeration) => { + this.inflightMessageModeration = inflightMessageModeration; + }; + + setMessageHistory = (messageHistory) => { + this.messageHistory = messageHistory; + }; + + setViewProfile = (viewProfile) => { + this.viewProfile = viewProfile; + }; + + setMessageInPrivate = (messageInPrivate) => { + this.messageInPrivate = messageInPrivate; + }; + + // setChatWindow = (chatWindow) => { + // this.chatWindow = chatWindow; + // }; + + returnMatchedKey = (matchWith, optionToMatch) => { + for (const [key, value] of Object.entries(matchWith)) { + if (value === optionToMatch) { + return key; + } + } + + return false; + }; +} diff --git a/src/utils/settings.js b/src/utils/settings.js deleted file mode 100644 index 24d23b7..0000000 --- a/src/utils/settings.js +++ /dev/null @@ -1 +0,0 @@ -export const HIDE_DELETED_MSG = false;