@messenger-box/platform-mobile 0.0.1-alpha.392 → 0.0.1-alpha.393
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/lib/index.js +167 -586
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/screens/inbox/components/DialogsListItem.tsx +85 -27
- package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +36 -12
- package/src/screens/inbox/config/config.ts +1 -1
- package/src/screens/inbox/containers/ConversationView.tsx +72 -561
- package/src/screens/inbox/containers/ThreadConversationView.tsx +35 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@messenger-box/platform-mobile",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.393",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"watch": "yarn build:lib:watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@messenger-box/core": "0.0.1-alpha.
|
|
23
|
-
"@messenger-box/platform-client": "0.0.1-alpha.
|
|
22
|
+
"@messenger-box/core": "0.0.1-alpha.393",
|
|
23
|
+
"@messenger-box/platform-client": "0.0.1-alpha.393",
|
|
24
24
|
"base-64": "1.0.0",
|
|
25
25
|
"react-native-gifted-chat": "1.0.4"
|
|
26
26
|
},
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"typescript": {
|
|
41
41
|
"definition": "lib/index.d.ts"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "f254347ff1e530eebfa57500fd05521a6d87c361"
|
|
44
44
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useMemo, useState } from 'react';
|
|
2
2
|
import { Text, Image, Pressable, HStack, Stack, Box, Avatar, View } from 'native-base';
|
|
3
3
|
import { format, isToday, isYesterday } from 'date-fns';
|
|
4
4
|
import { useFocusEffect } from '@react-navigation/native';
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
IUserAccount,
|
|
9
9
|
useMessagesQuery,
|
|
10
10
|
useOnChatMessageAddedSubscription,
|
|
11
|
+
OnChatMessageAddedDocument as CHAT_MESSAGE_ADDED,
|
|
11
12
|
useUserAccountQuery,
|
|
12
13
|
} from '@messenger-box/platform-client';
|
|
13
14
|
import { startCase } from 'lodash';
|
|
@@ -45,22 +46,25 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
45
46
|
onOpen,
|
|
46
47
|
}) {
|
|
47
48
|
const parentId: any = null;
|
|
49
|
+
const [messages, setMessages] = useState<any>([]);
|
|
48
50
|
const {
|
|
49
51
|
data: messagesQuery,
|
|
50
52
|
loading: messageLoading,
|
|
51
53
|
refetch: refetchMessages,
|
|
54
|
+
subscribeToMore,
|
|
52
55
|
} = useMessagesQuery({
|
|
53
56
|
variables: {
|
|
54
57
|
channelId: channel?.id?.toString(),
|
|
55
58
|
parentId: parentId,
|
|
56
59
|
limit: 10,
|
|
57
|
-
sort: {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
60
|
+
// sort: {
|
|
61
|
+
// key: 'updatedAt',
|
|
62
|
+
// value: ISortEnum.Desc,
|
|
63
|
+
// },
|
|
61
64
|
//limit: 25,
|
|
62
65
|
},
|
|
63
66
|
fetchPolicy: 'cache-and-network',
|
|
67
|
+
refetchWritePolicy: 'merge',
|
|
64
68
|
});
|
|
65
69
|
|
|
66
70
|
const {
|
|
@@ -80,10 +84,10 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
80
84
|
channelId: channel?.id?.toString(),
|
|
81
85
|
parentId: parentId,
|
|
82
86
|
limit: 10,
|
|
83
|
-
sort: {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
+
// sort: {
|
|
88
|
+
// key: 'updatedAt',
|
|
89
|
+
// value: ISortEnum.Desc,
|
|
90
|
+
// },
|
|
87
91
|
//limit: 25
|
|
88
92
|
});
|
|
89
93
|
|
|
@@ -95,28 +99,31 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
95
99
|
);
|
|
96
100
|
|
|
97
101
|
React.useEffect(() => {
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
sort: {
|
|
104
|
-
key: 'updatedAt',
|
|
105
|
-
value: ISortEnum.Desc,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
102
|
+
if (messagesQuery) {
|
|
103
|
+
if (messagesQuery?.messages?.data?.length) {
|
|
104
|
+
const msg = messagesQuery?.messages?.data;
|
|
105
|
+
setMessages((pre: any[]) => [...pre, ...msg]);
|
|
106
|
+
}
|
|
108
107
|
}
|
|
109
|
-
}, [
|
|
108
|
+
}, [messagesQuery]);
|
|
110
109
|
|
|
111
110
|
const lastMessage = useMemo(() => {
|
|
112
|
-
if (!
|
|
111
|
+
if (!messages?.length) {
|
|
113
112
|
return null;
|
|
114
113
|
}
|
|
115
|
-
const { data } = messagesQuery.messages;
|
|
116
|
-
const
|
|
117
|
-
|
|
114
|
+
// const { data } = messagesQuery.messages;
|
|
115
|
+
const data = messages;
|
|
116
|
+
const filteredData: any = data?.filter((p: any) => p?.message !== '');
|
|
117
|
+
// return filteredData[0];
|
|
118
|
+
let filteredLastMessage =
|
|
119
|
+
filteredData && filteredData?.length
|
|
120
|
+
? filteredData?.reduce((a, b) => {
|
|
121
|
+
return new Date(a?.updatedAt) > new Date(b?.updatedAt) ? a : b;
|
|
122
|
+
}, []) ?? null
|
|
123
|
+
: null;
|
|
124
|
+
return filteredLastMessage;
|
|
118
125
|
//return data[data.length - 1];
|
|
119
|
-
}, [
|
|
126
|
+
}, [messages]);
|
|
120
127
|
|
|
121
128
|
const channelMembers = useMemo(
|
|
122
129
|
() =>
|
|
@@ -196,7 +203,7 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
196
203
|
</Avatar.Group>
|
|
197
204
|
</Box>
|
|
198
205
|
<Box flex={0.9}>
|
|
199
|
-
<HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
206
|
+
{/* <HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
200
207
|
<Box flex={0.8}>
|
|
201
208
|
<Text color="gray.600" fontSize="lg" flexWrap={'wrap'} fontWeight="semibold">
|
|
202
209
|
{title}
|
|
@@ -209,7 +216,38 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
209
216
|
<Box flex={0.2}>
|
|
210
217
|
<Text color="gray.500">{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
211
218
|
</Box>
|
|
212
|
-
</HStack>
|
|
219
|
+
</HStack> */}
|
|
220
|
+
<LastMessageComponent
|
|
221
|
+
title={title}
|
|
222
|
+
lastMessage={lastMessage}
|
|
223
|
+
channelId={channel?.id}
|
|
224
|
+
subscribeToNewMessages={() =>
|
|
225
|
+
subscribeToMore({
|
|
226
|
+
document: CHAT_MESSAGE_ADDED,
|
|
227
|
+
variables: {
|
|
228
|
+
channelId: channel.id?.toString(),
|
|
229
|
+
},
|
|
230
|
+
updateQuery: (prev, { subscriptionData }: any) => {
|
|
231
|
+
if (!subscriptionData.data) return prev;
|
|
232
|
+
const newMessage: any = subscriptionData?.data?.chatMessageAdded;
|
|
233
|
+
const existingMessages: any = prev?.messages;
|
|
234
|
+
const previousData = existingMessages?.data
|
|
235
|
+
? [...existingMessages.data, newMessage]
|
|
236
|
+
: [];
|
|
237
|
+
const totalMsgCount = existingMessages?.totalCount + 1;
|
|
238
|
+
const merged = {
|
|
239
|
+
...prev,
|
|
240
|
+
messages: {
|
|
241
|
+
...existingMessages,
|
|
242
|
+
data: previousData,
|
|
243
|
+
totalCount: totalMsgCount,
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
return merged;
|
|
247
|
+
},
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
/>
|
|
213
251
|
{/* <Text
|
|
214
252
|
flex={1}
|
|
215
253
|
color="gray.600"
|
|
@@ -234,4 +272,24 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
234
272
|
);
|
|
235
273
|
};
|
|
236
274
|
|
|
275
|
+
const LastMessageComponent = ({ subscribeToNewMessages, title, lastMessage, channelId }) => {
|
|
276
|
+
React.useEffect(() => subscribeToNewMessages(), [channelId]);
|
|
277
|
+
return (
|
|
278
|
+
<HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
279
|
+
<Box flex={0.8}>
|
|
280
|
+
<Text color="gray.600" fontSize="lg" flexWrap={'wrap'} fontWeight="semibold">
|
|
281
|
+
{title}
|
|
282
|
+
</Text>
|
|
283
|
+
<Text color="gray.600" noOfLines={1}>
|
|
284
|
+
{lastMessage?.message ?? ''}
|
|
285
|
+
</Text>
|
|
286
|
+
</Box>
|
|
287
|
+
|
|
288
|
+
<Box flex={0.2}>
|
|
289
|
+
<Text color="gray.500">{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
290
|
+
</Box>
|
|
291
|
+
</HStack>
|
|
292
|
+
);
|
|
293
|
+
};
|
|
294
|
+
|
|
237
295
|
export const DialogsListItem = React.memo(DialogsListItemComponent);
|
|
@@ -5,6 +5,7 @@ import React from 'react';
|
|
|
5
5
|
import { View, ViewPropTypes, StyleSheet } from 'react-native';
|
|
6
6
|
|
|
7
7
|
import { Avatar, Day, utils } from 'react-native-gifted-chat';
|
|
8
|
+
import { Avatar as AvatarNativeBase } from 'native-base';
|
|
8
9
|
import Bubble from './SlackBubble';
|
|
9
10
|
|
|
10
11
|
const { isSameUser, isSameDay } = utils;
|
|
@@ -19,8 +20,8 @@ export default class Message extends React.Component<any> {
|
|
|
19
20
|
previousMessage: {};
|
|
20
21
|
user: {};
|
|
21
22
|
containerStyle: {};
|
|
22
|
-
isShowImageViewer:false
|
|
23
|
-
setImageViewer:(obj:any,v:boolean) => void
|
|
23
|
+
isShowImageViewer: false;
|
|
24
|
+
setImageViewer: (obj: any, v: boolean) => void;
|
|
24
25
|
};
|
|
25
26
|
getInnerComponentProps() {
|
|
26
27
|
const { containerStyle, ...props } = this.props;
|
|
@@ -48,28 +49,50 @@ export default class Message extends React.Component<any> {
|
|
|
48
49
|
if (this.props.renderBubble) {
|
|
49
50
|
return this.props.renderBubble(bubbleProps);
|
|
50
51
|
}
|
|
51
|
-
return
|
|
52
|
+
return (
|
|
53
|
+
<Bubble
|
|
54
|
+
{...bubbleProps}
|
|
55
|
+
isShowImageViewer={this.props.isShowImageViewer}
|
|
56
|
+
setImageViewer={this.props.setImageViewer}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
renderAvatar() {
|
|
55
62
|
let extraStyle: any;
|
|
63
|
+
//new param added
|
|
64
|
+
let isSameUserAndSameDay: boolean = false;
|
|
56
65
|
if (
|
|
57
66
|
isSameUser(this.props.currentMessage, this.props.previousMessage) &&
|
|
58
67
|
isSameDay(this.props.currentMessage, this.props.previousMessage)
|
|
59
68
|
) {
|
|
60
69
|
// Set the invisible avatar height to 0, but keep the width, padding, etc.
|
|
61
70
|
extraStyle = { height: 0 };
|
|
71
|
+
isSameUserAndSameDay = true;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
const avatarProps: any = this.getInnerComponentProps();
|
|
75
|
+
|
|
65
76
|
return (
|
|
66
|
-
<
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
<AvatarNativeBase
|
|
78
|
+
size={'sm'}
|
|
79
|
+
bg={'transparent'}
|
|
80
|
+
borderRadius={0}
|
|
81
|
+
source={{
|
|
82
|
+
uri: isSameUserAndSameDay ? null : avatarProps?.currentMessage?.user?.avatar,
|
|
71
83
|
}}
|
|
72
|
-
|
|
84
|
+
marginRight={2}
|
|
85
|
+
_image={{ ...styles.slackAvatar, ...avatarProps.imageStyle }}
|
|
86
|
+
>
|
|
87
|
+
{isSameUserAndSameDay ? '' : avatarProps?.currentMessage?.user?.name[0]}
|
|
88
|
+
</AvatarNativeBase>
|
|
89
|
+
// <Avatar
|
|
90
|
+
// {...avatarProps}
|
|
91
|
+
// showAvatarForEveryMessage={true}
|
|
92
|
+
// imageStyle={{
|
|
93
|
+
// left: [styles.slackAvatar, avatarProps.imageStyle, extraStyle],
|
|
94
|
+
// }}
|
|
95
|
+
// />
|
|
73
96
|
);
|
|
74
97
|
}
|
|
75
98
|
|
|
@@ -101,7 +124,8 @@ const styles = StyleSheet.create({
|
|
|
101
124
|
height: 40,
|
|
102
125
|
width: 40,
|
|
103
126
|
borderRadius: 3,
|
|
104
|
-
marginTop: 0,
|
|
127
|
+
// marginTop: 0,
|
|
128
|
+
marginTop: 1,
|
|
105
129
|
},
|
|
106
130
|
});
|
|
107
131
|
|
|
@@ -114,6 +138,6 @@ Message.defaultProps = {
|
|
|
114
138
|
previousMessage: {},
|
|
115
139
|
user: {},
|
|
116
140
|
containerStyle: {},
|
|
117
|
-
isShowImageViewer:false,
|
|
118
|
-
setImageViewer:(obj:any,v:boolean) => null,
|
|
141
|
+
isShowImageViewer: false,
|
|
142
|
+
setImageViewer: (obj: any, v: boolean) => null,
|
|
119
143
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cleanEnv, num, str } from 'envalid';
|
|
2
2
|
|
|
3
3
|
export const config = cleanEnv(process['APP_ENV'] || process.env, {
|
|
4
|
-
MESSAGES_PER_PAGE: num({ devDefault:
|
|
4
|
+
MESSAGES_PER_PAGE: num({ devDefault: 20, default: 20 }),
|
|
5
5
|
FILES_PER_MESSAGE: num({ default: 10 }),
|
|
6
6
|
INBOX_MESSEGE_PATH: str({ default: 'MainStack.Message' }),
|
|
7
7
|
// THREAD_MESSEGE_PATH: str({ default: 'MainStack.Thread' }),
|