-
Notifications
You must be signed in to change notification settings - Fork 375
Expand file tree
/
Copy pathChatWrapper.tsx
More file actions
76 lines (63 loc) · 2.21 KB
/
Copy pathChatWrapper.tsx
File metadata and controls
76 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React, { PropsWithChildren } from 'react';
import { UserResponse } from 'stream-chat';
import {
Chat,
enTranslations,
OverlayProvider,
SqliteClient,
Streami18n,
useCreateChatClient,
WithComponents,
} from 'stream-chat-expo';
import { AuthProgressLoader } from './AuthProgressLoader';
import { useExpoMessagingComponentOverrides } from './ExpoMessagingComponentOverrides';
import { useStreamChatTheme } from '../hooks/useStreamChatTheme';
import { STREAM_API_KEY, USER_TOKENS } from '@/constants/ChatUsers';
import { useUserContext } from '@/context/UserContext';
import { usePushNotifications } from '@/hooks/usePushNotifications';
import '../utils/backgroundMessageHandler';
const streami18n = new Streami18n({
language: 'en',
});
SqliteClient.logger = (_level, _message, _extraData) => {
// console.log(_level, `SqliteClient: ${_message}`, _extraData);
};
export const ChatWrapper = ({ children }: PropsWithChildren) => {
const { user } = useUserContext();
const chatClient = useCreateChatClient({
apiKey: STREAM_API_KEY,
userData: user as UserResponse,
tokenOrProvider: USER_TOKENS[user?.id as string],
});
usePushNotifications({ chatClient });
streami18n.registerTranslation('en', {
...enTranslations,
// Custom translation key used by the live-location feature. It is not part of the
// SDK's `enTranslations` (a closed key set), but i18next resolves arbitrary keys at
// runtime, so we cast to the expected parameter type to register it.
'timestamp/Location end at': '{{ milliseconds | durationFormatter(withSuffix: false) }}',
} as typeof enTranslations);
const theme = useStreamChatTheme();
const componentOverrides = useExpoMessagingComponentOverrides();
if (!chatClient) {
return <AuthProgressLoader />;
}
return (
<WithComponents overrides={componentOverrides}>
<OverlayProvider
accessibility={{ enabled: true }}
i18nInstance={streami18n}
value={{ style: theme }}
>
<Chat
client={chatClient}
i18nInstance={streami18n}
enableOfflineSupport
useNativeMultipartUpload
>
{children}
</Chat>
</OverlayProvider>
</WithComponents>
);
};