@messenger-box/platform-mobile 0.0.1-alpha.391 → 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 +8 -0
- package/lib/index.js +412 -573
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/screens/inbox/components/DialogsListItem.tsx +115 -12
- 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 +173 -551
- package/src/screens/inbox/containers/ThreadConversationView.tsx +228 -86
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,8 +1,16 @@
|
|
|
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';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
IChannel,
|
|
7
|
+
ISortEnum,
|
|
8
|
+
IUserAccount,
|
|
9
|
+
useMessagesQuery,
|
|
10
|
+
useOnChatMessageAddedSubscription,
|
|
11
|
+
OnChatMessageAddedDocument as CHAT_MESSAGE_ADDED,
|
|
12
|
+
useUserAccountQuery,
|
|
13
|
+
} from '@messenger-box/platform-client';
|
|
6
14
|
import { startCase } from 'lodash';
|
|
7
15
|
|
|
8
16
|
const createdAtText = (value: string) => {
|
|
@@ -37,24 +45,51 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
37
45
|
channel,
|
|
38
46
|
onOpen,
|
|
39
47
|
}) {
|
|
40
|
-
const parentId:any = null;
|
|
48
|
+
const parentId: any = null;
|
|
49
|
+
const [messages, setMessages] = useState<any>([]);
|
|
41
50
|
const {
|
|
42
51
|
data: messagesQuery,
|
|
43
52
|
loading: messageLoading,
|
|
44
53
|
refetch: refetchMessages,
|
|
54
|
+
subscribeToMore,
|
|
45
55
|
} = useMessagesQuery({
|
|
46
56
|
variables: {
|
|
47
57
|
channelId: channel?.id?.toString(),
|
|
48
58
|
parentId: parentId,
|
|
49
|
-
limit:
|
|
59
|
+
limit: 10,
|
|
60
|
+
// sort: {
|
|
61
|
+
// key: 'updatedAt',
|
|
62
|
+
// value: ISortEnum.Desc,
|
|
63
|
+
// },
|
|
64
|
+
//limit: 25,
|
|
50
65
|
},
|
|
51
66
|
fetchPolicy: 'cache-and-network',
|
|
67
|
+
refetchWritePolicy: 'merge',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const {
|
|
71
|
+
data: newMessage,
|
|
72
|
+
loading: newMsgLoading,
|
|
73
|
+
error: newMsgError,
|
|
74
|
+
}: any = useOnChatMessageAddedSubscription({
|
|
75
|
+
variables: {
|
|
76
|
+
channelId: channel?.id?.toString(),
|
|
77
|
+
},
|
|
52
78
|
});
|
|
53
79
|
|
|
54
80
|
useFocusEffect(
|
|
55
81
|
React.useCallback(() => {
|
|
56
82
|
// Do something when the screen is focused
|
|
57
|
-
refetchMessages({
|
|
83
|
+
refetchMessages({
|
|
84
|
+
channelId: channel?.id?.toString(),
|
|
85
|
+
parentId: parentId,
|
|
86
|
+
limit: 10,
|
|
87
|
+
// sort: {
|
|
88
|
+
// key: 'updatedAt',
|
|
89
|
+
// value: ISortEnum.Desc,
|
|
90
|
+
// },
|
|
91
|
+
//limit: 25
|
|
92
|
+
});
|
|
58
93
|
|
|
59
94
|
return () => {
|
|
60
95
|
// Do something when the screen is unfocused
|
|
@@ -63,15 +98,32 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
63
98
|
}, []),
|
|
64
99
|
);
|
|
65
100
|
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
if (messagesQuery) {
|
|
103
|
+
if (messagesQuery?.messages?.data?.length) {
|
|
104
|
+
const msg = messagesQuery?.messages?.data;
|
|
105
|
+
setMessages((pre: any[]) => [...pre, ...msg]);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}, [messagesQuery]);
|
|
109
|
+
|
|
66
110
|
const lastMessage = useMemo(() => {
|
|
67
|
-
if (!
|
|
111
|
+
if (!messages?.length) {
|
|
68
112
|
return null;
|
|
69
113
|
}
|
|
70
|
-
const { data } = messagesQuery.messages;
|
|
71
|
-
const
|
|
72
|
-
|
|
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;
|
|
73
125
|
//return data[data.length - 1];
|
|
74
|
-
}, [
|
|
126
|
+
}, [messages]);
|
|
75
127
|
|
|
76
128
|
const channelMembers = useMemo(
|
|
77
129
|
() =>
|
|
@@ -151,7 +203,7 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
151
203
|
</Avatar.Group>
|
|
152
204
|
</Box>
|
|
153
205
|
<Box flex={0.9}>
|
|
154
|
-
<HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
206
|
+
{/* <HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
155
207
|
<Box flex={0.8}>
|
|
156
208
|
<Text color="gray.600" fontSize="lg" flexWrap={'wrap'} fontWeight="semibold">
|
|
157
209
|
{title}
|
|
@@ -164,7 +216,38 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
164
216
|
<Box flex={0.2}>
|
|
165
217
|
<Text color="gray.500">{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
166
218
|
</Box>
|
|
167
|
-
</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
|
+
/>
|
|
168
251
|
{/* <Text
|
|
169
252
|
flex={1}
|
|
170
253
|
color="gray.600"
|
|
@@ -189,4 +272,24 @@ export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function
|
|
|
189
272
|
);
|
|
190
273
|
};
|
|
191
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
|
+
|
|
192
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' }),
|