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
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import type { Event, StreamChat } from 'stream-chat';
|
|
2
|
-
|
|
3
|
-
import { deleteChannel } from '../../../store/apis/deleteChannel';
|
|
4
|
-
import { deleteMember } from '../../../store/apis/deleteMember';
|
|
5
|
-
import { deleteMessagesForChannel } from '../../../store/apis/deleteMessagesForChannel';
|
|
6
|
-
import { updateMessage } from '../../../store/apis/updateMessage';
|
|
7
|
-
import { updatePollMessage } from '../../../store/apis/updatePollMessage';
|
|
8
|
-
import { upsertChannelData } from '../../../store/apis/upsertChannelData';
|
|
9
|
-
import { upsertChannelDataFromChannel } from '../../../store/apis/upsertChannelDataFromChannel';
|
|
10
|
-
import { upsertChannels } from '../../../store/apis/upsertChannels';
|
|
11
|
-
import { upsertMembers } from '../../../store/apis/upsertMembers';
|
|
12
|
-
import { upsertMessages } from '../../../store/apis/upsertMessages';
|
|
13
|
-
import { upsertReads } from '../../../store/apis/upsertReads';
|
|
14
|
-
import { createSelectQuery } from '../../../store/sqlite-utils/createSelectQuery';
|
|
15
|
-
import { SqliteClient } from '../../../store/SqliteClient';
|
|
16
|
-
import { PreparedQueries } from '../../../store/types';
|
|
17
|
-
|
|
18
|
-
export const handleEventToSyncDB = async (event: Event, client: StreamChat, flush?: boolean) => {
|
|
19
|
-
const { type } = event;
|
|
20
|
-
|
|
21
|
-
// This function is used to guard the queries that require channel to be present in the db first
|
|
22
|
-
// If channel is not present in the db, we first fetch the channel data from the channel object
|
|
23
|
-
// and then add the queries with a channel create query first
|
|
24
|
-
const queriesWithChannelGuard = async (
|
|
25
|
-
createQueries: (flushOverride?: boolean) => Promise<PreparedQueries[]>,
|
|
26
|
-
) => {
|
|
27
|
-
const cid = event.cid || event.channel?.cid;
|
|
28
|
-
|
|
29
|
-
if (!cid) {
|
|
30
|
-
return await createQueries(flush);
|
|
31
|
-
}
|
|
32
|
-
const channels = await SqliteClient.executeSql.apply(
|
|
33
|
-
null,
|
|
34
|
-
createSelectQuery('channels', ['cid'], {
|
|
35
|
-
cid,
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
// a channel is not present in the db, we first fetch the channel data from the channel object.
|
|
39
|
-
// this can happen for example when a message.new event is received for a channel that is not in the db due to a channel being hidden.
|
|
40
|
-
if (channels.length === 0) {
|
|
41
|
-
const channel =
|
|
42
|
-
event.channel_type && event.channel_id
|
|
43
|
-
? client.channel(event.channel_type, event.channel_id)
|
|
44
|
-
: undefined;
|
|
45
|
-
if (channel && channel.initialized && !channel.disconnected) {
|
|
46
|
-
const channelQuery = await upsertChannelDataFromChannel({
|
|
47
|
-
channel,
|
|
48
|
-
flush,
|
|
49
|
-
});
|
|
50
|
-
if (channelQuery) {
|
|
51
|
-
const createdQueries = await createQueries(false);
|
|
52
|
-
const newQueries = [...channelQuery, ...createdQueries];
|
|
53
|
-
if (flush !== false) {
|
|
54
|
-
await SqliteClient.executeSqlBatch(newQueries);
|
|
55
|
-
}
|
|
56
|
-
return newQueries;
|
|
57
|
-
} else {
|
|
58
|
-
console.warn(
|
|
59
|
-
`Couldnt create channel queries on ${type} event for an initialized channel that is not in DB, skipping event`,
|
|
60
|
-
{ event },
|
|
61
|
-
);
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
console.warn(
|
|
66
|
-
`Received ${type} event for a non initialized channel that is not in DB, skipping event`,
|
|
67
|
-
{ event },
|
|
68
|
-
);
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return createQueries(flush);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
if (type === 'message.read' || type === 'notification.mark_read') {
|
|
76
|
-
const cid = event.cid;
|
|
77
|
-
const user = event.user;
|
|
78
|
-
if (user?.id && cid) {
|
|
79
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
80
|
-
upsertReads({
|
|
81
|
-
cid,
|
|
82
|
-
flush: flushOverride,
|
|
83
|
-
reads: [
|
|
84
|
-
{
|
|
85
|
-
last_read: event.received_at as string,
|
|
86
|
-
last_read_message_id: event.last_read_message_id,
|
|
87
|
-
unread_messages: 0,
|
|
88
|
-
user,
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (type === 'notification.mark_unread') {
|
|
97
|
-
const cid = event.cid;
|
|
98
|
-
const user = event.user;
|
|
99
|
-
if (user?.id && cid) {
|
|
100
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
101
|
-
upsertReads({
|
|
102
|
-
cid,
|
|
103
|
-
flush: flushOverride,
|
|
104
|
-
reads: [
|
|
105
|
-
{
|
|
106
|
-
last_read: event.received_at as string,
|
|
107
|
-
last_read_message_id: event.last_read_message_id,
|
|
108
|
-
unread_messages: event.unread_messages,
|
|
109
|
-
user,
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
}),
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (type === 'message.new') {
|
|
118
|
-
const { cid, message, user } = event;
|
|
119
|
-
|
|
120
|
-
if (message && (!message.parent_id || message.show_in_channel)) {
|
|
121
|
-
return await queriesWithChannelGuard(async (flushOverride) => {
|
|
122
|
-
let queries = await upsertMessages({
|
|
123
|
-
flush: flushOverride,
|
|
124
|
-
messages: [message],
|
|
125
|
-
});
|
|
126
|
-
if (cid && client.user && client.user.id !== user?.id) {
|
|
127
|
-
const userId = client.user.id;
|
|
128
|
-
const channel = client.activeChannels[cid];
|
|
129
|
-
if (channel) {
|
|
130
|
-
const ownReads = channel.state.read[userId];
|
|
131
|
-
const unreadCount = channel.countUnread();
|
|
132
|
-
const upsertReadsQueries = await upsertReads({
|
|
133
|
-
cid,
|
|
134
|
-
flush: flushOverride,
|
|
135
|
-
reads: [
|
|
136
|
-
{
|
|
137
|
-
last_read: ownReads.last_read.toString() as string,
|
|
138
|
-
last_read_message_id: ownReads.last_read_message_id,
|
|
139
|
-
unread_messages: unreadCount,
|
|
140
|
-
user: client.user,
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
});
|
|
144
|
-
queries = [...queries, ...upsertReadsQueries];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return queries;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (type === 'message.updated' || type === 'message.deleted') {
|
|
153
|
-
const message = event.message;
|
|
154
|
-
if (message && !message.parent_id) {
|
|
155
|
-
// Update only if it exists, otherwise event could be related
|
|
156
|
-
// to a message which is not in database.
|
|
157
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
158
|
-
updateMessage({
|
|
159
|
-
flush: flushOverride,
|
|
160
|
-
message,
|
|
161
|
-
}),
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (type === 'reaction.updated') {
|
|
167
|
-
const message = event.message;
|
|
168
|
-
if (message && event.reaction) {
|
|
169
|
-
// We update the entire message to make sure we also update reaction_groups
|
|
170
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
171
|
-
updateMessage({
|
|
172
|
-
flush: flushOverride,
|
|
173
|
-
message,
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (type === 'reaction.new' || type === 'reaction.deleted') {
|
|
180
|
-
const message = event.message;
|
|
181
|
-
if (message && !message.parent_id) {
|
|
182
|
-
// Here we are relying on the fact message.latest_reactions always includes
|
|
183
|
-
// the new reaction. So we first delete all the existing reactions and populate
|
|
184
|
-
// the reactions table with message.latest_reactions
|
|
185
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
186
|
-
updateMessage({
|
|
187
|
-
flush: flushOverride,
|
|
188
|
-
message,
|
|
189
|
-
}),
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
type === 'channel.updated' ||
|
|
196
|
-
type === 'channel.visible' ||
|
|
197
|
-
type === 'notification.added_to_channel' ||
|
|
198
|
-
type === 'notification.message_new'
|
|
199
|
-
) {
|
|
200
|
-
if (event.channel) {
|
|
201
|
-
return upsertChannelData({
|
|
202
|
-
channel: event.channel,
|
|
203
|
-
flush,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (
|
|
209
|
-
type === 'channel.hidden' ||
|
|
210
|
-
type === 'channel.deleted' ||
|
|
211
|
-
type === 'notification.removed_from_channel'
|
|
212
|
-
) {
|
|
213
|
-
if (event.channel) {
|
|
214
|
-
return deleteChannel({
|
|
215
|
-
cid: event.channel.cid,
|
|
216
|
-
flush,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (type === 'channel.truncated') {
|
|
222
|
-
if (event.channel) {
|
|
223
|
-
return deleteMessagesForChannel({
|
|
224
|
-
cid: event.channel.cid,
|
|
225
|
-
flush,
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (type === 'channels.queried') {
|
|
231
|
-
if (event.queriedChannels?.channels?.length) {
|
|
232
|
-
return upsertChannels({
|
|
233
|
-
channels: event.queriedChannels?.channels,
|
|
234
|
-
flush,
|
|
235
|
-
isLatestMessagesSet: event.queriedChannels?.isLatestMessageSet,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (type === 'member.added' || type === 'member.updated') {
|
|
241
|
-
const member = event.member;
|
|
242
|
-
const cid = event.cid;
|
|
243
|
-
if (member && cid) {
|
|
244
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
245
|
-
upsertMembers({
|
|
246
|
-
cid,
|
|
247
|
-
flush: flushOverride,
|
|
248
|
-
members: [member],
|
|
249
|
-
}),
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (type === 'member.removed') {
|
|
255
|
-
const member = event.member;
|
|
256
|
-
const cid = event.cid;
|
|
257
|
-
if (member && cid) {
|
|
258
|
-
return await queriesWithChannelGuard((flushOverride) =>
|
|
259
|
-
deleteMember({
|
|
260
|
-
cid,
|
|
261
|
-
flush: flushOverride,
|
|
262
|
-
member,
|
|
263
|
-
}),
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
[
|
|
270
|
-
'poll.closed',
|
|
271
|
-
'poll.updated',
|
|
272
|
-
'poll.vote_casted',
|
|
273
|
-
'poll.vote_changed',
|
|
274
|
-
'poll.vote_removed',
|
|
275
|
-
].includes(type)
|
|
276
|
-
) {
|
|
277
|
-
const { poll, poll_vote, type } = event;
|
|
278
|
-
if (poll) {
|
|
279
|
-
return updatePollMessage({
|
|
280
|
-
eventType: type,
|
|
281
|
-
flush,
|
|
282
|
-
poll,
|
|
283
|
-
poll_vote,
|
|
284
|
-
userID: client?.userID || '',
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return [];
|
|
290
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { isVoteAnswer, PollAnswer, PollResponse, PollVote } from 'stream-chat';
|
|
2
|
-
|
|
3
|
-
import { mapPollToStorable } from '../mappers/mapPollToStorable';
|
|
4
|
-
import { mapStorableToPoll } from '../mappers/mapStorableToPoll';
|
|
5
|
-
import { createSelectQuery } from '../sqlite-utils/createSelectQuery';
|
|
6
|
-
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
|
|
7
|
-
import { SqliteClient } from '../SqliteClient';
|
|
8
|
-
import type { PreparedQueries, TableRow } from '../types';
|
|
9
|
-
|
|
10
|
-
export const updatePollMessage = async ({
|
|
11
|
-
eventType,
|
|
12
|
-
flush = true,
|
|
13
|
-
poll,
|
|
14
|
-
poll_vote,
|
|
15
|
-
userID,
|
|
16
|
-
}: {
|
|
17
|
-
eventType: string;
|
|
18
|
-
poll: PollResponse;
|
|
19
|
-
userID: string;
|
|
20
|
-
flush?: boolean;
|
|
21
|
-
poll_vote?: PollVote | PollAnswer;
|
|
22
|
-
}) => {
|
|
23
|
-
const queries: PreparedQueries[] = [];
|
|
24
|
-
|
|
25
|
-
const pollsFromDB = await SqliteClient.executeSql.apply(
|
|
26
|
-
null,
|
|
27
|
-
createSelectQuery('poll', ['*'], {
|
|
28
|
-
id: poll.id,
|
|
29
|
-
}),
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
for (const pollFromDB of pollsFromDB) {
|
|
33
|
-
const serializedPoll = mapStorableToPoll(pollFromDB as unknown as TableRow<'poll'>);
|
|
34
|
-
const { latest_answers = [], own_votes = [] } = serializedPoll;
|
|
35
|
-
let newOwnVotes = own_votes;
|
|
36
|
-
if (poll_vote && poll_vote.user?.id === userID) {
|
|
37
|
-
newOwnVotes =
|
|
38
|
-
eventType === 'poll.vote_removed'
|
|
39
|
-
? newOwnVotes.filter((vote) => vote.id !== poll_vote.id)
|
|
40
|
-
: [poll_vote, ...newOwnVotes.filter((vote) => vote.id !== poll_vote.id)];
|
|
41
|
-
}
|
|
42
|
-
let newLatestAnswers = latest_answers;
|
|
43
|
-
if (poll_vote && isVoteAnswer(poll_vote)) {
|
|
44
|
-
newLatestAnswers =
|
|
45
|
-
eventType === 'poll.vote_removed'
|
|
46
|
-
? newLatestAnswers.filter((answer) => answer.id !== poll_vote?.id)
|
|
47
|
-
: [poll_vote, ...newLatestAnswers.filter((answer) => answer.id !== poll_vote?.id)];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const storablePoll = mapPollToStorable({
|
|
51
|
-
...poll,
|
|
52
|
-
latest_answers: newLatestAnswers,
|
|
53
|
-
own_votes: newOwnVotes,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
queries.push(
|
|
57
|
-
createUpdateQuery('poll', storablePoll, {
|
|
58
|
-
id: poll.id,
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
SqliteClient.logger?.('info', 'updatePoll', {
|
|
62
|
-
poll: storablePoll,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (flush) {
|
|
67
|
-
SqliteClient.executeSqlBatch(queries);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return queries;
|
|
71
|
-
};
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import type { AxiosError } from 'axios';
|
|
2
|
-
import dayjs from 'dayjs';
|
|
3
|
-
import type { APIErrorResponse, StreamChat } from 'stream-chat';
|
|
4
|
-
|
|
5
|
-
import { handleEventToSyncDB } from '../components/Chat/hooks/handleEventToSyncDB';
|
|
6
|
-
import { getAllChannelIds, getLastSyncedAt, upsertUserSyncStatus } from '../store/apis';
|
|
7
|
-
|
|
8
|
-
import { addPendingTask } from '../store/apis/addPendingTask';
|
|
9
|
-
|
|
10
|
-
import { deletePendingTask } from '../store/apis/deletePendingTask';
|
|
11
|
-
import { getPendingTasks } from '../store/apis/getPendingTasks';
|
|
12
|
-
import { SqliteClient } from '../store/SqliteClient';
|
|
13
|
-
import type { PendingTask } from '../store/types';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* DBSyncManager has the responsibility to sync the channel states
|
|
17
|
-
* within local database whenever possible.
|
|
18
|
-
*
|
|
19
|
-
* Components can get the current sync status using DBSyncManager.getCurrentStatus().
|
|
20
|
-
* Or components can attach a listener for status change as following:
|
|
21
|
-
*
|
|
22
|
-
* ```tsx
|
|
23
|
-
* useEffect(() => {
|
|
24
|
-
* const unsubscribe = DBSyncManager.onSyncStatusChange((syncStatus) => {
|
|
25
|
-
* if (syncStatus) {
|
|
26
|
-
* doSomething();
|
|
27
|
-
* }
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* return () => unsubscribe();
|
|
31
|
-
* })
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
const restBeforeNextTask = () => new Promise((resolve) => setTimeout(resolve, 500));
|
|
35
|
-
|
|
36
|
-
export class DBSyncManager {
|
|
37
|
-
static syncStatus = false;
|
|
38
|
-
static listeners: Array<(status: boolean) => void> = [];
|
|
39
|
-
static client: StreamChat | null = null;
|
|
40
|
-
static connectionChangedListener: { unsubscribe: () => void } | null = null;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Returns weather channel states in local DB are synced with backend or not.
|
|
44
|
-
* @returns boolean
|
|
45
|
-
*/
|
|
46
|
-
static getSyncStatus = () => this.syncStatus;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Initializes the DBSyncManager. This function should be called only once
|
|
50
|
-
* throughout the lifetime of SDK.
|
|
51
|
-
*
|
|
52
|
-
* @param client
|
|
53
|
-
*/
|
|
54
|
-
static init = async (client: StreamChat) => {
|
|
55
|
-
try {
|
|
56
|
-
this.client = client;
|
|
57
|
-
// If the websocket connection is already active, then straightaway
|
|
58
|
-
// call the sync api and also execute pending api calls.
|
|
59
|
-
// Otherwise wait for `connection.changed` event.
|
|
60
|
-
if (client.user?.id && client.wsConnection?.isHealthy) {
|
|
61
|
-
await this.syncAndExecutePendingTasks();
|
|
62
|
-
this.syncStatus = true;
|
|
63
|
-
this.listeners.forEach((l) => l(true));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// If a listener has already been registered, unsubscribe from it so
|
|
67
|
-
// that it can be reinstated. This can happen if we reconnect with a
|
|
68
|
-
// different user or the component invoking the init() function gets
|
|
69
|
-
// unmounted and then remounted again. This part of the code makes
|
|
70
|
-
// sure the stale listener doesn't produce a memory leak.
|
|
71
|
-
if (this.connectionChangedListener) {
|
|
72
|
-
this.connectionChangedListener.unsubscribe();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.connectionChangedListener = this.client.on('connection.changed', async (event) => {
|
|
76
|
-
if (event.online) {
|
|
77
|
-
await this.syncAndExecutePendingTasks();
|
|
78
|
-
this.syncStatus = true;
|
|
79
|
-
this.listeners.forEach((l) => l(true));
|
|
80
|
-
} else {
|
|
81
|
-
this.syncStatus = false;
|
|
82
|
-
this.listeners.forEach((l) => l(false));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.log('Error in DBSyncManager.init: ', error);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Subscribes a listener for sync status change.
|
|
92
|
-
*
|
|
93
|
-
* @param listener {function}
|
|
94
|
-
* @returns {function} to unsubscribe the listener.
|
|
95
|
-
*/
|
|
96
|
-
static onSyncStatusChange = (listener: (status: boolean) => void) => {
|
|
97
|
-
this.listeners.push(listener);
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
unsubscribe: () => {
|
|
101
|
-
this.listeners = this.listeners.filter((el) => el !== listener);
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
static sync = async (client: StreamChat) => {
|
|
107
|
-
if (!this.client?.user) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const cids = await getAllChannelIds();
|
|
111
|
-
// If there are no channels, then there is no need to sync.
|
|
112
|
-
if (cids.length === 0) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const lastSyncedAt = await getLastSyncedAt({
|
|
117
|
-
currentUserId: this.client.user.id,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (lastSyncedAt) {
|
|
121
|
-
const lastSyncedAtDate = new Date(lastSyncedAt);
|
|
122
|
-
const lastSyncedAtDayJs = dayjs(lastSyncedAtDate);
|
|
123
|
-
const nowDayJs = dayjs();
|
|
124
|
-
const diff = nowDayJs.diff(lastSyncedAtDayJs, 'days');
|
|
125
|
-
if (diff > 30) {
|
|
126
|
-
// stream backend will send an error if we try to sync after 30 days.
|
|
127
|
-
// In that case reset the entire DB and start fresh.
|
|
128
|
-
await SqliteClient.resetDB();
|
|
129
|
-
} else {
|
|
130
|
-
try {
|
|
131
|
-
const result = await this.client.sync(cids, lastSyncedAtDate.toISOString());
|
|
132
|
-
const queryPromises = result.events.map(
|
|
133
|
-
async (event) => await handleEventToSyncDB(event, client),
|
|
134
|
-
);
|
|
135
|
-
const queriesArray = await Promise.all(queryPromises);
|
|
136
|
-
const queries = queriesArray.flat();
|
|
137
|
-
|
|
138
|
-
if (queries.length) {
|
|
139
|
-
await SqliteClient.executeSqlBatch(queries);
|
|
140
|
-
}
|
|
141
|
-
} catch (e) {
|
|
142
|
-
// Error will be raised by the sync API if there are too many events.
|
|
143
|
-
// In that case reset the entire DB and start fresh.
|
|
144
|
-
await SqliteClient.resetDB();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
await upsertUserSyncStatus({
|
|
149
|
-
currentUserId: this.client.user.id,
|
|
150
|
-
lastSyncedAt: new Date().toString(),
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
static syncAndExecutePendingTasks = async () => {
|
|
155
|
-
if (!this.client) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
await this.executePendingTasks(this.client);
|
|
160
|
-
await this.sync(this.client);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
static queueTask = async ({ client, task }: { client: StreamChat; task: PendingTask }) => {
|
|
164
|
-
const removeFromApi = await addPendingTask(task);
|
|
165
|
-
|
|
166
|
-
let response;
|
|
167
|
-
try {
|
|
168
|
-
response = await this.executeTask({ client, task });
|
|
169
|
-
} catch (e) {
|
|
170
|
-
if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {
|
|
171
|
-
// Error code 16 - message already exists
|
|
172
|
-
// ignore
|
|
173
|
-
} else {
|
|
174
|
-
throw e;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
await removeFromApi();
|
|
179
|
-
|
|
180
|
-
return response;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
static executeTask = async ({ client, task }: { client: StreamChat; task: PendingTask }) => {
|
|
184
|
-
const channel = client.channel(task.channelType, task.channelId);
|
|
185
|
-
|
|
186
|
-
if (task.type === 'send-reaction') {
|
|
187
|
-
return await channel.sendReaction(...task.payload);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (task.type === 'delete-reaction') {
|
|
191
|
-
return await channel.deleteReaction(...task.payload);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (task.type === 'delete-message') {
|
|
195
|
-
return await client.deleteMessage(...task.payload);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
throw new Error('Invalid task type');
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
static executePendingTasks = async (client: StreamChat) => {
|
|
202
|
-
const queue = await getPendingTasks();
|
|
203
|
-
for (const task of queue) {
|
|
204
|
-
if (!task.id) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
await this.executeTask({
|
|
210
|
-
client,
|
|
211
|
-
task,
|
|
212
|
-
});
|
|
213
|
-
} catch (e) {
|
|
214
|
-
if ((e as AxiosError<APIErrorResponse>)?.response?.data?.code === 4) {
|
|
215
|
-
// Error code 16 - message already exists
|
|
216
|
-
// ignore
|
|
217
|
-
} else {
|
|
218
|
-
throw e;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
await deletePendingTask({
|
|
223
|
-
id: task.id,
|
|
224
|
-
});
|
|
225
|
-
await restBeforeNextTask();
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
static dropPendingTasks = async (conditions: { messageId: string }) => {
|
|
230
|
-
const tasks = await getPendingTasks(conditions);
|
|
231
|
-
|
|
232
|
-
for (const task of tasks) {
|
|
233
|
-
if (!task.id) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
await deletePendingTask({
|
|
238
|
-
id: task.id,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
}
|