@messenger-box/platform-mobile 10.0.3-alpha.18 → 10.0.3-alpha.180
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/lib/compute.js +2 -3
- package/lib/compute.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/module.js.map +1 -1
- package/lib/queries/inboxQueries.js +65 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogMessages.js +8 -3
- package/lib/screens/inbox/DialogMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreadMessages.js +6 -11
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +58 -20
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/Inbox.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/consts.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/index.js +125 -115
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogItem.js +160 -0
- package/lib/screens/inbox/components/DialogItem.js.map +1 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js +2 -0
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js +194 -0
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +144 -32
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js +3 -4
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +22 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/components/ThreadsViewItem.js +67 -47
- package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
- package/lib/screens/inbox/config/config.js +4 -2
- package/lib/screens/inbox/config/config.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +1098 -1093
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +179 -333
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +873 -866
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +81 -54
- package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
- package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
- package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
- package/package.json +5 -5
- package/CHANGELOG.md +0 -156
- package/jest.config.js +0 -24
- package/lib/screens/inbox/components/DialogsListItem.js +0 -175
- package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -165
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js +0 -380
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +0 -235
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js +0 -438
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js.map +0 -1
- package/rollup.config.mjs +0 -45
- package/src/components/index.ts +0 -0
- package/src/compute.ts +0 -63
- package/src/index.ts +0 -7
- package/src/module.ts +0 -10
- package/src/navigation/InboxNavigation.tsx +0 -102
- package/src/navigation/index.ts +0 -1
- package/src/screens/inbox/DialogMessages.tsx +0 -21
- package/src/screens/inbox/DialogThreadMessages.tsx +0 -97
- package/src/screens/inbox/DialogThreads.tsx +0 -129
- package/src/screens/inbox/Inbox.tsx +0 -17
- package/src/screens/inbox/components/CachedImage/consts.ts +0 -6
- package/src/screens/inbox/components/CachedImage/index.tsx +0 -223
- package/src/screens/inbox/components/DialogsHeader.tsx +0 -30
- package/src/screens/inbox/components/DialogsListItem.tsx +0 -302
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +0 -287
- package/src/screens/inbox/components/SlackMessageContainer/ImageViewerModal.tsx +0 -113
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +0 -313
- package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +0 -145
- package/src/screens/inbox/components/SlackMessageContainer/index.ts +0 -3
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +0 -283
- package/src/screens/inbox/components/ThreadsViewItem.tsx +0 -321
- package/src/screens/inbox/config/config.ts +0 -15
- package/src/screens/inbox/config/index.ts +0 -1
- package/src/screens/inbox/containers/ConversationView.tsx +0 -1782
- package/src/screens/inbox/containers/Dialogs.tsx +0 -544
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +0 -119
- package/src/screens/inbox/containers/ThreadConversationView.tsx +0 -1537
- package/src/screens/inbox/containers/ThreadsView.tsx +0 -305
- package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +0 -20
- package/src/screens/inbox/containers/workflow/conversation-xstate.ts +0 -313
- package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +0 -196
- package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +0 -401
- package/src/screens/index.ts +0 -4
- package/tsconfig.json +0 -13
- package/webpack.config.js +0 -58
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
-
import { Image, View, Text } from 'react-native';
|
|
3
|
-
// import { Image } from "react-native"
|
|
4
|
-
import * as FileSystem from 'expo-file-system';
|
|
5
|
-
|
|
6
|
-
import * as CONST from './consts';
|
|
7
|
-
|
|
8
|
-
// Ensure the cache directory exists
|
|
9
|
-
const ensureCacheDirectory = async () => {
|
|
10
|
-
try {
|
|
11
|
-
const dirInfo = await FileSystem.getInfoAsync(CONST.IMAGE_CACHE_FOLDER);
|
|
12
|
-
if (!dirInfo.exists) {
|
|
13
|
-
console.log('Creating cache directory:', CONST.IMAGE_CACHE_FOLDER);
|
|
14
|
-
await FileSystem.makeDirectoryAsync(CONST.IMAGE_CACHE_FOLDER, { intermediates: true });
|
|
15
|
-
}
|
|
16
|
-
} catch (error) {
|
|
17
|
-
console.error('Failed to create cache directory:', error);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// Validate and sanitize the image URL
|
|
22
|
-
const validateImageUri = (uri: string): string | null => {
|
|
23
|
-
if (!uri) return null;
|
|
24
|
-
|
|
25
|
-
// Trim whitespace
|
|
26
|
-
uri = uri.trim();
|
|
27
|
-
|
|
28
|
-
// Check if it's a valid URL format
|
|
29
|
-
try {
|
|
30
|
-
new URL(uri);
|
|
31
|
-
} catch (e) {
|
|
32
|
-
console.log('Invalid URL format:', uri);
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Add more validation as needed for your specific case
|
|
37
|
-
return uri;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const CachedImage = (props: any) => {
|
|
41
|
-
const { source, cacheKey, placeholderContent } = props;
|
|
42
|
-
const { uri: originalUri, headers, expiresIn } = source;
|
|
43
|
-
|
|
44
|
-
// Validate and sanitize the URI
|
|
45
|
-
const uri = validateImageUri(originalUri);
|
|
46
|
-
|
|
47
|
-
const fileURI = `${CONST.IMAGE_CACHE_FOLDER}${cacheKey}`;
|
|
48
|
-
|
|
49
|
-
const [imgUri, setImgUri] = useState<any>(fileURI);
|
|
50
|
-
const [loadError, setLoadError] = useState<boolean>(false);
|
|
51
|
-
const [useFallbackUri, setUseFallbackUri] = useState<boolean>(false);
|
|
52
|
-
|
|
53
|
-
const componentIsMounted = useRef(true);
|
|
54
|
-
const requestOption = headers ? { headers } : {};
|
|
55
|
-
|
|
56
|
-
const _callback = (downloadProgress: any) => {
|
|
57
|
-
if (componentIsMounted.current === false) {
|
|
58
|
-
downloadResumableRef.current?.pauseAsync();
|
|
59
|
-
FileSystem.deleteAsync(fileURI, { idempotent: true }); // delete file locally if it was not downloaded properly
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const downloadResumableRef = useRef(
|
|
64
|
-
uri ? FileSystem.createDownloadResumable(uri, fileURI, requestOption, _callback) : null,
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const initCache = async () => {
|
|
69
|
-
await ensureCacheDirectory();
|
|
70
|
-
if (uri) {
|
|
71
|
-
loadImage();
|
|
72
|
-
} else {
|
|
73
|
-
console.log('Image URI is invalid, not loading');
|
|
74
|
-
setLoadError(true);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
console.log('CachedImage loading with URI:', uri);
|
|
79
|
-
console.log('Cache key:', cacheKey);
|
|
80
|
-
|
|
81
|
-
initCache();
|
|
82
|
-
|
|
83
|
-
return () => {
|
|
84
|
-
componentIsMounted.current = false;
|
|
85
|
-
};
|
|
86
|
-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
87
|
-
|
|
88
|
-
const loadImage = async () => {
|
|
89
|
-
try {
|
|
90
|
-
// Use the cached image if it exists
|
|
91
|
-
const metadata: any = await FileSystem.getInfoAsync(fileURI);
|
|
92
|
-
const expired = expiresIn && new Date().getTime() / 1000 - metadata?.modificationTime > expiresIn;
|
|
93
|
-
console.log({ expiresIn, expired });
|
|
94
|
-
|
|
95
|
-
console.log({ modificationTime: metadata.modificationTime, currentTime: new Date().getTime() / 1000 });
|
|
96
|
-
console.log({ metadata });
|
|
97
|
-
|
|
98
|
-
if (!metadata.exists || metadata?.size === 0 || expired) {
|
|
99
|
-
if (componentIsMounted.current) {
|
|
100
|
-
setImgUri(null);
|
|
101
|
-
|
|
102
|
-
if (expired) {
|
|
103
|
-
await FileSystem.deleteAsync(fileURI, { idempotent: true });
|
|
104
|
-
}
|
|
105
|
-
// download to cache
|
|
106
|
-
setImgUri(null);
|
|
107
|
-
|
|
108
|
-
console.log('Downloading image from URI:', uri);
|
|
109
|
-
if (!uri) {
|
|
110
|
-
console.log('Image URI is undefined or null');
|
|
111
|
-
setLoadError(true);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!downloadResumableRef.current) {
|
|
116
|
-
console.log('Download resumable is null');
|
|
117
|
-
setUseFallbackUri(true);
|
|
118
|
-
setImgUri(uri);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const response: any = await downloadResumableRef.current.downloadAsync();
|
|
124
|
-
console.log('Download response:', response);
|
|
125
|
-
|
|
126
|
-
if (componentIsMounted.current && response && response.status === 200) {
|
|
127
|
-
setImgUri(`${fileURI}?`); // deep clone to force re-render
|
|
128
|
-
console.log('Image cached successfully, new URI:', `${fileURI}?`);
|
|
129
|
-
} else {
|
|
130
|
-
console.log('Failed to download image, status:', response?.status);
|
|
131
|
-
console.log('Falling back to original URI');
|
|
132
|
-
setUseFallbackUri(true);
|
|
133
|
-
setImgUri(uri);
|
|
134
|
-
FileSystem.deleteAsync(fileURI, { idempotent: true }); // delete file locally if it was not downloaded properly
|
|
135
|
-
}
|
|
136
|
-
} catch (downloadError) {
|
|
137
|
-
console.log('Error downloading image:', downloadError);
|
|
138
|
-
console.log('Falling back to original URI');
|
|
139
|
-
setUseFallbackUri(true);
|
|
140
|
-
setImgUri(uri);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
} else {
|
|
144
|
-
console.log('Using cached image at:', fileURI);
|
|
145
|
-
}
|
|
146
|
-
} catch (err) {
|
|
147
|
-
console.log({ err });
|
|
148
|
-
console.log('Falling back to original URI');
|
|
149
|
-
setUseFallbackUri(true);
|
|
150
|
-
setImgUri(uri);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
console.log({ placeholderContent, imgUri, loadError, useFallbackUri });
|
|
155
|
-
|
|
156
|
-
// Default placeholder if none is provided
|
|
157
|
-
const defaultPlaceholder = (
|
|
158
|
-
<View
|
|
159
|
-
style={{
|
|
160
|
-
width: '100%',
|
|
161
|
-
height: '100%',
|
|
162
|
-
backgroundColor: '#e1e1e1',
|
|
163
|
-
justifyContent: 'center',
|
|
164
|
-
alignItems: 'center',
|
|
165
|
-
borderRadius: 3,
|
|
166
|
-
}}
|
|
167
|
-
>
|
|
168
|
-
<Text>Image not available</Text>
|
|
169
|
-
</View>
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
if (!imgUri) {
|
|
173
|
-
return placeholderContent || defaultPlaceholder;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return (
|
|
177
|
-
<Image
|
|
178
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
179
|
-
{...props}
|
|
180
|
-
source={{
|
|
181
|
-
...source,
|
|
182
|
-
uri: useFallbackUri ? uri : imgUri,
|
|
183
|
-
}}
|
|
184
|
-
onError={(e) => {
|
|
185
|
-
console.log('Image loading error:', e.nativeEvent.error);
|
|
186
|
-
// If we're already using the fallback URI and still getting an error,
|
|
187
|
-
// then show the placeholder
|
|
188
|
-
if (useFallbackUri) {
|
|
189
|
-
setLoadError(true);
|
|
190
|
-
setImgUri(null);
|
|
191
|
-
} else {
|
|
192
|
-
console.log('Falling back to original URI after onError');
|
|
193
|
-
setUseFallbackUri(true);
|
|
194
|
-
setImgUri(uri);
|
|
195
|
-
}
|
|
196
|
-
}}
|
|
197
|
-
/>
|
|
198
|
-
);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export const CacheManager = {
|
|
202
|
-
addToCache: async ({ file, key }: any) => {
|
|
203
|
-
await FileSystem.copyAsync({
|
|
204
|
-
from: file,
|
|
205
|
-
to: `${CONST.IMAGE_CACHE_FOLDER}${key}`,
|
|
206
|
-
});
|
|
207
|
-
// const uri = await FileSystem.getContentUriAsync(`${CONST.IMAGE_CACHE_FOLDER}${key}`)
|
|
208
|
-
// return uri
|
|
209
|
-
const uri = await CacheManager.getCachedUri({ key });
|
|
210
|
-
return uri;
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
getCachedUri: async ({ key }: any) => {
|
|
214
|
-
const uri = await FileSystem.getContentUriAsync(`${CONST.IMAGE_CACHE_FOLDER}${key}`);
|
|
215
|
-
return uri;
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
downloadAsync: async ({ uri, key, options }: any) => {
|
|
219
|
-
return await FileSystem.downloadAsync(uri, `${CONST.IMAGE_CACHE_FOLDER}${key}`, options);
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
export default CachedImage;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { HStack, Text, View } from '@admin-layout/gluestack-ui-mobile';
|
|
3
|
-
import { AntDesign } from '@expo/vector-icons';
|
|
4
|
-
import { StyleProp, ViewStyle } from 'react-native';
|
|
5
|
-
|
|
6
|
-
export function DialogsHeader({
|
|
7
|
-
onBack,
|
|
8
|
-
extra,
|
|
9
|
-
style,
|
|
10
|
-
title,
|
|
11
|
-
}: {
|
|
12
|
-
onBack?: () => void;
|
|
13
|
-
extra?: any;
|
|
14
|
-
style?: StyleProp<ViewStyle>;
|
|
15
|
-
title: string;
|
|
16
|
-
}) {
|
|
17
|
-
return (
|
|
18
|
-
<HStack className="px-4 py-2 items-center justify-between" style={style}>
|
|
19
|
-
<View style={{ flex: 1 }}>{onBack ? <AntDesign onPress={onBack} name="left" size={18} /> : null}</View>
|
|
20
|
-
<View style={{ flexDirection: 'row', flex: 1, flexGrow: 1 }}>
|
|
21
|
-
<Text numberOfLines={1} style={{ fontSize: 20 }} className="shrink font-semibold text-center grow">
|
|
22
|
-
{title || ' '}
|
|
23
|
-
</Text>
|
|
24
|
-
</View>
|
|
25
|
-
<View style={{ flex: 1, alignItems: 'flex-end', justifyContent: 'center' }}>
|
|
26
|
-
<Text className="text-right">{extra}</Text>
|
|
27
|
-
</View>
|
|
28
|
-
</HStack>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Text,
|
|
4
|
-
Image,
|
|
5
|
-
Pressable,
|
|
6
|
-
HStack,
|
|
7
|
-
Box,
|
|
8
|
-
AvatarGroup,
|
|
9
|
-
Avatar,
|
|
10
|
-
AvatarFallbackText,
|
|
11
|
-
AvatarImage,
|
|
12
|
-
AvatarBadge,
|
|
13
|
-
View,
|
|
14
|
-
} from '@admin-layout/gluestack-ui-mobile';
|
|
15
|
-
import { format, isToday, isYesterday } from 'date-fns';
|
|
16
|
-
import { useFocusEffect } from '@react-navigation/native';
|
|
17
|
-
import { IChannel, SortEnum, IUserAccount } from 'common';
|
|
18
|
-
import {
|
|
19
|
-
useMessagesQuery,
|
|
20
|
-
useOnChatMessageAddedSubscription,
|
|
21
|
-
OnChatMessageAddedDocument as CHAT_MESSAGE_ADDED,
|
|
22
|
-
useUserAccountQuery,
|
|
23
|
-
} from 'common/graphql';
|
|
24
|
-
import { startCase } from 'lodash-es';
|
|
25
|
-
import colors from 'tailwindcss/colors';
|
|
26
|
-
|
|
27
|
-
const createdAtText = (value: string) => {
|
|
28
|
-
if (!value) return '';
|
|
29
|
-
let date = new Date(value);
|
|
30
|
-
if (isToday(date)) return 'Today';
|
|
31
|
-
if (isYesterday(date)) return 'Yesterday';
|
|
32
|
-
return format(new Date(value), 'MMM dd, yyyy');
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export interface IDialogListChannel extends IChannel {
|
|
36
|
-
users: IUserAccount[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface IDialogListItemProps {
|
|
40
|
-
currentUser?: any;
|
|
41
|
-
users?: any;
|
|
42
|
-
selectedChannelId?: any;
|
|
43
|
-
channel?: any;
|
|
44
|
-
onOpen: (id: any, title: any) => void;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* TODO:
|
|
49
|
-
* - Get Reservation info: reservation date, status
|
|
50
|
-
* - Add ability to get property information: name, logo
|
|
51
|
-
*/
|
|
52
|
-
export const DialogsListItemComponent: React.FC<IDialogListItemProps> = function DialogsListItem({
|
|
53
|
-
currentUser,
|
|
54
|
-
// users,
|
|
55
|
-
selectedChannelId,
|
|
56
|
-
channel,
|
|
57
|
-
onOpen,
|
|
58
|
-
}) {
|
|
59
|
-
const parentId: any = null;
|
|
60
|
-
const [messages, setMessages] = useState<any>([]);
|
|
61
|
-
const {
|
|
62
|
-
data: messagesQuery,
|
|
63
|
-
loading: messageLoading,
|
|
64
|
-
refetch: refetchMessages,
|
|
65
|
-
subscribeToMore,
|
|
66
|
-
} = useMessagesQuery({
|
|
67
|
-
variables: {
|
|
68
|
-
channelId: channel?.id?.toString(),
|
|
69
|
-
parentId: parentId,
|
|
70
|
-
limit: 10,
|
|
71
|
-
// sort: {
|
|
72
|
-
// key: 'updatedAt',
|
|
73
|
-
// value: SortEnum.Desc,
|
|
74
|
-
// },
|
|
75
|
-
//limit: 25,
|
|
76
|
-
},
|
|
77
|
-
fetchPolicy: 'cache-and-network',
|
|
78
|
-
refetchWritePolicy: 'merge',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const {
|
|
82
|
-
data: newMessage,
|
|
83
|
-
loading: newMsgLoading,
|
|
84
|
-
error: newMsgError,
|
|
85
|
-
}: any = useOnChatMessageAddedSubscription({
|
|
86
|
-
variables: {
|
|
87
|
-
channelId: channel?.id?.toString(),
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
useFocusEffect(
|
|
92
|
-
React.useCallback(() => {
|
|
93
|
-
// Do something when the screen is focused
|
|
94
|
-
refetchMessages({
|
|
95
|
-
channelId: channel?.id?.toString(),
|
|
96
|
-
parentId: parentId,
|
|
97
|
-
limit: 10,
|
|
98
|
-
// sort: {
|
|
99
|
-
// key: 'updatedAt',
|
|
100
|
-
// value: SortEnum.Desc,
|
|
101
|
-
// },
|
|
102
|
-
//limit: 25
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return () => {
|
|
106
|
-
// Do something when the screen is unfocused
|
|
107
|
-
// Useful for cleanup functions
|
|
108
|
-
};
|
|
109
|
-
}, []),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
React.useEffect(() => {
|
|
113
|
-
if (messagesQuery) {
|
|
114
|
-
if (messagesQuery?.messages?.data?.length) {
|
|
115
|
-
const msg = messagesQuery?.messages?.data;
|
|
116
|
-
setMessages((pre: any[]) => [...pre, ...msg]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}, [messagesQuery]);
|
|
120
|
-
|
|
121
|
-
const lastMessage = useMemo(() => {
|
|
122
|
-
if (!messages?.length) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
// const { data } = messagesQuery.messages;
|
|
126
|
-
const data = messages;
|
|
127
|
-
const filteredData: any = data?.filter((p: any) => p?.message !== '');
|
|
128
|
-
// return filteredData[0];
|
|
129
|
-
let filteredLastMessage =
|
|
130
|
-
filteredData && filteredData?.length
|
|
131
|
-
? filteredData?.reduce((a, b) => {
|
|
132
|
-
return new Date(a?.updatedAt) > new Date(b?.updatedAt) ? a : b;
|
|
133
|
-
}, []) ?? null
|
|
134
|
-
: null;
|
|
135
|
-
return filteredLastMessage;
|
|
136
|
-
//return data[data.length - 1];
|
|
137
|
-
}, [messages]);
|
|
138
|
-
|
|
139
|
-
const channelMembers = useMemo(
|
|
140
|
-
() =>
|
|
141
|
-
channel?.members
|
|
142
|
-
?.filter((ch: any) => ch?.user?.id != currentUser?.id && ch?.user?.__typename == 'UserAccount')
|
|
143
|
-
?.map((m: any) => m?.user) ?? null,
|
|
144
|
-
[currentUser, channel],
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const title = useMemo(() => {
|
|
148
|
-
const titleString =
|
|
149
|
-
channelMembers
|
|
150
|
-
?.map((u: any) => u?.givenName + ' ' + (u?.familyName ?? ''))
|
|
151
|
-
?.filter((mu: any) => mu)
|
|
152
|
-
?.join(', ') ?? '';
|
|
153
|
-
|
|
154
|
-
const length = 30;
|
|
155
|
-
return titleString.length > length ? titleString.substring(0, length - 3) + '...' : titleString;
|
|
156
|
-
}, [channelMembers]);
|
|
157
|
-
|
|
158
|
-
return (
|
|
159
|
-
<Pressable
|
|
160
|
-
onPress={() => channel?.id !== selectedChannelId && onOpen(channel?.id, title)}
|
|
161
|
-
className="flex-1 border-gray-200 rounded-md dark:border-gray-600 dark:bg-gray-700"
|
|
162
|
-
style={{ borderBottomWidth: 1, borderColor: '#e5e7eb', marginVertical: 0, paddingHorizontal: 10 }}
|
|
163
|
-
>
|
|
164
|
-
<HStack space={'md'} className="flex-1 w-[100%] py-3 items-center">
|
|
165
|
-
<Box className="flex-[0.1] items-start pl-3">
|
|
166
|
-
<AvatarGroup>
|
|
167
|
-
{channelMembers &&
|
|
168
|
-
channelMembers?.length > 0 &&
|
|
169
|
-
channelMembers?.slice(0, 1)?.map((ch: any, i: Number) => (
|
|
170
|
-
<Avatar
|
|
171
|
-
key={'dialogs-list-' + i}
|
|
172
|
-
size={'sm'}
|
|
173
|
-
className={`bg-transparent top-[${i == 1 ? '4' : '0'}] right-[${
|
|
174
|
-
i == 1 ? '-2' : '0'
|
|
175
|
-
}] z-[${i == 1 ? 5 : 1}]`}
|
|
176
|
-
>
|
|
177
|
-
<AvatarFallbackText>{startCase(ch?.username?.charAt(0))}</AvatarFallbackText>
|
|
178
|
-
|
|
179
|
-
{channelMembers?.length > 1 && (
|
|
180
|
-
<AvatarBadge
|
|
181
|
-
style={{
|
|
182
|
-
width: '100%',
|
|
183
|
-
height: '100%',
|
|
184
|
-
backgroundColor: '#e5e7eb',
|
|
185
|
-
borderRadius: 5,
|
|
186
|
-
}}
|
|
187
|
-
className="items-center justify-center bg-gray-200 rounded-md"
|
|
188
|
-
>
|
|
189
|
-
<Text style={{ fontSize: 12, fontWeight: 'bold', color: '#000' }}>
|
|
190
|
-
{channelMembers?.length}
|
|
191
|
-
</Text>
|
|
192
|
-
</AvatarBadge>
|
|
193
|
-
)}
|
|
194
|
-
{channelMembers?.length == 1 && (
|
|
195
|
-
<>
|
|
196
|
-
<AvatarImage
|
|
197
|
-
alt="user image"
|
|
198
|
-
style={{ borderRadius: 6, borderWidth: 2, borderColor: '#fff' }}
|
|
199
|
-
source={{
|
|
200
|
-
uri: ch?.picture,
|
|
201
|
-
}}
|
|
202
|
-
/>
|
|
203
|
-
<AvatarBadge style={{ width: 10, height: 10 }} />
|
|
204
|
-
</>
|
|
205
|
-
)}
|
|
206
|
-
</Avatar>
|
|
207
|
-
))}
|
|
208
|
-
</AvatarGroup>
|
|
209
|
-
</Box>
|
|
210
|
-
<Box className="flex-1 bg-gray-400">
|
|
211
|
-
{/* <HStack space={1} flex={1} direction={'row'} justifyContent={'center'} alignItems={'center'}>
|
|
212
|
-
<Box flex={0.8}>
|
|
213
|
-
<Text color="gray.600" fontSize="lg" flexWrap={'wrap'} fontWeight="semibold">
|
|
214
|
-
{title}
|
|
215
|
-
</Text>
|
|
216
|
-
<Text color="gray.600" noOfLines={1}>
|
|
217
|
-
{lastMessage?.message ?? ''}
|
|
218
|
-
</Text>
|
|
219
|
-
</Box>
|
|
220
|
-
|
|
221
|
-
<Box flex={0.2}>
|
|
222
|
-
<Text color="gray.500">{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
223
|
-
</Box>
|
|
224
|
-
</HStack> */}
|
|
225
|
-
<LastMessageComponent
|
|
226
|
-
title={title}
|
|
227
|
-
lastMessage={lastMessage}
|
|
228
|
-
channelId={channel?.id}
|
|
229
|
-
subscribeToNewMessages={() =>
|
|
230
|
-
subscribeToMore({
|
|
231
|
-
document: CHAT_MESSAGE_ADDED,
|
|
232
|
-
variables: {
|
|
233
|
-
channelId: channel.id?.toString(),
|
|
234
|
-
},
|
|
235
|
-
updateQuery: (prev, { subscriptionData }: any) => {
|
|
236
|
-
if (!subscriptionData.data) return prev;
|
|
237
|
-
const newMessage: any = subscriptionData?.data?.chatMessageAdded;
|
|
238
|
-
const existingMessages: any = prev?.messages;
|
|
239
|
-
const previousData = existingMessages?.data
|
|
240
|
-
? [...existingMessages.data, newMessage]
|
|
241
|
-
: [];
|
|
242
|
-
const totalMsgCount = existingMessages?.totalCount + 1;
|
|
243
|
-
const merged = {
|
|
244
|
-
...prev,
|
|
245
|
-
messages: {
|
|
246
|
-
...existingMessages,
|
|
247
|
-
data: previousData,
|
|
248
|
-
totalCount: totalMsgCount,
|
|
249
|
-
},
|
|
250
|
-
};
|
|
251
|
-
return merged;
|
|
252
|
-
},
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
/>
|
|
256
|
-
{/* <Text
|
|
257
|
-
flex={1}
|
|
258
|
-
color="gray.600"
|
|
259
|
-
p={0}
|
|
260
|
-
m={0}
|
|
261
|
-
w={'100%'}
|
|
262
|
-
justifyContent={''}
|
|
263
|
-
fontSize="lg"
|
|
264
|
-
fontWeight="semibold"
|
|
265
|
-
>
|
|
266
|
-
{title}
|
|
267
|
-
</Text> */}
|
|
268
|
-
{/* <Text flex={0.1} color="gray.600">
|
|
269
|
-
{lastMessage?.message ?? ''}
|
|
270
|
-
</Text> */}
|
|
271
|
-
</Box>
|
|
272
|
-
{/* <Text flex={0.2} color="gray.500">
|
|
273
|
-
{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}
|
|
274
|
-
</Text> */}
|
|
275
|
-
</HStack>
|
|
276
|
-
</Pressable>
|
|
277
|
-
);
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const LastMessageComponent = ({ subscribeToNewMessages, title, lastMessage, channelId }) => {
|
|
281
|
-
React.useEffect(() => subscribeToNewMessages(), [channelId]);
|
|
282
|
-
const count = 30;
|
|
283
|
-
const channelTitle = title.slice(0, count) + (title.length > count ? '...' : '');
|
|
284
|
-
return (
|
|
285
|
-
<HStack space={'sm'} className="flex-1 justify-between">
|
|
286
|
-
<Box className="flex-[0.8]">
|
|
287
|
-
<Text color={colors.gray[600]} className="text-base text-wrap flex-wrap font-semibold">
|
|
288
|
-
{channelTitle}
|
|
289
|
-
</Text>
|
|
290
|
-
<Text color={colors.gray[600]} numberOfLines={1}>
|
|
291
|
-
{lastMessage?.message ?? ''}
|
|
292
|
-
</Text>
|
|
293
|
-
</Box>
|
|
294
|
-
|
|
295
|
-
<Box className="flex-[0.2]">
|
|
296
|
-
<Text color={colors.gray[500]}>{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
297
|
-
</Box>
|
|
298
|
-
</HStack>
|
|
299
|
-
);
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
export const DialogsListItem = React.memo(DialogsListItemComponent);
|