Skip to content

Commit c8adf6d

Browse files
authored
Merge pull request #46 from cometchat-pro/v2
V2
2 parents 5db7b3e + ed8ef51 commit c8adf6d

File tree

11 files changed

+166
-63
lines changed

11 files changed

+166
-63
lines changed

CometChatWorkspace/cometchat-app/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010
// }
1111
ext {
1212
buildToolsVersion = "29.0.2"
13-
minSdkVersion = 21
13+
minSdkVersion = 24
1414
compileSdkVersion = 29
1515
targetSdkVersion = 29
1616
}

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cometchat-pro-react-native-ui-kit",
3-
"version": "2.4.0-1",
3+
"version": "2.4.0-2",
44
"description": "Chat UI Kit for React Native App",
55
"main": "./src/index.js",
66
"scripts": {

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/components/Messages/CometChatMessageHeader/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import { MessageHeaderManager } from './controller';
44
import { View, Text, TouchableOpacity, Image } from 'react-native';
5+
56
import { CometChatUserPresence, CometChatAvatar } from '../../Shared';
67
import * as enums from '../../../utils/enums';
78
import * as actions from '../../../utils/actions';
@@ -37,10 +38,14 @@ class CometChatMessageHeader extends React.Component {
3738
}
3839

3940
checkRestrictions = async () => {
40-
let isGroupVideoCallEnabled = await this.context.FeatureRestriction.isGroupVideoCallEnabled();
41-
let isOneOnOneAudioCallEnabled = await this.context.FeatureRestriction.isOneOnOneAudioCallEnabled();
42-
let isTypingIndicatorsEnabled = await this.context.FeatureRestriction.isTypingIndicatorsEnabled();
43-
let isOneOnOneVideoCallEnabled = await this.context.FeatureRestriction.isOneOnOneVideoCallEnabled();
41+
let isGroupVideoCallEnabled =
42+
await this.context.FeatureRestriction.isGroupVideoCallEnabled();
43+
let isOneOnOneAudioCallEnabled =
44+
await this.context.FeatureRestriction.isOneOnOneAudioCallEnabled();
45+
let isTypingIndicatorsEnabled =
46+
await this.context.FeatureRestriction.isTypingIndicatorsEnabled();
47+
let isOneOnOneVideoCallEnabled =
48+
await this.context.FeatureRestriction.isOneOnOneVideoCallEnabled();
4449
this.setState({
4550
restrictions: {
4651
isGroupVideoCallEnabled,
@@ -172,6 +177,7 @@ class CometChatMessageHeader extends React.Component {
172177
) {
173178
this.setState({ status: item.status, presence: item.status });
174179
}
180+
this.props.actionGenerated(actions.STATUS_UPDATED, item.status);
175181
break;
176182
}
177183
case enums.GROUP_MEMBER_KICKED:

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/components/Messages/CometChatMessages/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ class CometChatMessages extends React.PureComponent {
371371
case actions.DIRECT_CALL_ENDED:
372372
this.setState({ joinDirectCall: false, ongoingDirectCall: null });
373373

374+
break;
375+
case actions.STATUS_UPDATED:
376+
this.setState({ user: { ...this.state.user, status: messages } });
377+
374378
break;
375379
default:
376380
break;

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/components/Messages/CometChatStickerKeyboard/index.js

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
/* eslint-disable react/jsx-fragments */
22
import React from 'react';
3-
import { View, Text, TouchableOpacity, Image, ScrollView } from 'react-native';
3+
import {
4+
View,
5+
Text,
6+
TouchableOpacity,
7+
ScrollView,
8+
FlatList,
9+
} from 'react-native';
10+
import FastImage from 'react-native-fast-image';
411
import theme from '../../../resources/theme';
512
import Icon from 'react-native-vector-icons/MaterialIcons';
613
import style from './styles';
@@ -130,49 +137,71 @@ class CometChatStickerKeyboard extends React.PureComponent {
130137

131138
let stickers = null;
132139
if (Object.keys(this.state.stickerSet).length) {
133-
const sectionItems = Object.keys(this.state.stickerSet).map(
134-
(sectionItem, key) => {
135-
const stickerSetThumbnail = this.state.stickerSet[sectionItem][0]
136-
.stickerUrl;
137-
return (
138-
<TouchableOpacity
139-
key={key}
140-
style={style.sectionListItemStyle}
141-
onPress={() => this.onStickerSetClicked(sectionItem)}>
142-
<Image
143-
source={{ uri: stickerSetThumbnail }}
144-
alt={sectionItem}
145-
style={style.stickerHeaderImageStyle}
146-
/>
147-
</TouchableOpacity>
148-
);
149-
},
140+
const sectionItems = (
141+
<FlatList
142+
style={{
143+
width: '100%',
144+
flexDirection: 'row',
145+
backgroundColor: 'red',
146+
}}
147+
nestedScrollEnabled
148+
style={{ paddingVertical: 10 }}
149+
horizontal
150+
bounces={false}
151+
showsHorizontalScrollIndicator={false}
152+
data={Object.keys(this.state.stickerSet)}
153+
renderItem={({ item: sectionItem, index: key }) => {
154+
const stickerSetThumbnail =
155+
this.state.stickerSet[sectionItem][0].stickerUrl;
156+
157+
return (
158+
<TouchableOpacity
159+
key={sectionItem}
160+
style={style.sectionListItemStyle}
161+
onPress={() => this.onStickerSetClicked(sectionItem)}>
162+
<FastImage
163+
source={{ uri: stickerSetThumbnail }}
164+
alt={sectionItem}
165+
style={style.stickerHeaderImageStyle}
166+
/>
167+
</TouchableOpacity>
168+
);
169+
}}
170+
/>
150171
);
151172

152173
let activeStickerList = [];
153174
if (this.state.activeStickerList.length) {
154175
const stickerList = [...this.state.activeStickerList];
155-
activeStickerList = stickerList.map((stickerItem, key) => {
156-
return (
157-
<TouchableOpacity
158-
key={key}
159-
style={style.stickerItemStyle}
160-
onPress={() => this.sendStickerMessage(stickerItem)}>
161-
<Image
162-
source={{ uri: stickerItem.stickerUrl }}
163-
alt={stickerItem.stickerName}
164-
style={style.stickerImageStyle}
165-
/>
166-
</TouchableOpacity>
167-
);
168-
});
176+
activeStickerList = (
177+
<FlatList
178+
numColumns={3}
179+
style={{
180+
width: '100%',
181+
alignSelf: 'center',
182+
}}
183+
data={stickerList}
184+
renderItem={({ item: stickerItem, index: key }) => {
185+
return (
186+
<TouchableOpacity
187+
key={stickerItem.stickerName}
188+
style={style.stickerItemStyle}
189+
onPress={() => this.sendStickerMessage(stickerItem)}>
190+
<FastImage
191+
source={{ uri: stickerItem.stickerUrl }}
192+
alt={stickerItem.stickerName}
193+
style={style.stickerImageStyle}
194+
/>
195+
</TouchableOpacity>
196+
);
197+
}}
198+
/>
199+
);
169200
}
170201

171202
stickers = (
172203
<>
173-
<ScrollView bounces={false}>
174-
<View style={style.stickerListStyle}>{activeStickerList}</View>
175-
</ScrollView>
204+
<View style={style.stickerListStyle}>{activeStickerList}</View>
176205

177206
<View
178207
style={[
@@ -182,13 +211,7 @@ class CometChatStickerKeyboard extends React.PureComponent {
182211
backgroundColor: this.viewTheme.backgroundColor.silver,
183212
},
184213
]}>
185-
<ScrollView
186-
style={{ paddingVertical: 10 }}
187-
horizontal
188-
bounces={false}
189-
showsHorizontalScrollIndicator={false}>
190-
{sectionItems}
191-
</ScrollView>
214+
{sectionItems}
192215
</View>
193216
</>
194217
);

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/components/Messages/CometChatStickerKeyboard/styles.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export default StyleSheet.create({
2424
marginHorizontal: 8,
2525
},
2626
stickerItemStyle: {
27-
minWidth: 50,
27+
width: '30%',
2828
minHeight: 50,
29-
maxWidth: 70,
29+
marginLeft: '2.5%',
3030
maxHeight: 70,
3131
flexShrink: 0,
3232
marginRight: 20,
@@ -37,8 +37,10 @@ export default StyleSheet.create({
3737
flexWrap: 'wrap',
3838
justifyContent: 'space-between',
3939
alignItems: 'center',
40-
paddingLeft: 20,
40+
// paddingHorizontal: 20,
41+
paddingRight: '2.5%',
4142
paddingBottom: 10,
43+
flex: 1,
4244
},
4345
stickerSectionListStyle: {
4446
borderTopWidth: 1,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CometChat } from '@cometchat-pro/react-native-chat';
2+
import * as enums from '../../../utils/enums';
3+
4+
export class UserDetailManager {
5+
userListenerId = 'user_detail_' + new Date().getTime();
6+
7+
attachListeners(callback) {
8+
CometChat.addUserListener(
9+
this.userListenerId,
10+
new CometChat.UserListener({
11+
onUserOnline: (onlineUser) => {
12+
/* when someuser/friend comes online, user will be received here */
13+
callback(enums.USER_ONLINE, onlineUser);
14+
},
15+
onUserOffline: (offlineUser) => {
16+
/* when someuser/friend went offline, user will be received here */
17+
callback(enums.USER_OFFLINE, offlineUser);
18+
},
19+
}),
20+
);
21+
}
22+
23+
removeListeners() {
24+
CometChat.removeUserListener(this.userListenerId);
25+
}
26+
}

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/components/Users/CometChatUserDetails/index.js

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
22
import { View, Text, TouchableOpacity, Dimensions, Modal } from 'react-native';
3+
import { UserDetailManager } from './controller';
4+
import * as enums from '../../../utils/enums';
35
import theme from '../../../resources/theme';
46
import Icon from 'react-native-vector-icons/MaterialIcons';
57
import {
@@ -30,24 +32,63 @@ export default class CometChatUserDetails extends React.Component {
3032
}
3133

3234
componentDidMount() {
33-
this.setStatusForUser();
3435
this.checkRestrictions();
36+
this.setStatusForUser();
37+
this.UserDetailManager = new UserDetailManager();
38+
this.UserDetailManager.attachListeners(this.updateUser);
3539
}
3640

41+
updateUser = (key, user) => {
42+
console.log('updateUser', key, user);
43+
switch (key) {
44+
case enums.USER_ONLINE:
45+
case enums.USER_OFFLINE: {
46+
if (
47+
this.props.type === CometChat.ACTION_TYPE.TYPE_USER &&
48+
this.props.item.uid === user.uid
49+
) {
50+
//if user presence feature is disabled
51+
if (this.state.isUserPresenceEnabled === false) {
52+
return false;
53+
}
54+
55+
let status = '';
56+
if (user.status === CometChat.USER_STATUS.OFFLINE) {
57+
status = 'OFFLINE';
58+
} else if (user.status === CometChat.USER_STATUS.ONLINE) {
59+
status = 'ONLINE';
60+
}
61+
62+
this.setState({ status: status });
63+
}
64+
break;
65+
}
66+
default:
67+
break;
68+
}
69+
};
70+
3771
/**
3872
* Update bottom sheet to 0th snap point if prop received as open
3973
*/
4074
componentDidUpdate(prevProps) {
4175
if (!prevProps.open && this.props.open) {
4276
this.sheetRef.current.snapTo(0);
4377
}
78+
if (JSON.stringify(prevProps.item) !== JSON.stringify(this.props.item)) {
79+
this.setStatusForUser();
80+
}
4481
}
4582

4683
checkRestrictions = async () => {
47-
let isSharedMediaEnabled = await this.context.FeatureRestriction.isSharedMediaEnabled();
48-
let isBlockUserEnabled = await this.context.FeatureRestriction.isBlockUserEnabled();
49-
let isViewProfileEnabled = await this.context.FeatureRestriction.isViewProfileEnabled();
50-
let isUserPresenceEnabled = await this.context.FeatureRestriction.isUserPresenceEnabled();
84+
let isSharedMediaEnabled =
85+
await this.context.FeatureRestriction.isSharedMediaEnabled();
86+
let isBlockUserEnabled =
87+
await this.context.FeatureRestriction.isBlockUserEnabled();
88+
let isViewProfileEnabled =
89+
await this.context.FeatureRestriction.isViewProfileEnabled();
90+
let isUserPresenceEnabled =
91+
await this.context.FeatureRestriction.isUserPresenceEnabled();
5192
this.setState({
5293
restrictions: {
5394
isSharedMediaEnabled,
@@ -127,7 +168,7 @@ export default class CometChatUserDetails extends React.Component {
127168
this.props.item.blockedByMe &&
128169
!this.state.restrictions?.isUserPresenceEnabled ? null : (
129170
<CometChatUserPresence
130-
status={this.props.item.status}
171+
status={this.state.status}
131172
style={{ top: 35 }}
132173
cornerRadius={9}
133174
borderColor={theme.borderColor.white}

CometChatWorkspace/cometchat-app/cometchat-pro-react-native-ui-kit/src/utils/actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const CLOSE_DETAIL = 'closeDetail';
2222
export const CLOSE_DETAIL_CLICKED = 'closeDetailClicked';
2323
export const CLOSE_THREAD_CLICKED = 'closeThreadClicked';
2424
export const MENU_CLICKED = 'menuClicked';
25+
export const STATUS_UPDATED = 'statusUpdated';
2526

2627
export const GROUP_UPDATED = 'groupUpdated';
2728
export const GROUP_DELETED = 'groupDeleted';

CometChatWorkspace/cometchat-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "example",
3-
"version": "2.4.0-1",
3+
"version": "2.4.0-2",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",
@@ -10,7 +10,7 @@
1010
"lint": "eslint ."
1111
},
1212
"dependencies": {
13-
"@cometchat-pro/react-native-calls": "2.0.3-beta1",
13+
"@cometchat-pro/react-native-calls": "2.1.1",
1414
"@cometchat-pro/react-native-chat": "2.4.0",
1515
"@react-native-async-storage/async-storage": "^1.13.4",
1616
"@react-native-community/masked-view": "^0.1.10",

CometChatWorkspace/cometchat-app/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,10 @@
708708
exec-sh "^0.3.2"
709709
minimist "^1.2.0"
710710

711-
"@cometchat-pro/react-native-calls@2.0.3-beta1":
712-
version "2.0.3-beta1"
713-
resolved "https://registry.yarnpkg.com/@cometchat-pro/react-native-calls/-/react-native-calls-2.0.3-beta1.tgz#404d4057a3a4614300f5677d0c0c6d4fc3b48831"
714-
integrity sha512-HmdnlDMiZ1RlLgfHxog/BamTxv7xyQevwv//GgATe+v1zghvAcc4mRWcXkWZTlq7qjjiOEzJ1K+fjLyZoA7eBQ==
711+
"@cometchat-pro/react-native-calls@2.1.1":
712+
version "2.1.1"
713+
resolved "https://registry.yarnpkg.com/@cometchat-pro/react-native-calls/-/react-native-calls-2.1.1.tgz#6331f973c094510d6db6e3419099d932d18c9aaf"
714+
integrity sha512-+I8NbbE+JB5ItinLgcNewlg+2cMkDMMPlGLSFpXTahq5z+op2vtrImxixF5g31OIONWVqLP9mGlMSpLE/5nKsA==
715715

716716
"@cometchat-pro/[email protected]":
717717
version "2.4.0"

0 commit comments

Comments
 (0)