chat 1.0.8 → 3.0.0
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/package.json +2 -96
- package/readme.md +1 -201
- package/lib/module/ChatContext/index.js +0 -2
- package/lib/module/ChatContext/index.js.map +0 -1
- package/lib/module/ChatContext/types.js +0 -2
- package/lib/module/ChatContext/types.js.map +0 -1
- package/lib/module/classes/Chat/index.js +0 -2
- package/lib/module/classes/Chat/index.js.map +0 -1
- package/lib/module/classes/Chat/types.js +0 -2
- package/lib/module/classes/Chat/types.js.map +0 -1
- package/lib/module/classes/Inbox/index.js +0 -2
- package/lib/module/classes/Inbox/index.js.map +0 -1
- package/lib/module/classes/Inbox/types.js +0 -2
- package/lib/module/classes/Inbox/types.js.map +0 -1
- package/lib/module/classes/Message/index.js +0 -2
- package/lib/module/classes/Message/index.js.map +0 -1
- package/lib/module/classes/Message/types.js +0 -2
- package/lib/module/classes/Message/types.js.map +0 -1
- package/lib/module/classes/Reaction/index.js +0 -2
- package/lib/module/classes/Reaction/index.js.map +0 -1
- package/lib/module/classes/Reaction/types.js +0 -2
- package/lib/module/classes/Reaction/types.js.map +0 -1
- package/lib/module/classes/Room/index.js +0 -2
- package/lib/module/classes/Room/index.js.map +0 -1
- package/lib/module/classes/Room/types.js +0 -2
- package/lib/module/classes/Room/types.js.map +0 -1
- package/lib/module/classes/index.js +0 -2
- package/lib/module/classes/index.js.map +0 -1
- package/lib/module/components/Avatar/index.js +0 -2
- package/lib/module/components/Avatar/index.js.map +0 -1
- package/lib/module/components/Chat/Bubble/index.js +0 -2
- package/lib/module/components/Chat/Bubble/index.js.map +0 -1
- package/lib/module/components/Chat/Composer/Input/index.js +0 -2
- package/lib/module/components/Chat/Composer/Input/index.js.map +0 -1
- package/lib/module/components/Chat/Composer/Send/index.js +0 -2
- package/lib/module/components/Chat/Composer/Send/index.js.map +0 -1
- package/lib/module/components/Chat/Composer/index.js +0 -2
- package/lib/module/components/Chat/Composer/index.js.map +0 -1
- package/lib/module/components/Chat/Media/Image/index.js +0 -2
- package/lib/module/components/Chat/Media/Image/index.js.map +0 -1
- package/lib/module/components/Chat/Media/index.js +0 -2
- package/lib/module/components/Chat/Media/index.js.map +0 -1
- package/lib/module/components/Chat/Message/Swiper/Action/index.js +0 -2
- package/lib/module/components/Chat/Message/Swiper/Action/index.js.map +0 -1
- package/lib/module/components/Chat/Message/Swiper/index.js +0 -2
- package/lib/module/components/Chat/Message/Swiper/index.js.map +0 -1
- package/lib/module/components/Chat/Message/Touchable/index.js +0 -2
- package/lib/module/components/Chat/Message/Touchable/index.js.map +0 -1
- package/lib/module/components/Chat/Message/index.js +0 -2
- package/lib/module/components/Chat/Message/index.js.map +0 -1
- package/lib/module/components/Chat/SystemMessage/index.js +0 -2
- package/lib/module/components/Chat/SystemMessage/index.js.map +0 -1
- package/lib/module/components/Chat/TypingFooter/index.js +0 -2
- package/lib/module/components/Chat/TypingFooter/index.js.map +0 -1
- package/lib/module/components/Chat/index.js +0 -2
- package/lib/module/components/Chat/index.js.map +0 -1
- package/lib/module/components/Chat/types.js +0 -2
- package/lib/module/components/Chat/types.js.map +0 -1
- package/lib/module/components/Chat-Old/Bubble/index.js +0 -2
- package/lib/module/components/Chat-Old/Bubble/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Composer/Input/index.js +0 -2
- package/lib/module/components/Chat-Old/Composer/Input/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Composer/Send/index.js +0 -2
- package/lib/module/components/Chat-Old/Composer/Send/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Composer/index.js +0 -2
- package/lib/module/components/Chat-Old/Composer/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Message/index.js +0 -2
- package/lib/module/components/Chat-Old/Message/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Swiper/Action/index.js +0 -2
- package/lib/module/components/Chat-Old/Swiper/Action/index.js.map +0 -1
- package/lib/module/components/Chat-Old/Swiper/index.js +0 -2
- package/lib/module/components/Chat-Old/Swiper/index.js.map +0 -1
- package/lib/module/components/Chat-Old/SystemMessage/index.js +0 -2
- package/lib/module/components/Chat-Old/SystemMessage/index.js.map +0 -1
- package/lib/module/components/Chat-Old/index.js +0 -2
- package/lib/module/components/Chat-Old/index.js.map +0 -1
- package/lib/module/components/Chat-Old/types.js +0 -2
- package/lib/module/components/Chat-Old/types.js.map +0 -1
- package/lib/module/components/ChatProvider/index.js +0 -2
- package/lib/module/components/ChatProvider/index.js.map +0 -1
- package/lib/module/components/ChatProvider/types.js +0 -2
- package/lib/module/components/ChatProvider/types.js.map +0 -1
- package/lib/module/components/Inbox/Item/Circle/index.js +0 -2
- package/lib/module/components/Inbox/Item/Circle/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/Circle/types.js +0 -2
- package/lib/module/components/Inbox/Item/Circle/types.js.map +0 -1
- package/lib/module/components/Inbox/Item/Initials/index.js +0 -2
- package/lib/module/components/Inbox/Item/Initials/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/ItemDate/index.js +0 -2
- package/lib/module/components/Inbox/Item/ItemDate/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/Separator/index.js +0 -2
- package/lib/module/components/Inbox/Item/Separator/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/Subtitle/index.js +0 -2
- package/lib/module/components/Inbox/Item/Subtitle/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/Swipeable/index.js +0 -2
- package/lib/module/components/Inbox/Item/Swipeable/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/Title/index.js +0 -2
- package/lib/module/components/Inbox/Item/Title/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/UnreadIndicator/index.js +0 -2
- package/lib/module/components/Inbox/Item/UnreadIndicator/index.js.map +0 -1
- package/lib/module/components/Inbox/Item/index.js +0 -2
- package/lib/module/components/Inbox/Item/index.js.map +0 -1
- package/lib/module/components/Inbox/index.js +0 -2
- package/lib/module/components/Inbox/index.js.map +0 -1
- package/lib/module/components/Inbox/question.md +0 -21
- package/lib/module/components/Inbox/readme.md +0 -21
- package/lib/module/components/Inbox/types.js +0 -2
- package/lib/module/components/Inbox/types.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/Footer/Button/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/Footer/Button/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/Footer/Input/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/Footer/Input/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/Footer/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/Footer/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/Item/Icon/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/Item/Icon/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/Item/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/Item/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Content/index.js +0 -2
- package/lib/module/components/RoomCreator/Content/index.js.map +0 -1
- package/lib/module/components/RoomCreator/Header/index.js +0 -2
- package/lib/module/components/RoomCreator/Header/index.js.map +0 -1
- package/lib/module/components/RoomCreator/index.js +0 -2
- package/lib/module/components/RoomCreator/index.js.map +0 -1
- package/lib/module/components/RoomCreator/types.js +0 -2
- package/lib/module/components/RoomCreator/types.js.map +0 -1
- package/lib/module/components/TypingIndicator/index.js +0 -2
- package/lib/module/components/TypingIndicator/index.js.map +0 -1
- package/lib/module/components/index.js +0 -2
- package/lib/module/components/index.js.map +0 -1
- package/lib/module/helpers/getInitials.js +0 -2
- package/lib/module/helpers/getInitials.js.map +0 -1
- package/lib/module/helpers/sortByAvatar.js +0 -2
- package/lib/module/helpers/sortByAvatar.js.map +0 -1
- package/lib/module/hooks/index.js +0 -2
- package/lib/module/hooks/index.js.map +0 -1
- package/lib/module/hooks/useCreateRoom/index.js +0 -2
- package/lib/module/hooks/useCreateRoom/index.js.map +0 -1
- package/lib/module/hooks/useCreator/index.js +0 -2
- package/lib/module/hooks/useCreator/index.js.map +0 -1
- package/lib/module/hooks/useInbox/index.js +0 -2
- package/lib/module/hooks/useInbox/index.js.map +0 -1
- package/lib/module/hooks/useInbox/types.js +0 -2
- package/lib/module/hooks/useInbox/types.js.map +0 -1
- package/lib/module/hooks/useMessages/index.js +0 -2
- package/lib/module/hooks/useMessages/index.js.map +0 -1
- package/lib/module/hooks/useMessages/types.js +0 -2
- package/lib/module/hooks/useMessages/types.js.map +0 -1
- package/lib/module/hooks/useRoom/index.js +0 -2
- package/lib/module/hooks/useRoom/index.js.map +0 -1
- package/lib/module/hooks/useRoom/types.js +0 -2
- package/lib/module/hooks/useRoom/types.js.map +0 -1
- package/lib/module/hooks/useSend/useSendToGroup/index.js +0 -2
- package/lib/module/hooks/useSend/useSendToGroup/index.js.map +0 -1
- package/lib/module/hooks/useSend/useSendToPeople/index.js +0 -2
- package/lib/module/hooks/useSend/useSendToPeople/index.js.map +0 -1
- package/lib/module/hooks/useTyping/index.js +0 -2
- package/lib/module/hooks/useTyping/index.js.map +0 -1
- package/lib/module/hooks/useTypingOLD/index.js +0 -2
- package/lib/module/hooks/useTypingOLD/index.js.map +0 -1
- package/lib/module/hooks/useTypingOLD/types.js +0 -2
- package/lib/module/hooks/useTypingOLD/types.js.map +0 -1
- package/lib/module/hooks/useViewMessages/index.js +0 -2
- package/lib/module/hooks/useViewMessages/index.js.map +0 -1
- package/lib/module/hooks/useViewMessages/types.js +0 -2
- package/lib/module/hooks/useViewMessages/types.js.map +0 -1
- package/lib/module/hooks/useViewMessagesOld/index.js +0 -2
- package/lib/module/hooks/useViewMessagesOld/index.js.map +0 -1
- package/lib/module/index.js +0 -2
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/ChatContext/index.d.ts +0 -2
- package/lib/typescript/ChatContext/types.d.ts +0 -4
- package/lib/typescript/classes/Chat/index.d.ts +0 -14
- package/lib/typescript/classes/Chat/types.d.ts +0 -21
- package/lib/typescript/classes/Inbox/types.d.ts +0 -2
- package/lib/typescript/classes/Message/index.d.ts +0 -47
- package/lib/typescript/classes/Message/types.d.ts +0 -66
- package/lib/typescript/classes/Reaction/index.d.ts +0 -17
- package/lib/typescript/classes/Reaction/types.d.ts +0 -33
- package/lib/typescript/classes/Room/index.d.ts +0 -42
- package/lib/typescript/classes/Room/types.d.ts +0 -112
- package/lib/typescript/classes/index.d.ts +0 -4
- package/lib/typescript/components/Avatar/index.d.ts +0 -4
- package/lib/typescript/components/Chat/Bubble/index.d.ts +0 -4
- package/lib/typescript/components/Chat/Composer/Input/index.d.ts +0 -7
- package/lib/typescript/components/Chat/Composer/Send/index.d.ts +0 -4
- package/lib/typescript/components/Chat/Composer/index.d.ts +0 -8
- package/lib/typescript/components/Chat/Media/Image/index.d.ts +0 -7
- package/lib/typescript/components/Chat/Media/index.d.ts +0 -4
- package/lib/typescript/components/Chat/Message/Touchable/index.d.ts +0 -4
- package/lib/typescript/components/Chat/Message/index.d.ts +0 -8
- package/lib/typescript/components/Chat/SystemMessage/index.d.ts +0 -4
- package/lib/typescript/components/Chat/TypingFooter/index.d.ts +0 -4
- package/lib/typescript/components/Chat/index.d.ts +0 -8
- package/lib/typescript/components/Chat/types.d.ts +0 -843
- package/lib/typescript/components/ChatProvider/index.d.ts +0 -10
- package/lib/typescript/components/ChatProvider/types.d.ts +0 -7
- package/lib/typescript/components/Inbox/Item/Initials/index.d.ts +0 -4
- package/lib/typescript/components/Inbox/Item/ItemDate/index.d.ts +0 -4
- package/lib/typescript/components/Inbox/Item/Separator/index.d.ts +0 -6
- package/lib/typescript/components/Inbox/Item/Subtitle/index.d.ts +0 -3
- package/lib/typescript/components/Inbox/Item/Swipeable/index.d.ts +0 -4
- package/lib/typescript/components/Inbox/Item/Title/index.d.ts +0 -3
- package/lib/typescript/components/Inbox/Item/UnreadIndicator/index.d.ts +0 -4
- package/lib/typescript/components/Inbox/Item/index.d.ts +0 -6
- package/lib/typescript/components/Inbox/index.d.ts +0 -4
- package/lib/typescript/components/Inbox/types.d.ts +0 -304
- package/lib/typescript/components/RoomCreator/Content/Footer/Button/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/Content/Footer/Input/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/Content/Footer/index.d.ts +0 -3
- package/lib/typescript/components/RoomCreator/Content/Item/Icon/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/Content/Item/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/Content/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/Header/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/index.d.ts +0 -4
- package/lib/typescript/components/RoomCreator/types.d.ts +0 -208
- package/lib/typescript/components/TypingIndicator/index.d.ts +0 -9
- package/lib/typescript/components/index.d.ts +0 -12
- package/lib/typescript/helpers/getInitials.d.ts +0 -1
- package/lib/typescript/hooks/index.d.ts +0 -8
- package/lib/typescript/hooks/useCreator/index.d.ts +0 -27
- package/lib/typescript/hooks/useInbox/index.d.ts +0 -29
- package/lib/typescript/hooks/useInbox/types.d.ts +0 -5
- package/lib/typescript/hooks/useMessages/index.d.ts +0 -24
- package/lib/typescript/hooks/useMessages/types.d.ts +0 -5
- package/lib/typescript/hooks/useRoom/index.d.ts +0 -26
- package/lib/typescript/hooks/useRoom/types.d.ts +0 -5
- package/lib/typescript/hooks/useSend/useSendToGroup/index.d.ts +0 -6
- package/lib/typescript/hooks/useSend/useSendToPeople/index.d.ts +0 -6
- package/lib/typescript/hooks/useTyping/index.d.ts +0 -36
- package/lib/typescript/hooks/useViewMessages/index.d.ts +0 -18
- package/lib/typescript/hooks/useViewMessages/types.d.ts +0 -20
- package/lib/typescript/index.d.ts +0 -11
- package/src/ChatContext/index.tsx +0 -9
- package/src/ChatContext/types.ts +0 -4
- package/src/classes/Chat/index.ts +0 -46
- package/src/classes/Chat/types.ts +0 -23
- package/src/classes/Inbox/index.ts +0 -12
- package/src/classes/Inbox/types.ts +0 -3
- package/src/classes/Message/index.ts +0 -310
- package/src/classes/Message/types.ts +0 -118
- package/src/classes/Reaction/index.ts +0 -108
- package/src/classes/Reaction/types.ts +0 -37
- package/src/classes/Room/index.ts +0 -323
- package/src/classes/Room/types.ts +0 -161
- package/src/classes/index.ts +0 -4
- package/src/components/Avatar/index.tsx +0 -25
- package/src/components/Chat/Bubble/index.tsx +0 -139
- package/src/components/Chat/Composer/Input/index.tsx +0 -45
- package/src/components/Chat/Composer/Send/index.tsx +0 -51
- package/src/components/Chat/Composer/index.tsx +0 -187
- package/src/components/Chat/Media/Image/index.tsx +0 -26
- package/src/components/Chat/Media/index.tsx +0 -11
- package/src/components/Chat/Message/Swiper/Action/index.tsx +0 -7
- package/src/components/Chat/Message/Swiper/index.tsx +0 -32
- package/src/components/Chat/Message/Touchable/index.tsx +0 -60
- package/src/components/Chat/Message/index.tsx +0 -328
- package/src/components/Chat/SystemMessage/index.tsx +0 -44
- package/src/components/Chat/TypingFooter/index.tsx +0 -48
- package/src/components/Chat/index.tsx +0 -596
- package/src/components/Chat/types.ts +0 -913
- package/src/components/Chat-Old/Bubble/index.tsx +0 -58
- package/src/components/Chat-Old/Composer/Input/index.tsx +0 -34
- package/src/components/Chat-Old/Composer/Send/index.tsx +0 -37
- package/src/components/Chat-Old/Composer/index.tsx +0 -131
- package/src/components/Chat-Old/Message/index.tsx +0 -160
- package/src/components/Chat-Old/Swiper/Action/index.tsx +0 -7
- package/src/components/Chat-Old/Swiper/index.tsx +0 -30
- package/src/components/Chat-Old/SystemMessage/index.tsx +0 -44
- package/src/components/Chat-Old/index.tsx +0 -356
- package/src/components/Chat-Old/types.ts +0 -752
- package/src/components/ChatProvider/index.tsx +0 -31
- package/src/components/ChatProvider/types.ts +0 -8
- package/src/components/Inbox/Item/Circle/index.tsx +0 -47
- package/src/components/Inbox/Item/Circle/types.ts +0 -8
- package/src/components/Inbox/Item/Initials/index.tsx +0 -41
- package/src/components/Inbox/Item/ItemDate/index.tsx +0 -26
- package/src/components/Inbox/Item/Separator/index.tsx +0 -13
- package/src/components/Inbox/Item/Subtitle/index.tsx +0 -23
- package/src/components/Inbox/Item/Swipeable/index.tsx +0 -143
- package/src/components/Inbox/Item/Title/index.tsx +0 -23
- package/src/components/Inbox/Item/UnreadIndicator/index.tsx +0 -84
- package/src/components/Inbox/Item/index.tsx +0 -307
- package/src/components/Inbox/index.tsx +0 -315
- package/src/components/Inbox/question.md +0 -21
- package/src/components/Inbox/readme.md +0 -21
- package/src/components/Inbox/types.ts +0 -371
- package/src/components/RoomCreator/Content/Footer/Button/index.tsx +0 -55
- package/src/components/RoomCreator/Content/Footer/Input/index.tsx +0 -27
- package/src/components/RoomCreator/Content/Footer/index.tsx +0 -72
- package/src/components/RoomCreator/Content/Item/Icon/index.tsx +0 -16
- package/src/components/RoomCreator/Content/Item/index.tsx +0 -87
- package/src/components/RoomCreator/Content/index.tsx +0 -75
- package/src/components/RoomCreator/Header/index.tsx +0 -74
- package/src/components/RoomCreator/index.tsx +0 -177
- package/src/components/RoomCreator/types.ts +0 -233
- package/src/components/TypingIndicator/index.tsx +0 -169
- package/src/components/index.ts +0 -18
- package/src/helpers/getInitials.ts +0 -11
- package/src/helpers/sortByAvatar.ts +0 -1
- package/src/hooks/index.ts +0 -8
- package/src/hooks/useCreateRoom/index.ts +0 -34
- package/src/hooks/useCreator/index.ts +0 -33
- package/src/hooks/useInbox/index.ts +0 -76
- package/src/hooks/useInbox/types.ts +0 -6
- package/src/hooks/useMessages/index.ts +0 -109
- package/src/hooks/useMessages/types.ts +0 -6
- package/src/hooks/useRoom/index.ts +0 -82
- package/src/hooks/useRoom/types.ts +0 -6
- package/src/hooks/useSend/useSendToGroup/index.ts +0 -38
- package/src/hooks/useSend/useSendToPeople/index.ts +0 -38
- package/src/hooks/useTyping/index.ts +0 -154
- package/src/hooks/useTypingOLD/index.ts +0 -67
- package/src/hooks/useTypingOLD/types.ts +0 -7
- package/src/hooks/useViewMessages/index.ts +0 -61
- package/src/hooks/useViewMessages/types.ts +0 -22
- package/src/hooks/useViewMessagesOld/index.ts +0 -39
- package/src/index.ts +0 -13
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { default as useMessages } from './useMessages';
|
|
2
|
-
export { default as useRoom } from './useRoom';
|
|
3
|
-
export { default as useTyping } from './useTyping';
|
|
4
|
-
export { default as useInbox } from './useInbox';
|
|
5
|
-
export { default as useCreator } from './useCreator';
|
|
6
|
-
export { default as useViewMessages } from './useViewMessages';
|
|
7
|
-
export { default as useSendToPeople } from './useSend/useSendToPeople';
|
|
8
|
-
export { default as useSendToGroup } from './useSend/useSendToGroup';
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
2
|
-
import { RoomCreatorRef } from '../../components/RoomCreator/types';
|
|
3
|
-
declare const _default: () => [MutableRefObject<RoomCreatorRef | undefined>, {
|
|
4
|
-
open: () => void;
|
|
5
|
-
close: () => void;
|
|
6
|
-
}];
|
|
7
|
-
/**
|
|
8
|
-
* React hook for managing RoomCreator component in usechat
|
|
9
|
-
*
|
|
10
|
-
* @returns An array with a ref and then convenience functions for the creator
|
|
11
|
-
* [ref, { open, close }]
|
|
12
|
-
*
|
|
13
|
-
* **Required** In order for the methods to work, you must pass creator to sheetRef prop.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```javascript
|
|
17
|
-
* export default () => {
|
|
18
|
-
* const [creator, { open, close }]
|
|
19
|
-
*
|
|
20
|
-
* // ...some other method
|
|
21
|
-
* const onPress = () => open()
|
|
22
|
-
*
|
|
23
|
-
* return <RoomCreator sheetRef={creator} />
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export default _default;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { QueryDataHandler } from '@nandorojo/fuego/lib/typescript/hooks/useFuego/types';
|
|
2
|
-
import { ExistingRoomDocument } from '../../classes/Room/types';
|
|
3
|
-
import { InboxModel } from '../../classes/Inbox/types';
|
|
4
|
-
import { UseInboxConfig } from './types';
|
|
5
|
-
declare const _default: (config?: UseInboxConfig, options?: QueryDataHandler<ExistingRoomDocument>) => {
|
|
6
|
-
path: string;
|
|
7
|
-
loading: boolean;
|
|
8
|
-
error: import("@nandorojo/fuego/lib/typescript/hooks/useFuego/types").QueryError;
|
|
9
|
-
db: import("firebase").firestore.Firestore;
|
|
10
|
-
ref: import("@nandorojo/fuego").FirestoreRefType;
|
|
11
|
-
unsubscribe: (name: string) => void;
|
|
12
|
-
exists: boolean | null;
|
|
13
|
-
refetch: () => void;
|
|
14
|
-
data: InboxModel;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* React hook to query the chat inbox in realtime. Used with the [Juice.Inbox] component from Juice.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```
|
|
21
|
-
* const { data } = useInbox()
|
|
22
|
-
*
|
|
23
|
-
* return <Juice.Inbox rooms={data} />
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @returns
|
|
27
|
-
* { data, loading, path, error } and other values returned by useFuego() hook. Data is properly formatted for rendering.
|
|
28
|
-
*/
|
|
29
|
-
export default _default;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { UseMessagesConfig } from './types';
|
|
2
|
-
import { NewMessageModel, EditMessageModel, MessageModelDocument } from '../../classes/Message/types';
|
|
3
|
-
import { QueryDataHandler } from '@nandorojo/fuego/lib/typescript/hooks/useFuego/types';
|
|
4
|
-
declare const _default: ({ id, ...config }: UseMessagesConfig, options?: QueryDataHandler<MessageModelDocument>) => {
|
|
5
|
-
data: NewMessageModel[];
|
|
6
|
-
loading: boolean;
|
|
7
|
-
error: import("@nandorojo/fuego/lib/typescript/hooks/useFuego/types").QueryError;
|
|
8
|
-
ref: import("@nandorojo/fuego").FirestoreRefType;
|
|
9
|
-
path: string;
|
|
10
|
-
empty: boolean;
|
|
11
|
-
send: (message: NewMessageModel[]) => void;
|
|
12
|
-
edit: (message: EditMessageModel) => Promise<void>;
|
|
13
|
-
fetchMore: () => void;
|
|
14
|
-
fetchingMore: number | false;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* React hook to set up a lisener for a room's messages
|
|
18
|
-
*
|
|
19
|
-
* @param { id } the roomId, along with other query options from `useFuego` hook
|
|
20
|
-
*
|
|
21
|
-
* @returns { data: formattedMessages, loading, error, ref, path, empty, send, edit, fetchMore }
|
|
22
|
-
* data is formatted for rendering.
|
|
23
|
-
*/
|
|
24
|
-
export default _default;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { EditRoomModel, CreateCallableRoomModel, ExistingRoomDocument, ExistingRoomModel } from '../../classes/Room/types';
|
|
2
|
-
import { UseRoomType } from './types';
|
|
3
|
-
import { QueryDataHandler } from '@nandorojo/fuego/lib/typescript/hooks/useFuego/types';
|
|
4
|
-
declare const _default: ({ id, ...config }: UseRoomType, options?: QueryDataHandler<ExistingRoomDocument>) => {
|
|
5
|
-
data: ExistingRoomModel | null;
|
|
6
|
-
loading: boolean;
|
|
7
|
-
error: import("@nandorojo/fuego/lib/typescript/hooks/useFuego/types").QueryError;
|
|
8
|
-
ref: import("@nandorojo/fuego").FirestoreRefType;
|
|
9
|
-
create: (room: CreateCallableRoomModel) => Promise<import("firebase").functions.HttpsCallableResult>;
|
|
10
|
-
edit: (room: EditRoomModel) => Promise<void> | null;
|
|
11
|
-
usersAreTyping: boolean;
|
|
12
|
-
namesOfUsersTyping: string[];
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Fetches or subscribes to a chatroom. It automatically handles unmounts, etc.
|
|
16
|
-
*
|
|
17
|
-
* @param config - config dictionary.
|
|
18
|
-
* @param config.id - Required: the unique ID for this chatroom, typically generated by the backend. If using the [[useInbox]] hook, each item in [[useInbox]]'s data array has this ID.
|
|
19
|
-
* @param config.listen Boolean to determine if this room should update state as a subscription. Default false.
|
|
20
|
-
* @param options - added options dictionary for useRoom
|
|
21
|
-
*
|
|
22
|
-
* @remarks Look at the fuego library's useFuego hook to see all the available arguments for config and options.
|
|
23
|
-
*
|
|
24
|
-
* @returns { data: room, loading, error, ref, create, edit, usersAreTyping, namesOfUsersTyping } data is formatted for rendering room.
|
|
25
|
-
*/
|
|
26
|
-
export default _default;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
declare const _default: ({ roomId, text, delay }: {
|
|
2
|
-
roomId: string;
|
|
3
|
-
text: string;
|
|
4
|
-
delay?: number | null | undefined;
|
|
5
|
-
}) => void;
|
|
6
|
-
/**
|
|
7
|
-
* useTyping automatically updates the backend whenever a user is typing.
|
|
8
|
-
*
|
|
9
|
-
* @param options - A dictionary to configure the typing.
|
|
10
|
-
* @param options.roomId - **Required** unique id of the room you're typing in.
|
|
11
|
-
* @param options.text - **Required** The current text state of your chat input
|
|
12
|
-
* @param options.delay (Optional) Set the timeout delay to mark typing false. Set null if you don't want a time out.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```javascript
|
|
16
|
-
* // input text state
|
|
17
|
-
* const [text, setText] = useState('')
|
|
18
|
-
* // let's say we're getting our room id from our react-navigation params
|
|
19
|
-
* const navigation = useNavigation()
|
|
20
|
-
* const roomId = navigation.params.id
|
|
21
|
-
*
|
|
22
|
-
* useTyping({ roomId, text })
|
|
23
|
-
*
|
|
24
|
-
* <ChatComponent text={text} onChangeText={setText} />
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @returns
|
|
28
|
-
* Doesn't return anything. We live in an undefined world, I suppose.
|
|
29
|
-
*
|
|
30
|
-
* @remarks
|
|
31
|
-
* The actual data of who is typing is stored in the chatroom object.
|
|
32
|
-
* If you want to get this data realtime in a room, consider using useRoom({ listen: true }). This data will also be in useInbox().
|
|
33
|
-
* See docs for useRoom or useInbox for more.
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export default _default;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { NewMessageModel } from '../../classes/Message/types';
|
|
2
|
-
import { UseViewMessagesConfig, UseViewMessagesMethods } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* React hook that returns a function useful for marking messages as viewed on the backend.
|
|
5
|
-
* It works by only clearing unread count when you've reached the most recent message, leveraging React Native FlatList's onViewableItemsChanged.
|
|
6
|
-
* This is only useful if you're using the Juice chat backend.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```js
|
|
10
|
-
* const onViewMessages = useViewMessages({ roomId: 'some_chat_room_id' })
|
|
11
|
-
*
|
|
12
|
-
* return <Juice.Chat onViewMessages={onViewMessages} />
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export default function <Model extends NewMessageModel = NewMessageModel>(config: UseViewMessagesConfig, methods?: UseViewMessagesMethods<Model>): ({ visibleMessages, latestMessageId }: {
|
|
16
|
-
visibleMessages: Model[] | null;
|
|
17
|
-
latestMessageId: string | null;
|
|
18
|
-
}) => void;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NewMessageModel } from '../../classes/Message/types';
|
|
2
|
-
export interface UseViewMessagesConfig {
|
|
3
|
-
roomId: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* An optional dictionary for using custom callbacks for viewed messages.
|
|
7
|
-
*/
|
|
8
|
-
export interface UseViewMessagesMethods<Model extends NewMessageModel = NewMessageModel> {
|
|
9
|
-
/**
|
|
10
|
-
* Callback function that is triggered whenever the messages in view changes.
|
|
11
|
-
* Since the `useViewMessages` hook is only concerned with updating a chat room's unread count and such, `onViewMessages` might be useful if you want to have your own analytics or message tracking.
|
|
12
|
-
*
|
|
13
|
-
* @param info - A dictionary containing info about the currently visible messages
|
|
14
|
-
* @param info.visibleMessages - An array of messages that are currently in view
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
onViewMessages?: (info: {
|
|
18
|
-
visibleMessages: Model[];
|
|
19
|
-
}) => void;
|
|
20
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './components';
|
|
2
|
-
export * from './classes';
|
|
3
|
-
export * from './hooks';
|
|
4
|
-
import * as ChatType from './components/Chat/types';
|
|
5
|
-
import * as InboxType from './components/Inbox/types';
|
|
6
|
-
import * as MessageType from './classes/Message/types';
|
|
7
|
-
import * as RoomType from './classes/Room/types';
|
|
8
|
-
export declare const ChatTypes: typeof ChatType;
|
|
9
|
-
export declare const InboxTypes: typeof InboxType;
|
|
10
|
-
export declare const MessageTypes: typeof MessageType;
|
|
11
|
-
export declare const RoomTypes: typeof RoomType;
|
package/src/ChatContext/types.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { ChatConfig } from './types'
|
|
2
|
-
|
|
3
|
-
export default class Chat {
|
|
4
|
-
private chat: ChatConfig
|
|
5
|
-
constructor(chat: ChatConfig = {}) {
|
|
6
|
-
this.chat = chat
|
|
7
|
-
// this.chat = {
|
|
8
|
-
// ...chat,
|
|
9
|
-
// httpCallables: {
|
|
10
|
-
// sendMessageFromFeed: 'sendMessageFromFeed',
|
|
11
|
-
// sendMessageToPeople: 'sendToPeople',
|
|
12
|
-
// sendMessageToGroup: 'sendToGroup',
|
|
13
|
-
// ...(chat.httpCallables || {})
|
|
14
|
-
// }
|
|
15
|
-
// }
|
|
16
|
-
}
|
|
17
|
-
get roomsCollection() {
|
|
18
|
-
return this.chat.roomsCollection || 'rooms'
|
|
19
|
-
}
|
|
20
|
-
get messagesCollection() {
|
|
21
|
-
return this.chat.messagesCollection || 'messages'
|
|
22
|
-
}
|
|
23
|
-
get httpCallables() {
|
|
24
|
-
return {
|
|
25
|
-
sendMessageFromFeed:
|
|
26
|
-
(this.chat.httpCallables &&
|
|
27
|
-
this.chat.httpCallables.sendMessageFromFeed) ||
|
|
28
|
-
'sendMessageFromFeed',
|
|
29
|
-
sendMessageToPeople:
|
|
30
|
-
(this.chat.httpCallables &&
|
|
31
|
-
this.chat.httpCallables.sendMessageToPeople) ||
|
|
32
|
-
'sendMessageToPeople',
|
|
33
|
-
sendMessageToGroup:
|
|
34
|
-
(this.chat.httpCallables &&
|
|
35
|
-
this.chat.httpCallables.sendMessageToGroup) ||
|
|
36
|
-
'sendMessageToGroup',
|
|
37
|
-
createRoom:
|
|
38
|
-
(this.chat.httpCallables && this.chat.httpCallables.createRoom) ||
|
|
39
|
-
'createRoom',
|
|
40
|
-
sendMessageToRooms:
|
|
41
|
-
(this.chat.httpCallables &&
|
|
42
|
-
this.chat.httpCallables.sendMessageToRooms) ||
|
|
43
|
-
'sendMessageToRooms'
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type RoomPathFunc = (roomId: string) => string
|
|
2
|
-
|
|
3
|
-
export interface ChatConfig {
|
|
4
|
-
roomsCollection?: string
|
|
5
|
-
messagesCollection?: string
|
|
6
|
-
httpCallables?: {
|
|
7
|
-
sendMessageFromFeed: string
|
|
8
|
-
sendMessageToPeople: string
|
|
9
|
-
sendMessageToGroup: string
|
|
10
|
-
sendMessageToRooms: string
|
|
11
|
-
createRoom: string
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ChatModel {
|
|
16
|
-
roomsCollection: string
|
|
17
|
-
messagesCollection: string
|
|
18
|
-
httpCallables: {
|
|
19
|
-
sendMessageFromFeed: string
|
|
20
|
-
sendMessageToPeople: string
|
|
21
|
-
sendMessageToGroup: string
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InboxModel } from './types'
|
|
2
|
-
import { chat } from '../../components/ChatProvider'
|
|
3
|
-
|
|
4
|
-
export default class {
|
|
5
|
-
private inbox: InboxModel
|
|
6
|
-
constructor(inbox: InboxModel) {
|
|
7
|
-
this.inbox = inbox
|
|
8
|
-
}
|
|
9
|
-
get path() {
|
|
10
|
-
return chat.messagesCollection
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MessageModel,
|
|
3
|
-
EditMessageModel,
|
|
4
|
-
RoomId,
|
|
5
|
-
NewMessageModel,
|
|
6
|
-
MessageModelDocument,
|
|
7
|
-
SendFromFeedRecipients,
|
|
8
|
-
recipientHasId,
|
|
9
|
-
recipientHasMembers,
|
|
10
|
-
SendFromFeedModel,
|
|
11
|
-
isNewMessageModel,
|
|
12
|
-
NewMessageFormattedForServer
|
|
13
|
-
} from './types'
|
|
14
|
-
import { fuego, chat } from '../../components/ChatProvider/index'
|
|
15
|
-
import Room from '../Room'
|
|
16
|
-
import { LastMessageServer, RoomMembers, RoomMember } from '../Room/types'
|
|
17
|
-
import { ReactionOption } from '../Reaction/types'
|
|
18
|
-
|
|
19
|
-
export default class {
|
|
20
|
-
private message: MessageModel
|
|
21
|
-
constructor(message: MessageModel) {
|
|
22
|
-
this.message = message
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A function to send one message to many different existing rooms/group chats separately.
|
|
26
|
-
*
|
|
27
|
-
* @param recipients An array of rooms ids where this message will be sent to separately
|
|
28
|
-
* @returns Promise that returns a room ID if there is only one (or promise that resolves as null if the message object isn't valid)
|
|
29
|
-
*/
|
|
30
|
-
async sendToRooms(recipients: string[]) {
|
|
31
|
-
try {
|
|
32
|
-
const send = fuego.firebase
|
|
33
|
-
.functions()
|
|
34
|
-
.httpsCallable(chat.httpCallables.sendMessageToRooms)
|
|
35
|
-
if (!isNewMessageModel(this.message)) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
'FAILED TO SEND TO ROOMS: message object is not NewMessageModel'
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
this.message = {
|
|
41
|
-
...this.message,
|
|
42
|
-
createdAt: fuego.firebase.firestore.FieldValue.serverTimestamp()
|
|
43
|
-
} as NewMessageFormattedForServer
|
|
44
|
-
return send({
|
|
45
|
-
message: this.message,
|
|
46
|
-
recipients
|
|
47
|
-
})
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.error(e)
|
|
50
|
-
return {
|
|
51
|
-
data: null
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* A function to send one message to many different people individually.
|
|
57
|
-
* For each recipient, if a room for them doesn't exist, it will get created and the message will be added to it.
|
|
58
|
-
* If the room does exist, the message will be added to it.
|
|
59
|
-
*
|
|
60
|
-
* @param recipients An array of user ids whom this message will be sent to separately
|
|
61
|
-
* @returns Promise that returns a room ID (or promise that resolves as null if the message object isn't valid)
|
|
62
|
-
*/
|
|
63
|
-
async sendToPeople(recipients: string[]) {
|
|
64
|
-
const send = fuego.firebase
|
|
65
|
-
.functions()
|
|
66
|
-
.httpsCallable(chat.httpCallables.sendMessageToPeople)
|
|
67
|
-
try {
|
|
68
|
-
if (!isNewMessageModel(this.message)) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
'FAILED TO SEND TO PEOPLE: message object is not NewMessageModel'
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
this.message = {
|
|
74
|
-
...this.message,
|
|
75
|
-
createdAt: fuego.firebase.firestore.FieldValue.serverTimestamp()
|
|
76
|
-
} as NewMessageFormattedForServer
|
|
77
|
-
return send({
|
|
78
|
-
message: this.message,
|
|
79
|
-
recipients
|
|
80
|
-
})
|
|
81
|
-
} catch (e) {
|
|
82
|
-
console.error(e)
|
|
83
|
-
return {
|
|
84
|
-
data: null
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Sends message to a group. This is useful when you don't have a room id but do have a list of people you want to send a message to. If you want to send the message to them separately, try sendToPeople instead.
|
|
90
|
-
* This function will create a group chat with the specified users if one doesn't exist yet. If it does exist already, then it will add to that existing room.
|
|
91
|
-
* @param recipients Array of uids for people in the group this message should send to.
|
|
92
|
-
* @returns Promise that returns a room ID (or promise that resolves as null if the message object isn't valid)
|
|
93
|
-
*/
|
|
94
|
-
async sendToGroup(recipients: string[]) {
|
|
95
|
-
const send = fuego.firebase
|
|
96
|
-
.functions()
|
|
97
|
-
.httpsCallable(chat.httpCallables.sendMessageToGroup)
|
|
98
|
-
try {
|
|
99
|
-
if (!isNewMessageModel(this.message)) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
'FAILED TO SEND TO PEOPLE: message object is not NewMessageModel'
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
this.message = {
|
|
105
|
-
...this.message,
|
|
106
|
-
createdAt: fuego.firebase.firestore.FieldValue.serverTimestamp()
|
|
107
|
-
} as NewMessageFormattedForServer
|
|
108
|
-
return send({
|
|
109
|
-
message: this.message,
|
|
110
|
-
recipients
|
|
111
|
-
})
|
|
112
|
-
} catch (e) {
|
|
113
|
-
console.error(e)
|
|
114
|
-
return {
|
|
115
|
-
data: null
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* deprecated: fuck this function
|
|
121
|
-
*/
|
|
122
|
-
sendFromFeed(to: SendFromFeedRecipients) {
|
|
123
|
-
const batch = fuego.db.batch()
|
|
124
|
-
const promises: Promise<firebase.functions.HttpsCallableResult>[] = []
|
|
125
|
-
|
|
126
|
-
// the to variable is an array of dictionaries
|
|
127
|
-
// the dictionaries can be EITHER { id: string } or { recipients: Array<recipient> }
|
|
128
|
-
// example:
|
|
129
|
-
// you might send a message to five different places
|
|
130
|
-
// could be 3 people, and 2 existing rooms
|
|
131
|
-
// this would be an array of 5 items, 3 with recipients, 2 with id
|
|
132
|
-
// example of the array:
|
|
133
|
-
// [
|
|
134
|
-
// 1) send to a room that has these two users
|
|
135
|
-
// { recipients: [{id: uid, name: username }, {uid: uid2, name: name2 }]},
|
|
136
|
-
// 2) send to an already existing room (likely pressing a group)
|
|
137
|
-
// { id: roomId },
|
|
138
|
-
// 3) send to one person, unaware if this room exists
|
|
139
|
-
// { recipients: [{id: uid, name: username }]},
|
|
140
|
-
// ]
|
|
141
|
-
|
|
142
|
-
// now, set of people we're sending this to...
|
|
143
|
-
to.forEach(room => {
|
|
144
|
-
const { id, ...message } = this.message as NewMessageModel
|
|
145
|
-
if (recipientHasId(room)) {
|
|
146
|
-
// if this recipient is a specified room, then send to that
|
|
147
|
-
const { messagesPath } = new Room({ id: room.id })
|
|
148
|
-
const ref = fuego.db.collection(messagesPath).doc(id)
|
|
149
|
-
batch.set(ref, message)
|
|
150
|
-
} else if (recipientHasMembers(room)) {
|
|
151
|
-
// otherwise, if you're just sending to a list of ambigious recipients...
|
|
152
|
-
// note: this list will often be one person you're choosing from a feed
|
|
153
|
-
// list could be: { recipients: [{ name: string, id: string }, { ...otherRecipient }]}
|
|
154
|
-
const peopleInThisRoomOtherThanMe = room.recipients
|
|
155
|
-
.slice()
|
|
156
|
-
.sort((a, b) => (a.id > b.id ? 1 : -1))
|
|
157
|
-
const addMessage = fuego.firebase
|
|
158
|
-
.functions()
|
|
159
|
-
.httpsCallable(chat.httpCallables.sendMessageFromFeed)
|
|
160
|
-
const newMessage: SendFromFeedModel = {
|
|
161
|
-
...(message as NewMessageModel),
|
|
162
|
-
recipients: peopleInThisRoomOtherThanMe
|
|
163
|
-
}
|
|
164
|
-
promises.push(addMessage(newMessage))
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
return Promise.all<any>([batch.commit(), ...promises])
|
|
169
|
-
|
|
170
|
-
// return {
|
|
171
|
-
// batch: () => batch.commit(),
|
|
172
|
-
// toRecipients: () => Promise.all(promises)
|
|
173
|
-
// }
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Send message by adding it directly to the backend
|
|
177
|
-
* @param roomId The id of the room you want to send this to. Could also be an array of ids, if the same message should go to multiple rooms.
|
|
178
|
-
*/
|
|
179
|
-
send(roomId: RoomId) {
|
|
180
|
-
this.addToFirebase(roomId)
|
|
181
|
-
}
|
|
182
|
-
edit(roomId: string) {
|
|
183
|
-
return this.updateOnFirebase(roomId)
|
|
184
|
-
}
|
|
185
|
-
formatForRender(): NewMessageModel[] | NewMessageModel | null {
|
|
186
|
-
function isDocList(m: MessageModel): m is MessageModelDocument[] {
|
|
187
|
-
return !!(m as MessageModelDocument[])
|
|
188
|
-
}
|
|
189
|
-
function isDocument(m: MessageModel): m is MessageModelDocument {
|
|
190
|
-
return !!(m as MessageModelDocument)
|
|
191
|
-
}
|
|
192
|
-
try {
|
|
193
|
-
if (isDocList(this.message)) {
|
|
194
|
-
return (
|
|
195
|
-
(this.message as MessageModelDocument[]).map(
|
|
196
|
-
(doc: MessageModelDocument) => ({
|
|
197
|
-
...doc,
|
|
198
|
-
id: doc.id,
|
|
199
|
-
createdAt: doc.createdAt.toDate()
|
|
200
|
-
})
|
|
201
|
-
) || []
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
if (isDocument(this.message))
|
|
205
|
-
return {
|
|
206
|
-
...this.message,
|
|
207
|
-
id: this.message.id,
|
|
208
|
-
createdAt: this.message.createdAt.toDate()
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
throw new Error('Wrong model here.')
|
|
212
|
-
} catch (e) {
|
|
213
|
-
console.error(
|
|
214
|
-
'wrong model given to format for render in Message class.',
|
|
215
|
-
e
|
|
216
|
-
)
|
|
217
|
-
return null
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
formatForSend() {
|
|
221
|
-
try {
|
|
222
|
-
const isNew = (m: MessageModel): m is NewMessageModel[] =>
|
|
223
|
-
!!(m as NewMessageModel[])
|
|
224
|
-
if (isNew(this.message)) {
|
|
225
|
-
this.message = (this.message as NewMessageModel[]).map(message => ({
|
|
226
|
-
...message,
|
|
227
|
-
text: (message.text && message.text.trim()) || '',
|
|
228
|
-
createdAt: fuego.firebase.firestore.FieldValue.serverTimestamp()
|
|
229
|
-
})) as NewMessageFormattedForServer[]
|
|
230
|
-
return this
|
|
231
|
-
}
|
|
232
|
-
throw new Error('wrong format for formatting for send')
|
|
233
|
-
} catch (e) {
|
|
234
|
-
console.error(e)
|
|
235
|
-
return this
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
addToFirebase(roomId: RoomId) {
|
|
239
|
-
const { message: messages } = this
|
|
240
|
-
|
|
241
|
-
const batch = fuego.db.batch()
|
|
242
|
-
|
|
243
|
-
const updateBatch = (roomId: string) => {
|
|
244
|
-
// for each message, add to this batch...
|
|
245
|
-
const addToBatch = (message: NewMessageFormattedForServer) => {
|
|
246
|
-
try {
|
|
247
|
-
const { messagesPath, path: roomPath } = new Room({ id: roomId })
|
|
248
|
-
const ref = fuego.db.collection(messagesPath).doc(message.id)
|
|
249
|
-
|
|
250
|
-
// remove id from message for single source of truth
|
|
251
|
-
// it'll be put back again upon format()-ing
|
|
252
|
-
const { id, ...messageDoc } = message
|
|
253
|
-
batch.set(ref, messageDoc)
|
|
254
|
-
|
|
255
|
-
// update the latest message
|
|
256
|
-
const { displayName, uid } = fuego.auth().currentUser as firebase.User
|
|
257
|
-
const roomRef = fuego.db.doc(roomPath)
|
|
258
|
-
const lastMessage: LastMessageServer = {
|
|
259
|
-
name: displayName || 'Name failed',
|
|
260
|
-
id: uid,
|
|
261
|
-
system: false,
|
|
262
|
-
text: message.text,
|
|
263
|
-
createdAt: message.createdAt
|
|
264
|
-
}
|
|
265
|
-
batch.update(roomRef, { lastMessage })
|
|
266
|
-
} catch (e) {
|
|
267
|
-
console.error('sending message had an error:', e)
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
;(messages as NewMessageFormattedForServer[]).forEach(addToBatch)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// if you're sending these message(s) to multiple rooms, loop through each room...
|
|
274
|
-
if (Array.isArray(roomId)) {
|
|
275
|
-
;(roomId as string[]).forEach(updateBatch)
|
|
276
|
-
} else {
|
|
277
|
-
// just send to this room
|
|
278
|
-
updateBatch(roomId as string)
|
|
279
|
-
}
|
|
280
|
-
// once everything has been added to the db batch, commit it
|
|
281
|
-
return batch.commit()
|
|
282
|
-
}
|
|
283
|
-
updateOnFirebase(roomId: string) {
|
|
284
|
-
const { path } = new Room({ id: roomId })
|
|
285
|
-
const { id, ...message } = this.message as EditMessageModel
|
|
286
|
-
return fuego.db
|
|
287
|
-
.collection(path)
|
|
288
|
-
.doc((this.message as EditMessageModel).id)
|
|
289
|
-
.set(message, { merge: true })
|
|
290
|
-
}
|
|
291
|
-
// TODO get members through some other method...idk
|
|
292
|
-
// eek. what a mess.
|
|
293
|
-
getUsersWhoReacted(
|
|
294
|
-
reaction: ReactionOption,
|
|
295
|
-
{ roomMembers }: { roomMembers: RoomMembers }
|
|
296
|
-
): RoomMember[] {
|
|
297
|
-
const users: RoomMember[] = []
|
|
298
|
-
if (!isNewMessageModel(this.message)) {
|
|
299
|
-
console.warn(
|
|
300
|
-
'error getting users who reacted. Needs the new message model passed as an argument, but instead it got this:',
|
|
301
|
-
this.message
|
|
302
|
-
)
|
|
303
|
-
} else if (this.message.reactions) {
|
|
304
|
-
this.message.reactions[reaction].forEach(
|
|
305
|
-
uid => roomMembers[uid] && users.push(roomMembers[uid])
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
return users
|
|
309
|
-
}
|
|
310
|
-
}
|