stream-chat-react-native-core 7.0.1 → 7.1.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/README.md +1 -1
- package/lib/commonjs/components/Channel/Channel.js +214 -237
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/ChannelList/ChannelList.js +2 -19
- package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +48 -176
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js +13 -2
- package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
- package/lib/commonjs/components/Chat/Chat.js +33 -46
- package/lib/commonjs/components/Chat/Chat.js.map +1 -1
- package/lib/commonjs/components/Chat/hooks/useAppSettings.js +47 -120
- package/lib/commonjs/components/Chat/hooks/useAppSettings.js.map +1 -1
- package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js +0 -15
- package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js.map +1 -1
- package/lib/commonjs/components/MessageMenu/MessageUserReactions.js +5 -0
- package/lib/commonjs/components/MessageMenu/MessageUserReactions.js.map +1 -1
- package/lib/commonjs/components/MessageMenu/hooks/useFetchReactions.js +92 -108
- package/lib/commonjs/components/MessageMenu/hooks/useFetchReactions.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock-builders/event/channelVisible.js +13 -0
- package/lib/commonjs/mock-builders/event/channelVisible.js.map +1 -0
- package/lib/commonjs/mock-builders/event/memberAdded.js +4 -2
- package/lib/commonjs/mock-builders/event/memberAdded.js.map +1 -1
- package/lib/commonjs/mock-builders/event/memberRemoved.js +2 -1
- package/lib/commonjs/mock-builders/event/memberRemoved.js.map +1 -1
- package/lib/commonjs/mock-builders/event/memberUpdated.js +2 -1
- package/lib/commonjs/mock-builders/event/memberUpdated.js.map +1 -1
- package/lib/commonjs/mock-builders/event/messageNew.js +4 -2
- package/lib/commonjs/mock-builders/event/messageNew.js.map +1 -1
- package/lib/commonjs/mock-builders/event/messageRead.js +6 -3
- package/lib/commonjs/mock-builders/event/messageRead.js.map +1 -1
- package/lib/commonjs/mock-builders/event/notificationMarkUnread.js +3 -0
- package/lib/commonjs/mock-builders/event/notificationMarkUnread.js.map +1 -1
- package/lib/commonjs/mock-builders/generator/channel.js +10 -3
- package/lib/commonjs/mock-builders/generator/channel.js.map +1 -1
- package/lib/commonjs/store/OfflineDB.js +108 -0
- package/lib/commonjs/store/OfflineDB.js.map +1 -0
- package/lib/commonjs/store/SqliteClient.js +11 -10
- package/lib/commonjs/store/SqliteClient.js.map +1 -1
- package/lib/commonjs/store/apis/addPendingTask.js.map +1 -1
- package/lib/commonjs/store/apis/channelExists.js +34 -0
- package/lib/commonjs/store/apis/channelExists.js.map +1 -0
- package/lib/commonjs/store/apis/deleteChannel.js +4 -4
- package/lib/commonjs/store/apis/deleteChannel.js.map +1 -1
- package/lib/commonjs/store/apis/deleteMember.js +4 -4
- package/lib/commonjs/store/apis/deleteMember.js.map +1 -1
- package/lib/commonjs/store/apis/deleteMessage.js +16 -12
- package/lib/commonjs/store/apis/deleteMessage.js.map +1 -1
- package/lib/commonjs/store/apis/deleteMessagesForChannel.js +11 -12
- package/lib/commonjs/store/apis/deleteMessagesForChannel.js.map +1 -1
- package/lib/commonjs/store/apis/deleteReaction.js +29 -17
- package/lib/commonjs/store/apis/deleteReaction.js.map +1 -1
- package/lib/commonjs/store/apis/deleteReactions.js +4 -4
- package/lib/commonjs/store/apis/deleteReactions.js.map +1 -1
- package/lib/commonjs/store/apis/dropPendingTasks.js +41 -0
- package/lib/commonjs/store/apis/dropPendingTasks.js.map +1 -0
- package/lib/commonjs/store/apis/getChannelMessages.js +1 -1
- package/lib/commonjs/store/apis/getChannelMessages.js.map +1 -1
- package/lib/commonjs/store/apis/getChannels.js +18 -21
- package/lib/commonjs/store/apis/getChannels.js.map +1 -1
- package/lib/commonjs/store/apis/getLastSyncedAt.js +3 -9
- package/lib/commonjs/store/apis/getLastSyncedAt.js.map +1 -1
- package/lib/commonjs/store/apis/getReactionsforFilterSort.js +5 -8
- package/lib/commonjs/store/apis/getReactionsforFilterSort.js.map +1 -1
- package/lib/commonjs/store/apis/index.js +103 -4
- package/lib/commonjs/store/apis/index.js.map +1 -1
- package/lib/commonjs/store/apis/insertReaction.js +4 -4
- package/lib/commonjs/store/apis/insertReaction.js.map +1 -1
- package/lib/commonjs/store/apis/queries/selectMessagesForChannels.js +1 -1
- package/lib/commonjs/store/apis/queries/selectMessagesForChannels.js.map +1 -1
- package/lib/commonjs/store/apis/queries/selectReactionsForMessages.js +25 -5
- package/lib/commonjs/store/apis/queries/selectReactionsForMessages.js.map +1 -1
- package/lib/commonjs/store/apis/softDeleteMessage.js +45 -0
- package/lib/commonjs/store/apis/softDeleteMessage.js.map +1 -0
- package/lib/commonjs/store/apis/updateMessage.js +7 -11
- package/lib/commonjs/store/apis/updateMessage.js.map +1 -1
- package/lib/commonjs/store/apis/updateReaction.js +11 -9
- package/lib/commonjs/store/apis/updateReaction.js.map +1 -1
- package/lib/commonjs/store/apis/upsertAppSettings.js +9 -7
- package/lib/commonjs/store/apis/upsertAppSettings.js.map +1 -1
- package/lib/commonjs/store/apis/upsertChannelData.js +4 -4
- package/lib/commonjs/store/apis/upsertChannelData.js.map +1 -1
- package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js +3 -3
- package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js.map +1 -1
- package/lib/commonjs/store/apis/upsertChannels.js +86 -83
- package/lib/commonjs/store/apis/upsertChannels.js.map +1 -1
- package/lib/commonjs/store/apis/upsertCidsForQuery.js +4 -4
- package/lib/commonjs/store/apis/upsertCidsForQuery.js.map +1 -1
- package/lib/commonjs/store/apis/upsertMembers.js +4 -4
- package/lib/commonjs/store/apis/upsertMembers.js.map +1 -1
- package/lib/commonjs/store/apis/upsertMessages.js +4 -4
- package/lib/commonjs/store/apis/upsertMessages.js.map +1 -1
- package/lib/commonjs/store/apis/upsertPoll.js +42 -0
- package/lib/commonjs/store/apis/upsertPoll.js.map +1 -0
- package/lib/commonjs/store/apis/upsertReads.js +4 -4
- package/lib/commonjs/store/apis/upsertReads.js.map +1 -1
- package/lib/commonjs/store/apis/upsertUserSyncStatus.js +13 -7
- package/lib/commonjs/store/apis/upsertUserSyncStatus.js.map +1 -1
- package/lib/commonjs/store/mappers/mapMemberToStorable.js +6 -2
- package/lib/commonjs/store/mappers/mapMemberToStorable.js.map +1 -1
- package/lib/commonjs/store/mappers/mapReadToStorable.js +3 -1
- package/lib/commonjs/store/mappers/mapReadToStorable.js.map +1 -1
- package/lib/commonjs/store/mappers/mapStorableToMember.js +5 -1
- package/lib/commonjs/store/mappers/mapStorableToMember.js.map +1 -1
- package/lib/commonjs/store/mappers/mapStorableToRead.js +3 -1
- package/lib/commonjs/store/mappers/mapStorableToRead.js.map +1 -1
- package/lib/commonjs/store/mappers/mapStorableToTask.js.map +1 -1
- package/lib/commonjs/store/schema.js +2 -0
- package/lib/commonjs/store/schema.js.map +1 -1
- package/lib/commonjs/utils/addReactionToLocalState.js +62 -81
- package/lib/commonjs/utils/addReactionToLocalState.js.map +1 -1
- package/lib/commonjs/utils/removeReactionFromLocalState.js +0 -6
- package/lib/commonjs/utils/removeReactionFromLocalState.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +214 -237
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/ChannelList/ChannelList.js +2 -19
- package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +48 -176
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js +13 -2
- package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
- package/lib/module/components/Chat/Chat.js +33 -46
- package/lib/module/components/Chat/Chat.js.map +1 -1
- package/lib/module/components/Chat/hooks/useAppSettings.js +47 -120
- package/lib/module/components/Chat/hooks/useAppSettings.js.map +1 -1
- package/lib/module/components/Chat/hooks/useSyncDatabase.js +0 -15
- package/lib/module/components/Chat/hooks/useSyncDatabase.js.map +1 -1
- package/lib/module/components/MessageMenu/MessageUserReactions.js +5 -0
- package/lib/module/components/MessageMenu/MessageUserReactions.js.map +1 -1
- package/lib/module/components/MessageMenu/hooks/useFetchReactions.js +92 -108
- package/lib/module/components/MessageMenu/hooks/useFetchReactions.js.map +1 -1
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock-builders/event/channelVisible.js +13 -0
- package/lib/module/mock-builders/event/channelVisible.js.map +1 -0
- package/lib/module/mock-builders/event/memberAdded.js +4 -2
- package/lib/module/mock-builders/event/memberAdded.js.map +1 -1
- package/lib/module/mock-builders/event/memberRemoved.js +2 -1
- package/lib/module/mock-builders/event/memberRemoved.js.map +1 -1
- package/lib/module/mock-builders/event/memberUpdated.js +2 -1
- package/lib/module/mock-builders/event/memberUpdated.js.map +1 -1
- package/lib/module/mock-builders/event/messageNew.js +4 -2
- package/lib/module/mock-builders/event/messageNew.js.map +1 -1
- package/lib/module/mock-builders/event/messageRead.js +6 -3
- package/lib/module/mock-builders/event/messageRead.js.map +1 -1
- package/lib/module/mock-builders/event/notificationMarkUnread.js +3 -0
- package/lib/module/mock-builders/event/notificationMarkUnread.js.map +1 -1
- package/lib/module/mock-builders/generator/channel.js +10 -3
- package/lib/module/mock-builders/generator/channel.js.map +1 -1
- package/lib/module/store/OfflineDB.js +108 -0
- package/lib/module/store/OfflineDB.js.map +1 -0
- package/lib/module/store/SqliteClient.js +11 -10
- package/lib/module/store/SqliteClient.js.map +1 -1
- package/lib/module/store/apis/addPendingTask.js.map +1 -1
- package/lib/module/store/apis/channelExists.js +34 -0
- package/lib/module/store/apis/channelExists.js.map +1 -0
- package/lib/module/store/apis/deleteChannel.js +4 -4
- package/lib/module/store/apis/deleteChannel.js.map +1 -1
- package/lib/module/store/apis/deleteMember.js +4 -4
- package/lib/module/store/apis/deleteMember.js.map +1 -1
- package/lib/module/store/apis/deleteMessage.js +16 -12
- package/lib/module/store/apis/deleteMessage.js.map +1 -1
- package/lib/module/store/apis/deleteMessagesForChannel.js +11 -12
- package/lib/module/store/apis/deleteMessagesForChannel.js.map +1 -1
- package/lib/module/store/apis/deleteReaction.js +29 -17
- package/lib/module/store/apis/deleteReaction.js.map +1 -1
- package/lib/module/store/apis/deleteReactions.js +4 -4
- package/lib/module/store/apis/deleteReactions.js.map +1 -1
- package/lib/module/store/apis/dropPendingTasks.js +41 -0
- package/lib/module/store/apis/dropPendingTasks.js.map +1 -0
- package/lib/module/store/apis/getChannelMessages.js +1 -1
- package/lib/module/store/apis/getChannelMessages.js.map +1 -1
- package/lib/module/store/apis/getChannels.js +18 -21
- package/lib/module/store/apis/getChannels.js.map +1 -1
- package/lib/module/store/apis/getLastSyncedAt.js +3 -9
- package/lib/module/store/apis/getLastSyncedAt.js.map +1 -1
- package/lib/module/store/apis/getReactionsforFilterSort.js +5 -8
- package/lib/module/store/apis/getReactionsforFilterSort.js.map +1 -1
- package/lib/module/store/apis/index.js +103 -4
- package/lib/module/store/apis/index.js.map +1 -1
- package/lib/module/store/apis/insertReaction.js +4 -4
- package/lib/module/store/apis/insertReaction.js.map +1 -1
- package/lib/module/store/apis/queries/selectMessagesForChannels.js +1 -1
- package/lib/module/store/apis/queries/selectMessagesForChannels.js.map +1 -1
- package/lib/module/store/apis/queries/selectReactionsForMessages.js +25 -5
- package/lib/module/store/apis/queries/selectReactionsForMessages.js.map +1 -1
- package/lib/module/store/apis/softDeleteMessage.js +45 -0
- package/lib/module/store/apis/softDeleteMessage.js.map +1 -0
- package/lib/module/store/apis/updateMessage.js +7 -11
- package/lib/module/store/apis/updateMessage.js.map +1 -1
- package/lib/module/store/apis/updateReaction.js +11 -9
- package/lib/module/store/apis/updateReaction.js.map +1 -1
- package/lib/module/store/apis/upsertAppSettings.js +9 -7
- package/lib/module/store/apis/upsertAppSettings.js.map +1 -1
- package/lib/module/store/apis/upsertChannelData.js +4 -4
- package/lib/module/store/apis/upsertChannelData.js.map +1 -1
- package/lib/module/store/apis/upsertChannelDataFromChannel.js +3 -3
- package/lib/module/store/apis/upsertChannelDataFromChannel.js.map +1 -1
- package/lib/module/store/apis/upsertChannels.js +86 -83
- package/lib/module/store/apis/upsertChannels.js.map +1 -1
- package/lib/module/store/apis/upsertCidsForQuery.js +4 -4
- package/lib/module/store/apis/upsertCidsForQuery.js.map +1 -1
- package/lib/module/store/apis/upsertMembers.js +4 -4
- package/lib/module/store/apis/upsertMembers.js.map +1 -1
- package/lib/module/store/apis/upsertMessages.js +4 -4
- package/lib/module/store/apis/upsertMessages.js.map +1 -1
- package/lib/module/store/apis/upsertPoll.js +42 -0
- package/lib/module/store/apis/upsertPoll.js.map +1 -0
- package/lib/module/store/apis/upsertReads.js +4 -4
- package/lib/module/store/apis/upsertReads.js.map +1 -1
- package/lib/module/store/apis/upsertUserSyncStatus.js +13 -7
- package/lib/module/store/apis/upsertUserSyncStatus.js.map +1 -1
- package/lib/module/store/mappers/mapMemberToStorable.js +6 -2
- package/lib/module/store/mappers/mapMemberToStorable.js.map +1 -1
- package/lib/module/store/mappers/mapReadToStorable.js +3 -1
- package/lib/module/store/mappers/mapReadToStorable.js.map +1 -1
- package/lib/module/store/mappers/mapStorableToMember.js +5 -1
- package/lib/module/store/mappers/mapStorableToMember.js.map +1 -1
- package/lib/module/store/mappers/mapStorableToRead.js +3 -1
- package/lib/module/store/mappers/mapStorableToRead.js.map +1 -1
- package/lib/module/store/mappers/mapStorableToTask.js.map +1 -1
- package/lib/module/store/schema.js +2 -0
- package/lib/module/store/schema.js.map +1 -1
- package/lib/module/utils/addReactionToLocalState.js +62 -81
- package/lib/module/utils/addReactionToLocalState.js.map +1 -1
- package/lib/module/utils/removeReactionFromLocalState.js +0 -6
- package/lib/module/utils/removeReactionFromLocalState.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
- package/lib/typescript/components/Channel/hooks/useCreateThreadContext.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/ChannelList.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +1 -1
- package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts.map +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/useIsChannelMuted.d.ts.map +1 -1
- package/lib/typescript/components/Chat/Chat.d.ts.map +1 -1
- package/lib/typescript/components/Chat/hooks/useAppSettings.d.ts.map +1 -1
- package/lib/typescript/components/Chat/hooks/useSyncDatabase.d.ts +9 -1
- package/lib/typescript/components/Chat/hooks/useSyncDatabase.d.ts.map +1 -1
- package/lib/typescript/components/MessageMenu/MessageUserReactions.d.ts.map +1 -1
- package/lib/typescript/components/MessageMenu/hooks/useFetchReactions.d.ts.map +1 -1
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +1 -1
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts.map +1 -1
- package/lib/typescript/hooks/useTranslatedMessage.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/store/OfflineDB.d.ts +112 -0
- package/lib/typescript/store/OfflineDB.d.ts.map +1 -0
- package/lib/typescript/store/SqliteClient.d.ts +1 -1
- package/lib/typescript/store/SqliteClient.d.ts.map +1 -1
- package/lib/typescript/store/apis/addPendingTask.d.ts +1 -1
- package/lib/typescript/store/apis/addPendingTask.d.ts.map +1 -1
- package/lib/typescript/store/apis/channelExists.d.ts +4 -0
- package/lib/typescript/store/apis/channelExists.d.ts.map +1 -0
- package/lib/typescript/store/apis/deleteChannel.d.ts +2 -2
- package/lib/typescript/store/apis/deleteChannel.d.ts.map +1 -1
- package/lib/typescript/store/apis/deleteMember.d.ts +2 -2
- package/lib/typescript/store/apis/deleteMember.d.ts.map +1 -1
- package/lib/typescript/store/apis/deleteMessage.d.ts +3 -3
- package/lib/typescript/store/apis/deleteMessage.d.ts.map +1 -1
- package/lib/typescript/store/apis/deleteMessagesForChannel.d.ts +4 -3
- package/lib/typescript/store/apis/deleteMessagesForChannel.d.ts.map +1 -1
- package/lib/typescript/store/apis/deleteReaction.d.ts +7 -6
- package/lib/typescript/store/apis/deleteReaction.d.ts.map +1 -1
- package/lib/typescript/store/apis/deleteReactions.d.ts +2 -2
- package/lib/typescript/store/apis/deleteReactions.d.ts.map +1 -1
- package/lib/typescript/store/apis/dropPendingTasks.d.ts +16 -0
- package/lib/typescript/store/apis/dropPendingTasks.d.ts.map +1 -0
- package/lib/typescript/store/apis/getChannels.d.ts.map +1 -1
- package/lib/typescript/store/apis/getLastSyncedAt.d.ts +1 -1
- package/lib/typescript/store/apis/getLastSyncedAt.d.ts.map +1 -1
- package/lib/typescript/store/apis/getPendingTasks.d.ts +1 -1
- package/lib/typescript/store/apis/getPendingTasks.d.ts.map +1 -1
- package/lib/typescript/store/apis/getReactionsforFilterSort.d.ts +5 -3
- package/lib/typescript/store/apis/getReactionsforFilterSort.d.ts.map +1 -1
- package/lib/typescript/store/apis/index.d.ts +10 -1
- package/lib/typescript/store/apis/index.d.ts.map +1 -1
- package/lib/typescript/store/apis/insertReaction.d.ts +2 -2
- package/lib/typescript/store/apis/insertReaction.d.ts.map +1 -1
- package/lib/typescript/store/apis/queries/selectReactionsForMessages.d.ts +5 -1
- package/lib/typescript/store/apis/queries/selectReactionsForMessages.d.ts.map +1 -1
- package/lib/typescript/store/apis/softDeleteMessage.d.ts +5 -0
- package/lib/typescript/store/apis/softDeleteMessage.d.ts.map +1 -0
- package/lib/typescript/store/apis/updateMessage.d.ts +2 -2
- package/lib/typescript/store/apis/updateMessage.d.ts.map +1 -1
- package/lib/typescript/store/apis/updateReaction.d.ts +2 -2
- package/lib/typescript/store/apis/updateReaction.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertAppSettings.d.ts +3 -3
- package/lib/typescript/store/apis/upsertAppSettings.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertChannelData.d.ts +2 -2
- package/lib/typescript/store/apis/upsertChannelData.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertChannelDataFromChannel.d.ts +2 -2
- package/lib/typescript/store/apis/upsertChannelDataFromChannel.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertChannels.d.ts +3 -5
- package/lib/typescript/store/apis/upsertChannels.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertCidsForQuery.d.ts +2 -2
- package/lib/typescript/store/apis/upsertCidsForQuery.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertMembers.d.ts +2 -2
- package/lib/typescript/store/apis/upsertMembers.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertMessages.d.ts +2 -2
- package/lib/typescript/store/apis/upsertMessages.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertPoll.d.ts +7 -0
- package/lib/typescript/store/apis/upsertPoll.d.ts.map +1 -0
- package/lib/typescript/store/apis/upsertReads.d.ts +2 -2
- package/lib/typescript/store/apis/upsertReads.d.ts.map +1 -1
- package/lib/typescript/store/apis/upsertUserSyncStatus.d.ts +3 -2
- package/lib/typescript/store/apis/upsertUserSyncStatus.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapMemberToStorable.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapReadToStorable.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapStorableToMember.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapStorableToRead.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapStorableToTask.d.ts +2 -1
- package/lib/typescript/store/mappers/mapStorableToTask.d.ts.map +1 -1
- package/lib/typescript/store/mappers/mapTaskToStorable.d.ts +18 -10
- package/lib/typescript/store/mappers/mapTaskToStorable.d.ts.map +1 -1
- package/lib/typescript/store/schema.d.ts +3 -2
- package/lib/typescript/store/schema.d.ts.map +1 -1
- package/lib/typescript/utils/addReactionToLocalState.d.ts +1 -1
- package/lib/typescript/utils/addReactionToLocalState.d.ts.map +1 -1
- package/lib/typescript/utils/removeReactionFromLocalState.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/__tests__/offline-support/offline-feature.js +894 -21
- package/src/__tests__/offline-support/optimistic-update.js +154 -44
- package/src/components/Channel/Channel.tsx +95 -118
- package/src/components/ChannelList/ChannelList.tsx +1 -23
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +9 -93
- package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +20 -2
- package/src/components/Chat/Chat.tsx +21 -45
- package/src/components/Chat/__tests__/Chat.test.js +21 -13
- package/src/components/Chat/hooks/useAppSettings.ts +17 -54
- package/src/components/Chat/hooks/useSyncDatabase.ts +11 -17
- package/src/components/MessageMenu/MessageUserReactions.tsx +7 -1
- package/src/components/MessageMenu/hooks/useFetchReactions.ts +68 -35
- package/src/contexts/messagesContext/MessagesContext.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/mock-builders/event/channelVisible.js +7 -0
- package/src/mock-builders/event/memberAdded.js +3 -1
- package/src/mock-builders/event/memberRemoved.js +1 -0
- package/src/mock-builders/event/memberUpdated.js +1 -0
- package/src/mock-builders/event/messageNew.js +1 -0
- package/src/mock-builders/event/messageRead.js +5 -2
- package/src/mock-builders/event/notificationMarkUnread.js +3 -0
- package/src/mock-builders/generator/channel.ts +15 -3
- package/src/store/OfflineDB.ts +93 -0
- package/src/store/SqliteClient.ts +7 -1
- package/src/store/apis/addPendingTask.ts +2 -1
- package/src/store/apis/channelExists.ts +14 -0
- package/src/store/apis/deleteChannel.ts +9 -3
- package/src/store/apis/deleteMember.ts +4 -4
- package/src/store/apis/deleteMessage.ts +18 -8
- package/src/store/apis/deleteMessagesForChannel.ts +12 -8
- package/src/store/apis/deleteReaction.ts +39 -19
- package/src/store/apis/deleteReactions.ts +4 -4
- package/src/store/apis/dropPendingTasks.ts +32 -0
- package/src/store/apis/getChannelMessages.ts +1 -1
- package/src/store/apis/getChannels.ts +10 -7
- package/src/store/apis/getLastSyncedAt.ts +2 -5
- package/src/store/apis/getReactionsforFilterSort.ts +8 -7
- package/src/store/apis/index.ts +10 -1
- package/src/store/apis/insertReaction.ts +4 -4
- package/src/store/apis/queries/selectMessagesForChannels.ts +2 -2
- package/src/store/apis/queries/selectReactionsForMessages.ts +21 -2
- package/src/store/apis/softDeleteMessage.ts +32 -0
- package/src/store/apis/updateMessage.ts +3 -10
- package/src/store/apis/updateReaction.ts +7 -5
- package/src/store/apis/upsertAppSettings.ts +13 -9
- package/src/store/apis/upsertChannelData.ts +4 -4
- package/src/store/apis/upsertChannelDataFromChannel.ts +3 -3
- package/src/store/apis/upsertChannels.ts +14 -24
- package/src/store/apis/upsertCidsForQuery.ts +4 -4
- package/src/store/apis/upsertMembers.ts +4 -4
- package/src/store/apis/upsertMessages.ts +4 -4
- package/src/store/apis/upsertPoll.ts +29 -0
- package/src/store/apis/upsertReads.ts +4 -4
- package/src/store/apis/upsertUserSyncStatus.ts +13 -5
- package/src/store/mappers/mapMemberToStorable.ts +4 -0
- package/src/store/mappers/mapReadToStorable.ts +2 -1
- package/src/store/mappers/mapStorableToMember.ts +4 -0
- package/src/store/mappers/mapStorableToRead.ts +2 -1
- package/src/store/mappers/mapStorableToTask.ts +3 -1
- package/src/store/mappers/mapTaskToStorable.ts +1 -1
- package/src/store/schema.ts +5 -3
- package/src/utils/addReactionToLocalState.ts +9 -63
- package/src/utils/removeReactionFromLocalState.ts +0 -8
- package/src/version.json +1 -1
- package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js +0 -406
- package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js.map +0 -1
- package/lib/commonjs/store/apis/updatePollMessage.js +0 -84
- package/lib/commonjs/store/apis/updatePollMessage.js.map +0 -1
- package/lib/commonjs/utils/DBSyncManager.js +0 -470
- package/lib/commonjs/utils/DBSyncManager.js.map +0 -1
- package/lib/module/components/Chat/hooks/handleEventToSyncDB.js +0 -406
- package/lib/module/components/Chat/hooks/handleEventToSyncDB.js.map +0 -1
- package/lib/module/store/apis/updatePollMessage.js +0 -84
- package/lib/module/store/apis/updatePollMessage.js.map +0 -1
- package/lib/module/utils/DBSyncManager.js +0 -470
- package/lib/module/utils/DBSyncManager.js.map +0 -1
- package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts +0 -4
- package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts.map +0 -1
- package/lib/typescript/store/apis/updatePollMessage.d.ts +0 -10
- package/lib/typescript/store/apis/updatePollMessage.d.ts.map +0 -1
- package/lib/typescript/utils/DBSyncManager.d.ts +0 -50
- package/lib/typescript/utils/DBSyncManager.d.ts.map +0 -1
- package/src/components/Chat/hooks/handleEventToSyncDB.ts +0 -290
- package/src/store/apis/updatePollMessage.ts +0 -71
- package/src/utils/DBSyncManager.ts +0 -242
|
@@ -13,17 +13,8 @@ import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
|
13
13
|
import { useStateStore } from '../../../hooks';
|
|
14
14
|
import { useIsMountedRef } from '../../../hooks/useIsMountedRef';
|
|
15
15
|
|
|
16
|
-
import { getChannelsForFilterSort } from '../../../store/apis/getChannelsForFilterSort';
|
|
17
|
-
|
|
18
|
-
import { ONE_SECOND_IN_MS } from '../../../utils/date';
|
|
19
|
-
import { DBSyncManager } from '../../../utils/DBSyncManager';
|
|
20
16
|
import { MAX_QUERY_CHANNELS_LIMIT } from '../utils';
|
|
21
17
|
|
|
22
|
-
const waitSeconds = (seconds: number) =>
|
|
23
|
-
new Promise((resolve) => {
|
|
24
|
-
setTimeout(resolve, seconds * ONE_SECOND_IN_MS);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
18
|
type Parameters = {
|
|
28
19
|
channelManager: ChannelManager;
|
|
29
20
|
enableOfflineSupport: boolean;
|
|
@@ -37,7 +28,6 @@ const DEFAULT_OPTIONS = {
|
|
|
37
28
|
message_limit: 10,
|
|
38
29
|
};
|
|
39
30
|
|
|
40
|
-
const MAX_NUMBER_OF_RETRIES = 3;
|
|
41
31
|
const RETRY_INTERVAL_IN_MS = 5000;
|
|
42
32
|
|
|
43
33
|
type QueryType = 'queryLocalDB' | 'reload' | 'refresh' | 'loadChannels';
|
|
@@ -48,6 +38,7 @@ const selector = (nextValue: ChannelManagerState) =>
|
|
|
48
38
|
({
|
|
49
39
|
channelListInitialized: nextValue.initialized,
|
|
50
40
|
channels: nextValue.channels,
|
|
41
|
+
error: nextValue.error,
|
|
51
42
|
pagination: nextValue.pagination,
|
|
52
43
|
}) as const;
|
|
53
44
|
|
|
@@ -56,16 +47,14 @@ export const usePaginatedChannels = ({
|
|
|
56
47
|
enableOfflineSupport,
|
|
57
48
|
filters = {},
|
|
58
49
|
options = DEFAULT_OPTIONS,
|
|
59
|
-
setForceUpdate,
|
|
60
50
|
sort = {},
|
|
61
51
|
}: Parameters) => {
|
|
62
|
-
const [error, setError] = useState<Error | undefined>(undefined);
|
|
63
52
|
const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
|
|
64
53
|
const [activeQueryType, setActiveQueryType] = useState<QueryType | null>('queryLocalDB');
|
|
65
54
|
const activeChannels = useActiveChannelsRefContext();
|
|
66
55
|
const isMountedRef = useIsMountedRef();
|
|
67
56
|
const { client } = useChatContext();
|
|
68
|
-
const { channelListInitialized, channels, pagination } =
|
|
57
|
+
const { channelListInitialized, channels, pagination, error } =
|
|
69
58
|
useStateStore(channelManager?.state, selector) ?? {};
|
|
70
59
|
const hasNextPage = pagination?.hasNext;
|
|
71
60
|
|
|
@@ -77,7 +66,6 @@ export const usePaginatedChannels = ({
|
|
|
77
66
|
|
|
78
67
|
const queryChannels: QueryChannels = async (
|
|
79
68
|
queryType: QueryType = 'loadChannels',
|
|
80
|
-
retryCount = 0,
|
|
81
69
|
): Promise<void> => {
|
|
82
70
|
if (!client || !isMountedRef.current) {
|
|
83
71
|
return;
|
|
@@ -106,7 +94,6 @@ export const usePaginatedChannels = ({
|
|
|
106
94
|
filtersRef.current = filters;
|
|
107
95
|
sortRef.current = sort;
|
|
108
96
|
isQueryingRef.current = true;
|
|
109
|
-
setError(undefined);
|
|
110
97
|
activeRequestId.current++;
|
|
111
98
|
const currentRequestId = activeRequestId.current;
|
|
112
99
|
setActiveQueryType(queryType);
|
|
@@ -138,27 +125,12 @@ export const usePaginatedChannels = ({
|
|
|
138
125
|
isQueryingRef.current = false;
|
|
139
126
|
} catch (err: unknown) {
|
|
140
127
|
isQueryingRef.current = false;
|
|
141
|
-
await waitSeconds(2);
|
|
142
128
|
|
|
143
129
|
if (isQueryStale()) {
|
|
144
130
|
return;
|
|
145
131
|
}
|
|
146
132
|
|
|
147
|
-
|
|
148
|
-
// state and then succeed (reconnect case)
|
|
149
|
-
if (retryCount === MAX_NUMBER_OF_RETRIES && !isQueryingRef.current) {
|
|
150
|
-
setActiveQueryType(null);
|
|
151
|
-
console.warn(err);
|
|
152
|
-
|
|
153
|
-
setError(
|
|
154
|
-
new Error(
|
|
155
|
-
`Maximum number of retries reached in queryChannels. Last error message is: ${err}`,
|
|
156
|
-
),
|
|
157
|
-
);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return queryChannels(queryType, retryCount + 1);
|
|
133
|
+
console.warn(err);
|
|
162
134
|
}
|
|
163
135
|
|
|
164
136
|
setActiveQueryType(null);
|
|
@@ -198,71 +170,15 @@ export const usePaginatedChannels = ({
|
|
|
198
170
|
const sortStr = useMemo(() => JSON.stringify(sort), [sort]);
|
|
199
171
|
|
|
200
172
|
useEffect(() => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
const channelsFromDB = await getChannelsForFilterSort({
|
|
208
|
-
currentUserId: client.user.id,
|
|
209
|
-
filters,
|
|
210
|
-
sort,
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
if (channelsFromDB) {
|
|
214
|
-
const offlineChannels = client.hydrateActiveChannels(channelsFromDB, {
|
|
215
|
-
offlineMode: true,
|
|
216
|
-
skipInitialization: [], // passing empty array will clear out the existing messages from channel state, this removes the possibility of duplicate messages
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
channelManager.setChannels(offlineChannels);
|
|
220
|
-
setStaticChannelsActive(true);
|
|
221
|
-
}
|
|
222
|
-
} catch (e) {
|
|
223
|
-
console.warn('Failed to get channels from database: ', e);
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
setActiveQueryType(null);
|
|
228
|
-
|
|
229
|
-
return true;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
let listener: ReturnType<typeof DBSyncManager.onSyncStatusChange>;
|
|
233
|
-
if (enableOfflineSupport) {
|
|
234
|
-
// Any time DB is synced, we need to update the UI with local DB channels first,
|
|
235
|
-
// and then call queryChannels to ensure any new channels are added to UI.
|
|
236
|
-
listener = DBSyncManager.onSyncStatusChange(async (syncStatus) => {
|
|
237
|
-
if (syncStatus) {
|
|
238
|
-
const loadingChannelsSucceeded = await loadOfflineChannels();
|
|
239
|
-
if (loadingChannelsSucceeded) {
|
|
240
|
-
await reloadList();
|
|
241
|
-
setForceUpdate((u) => u + 1);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
// On start, load the channels from local db.
|
|
246
|
-
loadOfflineChannels().then((success) => {
|
|
247
|
-
// If db is already synced (sync api and pending api calls), then
|
|
248
|
-
// right away call queryChannels.
|
|
249
|
-
if (success) {
|
|
250
|
-
const dbSyncStatus = DBSyncManager.getSyncStatus();
|
|
251
|
-
if (dbSyncStatus) {
|
|
252
|
-
reloadList();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
listener = client.on('connection.changed', async (event) => {
|
|
173
|
+
const listener: ReturnType<typeof client.on> = client.on(
|
|
174
|
+
'connection.changed',
|
|
175
|
+
async (event) => {
|
|
258
176
|
if (event.online) {
|
|
259
177
|
await refreshList();
|
|
260
|
-
setForceUpdate((u) => u + 1);
|
|
261
178
|
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
179
|
+
},
|
|
180
|
+
);
|
|
181
|
+
reloadList();
|
|
266
182
|
|
|
267
183
|
return () => listener?.unsubscribe?.();
|
|
268
184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -17,11 +17,29 @@ export const useIsChannelMuted = (channel: Channel) => {
|
|
|
17
17
|
|
|
18
18
|
useEffect(() => {
|
|
19
19
|
const handleEvent = () => {
|
|
20
|
+
const newMuteStatus = channel.muteStatus();
|
|
21
|
+
if (
|
|
22
|
+
newMuteStatus.muted === muted.muted &&
|
|
23
|
+
newMuteStatus.createdAt?.getTime?.() === muted.createdAt?.getTime?.() &&
|
|
24
|
+
newMuteStatus.expiresAt?.getTime?.() === muted.expiresAt?.getTime?.()
|
|
25
|
+
) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
setMuted(channel.muteStatus());
|
|
21
30
|
};
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
const listeners = [
|
|
33
|
+
client.on('notification.channel_mutes_updated', handleEvent),
|
|
34
|
+
client.on('health.check', (event) => {
|
|
35
|
+
if (event.me) {
|
|
36
|
+
handleEvent();
|
|
37
|
+
}
|
|
38
|
+
}),
|
|
39
|
+
];
|
|
40
|
+
return () => {
|
|
41
|
+
listeners.forEach((listener) => listener.unsubscribe());
|
|
42
|
+
};
|
|
25
43
|
}, [channel, client, muted]);
|
|
26
44
|
|
|
27
45
|
return muted ?? defaultMuteStatus;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useEffect, useState } from 'react';
|
|
2
2
|
import { Image, Platform } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { Channel, OfflineDBState } from 'stream-chat';
|
|
5
5
|
|
|
6
6
|
import { useAppSettings } from './hooks/useAppSettings';
|
|
7
7
|
import { useCreateChatContext } from './hooks/useCreateChatContext';
|
|
8
8
|
import { useIsOnline } from './hooks/useIsOnline';
|
|
9
9
|
import { useMutedUsers } from './hooks/useMutedUsers';
|
|
10
10
|
|
|
11
|
-
import { useSyncDatabase } from './hooks/useSyncDatabase';
|
|
12
|
-
|
|
13
11
|
import { ChannelsStateProvider } from '../../contexts/channelsStateContext/ChannelsStateContext';
|
|
14
12
|
import { ChatContextValue, ChatProvider } from '../../contexts/chatContext/ChatContext';
|
|
15
13
|
import { useDebugContext } from '../../contexts/debugContext/DebugContext';
|
|
@@ -20,13 +18,13 @@ import {
|
|
|
20
18
|
DEFAULT_USER_LANGUAGE,
|
|
21
19
|
TranslationProvider,
|
|
22
20
|
} from '../../contexts/translationContext/TranslationContext';
|
|
21
|
+
import { useStateStore } from '../../hooks';
|
|
23
22
|
import { useStreami18n } from '../../hooks/useStreami18n';
|
|
24
23
|
import init from '../../init';
|
|
25
24
|
|
|
26
25
|
import { NativeHandlers } from '../../native';
|
|
27
|
-
import {
|
|
26
|
+
import { OfflineDB } from '../../store/OfflineDB';
|
|
28
27
|
|
|
29
|
-
import { DBSyncManager } from '../../utils/DBSyncManager';
|
|
30
28
|
import type { Streami18n } from '../../utils/i18n/Streami18n';
|
|
31
29
|
import { version } from '../../version.json';
|
|
32
30
|
|
|
@@ -134,6 +132,12 @@ export type ChatProps = Pick<ChatContextValue, 'client'> &
|
|
|
134
132
|
style?: DeepPartial<Theme>;
|
|
135
133
|
};
|
|
136
134
|
|
|
135
|
+
const selector = (nextValue: OfflineDBState) =>
|
|
136
|
+
({
|
|
137
|
+
initialized: nextValue.initialized,
|
|
138
|
+
userId: nextValue.userId,
|
|
139
|
+
}) as const;
|
|
140
|
+
|
|
137
141
|
const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
|
|
138
142
|
const {
|
|
139
143
|
children,
|
|
@@ -157,13 +161,8 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
|
|
|
157
161
|
*/
|
|
158
162
|
const { connectionRecovering, isOnline } = useIsOnline(client, closeConnectionOnBackground);
|
|
159
163
|
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
userID?: string;
|
|
163
|
-
}>({
|
|
164
|
-
initialised: false,
|
|
165
|
-
userID: client.userID,
|
|
166
|
-
});
|
|
164
|
+
const { initialized: offlineDbInitialized, userId: offlineDbUserId } =
|
|
165
|
+
useStateStore(client.offlineDb?.state, selector) ?? {};
|
|
167
166
|
|
|
168
167
|
/**
|
|
169
168
|
* Setup muted user listener
|
|
@@ -212,30 +211,18 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
|
|
|
212
211
|
return;
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
const initializeDatabase = () => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
setInitialisedDatabaseConfig({ initialised: false, userID });
|
|
220
|
-
SqliteClient.initializeDatabase()
|
|
221
|
-
.then(async () => {
|
|
222
|
-
setInitialisedDatabaseConfig({ initialised: true, userID });
|
|
223
|
-
await DBSyncManager.init(client as unknown as StreamChat);
|
|
224
|
-
})
|
|
225
|
-
.catch((error) => {
|
|
226
|
-
console.log('Error Initializing DB:', error);
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
initializeDatabase();
|
|
214
|
+
const initializeDatabase = async () => {
|
|
215
|
+
if (!client.offlineDb) {
|
|
216
|
+
client.setOfflineDBApi(new OfflineDB({ client }));
|
|
217
|
+
}
|
|
231
218
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
SqliteClient.closeDB();
|
|
219
|
+
if (client.offlineDb) {
|
|
220
|
+
await client.offlineDb.init(userID);
|
|
235
221
|
}
|
|
236
222
|
};
|
|
237
|
-
|
|
238
|
-
|
|
223
|
+
|
|
224
|
+
initializeDatabase();
|
|
225
|
+
}, [userID, enableOfflineSupport, client]);
|
|
239
226
|
|
|
240
227
|
useEffect(() => {
|
|
241
228
|
if (!client) {
|
|
@@ -251,12 +238,7 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
|
|
|
251
238
|
};
|
|
252
239
|
}, [client]);
|
|
253
240
|
|
|
254
|
-
|
|
255
|
-
// on unmount if it exists to prevent a memory leak.
|
|
256
|
-
useEffect(() => () => DBSyncManager.connectionChangedListener?.unsubscribe(), []);
|
|
257
|
-
|
|
258
|
-
const initialisedDatabase =
|
|
259
|
-
initialisedDatabaseConfig.initialised && userID === initialisedDatabaseConfig.userID;
|
|
241
|
+
const initialisedDatabase = !!offlineDbInitialized && userID === offlineDbUserId;
|
|
260
242
|
|
|
261
243
|
const appSettings = useAppSettings(client, isOnline, enableOfflineSupport, initialisedDatabase);
|
|
262
244
|
|
|
@@ -273,12 +255,6 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
|
|
|
273
255
|
setActiveChannel,
|
|
274
256
|
});
|
|
275
257
|
|
|
276
|
-
useSyncDatabase({
|
|
277
|
-
client,
|
|
278
|
-
enableOfflineSupport,
|
|
279
|
-
initialisedDatabase,
|
|
280
|
-
});
|
|
281
|
-
|
|
282
258
|
if (userID && enableOfflineSupport && !initialisedDatabase) {
|
|
283
259
|
// if user id has been set and offline support is enabled, we need to wait for database to be initialised
|
|
284
260
|
return LoadingIndicator ? <LoadingIndicator /> : null;
|
|
@@ -11,7 +11,6 @@ import { useTranslationContext } from '../../../contexts/translationContext/Tran
|
|
|
11
11
|
import dispatchConnectionChangedEvent from '../../../mock-builders/event/connectionChanged';
|
|
12
12
|
import dispatchConnectionRecoveredEvent from '../../../mock-builders/event/connectionRecovered';
|
|
13
13
|
import { getTestClient, getTestClientWithUser, setUser } from '../../../mock-builders/mock';
|
|
14
|
-
import { DBSyncManager } from '../../../utils/DBSyncManager';
|
|
15
14
|
import { Streami18n } from '../../../utils/i18n/Streami18n';
|
|
16
15
|
import { Chat } from '../Chat';
|
|
17
16
|
|
|
@@ -132,10 +131,6 @@ describe('ChatContext', () => {
|
|
|
132
131
|
});
|
|
133
132
|
|
|
134
133
|
describe('TranslationContext', () => {
|
|
135
|
-
beforeEach(() => {
|
|
136
|
-
jest.spyOn(DBSyncManager, 'init');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
134
|
afterEach(() => {
|
|
140
135
|
jest.clearAllMocks();
|
|
141
136
|
cleanup();
|
|
@@ -240,10 +235,14 @@ describe('TranslationContext', () => {
|
|
|
240
235
|
|
|
241
236
|
let unsubscribeSpy;
|
|
242
237
|
let listenersAfterInitialMount;
|
|
238
|
+
const initSpy = jest.spyOn(chatClientWithUser.offlineDb.syncManager, 'init');
|
|
243
239
|
|
|
244
240
|
await waitFor(() => {
|
|
245
241
|
// the unsubscribe fn changes during init(), so we keep a reference to the spy
|
|
246
|
-
unsubscribeSpy = jest.spyOn(
|
|
242
|
+
unsubscribeSpy = jest.spyOn(
|
|
243
|
+
chatClientWithUser.offlineDb.syncManager.connectionChangedListener,
|
|
244
|
+
'unsubscribe',
|
|
245
|
+
);
|
|
247
246
|
listenersAfterInitialMount = chatClientWithUser.listeners['connection.changed'];
|
|
248
247
|
});
|
|
249
248
|
|
|
@@ -251,8 +250,8 @@ describe('TranslationContext', () => {
|
|
|
251
250
|
rerender(<Chat client={chatClientWithUser} enableOfflineSupport key={2} />);
|
|
252
251
|
|
|
253
252
|
await waitFor(() => {
|
|
254
|
-
expect(
|
|
255
|
-
expect(unsubscribeSpy).toHaveBeenCalledTimes(
|
|
253
|
+
expect(initSpy).toHaveBeenCalledTimes(1);
|
|
254
|
+
expect(unsubscribeSpy).toHaveBeenCalledTimes(0);
|
|
256
255
|
expect(chatClientWithUser.listeners['connection.changed'].length).toBe(
|
|
257
256
|
listenersAfterInitialMount.length,
|
|
258
257
|
);
|
|
@@ -267,10 +266,14 @@ describe('TranslationContext', () => {
|
|
|
267
266
|
|
|
268
267
|
let unsubscribeSpy;
|
|
269
268
|
let listenersAfterInitialMount;
|
|
269
|
+
const initSpy = jest.spyOn(chatClientWithUser.offlineDb.syncManager, 'init');
|
|
270
270
|
|
|
271
271
|
await waitFor(() => {
|
|
272
272
|
// the unsubscribe fn changes during init(), so we keep a reference to the spy
|
|
273
|
-
unsubscribeSpy = jest.spyOn(
|
|
273
|
+
unsubscribeSpy = jest.spyOn(
|
|
274
|
+
chatClientWithUser.offlineDb.syncManager.connectionChangedListener,
|
|
275
|
+
'unsubscribe',
|
|
276
|
+
);
|
|
274
277
|
listenersAfterInitialMount = chatClientWithUser.listeners['connection.changed'];
|
|
275
278
|
});
|
|
276
279
|
|
|
@@ -282,7 +285,7 @@ describe('TranslationContext', () => {
|
|
|
282
285
|
rerender(<Chat client={chatClientWithUser} enableOfflineSupport />);
|
|
283
286
|
|
|
284
287
|
await waitFor(() => {
|
|
285
|
-
expect(
|
|
288
|
+
expect(initSpy).toHaveBeenCalledTimes(2);
|
|
286
289
|
expect(unsubscribeSpy).toHaveBeenCalledTimes(1);
|
|
287
290
|
expect(chatClientWithUser.listeners['connection.changed'].length).toBe(
|
|
288
291
|
listenersAfterInitialMount.length,
|
|
@@ -297,9 +300,14 @@ describe('TranslationContext', () => {
|
|
|
297
300
|
const { rerender } = render(<Chat client={chatClientWithUser} enableOfflineSupport />);
|
|
298
301
|
|
|
299
302
|
let unsubscribeSpy;
|
|
303
|
+
const initSpy = jest.spyOn(chatClientWithUser.offlineDb.syncManager, 'init');
|
|
304
|
+
|
|
300
305
|
await waitFor(() => {
|
|
301
306
|
// the unsubscribe fn changes during init(), so we keep a reference to the spy
|
|
302
|
-
unsubscribeSpy = jest.spyOn(
|
|
307
|
+
unsubscribeSpy = jest.spyOn(
|
|
308
|
+
chatClientWithUser.offlineDb.syncManager.connectionChangedListener,
|
|
309
|
+
'unsubscribe',
|
|
310
|
+
);
|
|
303
311
|
});
|
|
304
312
|
|
|
305
313
|
const listenersAfterInitialMount = chatClientWithUser.listeners['connection.changed'];
|
|
@@ -308,8 +316,8 @@ describe('TranslationContext', () => {
|
|
|
308
316
|
rerender(<Chat client={chatClientWithUser} enableOfflineSupport />);
|
|
309
317
|
|
|
310
318
|
await waitFor(() => {
|
|
311
|
-
expect(
|
|
312
|
-
expect(unsubscribeSpy).toHaveBeenCalledTimes(
|
|
319
|
+
expect(initSpy).toHaveBeenCalledTimes(1);
|
|
320
|
+
expect(unsubscribeSpy).toHaveBeenCalledTimes(0);
|
|
313
321
|
expect(chatClientWithUser.listeners['connection.changed'].length).toBe(
|
|
314
322
|
listenersAfterInitialMount.length,
|
|
315
323
|
);
|
|
@@ -3,7 +3,6 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
3
3
|
import type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';
|
|
4
4
|
|
|
5
5
|
import { useIsMountedRef } from '../../../hooks/useIsMountedRef';
|
|
6
|
-
import * as dbApi from '../../../store/apis';
|
|
7
6
|
|
|
8
7
|
export const useAppSettings = (
|
|
9
8
|
client: StreamChat,
|
|
@@ -17,6 +16,10 @@ export const useAppSettings = (
|
|
|
17
16
|
const isMounted = useIsMountedRef();
|
|
18
17
|
|
|
19
18
|
useEffect(() => {
|
|
19
|
+
if (fetchedAppSettings.current) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
20
23
|
const fetchAppSettings = () => {
|
|
21
24
|
if (appSettingsPromise.current) {
|
|
22
25
|
return appSettingsPromise.current;
|
|
@@ -24,43 +27,16 @@ export const useAppSettings = (
|
|
|
24
27
|
appSettingsPromise.current = client.getAppSettings();
|
|
25
28
|
return appSettingsPromise.current;
|
|
26
29
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Fetches app settings from the backend when offline support is disabled.
|
|
29
|
-
*/
|
|
30
|
-
const enforceAppSettingsWithoutOfflineSupport = async () => {
|
|
31
|
-
if (!client.userID) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (isMounted.current) {
|
|
38
|
-
setAppSettings(appSettings);
|
|
39
|
-
fetchedAppSettings.current = true;
|
|
40
|
-
}
|
|
41
|
-
} catch (error: unknown) {
|
|
42
|
-
if (error instanceof Error) {
|
|
43
|
-
console.error(`An error occurred while getting app settings: ${error}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
31
|
+
const enforceAppSettings = async () => {
|
|
32
|
+
if (!client.userID) return;
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* TODO: Remove client.userID usage for offline support case.
|
|
53
|
-
*/
|
|
54
|
-
const enforceAppSettingsWithOfflineSupport = async () => {
|
|
55
|
-
if (!client.userID) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (!initialisedDatabase) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
34
|
+
if (enableOfflineSupport && !initialisedDatabase) return;
|
|
35
|
+
|
|
36
|
+
const userId = client.userID as string;
|
|
61
37
|
|
|
62
|
-
if (!isOnline) {
|
|
63
|
-
const appSettings = await
|
|
38
|
+
if (!isOnline && client.offlineDb) {
|
|
39
|
+
const appSettings = await client.offlineDb.getAppSettings({ userId });
|
|
64
40
|
setAppSettings(appSettings);
|
|
65
41
|
return;
|
|
66
42
|
}
|
|
@@ -70,10 +46,10 @@ export const useAppSettings = (
|
|
|
70
46
|
if (isMounted.current && appSettings) {
|
|
71
47
|
setAppSettings(appSettings);
|
|
72
48
|
fetchedAppSettings.current = true;
|
|
73
|
-
|
|
74
|
-
appSettings,
|
|
75
|
-
|
|
76
|
-
|
|
49
|
+
client.offlineDb?.executeQuerySafely(
|
|
50
|
+
(db) => db.upsertAppSettings({ appSettings, userId }),
|
|
51
|
+
{ method: 'upsertAppSettings' },
|
|
52
|
+
);
|
|
77
53
|
}
|
|
78
54
|
} catch (error: unknown) {
|
|
79
55
|
if (error instanceof Error) {
|
|
@@ -82,21 +58,8 @@ export const useAppSettings = (
|
|
|
82
58
|
}
|
|
83
59
|
};
|
|
84
60
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (enableOfflineSupport) {
|
|
91
|
-
await enforceAppSettingsWithOfflineSupport();
|
|
92
|
-
} else {
|
|
93
|
-
await enforceAppSettingsWithoutOfflineSupport();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
enforeAppSettings();
|
|
98
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
99
|
-
}, [client, isOnline, initialisedDatabase]);
|
|
61
|
+
enforceAppSettings();
|
|
62
|
+
}, [client, isOnline, initialisedDatabase, isMounted, enableOfflineSupport]);
|
|
100
63
|
|
|
101
64
|
return appSettings;
|
|
102
65
|
};
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
1
|
import type { StreamChat } from 'stream-chat';
|
|
4
2
|
|
|
5
|
-
import { handleEventToSyncDB } from './handleEventToSyncDB';
|
|
6
|
-
|
|
7
3
|
type Params = {
|
|
8
4
|
client: StreamChat;
|
|
9
5
|
enableOfflineSupport: boolean;
|
|
10
6
|
initialisedDatabase: boolean;
|
|
11
7
|
};
|
|
12
|
-
export const useSyncDatabase = ({ client, enableOfflineSupport, initialisedDatabase }: Params) => {
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
let listener: ReturnType<StreamChat['on']> | undefined;
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated
|
|
11
|
+
* With the recent rework of the Offline Support feature, the handling of events has been moved
|
|
12
|
+
* to the stream-chat client instead of the SDK. This hook now does nothing and you can safely
|
|
13
|
+
* remove it from your code if you were using it. It will be removed in the next major release.
|
|
14
|
+
* @param client
|
|
15
|
+
* @param initialisedDatabase
|
|
16
|
+
*/
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
export const useSyncDatabase = ({ client, initialisedDatabase }: Params) => {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
|
2
2
|
import { StyleSheet, Text, View } from 'react-native';
|
|
3
3
|
import { FlatList } from 'react-native-gesture-handler';
|
|
4
4
|
|
|
@@ -80,6 +80,12 @@ export const MessageUserReactions = (props: MessageUserReactionsProps) => {
|
|
|
80
80
|
setSelectedReaction(reactionType);
|
|
81
81
|
};
|
|
82
82
|
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (selectedReaction && reactionTypes.length > 0 && !reactionTypes.includes(selectedReaction)) {
|
|
85
|
+
setSelectedReaction(reactionTypes[0]);
|
|
86
|
+
}
|
|
87
|
+
}, [reactionTypes, selectedReaction]);
|
|
88
|
+
|
|
83
89
|
const messageReactions = useMemo(
|
|
84
90
|
() =>
|
|
85
91
|
reactionTypes.reduce<ReactionData[]>((acc, reaction) => {
|