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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
|
|
2
|
+
import { SqliteClient } from '../SqliteClient';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* dropPendingTasks - Drops all pending tasks from the DB given a specific messageId.
|
|
6
|
+
* Useful for when we do some message actions on a failed message and then we decide to
|
|
7
|
+
* delete it afterwards, removing it from the state.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} param
|
|
10
|
+
* @param {string} param.messageId The messageId for which we want to remove the pending tasks.
|
|
11
|
+
* @param {boolean} param.execute Whether we should immediately execute the query or return it as a prepared one.
|
|
12
|
+
*
|
|
13
|
+
* @return {() => void} - A function that can be called to remove the task from the database
|
|
14
|
+
*/
|
|
15
|
+
export const dropPendingTasks = async ({
|
|
16
|
+
messageId,
|
|
17
|
+
execute = true,
|
|
18
|
+
}: {
|
|
19
|
+
messageId: string;
|
|
20
|
+
execute?: boolean;
|
|
21
|
+
}) => {
|
|
22
|
+
const queries = [createDeleteQuery('pendingTasks', { messageId })];
|
|
23
|
+
SqliteClient.logger?.('info', 'dropPendingTasks', {
|
|
24
|
+
messageId,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (execute) {
|
|
28
|
+
await SqliteClient.executeSqlBatch(queries);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return queries;
|
|
32
|
+
};
|
|
@@ -25,7 +25,7 @@ export const getChannelMessages = async ({
|
|
|
25
25
|
const messageIds = messageRows.map(({ id }) => id);
|
|
26
26
|
|
|
27
27
|
// Populate the message reactions.
|
|
28
|
-
const reactionRows = await selectReactionsForMessages(messageIds);
|
|
28
|
+
const reactionRows = await selectReactionsForMessages(messageIds, null);
|
|
29
29
|
const messageIdVsReactions: Record<string, TableRowJoinedUser<'reactions'>[]> = {};
|
|
30
30
|
reactionRows.forEach((reaction) => {
|
|
31
31
|
if (!messageIdVsReactions[reaction.messageId]) {
|
|
@@ -25,19 +25,22 @@ export const getChannels = async ({
|
|
|
25
25
|
currentUserId: string;
|
|
26
26
|
}): Promise<Omit<ChannelAPIResponse, 'duration'>[]> => {
|
|
27
27
|
SqliteClient.logger?.('info', 'getChannels', { channelIds, currentUserId });
|
|
28
|
-
const channels = await selectChannels({ channelIds });
|
|
29
28
|
|
|
30
|
-
const cidVsMembers = await
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
channelIds,
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const [channels, cidVsMembers, cidVsReads, cidVsMessages] = await Promise.all([
|
|
30
|
+
selectChannels({ channelIds }),
|
|
31
|
+
getMembers({ channelIds }),
|
|
32
|
+
getReads({ channelIds }),
|
|
33
|
+
getChannelMessages({
|
|
34
|
+
channelIds,
|
|
35
|
+
currentUserId,
|
|
36
|
+
}),
|
|
37
|
+
]);
|
|
36
38
|
|
|
37
39
|
// Enrich the channels with state
|
|
38
40
|
return channels.map((c) => ({
|
|
39
41
|
...mapStorableToChannel(c),
|
|
40
42
|
members: cidVsMembers[c.cid] || [],
|
|
43
|
+
membership: (cidVsMembers[c.cid] || []).find((member) => member.user_id === currentUserId),
|
|
41
44
|
messages: cidVsMessages[c.cid] || [],
|
|
42
45
|
pinned_messages: [],
|
|
43
46
|
read: cidVsReads[c.cid] || [],
|
|
@@ -5,7 +5,7 @@ export const getLastSyncedAt = async ({
|
|
|
5
5
|
currentUserId,
|
|
6
6
|
}: {
|
|
7
7
|
currentUserId: string;
|
|
8
|
-
}): Promise<
|
|
8
|
+
}): Promise<string | undefined> => {
|
|
9
9
|
SqliteClient.logger?.('info', 'getLastSyncedAt', { currentUserId });
|
|
10
10
|
const result = await SqliteClient.executeSql.apply(
|
|
11
11
|
null,
|
|
@@ -14,8 +14,5 @@ export const getLastSyncedAt = async ({
|
|
|
14
14
|
}),
|
|
15
15
|
);
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
return result[0]?.lastSyncedAt;
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
17
|
+
return result[0]?.lastSyncedAt;
|
|
21
18
|
};
|
|
@@ -10,15 +10,18 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
10
10
|
* @param currentMessageId The message ID for which reactions are to be fetched.
|
|
11
11
|
* @param filters The filters to be applied while fetching reactions.
|
|
12
12
|
* @param sort The sort to be applied while fetching reactions.
|
|
13
|
+
* @param limit The limit of how many reactions should be returned.
|
|
13
14
|
*/
|
|
14
15
|
export const getReactionsForFilterSort = async ({
|
|
15
|
-
|
|
16
|
+
messageId,
|
|
16
17
|
filters,
|
|
17
18
|
sort,
|
|
19
|
+
limit,
|
|
18
20
|
}: {
|
|
19
|
-
|
|
20
|
-
filters?: ReactionFilters
|
|
21
|
+
messageId: string;
|
|
22
|
+
filters?: Pick<ReactionFilters, 'type'>;
|
|
21
23
|
sort?: ReactionSort;
|
|
24
|
+
limit?: number;
|
|
22
25
|
}): Promise<ReactionResponse[] | null> => {
|
|
23
26
|
if (!filters && !sort) {
|
|
24
27
|
console.warn('Please provide the query (filters/sort) to fetch channels from DB');
|
|
@@ -27,7 +30,7 @@ export const getReactionsForFilterSort = async ({
|
|
|
27
30
|
|
|
28
31
|
SqliteClient.logger?.('info', 'getReactionsForFilterSort', { filters, sort });
|
|
29
32
|
|
|
30
|
-
const reactions = await selectReactionsForMessages([
|
|
33
|
+
const reactions = await selectReactionsForMessages([messageId], limit, filters, sort);
|
|
31
34
|
|
|
32
35
|
if (!reactions) {
|
|
33
36
|
return null;
|
|
@@ -37,7 +40,5 @@ export const getReactionsForFilterSort = async ({
|
|
|
37
40
|
return [];
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return getReactions({ reactions: filteredReactions });
|
|
43
|
+
return getReactions({ reactions });
|
|
43
44
|
};
|
package/src/store/apis/index.ts
CHANGED
|
@@ -8,11 +8,14 @@ export * from './getAppSettings';
|
|
|
8
8
|
export * from './getChannelMessages';
|
|
9
9
|
export * from './getChannels';
|
|
10
10
|
export * from './getChannelsForFilterSort';
|
|
11
|
+
export * from './getReactionsforFilterSort';
|
|
11
12
|
export * from './getLastSyncedAt';
|
|
12
13
|
export * from './getMembers';
|
|
13
14
|
export * from './getReads';
|
|
14
15
|
export * from './updateMessage';
|
|
15
16
|
export * from './updateReaction';
|
|
17
|
+
export * from './insertReaction';
|
|
18
|
+
export * from './deleteReaction';
|
|
16
19
|
export * from './upsertAppSettings';
|
|
17
20
|
export * from './upsertChannelData';
|
|
18
21
|
export * from './upsertChannels';
|
|
@@ -21,4 +24,10 @@ export * from './upsertUserSyncStatus';
|
|
|
21
24
|
export * from './upsertMembers';
|
|
22
25
|
export * from './upsertMessages';
|
|
23
26
|
export * from './upsertReads';
|
|
24
|
-
export * from './
|
|
27
|
+
export * from './upsertPoll';
|
|
28
|
+
export * from './addPendingTask';
|
|
29
|
+
export * from './deletePendingTask';
|
|
30
|
+
export * from './getPendingTasks';
|
|
31
|
+
export * from './softDeleteMessage';
|
|
32
|
+
export * from './channelExists';
|
|
33
|
+
export * from './dropPendingTasks';
|
|
@@ -7,13 +7,13 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
7
7
|
import type { PreparedQueries } from '../types';
|
|
8
8
|
|
|
9
9
|
export const insertReaction = async ({
|
|
10
|
-
|
|
10
|
+
execute = true,
|
|
11
11
|
message,
|
|
12
12
|
reaction,
|
|
13
13
|
}: {
|
|
14
14
|
message: MessageResponse | LocalMessage;
|
|
15
15
|
reaction: ReactionResponse;
|
|
16
|
-
|
|
16
|
+
execute?: boolean;
|
|
17
17
|
}) => {
|
|
18
18
|
const queries: PreparedQueries[] = [];
|
|
19
19
|
|
|
@@ -34,11 +34,11 @@ export const insertReaction = async ({
|
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
SqliteClient.logger?.('info', 'insertReaction', {
|
|
37
|
-
|
|
37
|
+
execute,
|
|
38
38
|
reaction: storableReaction,
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
if (
|
|
41
|
+
if (execute) {
|
|
42
42
|
await SqliteClient.executeSqlBatch(queries);
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -30,7 +30,7 @@ export const selectMessagesForChannels = async (
|
|
|
30
30
|
*,
|
|
31
31
|
ROW_NUMBER() OVER (
|
|
32
32
|
PARTITION BY cid
|
|
33
|
-
ORDER BY
|
|
33
|
+
ORDER BY createdAt DESC
|
|
34
34
|
) RowNum
|
|
35
35
|
FROM messages
|
|
36
36
|
WHERE cid in (${questionMarks})
|
|
@@ -39,7 +39,7 @@ export const selectMessagesForChannels = async (
|
|
|
39
39
|
users b
|
|
40
40
|
ON b.id = a.userId
|
|
41
41
|
WHERE RowNum < 200
|
|
42
|
-
ORDER BY
|
|
42
|
+
ORDER BY a.createdAt ASC`,
|
|
43
43
|
cids,
|
|
44
44
|
);
|
|
45
45
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ReactionFilters, ReactionSort } from 'stream-chat';
|
|
2
|
+
|
|
1
3
|
import { tables } from '../../schema';
|
|
2
4
|
import { SqliteClient } from '../../SqliteClient';
|
|
3
5
|
import type { TableRowJoinedUser } from '../../types';
|
|
@@ -5,9 +7,15 @@ import type { TableRowJoinedUser } from '../../types';
|
|
|
5
7
|
/**
|
|
6
8
|
* Fetches reactions for a message from the database for messageIds.
|
|
7
9
|
* @param messageIds The message IDs for which reactions are to be fetched.
|
|
10
|
+
* @param limit The limit of how many reactions should be returned.
|
|
11
|
+
* @param filters A ReactionFilter for the reactions we want to fetch. Only type is currently supported.
|
|
12
|
+
* @param sort A sort for reactions to be used when querying. Custom data is currently not supported for sorting.
|
|
8
13
|
*/
|
|
9
14
|
export const selectReactionsForMessages = async (
|
|
10
15
|
messageIds: string[],
|
|
16
|
+
limit: number | null = 25,
|
|
17
|
+
filters?: Pick<ReactionFilters, 'type'>,
|
|
18
|
+
sort?: ReactionSort,
|
|
11
19
|
): Promise<TableRowJoinedUser<'reactions'>[]> => {
|
|
12
20
|
const questionMarks = Array(messageIds.length).fill('?').join(',');
|
|
13
21
|
const reactionsColumnNames = Object.keys(tables.reactions.columns)
|
|
@@ -16,6 +24,15 @@ export const selectReactionsForMessages = async (
|
|
|
16
24
|
const userColumnNames = Object.keys(tables.users.columns)
|
|
17
25
|
.map((name) => `'${name}', b.${name}`)
|
|
18
26
|
.join(', ');
|
|
27
|
+
const filterValue = filters?.type
|
|
28
|
+
? [typeof filters.type === 'string' ? filters.type : filters.type.$eq]
|
|
29
|
+
: [];
|
|
30
|
+
const createdAtSort = Array.isArray(sort)
|
|
31
|
+
? sort.find((s) => !!s.created_at)?.created_at
|
|
32
|
+
: sort?.created_at;
|
|
33
|
+
const orderByClause = createdAtSort
|
|
34
|
+
? `ORDER BY cast(strftime('%s', a.createdAt) AS INTEGER) ${createdAtSort === 1 ? 'ASC' : 'DESC'}`
|
|
35
|
+
: '';
|
|
19
36
|
|
|
20
37
|
SqliteClient.logger?.('info', 'selectReactionsForMessages', {
|
|
21
38
|
messageIds,
|
|
@@ -33,8 +50,10 @@ export const selectReactionsForMessages = async (
|
|
|
33
50
|
LEFT JOIN
|
|
34
51
|
users b
|
|
35
52
|
ON b.id = a.userId
|
|
36
|
-
WHERE a.messageId in (${questionMarks})
|
|
37
|
-
|
|
53
|
+
WHERE a.messageId in (${questionMarks}) ${filters?.type ? `AND a.type = ?` : ''}
|
|
54
|
+
${orderByClause}
|
|
55
|
+
${limit ? 'LIMIT ?' : ''}`,
|
|
56
|
+
[...messageIds, ...filterValue, ...(limit ? [limit] : [])],
|
|
38
57
|
);
|
|
39
58
|
|
|
40
59
|
return result.map((r) => JSON.parse(r.value));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MessageLabel } from 'stream-chat';
|
|
2
|
+
|
|
3
|
+
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
|
|
4
|
+
import { SqliteClient } from '../SqliteClient';
|
|
5
|
+
|
|
6
|
+
export const softDeleteMessage = async ({
|
|
7
|
+
execute = true,
|
|
8
|
+
id,
|
|
9
|
+
}: {
|
|
10
|
+
id: string;
|
|
11
|
+
execute?: boolean;
|
|
12
|
+
}) => {
|
|
13
|
+
const query = createUpdateQuery(
|
|
14
|
+
'messages',
|
|
15
|
+
{
|
|
16
|
+
deletedAt: new Date().toISOString(),
|
|
17
|
+
type: 'deleted' as MessageLabel,
|
|
18
|
+
},
|
|
19
|
+
{ id },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
SqliteClient.logger?.('info', 'softDeleteMessage', {
|
|
23
|
+
execute,
|
|
24
|
+
id,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (execute) {
|
|
28
|
+
await SqliteClient.executeSql.apply(null, query);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [query];
|
|
32
|
+
};
|
|
@@ -3,7 +3,6 @@ import type { LocalMessage, MessageResponse } from 'stream-chat';
|
|
|
3
3
|
import { mapMessageToStorable } from '../mappers/mapMessageToStorable';
|
|
4
4
|
import { mapReactionToStorable } from '../mappers/mapReactionToStorable';
|
|
5
5
|
import { mapUserToStorable } from '../mappers/mapUserToStorable';
|
|
6
|
-
import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
|
|
7
6
|
import { createSelectQuery } from '../sqlite-utils/createSelectQuery';
|
|
8
7
|
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
|
|
9
8
|
import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
|
|
@@ -11,11 +10,11 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
11
10
|
import type { PreparedQueries } from '../types';
|
|
12
11
|
|
|
13
12
|
export const updateMessage = async ({
|
|
14
|
-
|
|
13
|
+
execute = true,
|
|
15
14
|
message,
|
|
16
15
|
}: {
|
|
17
16
|
message: MessageResponse | LocalMessage;
|
|
18
|
-
|
|
17
|
+
execute?: boolean;
|
|
19
18
|
}) => {
|
|
20
19
|
const queries: PreparedQueries[] = [];
|
|
21
20
|
|
|
@@ -48,12 +47,6 @@ export const updateMessage = async ({
|
|
|
48
47
|
queries.push(createUpsertQuery('users', storableUser));
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
queries.push(
|
|
52
|
-
createDeleteQuery('reactions', {
|
|
53
|
-
messageId: message.id,
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
50
|
const latestReactions = message.latest_reactions || [];
|
|
58
51
|
const ownReactions = message.own_reactions || [];
|
|
59
52
|
|
|
@@ -77,7 +70,7 @@ export const updateMessage = async ({
|
|
|
77
70
|
users: storableUsers,
|
|
78
71
|
});
|
|
79
72
|
|
|
80
|
-
if (
|
|
73
|
+
if (execute) {
|
|
81
74
|
await SqliteClient.executeSqlBatch(queries);
|
|
82
75
|
}
|
|
83
76
|
|
|
@@ -3,19 +3,20 @@ import type { LocalMessage, MessageResponse, ReactionResponse } from 'stream-cha
|
|
|
3
3
|
import { mapMessageToStorable } from '../mappers/mapMessageToStorable';
|
|
4
4
|
import { mapReactionToStorable } from '../mappers/mapReactionToStorable';
|
|
5
5
|
import { mapUserToStorable } from '../mappers/mapUserToStorable';
|
|
6
|
+
import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
|
|
6
7
|
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
|
|
7
8
|
import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
|
|
8
9
|
import { SqliteClient } from '../SqliteClient';
|
|
9
10
|
import type { PreparedQueries } from '../types';
|
|
10
11
|
|
|
11
12
|
export const updateReaction = async ({
|
|
12
|
-
|
|
13
|
+
execute = true,
|
|
13
14
|
message,
|
|
14
15
|
reaction,
|
|
15
16
|
}: {
|
|
16
17
|
message: MessageResponse | LocalMessage;
|
|
17
18
|
reaction: ReactionResponse;
|
|
18
|
-
|
|
19
|
+
execute?: boolean;
|
|
19
20
|
}) => {
|
|
20
21
|
const queries: PreparedQueries[] = [];
|
|
21
22
|
let storableUser: ReturnType<typeof mapUserToStorable> | undefined;
|
|
@@ -28,11 +29,12 @@ export const updateReaction = async ({
|
|
|
28
29
|
const storableReaction = mapReactionToStorable(reaction);
|
|
29
30
|
|
|
30
31
|
queries.push(
|
|
31
|
-
|
|
32
|
+
createDeleteQuery('reactions', {
|
|
32
33
|
messageId: reaction.message_id,
|
|
33
34
|
userId: reaction.user_id,
|
|
34
35
|
}),
|
|
35
36
|
);
|
|
37
|
+
queries.push(createUpsertQuery('reactions', storableReaction));
|
|
36
38
|
|
|
37
39
|
let updatedReactionGroups: string | undefined;
|
|
38
40
|
if (message.reaction_groups) {
|
|
@@ -43,12 +45,12 @@ export const updateReaction = async ({
|
|
|
43
45
|
|
|
44
46
|
SqliteClient.logger?.('info', 'updateReaction', {
|
|
45
47
|
addedUser: storableUser,
|
|
46
|
-
|
|
48
|
+
execute,
|
|
47
49
|
updatedReaction: storableReaction,
|
|
48
50
|
updatedReactionGroups,
|
|
49
51
|
});
|
|
50
52
|
|
|
51
|
-
if (
|
|
53
|
+
if (execute) {
|
|
52
54
|
await SqliteClient.executeSqlBatch(queries);
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -6,25 +6,29 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
6
6
|
export const upsertAppSettings = async ({
|
|
7
7
|
appSettings,
|
|
8
8
|
currentUserId,
|
|
9
|
-
|
|
9
|
+
execute = true,
|
|
10
10
|
}: {
|
|
11
11
|
appSettings: AppSettingsAPIResponse;
|
|
12
12
|
currentUserId: string;
|
|
13
|
-
|
|
13
|
+
execute?: boolean;
|
|
14
14
|
}) => {
|
|
15
15
|
const storableAppSettings = JSON.stringify(appSettings);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const queries = [
|
|
17
|
+
createUpsertQuery('userSyncStatus', {
|
|
18
|
+
appSettings: storableAppSettings,
|
|
19
|
+
userId: currentUserId,
|
|
20
|
+
}),
|
|
21
|
+
];
|
|
20
22
|
|
|
21
23
|
SqliteClient.logger?.('info', 'upsertAppSettings', {
|
|
22
24
|
appSettings: storableAppSettings,
|
|
23
|
-
|
|
25
|
+
execute,
|
|
24
26
|
userId: currentUserId,
|
|
25
27
|
});
|
|
26
28
|
|
|
27
|
-
if (
|
|
28
|
-
await SqliteClient.
|
|
29
|
+
if (execute) {
|
|
30
|
+
await SqliteClient.executeSqlBatch(queries);
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
return queries;
|
|
30
34
|
};
|
|
@@ -6,19 +6,19 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
6
6
|
|
|
7
7
|
export const upsertChannelData = async ({
|
|
8
8
|
channel,
|
|
9
|
-
|
|
9
|
+
execute = true,
|
|
10
10
|
}: {
|
|
11
11
|
channel: ChannelResponse;
|
|
12
|
-
|
|
12
|
+
execute?: boolean;
|
|
13
13
|
}) => {
|
|
14
14
|
const storableChannel = mapChannelDataToStorable(channel);
|
|
15
15
|
const query = createUpsertQuery('channels', storableChannel);
|
|
16
16
|
SqliteClient.logger?.('info', 'upsertChannelData', {
|
|
17
17
|
channel: storableChannel,
|
|
18
|
-
|
|
18
|
+
execute,
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
if (
|
|
21
|
+
if (execute) {
|
|
22
22
|
await SqliteClient.executeSqlBatch([query]);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -6,17 +6,17 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
6
6
|
|
|
7
7
|
export const upsertChannelDataFromChannel = async ({
|
|
8
8
|
channel,
|
|
9
|
-
|
|
9
|
+
execute = true,
|
|
10
10
|
}: {
|
|
11
11
|
channel: Channel;
|
|
12
|
-
|
|
12
|
+
execute?: boolean;
|
|
13
13
|
}) => {
|
|
14
14
|
const storableChannel = mapChannelToStorable(channel);
|
|
15
15
|
if (!storableChannel) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
const query = createUpsertQuery('channels', storableChannel);
|
|
19
|
-
if (
|
|
19
|
+
if (execute) {
|
|
20
20
|
await SqliteClient.executeSqlBatch([query]);
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { ChannelAPIResponse,
|
|
1
|
+
import type { ChannelAPIResponse, ChannelMemberResponse } from 'stream-chat';
|
|
2
2
|
|
|
3
|
-
import { upsertCidsForQuery } from './upsertCidsForQuery';
|
|
4
3
|
import { upsertMembers } from './upsertMembers';
|
|
5
4
|
|
|
6
5
|
import { upsertMessages } from './upsertMessages';
|
|
@@ -13,16 +12,12 @@ import type { PreparedQueries } from '../types';
|
|
|
13
12
|
|
|
14
13
|
export const upsertChannels = async ({
|
|
15
14
|
channels,
|
|
16
|
-
|
|
17
|
-
flush = true,
|
|
15
|
+
execute = true,
|
|
18
16
|
isLatestMessagesSet,
|
|
19
|
-
sort,
|
|
20
17
|
}: {
|
|
21
18
|
channels: ChannelAPIResponse[];
|
|
22
|
-
|
|
23
|
-
flush?: boolean;
|
|
19
|
+
execute?: boolean;
|
|
24
20
|
isLatestMessagesSet?: boolean;
|
|
25
|
-
sort?: ChannelSort;
|
|
26
21
|
}) => {
|
|
27
22
|
// Update the database only if the query is provided.
|
|
28
23
|
let queries: PreparedQueries[] = [];
|
|
@@ -33,25 +28,20 @@ export const upsertChannels = async ({
|
|
|
33
28
|
channelIds,
|
|
34
29
|
});
|
|
35
30
|
|
|
36
|
-
if (filters || sort) {
|
|
37
|
-
queries = queries.concat(
|
|
38
|
-
await upsertCidsForQuery({
|
|
39
|
-
cids: channelIds,
|
|
40
|
-
filters,
|
|
41
|
-
flush: false,
|
|
42
|
-
sort,
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
31
|
for (const channel of channels) {
|
|
48
32
|
queries.push(createUpsertQuery('channels', mapChannelDataToStorable(channel.channel)));
|
|
49
33
|
|
|
50
|
-
const { members, messages, read } = channel;
|
|
34
|
+
const { members, membership, messages, read } = channel;
|
|
35
|
+
if (
|
|
36
|
+
membership &&
|
|
37
|
+
!members.includes((m: ChannelMemberResponse) => m.user?.id === membership.user?.id)
|
|
38
|
+
) {
|
|
39
|
+
members.push({ ...membership, user_id: membership.user?.id });
|
|
40
|
+
}
|
|
51
41
|
queries = queries.concat(
|
|
52
42
|
await upsertMembers({
|
|
53
43
|
cid: channel.channel.cid,
|
|
54
|
-
|
|
44
|
+
execute: false,
|
|
55
45
|
members,
|
|
56
46
|
}),
|
|
57
47
|
);
|
|
@@ -60,7 +50,7 @@ export const upsertChannels = async ({
|
|
|
60
50
|
queries = queries.concat(
|
|
61
51
|
await upsertReads({
|
|
62
52
|
cid: channel.channel.cid,
|
|
63
|
-
|
|
53
|
+
execute: false,
|
|
64
54
|
reads: read,
|
|
65
55
|
}),
|
|
66
56
|
);
|
|
@@ -69,14 +59,14 @@ export const upsertChannels = async ({
|
|
|
69
59
|
if (isLatestMessagesSet) {
|
|
70
60
|
queries = queries.concat(
|
|
71
61
|
await upsertMessages({
|
|
72
|
-
|
|
62
|
+
execute: false,
|
|
73
63
|
messages,
|
|
74
64
|
}),
|
|
75
65
|
);
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
68
|
|
|
79
|
-
if (
|
|
69
|
+
if (execute) {
|
|
80
70
|
await SqliteClient.executeSqlBatch(queries);
|
|
81
71
|
}
|
|
82
72
|
|
|
@@ -8,12 +8,12 @@ import { SqliteClient } from '../SqliteClient';
|
|
|
8
8
|
export const upsertCidsForQuery = async ({
|
|
9
9
|
cids,
|
|
10
10
|
filters,
|
|
11
|
-
|
|
11
|
+
execute = true,
|
|
12
12
|
sort,
|
|
13
13
|
}: {
|
|
14
14
|
cids: string[];
|
|
15
15
|
filters?: ChannelFilters;
|
|
16
|
-
|
|
16
|
+
execute?: boolean;
|
|
17
17
|
sort?: ChannelSort;
|
|
18
18
|
}) => {
|
|
19
19
|
// Update the database only if the query is provided.
|
|
@@ -26,11 +26,11 @@ export const upsertCidsForQuery = async ({
|
|
|
26
26
|
|
|
27
27
|
SqliteClient.logger?.('info', 'upsertCidsForQuery', {
|
|
28
28
|
cids: cidsString,
|
|
29
|
-
|
|
29
|
+
execute,
|
|
30
30
|
id,
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
if (
|
|
33
|
+
if (execute) {
|
|
34
34
|
await SqliteClient.executeSql.apply(null, query);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -8,12 +8,12 @@ import type { PreparedQueries } from '../types';
|
|
|
8
8
|
|
|
9
9
|
export const upsertMembers = async ({
|
|
10
10
|
cid,
|
|
11
|
-
|
|
11
|
+
execute = true,
|
|
12
12
|
members,
|
|
13
13
|
}: {
|
|
14
14
|
cid: string;
|
|
15
15
|
members: ChannelMemberResponse[];
|
|
16
|
-
|
|
16
|
+
execute?: boolean;
|
|
17
17
|
}) => {
|
|
18
18
|
const queries: PreparedQueries[] = [];
|
|
19
19
|
|
|
@@ -34,12 +34,12 @@ export const upsertMembers = async ({
|
|
|
34
34
|
|
|
35
35
|
SqliteClient.logger?.('info', 'upsertMembers', {
|
|
36
36
|
cid,
|
|
37
|
-
|
|
37
|
+
execute,
|
|
38
38
|
storableMembers,
|
|
39
39
|
storableUsers,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
if (
|
|
42
|
+
if (execute) {
|
|
43
43
|
await SqliteClient.executeSqlBatch(queries);
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -8,11 +8,11 @@ import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
|
|
|
8
8
|
import { SqliteClient } from '../SqliteClient';
|
|
9
9
|
|
|
10
10
|
export const upsertMessages = async ({
|
|
11
|
-
|
|
11
|
+
execute = true,
|
|
12
12
|
messages,
|
|
13
13
|
}: {
|
|
14
14
|
messages: MessageResponse[];
|
|
15
|
-
|
|
15
|
+
execute?: boolean;
|
|
16
16
|
}) => {
|
|
17
17
|
const storableMessages: Array<ReturnType<typeof mapMessageToStorable>> = [];
|
|
18
18
|
const storableUsers: Array<ReturnType<typeof mapUserToStorable>> = [];
|
|
@@ -45,14 +45,14 @@ export const upsertMessages = async ({
|
|
|
45
45
|
];
|
|
46
46
|
|
|
47
47
|
SqliteClient.logger?.('info', 'upsertMessages', {
|
|
48
|
-
|
|
48
|
+
execute,
|
|
49
49
|
messages: storableMessages,
|
|
50
50
|
polls: storablePolls,
|
|
51
51
|
reactions: storableReactions,
|
|
52
52
|
users: storableUsers,
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
if (
|
|
55
|
+
if (execute) {
|
|
56
56
|
await SqliteClient.executeSqlBatch(finalQueries);
|
|
57
57
|
}
|
|
58
58
|
|