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.
Files changed (409) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/components/Channel/Channel.js +214 -237
  3. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  4. package/lib/commonjs/components/ChannelList/ChannelList.js +2 -19
  5. package/lib/commonjs/components/ChannelList/ChannelList.js.map +1 -1
  6. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +48 -176
  7. package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  8. package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js +13 -2
  9. package/lib/commonjs/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
  10. package/lib/commonjs/components/Chat/Chat.js +33 -46
  11. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  12. package/lib/commonjs/components/Chat/hooks/useAppSettings.js +47 -120
  13. package/lib/commonjs/components/Chat/hooks/useAppSettings.js.map +1 -1
  14. package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js +0 -15
  15. package/lib/commonjs/components/Chat/hooks/useSyncDatabase.js.map +1 -1
  16. package/lib/commonjs/components/MessageMenu/MessageUserReactions.js +5 -0
  17. package/lib/commonjs/components/MessageMenu/MessageUserReactions.js.map +1 -1
  18. package/lib/commonjs/components/MessageMenu/hooks/useFetchReactions.js +92 -108
  19. package/lib/commonjs/components/MessageMenu/hooks/useFetchReactions.js.map +1 -1
  20. package/lib/commonjs/index.js +8 -0
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/mock-builders/event/channelVisible.js +13 -0
  23. package/lib/commonjs/mock-builders/event/channelVisible.js.map +1 -0
  24. package/lib/commonjs/mock-builders/event/memberAdded.js +4 -2
  25. package/lib/commonjs/mock-builders/event/memberAdded.js.map +1 -1
  26. package/lib/commonjs/mock-builders/event/memberRemoved.js +2 -1
  27. package/lib/commonjs/mock-builders/event/memberRemoved.js.map +1 -1
  28. package/lib/commonjs/mock-builders/event/memberUpdated.js +2 -1
  29. package/lib/commonjs/mock-builders/event/memberUpdated.js.map +1 -1
  30. package/lib/commonjs/mock-builders/event/messageNew.js +4 -2
  31. package/lib/commonjs/mock-builders/event/messageNew.js.map +1 -1
  32. package/lib/commonjs/mock-builders/event/messageRead.js +6 -3
  33. package/lib/commonjs/mock-builders/event/messageRead.js.map +1 -1
  34. package/lib/commonjs/mock-builders/event/notificationMarkUnread.js +3 -0
  35. package/lib/commonjs/mock-builders/event/notificationMarkUnread.js.map +1 -1
  36. package/lib/commonjs/mock-builders/generator/channel.js +10 -3
  37. package/lib/commonjs/mock-builders/generator/channel.js.map +1 -1
  38. package/lib/commonjs/store/OfflineDB.js +108 -0
  39. package/lib/commonjs/store/OfflineDB.js.map +1 -0
  40. package/lib/commonjs/store/SqliteClient.js +11 -10
  41. package/lib/commonjs/store/SqliteClient.js.map +1 -1
  42. package/lib/commonjs/store/apis/addPendingTask.js.map +1 -1
  43. package/lib/commonjs/store/apis/channelExists.js +34 -0
  44. package/lib/commonjs/store/apis/channelExists.js.map +1 -0
  45. package/lib/commonjs/store/apis/deleteChannel.js +4 -4
  46. package/lib/commonjs/store/apis/deleteChannel.js.map +1 -1
  47. package/lib/commonjs/store/apis/deleteMember.js +4 -4
  48. package/lib/commonjs/store/apis/deleteMember.js.map +1 -1
  49. package/lib/commonjs/store/apis/deleteMessage.js +16 -12
  50. package/lib/commonjs/store/apis/deleteMessage.js.map +1 -1
  51. package/lib/commonjs/store/apis/deleteMessagesForChannel.js +11 -12
  52. package/lib/commonjs/store/apis/deleteMessagesForChannel.js.map +1 -1
  53. package/lib/commonjs/store/apis/deleteReaction.js +29 -17
  54. package/lib/commonjs/store/apis/deleteReaction.js.map +1 -1
  55. package/lib/commonjs/store/apis/deleteReactions.js +4 -4
  56. package/lib/commonjs/store/apis/deleteReactions.js.map +1 -1
  57. package/lib/commonjs/store/apis/dropPendingTasks.js +41 -0
  58. package/lib/commonjs/store/apis/dropPendingTasks.js.map +1 -0
  59. package/lib/commonjs/store/apis/getChannelMessages.js +1 -1
  60. package/lib/commonjs/store/apis/getChannelMessages.js.map +1 -1
  61. package/lib/commonjs/store/apis/getChannels.js +18 -21
  62. package/lib/commonjs/store/apis/getChannels.js.map +1 -1
  63. package/lib/commonjs/store/apis/getLastSyncedAt.js +3 -9
  64. package/lib/commonjs/store/apis/getLastSyncedAt.js.map +1 -1
  65. package/lib/commonjs/store/apis/getReactionsforFilterSort.js +5 -8
  66. package/lib/commonjs/store/apis/getReactionsforFilterSort.js.map +1 -1
  67. package/lib/commonjs/store/apis/index.js +103 -4
  68. package/lib/commonjs/store/apis/index.js.map +1 -1
  69. package/lib/commonjs/store/apis/insertReaction.js +4 -4
  70. package/lib/commonjs/store/apis/insertReaction.js.map +1 -1
  71. package/lib/commonjs/store/apis/queries/selectMessagesForChannels.js +1 -1
  72. package/lib/commonjs/store/apis/queries/selectMessagesForChannels.js.map +1 -1
  73. package/lib/commonjs/store/apis/queries/selectReactionsForMessages.js +25 -5
  74. package/lib/commonjs/store/apis/queries/selectReactionsForMessages.js.map +1 -1
  75. package/lib/commonjs/store/apis/softDeleteMessage.js +45 -0
  76. package/lib/commonjs/store/apis/softDeleteMessage.js.map +1 -0
  77. package/lib/commonjs/store/apis/updateMessage.js +7 -11
  78. package/lib/commonjs/store/apis/updateMessage.js.map +1 -1
  79. package/lib/commonjs/store/apis/updateReaction.js +11 -9
  80. package/lib/commonjs/store/apis/updateReaction.js.map +1 -1
  81. package/lib/commonjs/store/apis/upsertAppSettings.js +9 -7
  82. package/lib/commonjs/store/apis/upsertAppSettings.js.map +1 -1
  83. package/lib/commonjs/store/apis/upsertChannelData.js +4 -4
  84. package/lib/commonjs/store/apis/upsertChannelData.js.map +1 -1
  85. package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js +3 -3
  86. package/lib/commonjs/store/apis/upsertChannelDataFromChannel.js.map +1 -1
  87. package/lib/commonjs/store/apis/upsertChannels.js +86 -83
  88. package/lib/commonjs/store/apis/upsertChannels.js.map +1 -1
  89. package/lib/commonjs/store/apis/upsertCidsForQuery.js +4 -4
  90. package/lib/commonjs/store/apis/upsertCidsForQuery.js.map +1 -1
  91. package/lib/commonjs/store/apis/upsertMembers.js +4 -4
  92. package/lib/commonjs/store/apis/upsertMembers.js.map +1 -1
  93. package/lib/commonjs/store/apis/upsertMessages.js +4 -4
  94. package/lib/commonjs/store/apis/upsertMessages.js.map +1 -1
  95. package/lib/commonjs/store/apis/upsertPoll.js +42 -0
  96. package/lib/commonjs/store/apis/upsertPoll.js.map +1 -0
  97. package/lib/commonjs/store/apis/upsertReads.js +4 -4
  98. package/lib/commonjs/store/apis/upsertReads.js.map +1 -1
  99. package/lib/commonjs/store/apis/upsertUserSyncStatus.js +13 -7
  100. package/lib/commonjs/store/apis/upsertUserSyncStatus.js.map +1 -1
  101. package/lib/commonjs/store/mappers/mapMemberToStorable.js +6 -2
  102. package/lib/commonjs/store/mappers/mapMemberToStorable.js.map +1 -1
  103. package/lib/commonjs/store/mappers/mapReadToStorable.js +3 -1
  104. package/lib/commonjs/store/mappers/mapReadToStorable.js.map +1 -1
  105. package/lib/commonjs/store/mappers/mapStorableToMember.js +5 -1
  106. package/lib/commonjs/store/mappers/mapStorableToMember.js.map +1 -1
  107. package/lib/commonjs/store/mappers/mapStorableToRead.js +3 -1
  108. package/lib/commonjs/store/mappers/mapStorableToRead.js.map +1 -1
  109. package/lib/commonjs/store/mappers/mapStorableToTask.js.map +1 -1
  110. package/lib/commonjs/store/schema.js +2 -0
  111. package/lib/commonjs/store/schema.js.map +1 -1
  112. package/lib/commonjs/utils/addReactionToLocalState.js +62 -81
  113. package/lib/commonjs/utils/addReactionToLocalState.js.map +1 -1
  114. package/lib/commonjs/utils/removeReactionFromLocalState.js +0 -6
  115. package/lib/commonjs/utils/removeReactionFromLocalState.js.map +1 -1
  116. package/lib/commonjs/version.json +1 -1
  117. package/lib/module/components/Channel/Channel.js +214 -237
  118. package/lib/module/components/Channel/Channel.js.map +1 -1
  119. package/lib/module/components/ChannelList/ChannelList.js +2 -19
  120. package/lib/module/components/ChannelList/ChannelList.js.map +1 -1
  121. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +48 -176
  122. package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
  123. package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js +13 -2
  124. package/lib/module/components/ChannelPreview/hooks/useIsChannelMuted.js.map +1 -1
  125. package/lib/module/components/Chat/Chat.js +33 -46
  126. package/lib/module/components/Chat/Chat.js.map +1 -1
  127. package/lib/module/components/Chat/hooks/useAppSettings.js +47 -120
  128. package/lib/module/components/Chat/hooks/useAppSettings.js.map +1 -1
  129. package/lib/module/components/Chat/hooks/useSyncDatabase.js +0 -15
  130. package/lib/module/components/Chat/hooks/useSyncDatabase.js.map +1 -1
  131. package/lib/module/components/MessageMenu/MessageUserReactions.js +5 -0
  132. package/lib/module/components/MessageMenu/MessageUserReactions.js.map +1 -1
  133. package/lib/module/components/MessageMenu/hooks/useFetchReactions.js +92 -108
  134. package/lib/module/components/MessageMenu/hooks/useFetchReactions.js.map +1 -1
  135. package/lib/module/index.js +8 -0
  136. package/lib/module/index.js.map +1 -1
  137. package/lib/module/mock-builders/event/channelVisible.js +13 -0
  138. package/lib/module/mock-builders/event/channelVisible.js.map +1 -0
  139. package/lib/module/mock-builders/event/memberAdded.js +4 -2
  140. package/lib/module/mock-builders/event/memberAdded.js.map +1 -1
  141. package/lib/module/mock-builders/event/memberRemoved.js +2 -1
  142. package/lib/module/mock-builders/event/memberRemoved.js.map +1 -1
  143. package/lib/module/mock-builders/event/memberUpdated.js +2 -1
  144. package/lib/module/mock-builders/event/memberUpdated.js.map +1 -1
  145. package/lib/module/mock-builders/event/messageNew.js +4 -2
  146. package/lib/module/mock-builders/event/messageNew.js.map +1 -1
  147. package/lib/module/mock-builders/event/messageRead.js +6 -3
  148. package/lib/module/mock-builders/event/messageRead.js.map +1 -1
  149. package/lib/module/mock-builders/event/notificationMarkUnread.js +3 -0
  150. package/lib/module/mock-builders/event/notificationMarkUnread.js.map +1 -1
  151. package/lib/module/mock-builders/generator/channel.js +10 -3
  152. package/lib/module/mock-builders/generator/channel.js.map +1 -1
  153. package/lib/module/store/OfflineDB.js +108 -0
  154. package/lib/module/store/OfflineDB.js.map +1 -0
  155. package/lib/module/store/SqliteClient.js +11 -10
  156. package/lib/module/store/SqliteClient.js.map +1 -1
  157. package/lib/module/store/apis/addPendingTask.js.map +1 -1
  158. package/lib/module/store/apis/channelExists.js +34 -0
  159. package/lib/module/store/apis/channelExists.js.map +1 -0
  160. package/lib/module/store/apis/deleteChannel.js +4 -4
  161. package/lib/module/store/apis/deleteChannel.js.map +1 -1
  162. package/lib/module/store/apis/deleteMember.js +4 -4
  163. package/lib/module/store/apis/deleteMember.js.map +1 -1
  164. package/lib/module/store/apis/deleteMessage.js +16 -12
  165. package/lib/module/store/apis/deleteMessage.js.map +1 -1
  166. package/lib/module/store/apis/deleteMessagesForChannel.js +11 -12
  167. package/lib/module/store/apis/deleteMessagesForChannel.js.map +1 -1
  168. package/lib/module/store/apis/deleteReaction.js +29 -17
  169. package/lib/module/store/apis/deleteReaction.js.map +1 -1
  170. package/lib/module/store/apis/deleteReactions.js +4 -4
  171. package/lib/module/store/apis/deleteReactions.js.map +1 -1
  172. package/lib/module/store/apis/dropPendingTasks.js +41 -0
  173. package/lib/module/store/apis/dropPendingTasks.js.map +1 -0
  174. package/lib/module/store/apis/getChannelMessages.js +1 -1
  175. package/lib/module/store/apis/getChannelMessages.js.map +1 -1
  176. package/lib/module/store/apis/getChannels.js +18 -21
  177. package/lib/module/store/apis/getChannels.js.map +1 -1
  178. package/lib/module/store/apis/getLastSyncedAt.js +3 -9
  179. package/lib/module/store/apis/getLastSyncedAt.js.map +1 -1
  180. package/lib/module/store/apis/getReactionsforFilterSort.js +5 -8
  181. package/lib/module/store/apis/getReactionsforFilterSort.js.map +1 -1
  182. package/lib/module/store/apis/index.js +103 -4
  183. package/lib/module/store/apis/index.js.map +1 -1
  184. package/lib/module/store/apis/insertReaction.js +4 -4
  185. package/lib/module/store/apis/insertReaction.js.map +1 -1
  186. package/lib/module/store/apis/queries/selectMessagesForChannels.js +1 -1
  187. package/lib/module/store/apis/queries/selectMessagesForChannels.js.map +1 -1
  188. package/lib/module/store/apis/queries/selectReactionsForMessages.js +25 -5
  189. package/lib/module/store/apis/queries/selectReactionsForMessages.js.map +1 -1
  190. package/lib/module/store/apis/softDeleteMessage.js +45 -0
  191. package/lib/module/store/apis/softDeleteMessage.js.map +1 -0
  192. package/lib/module/store/apis/updateMessage.js +7 -11
  193. package/lib/module/store/apis/updateMessage.js.map +1 -1
  194. package/lib/module/store/apis/updateReaction.js +11 -9
  195. package/lib/module/store/apis/updateReaction.js.map +1 -1
  196. package/lib/module/store/apis/upsertAppSettings.js +9 -7
  197. package/lib/module/store/apis/upsertAppSettings.js.map +1 -1
  198. package/lib/module/store/apis/upsertChannelData.js +4 -4
  199. package/lib/module/store/apis/upsertChannelData.js.map +1 -1
  200. package/lib/module/store/apis/upsertChannelDataFromChannel.js +3 -3
  201. package/lib/module/store/apis/upsertChannelDataFromChannel.js.map +1 -1
  202. package/lib/module/store/apis/upsertChannels.js +86 -83
  203. package/lib/module/store/apis/upsertChannels.js.map +1 -1
  204. package/lib/module/store/apis/upsertCidsForQuery.js +4 -4
  205. package/lib/module/store/apis/upsertCidsForQuery.js.map +1 -1
  206. package/lib/module/store/apis/upsertMembers.js +4 -4
  207. package/lib/module/store/apis/upsertMembers.js.map +1 -1
  208. package/lib/module/store/apis/upsertMessages.js +4 -4
  209. package/lib/module/store/apis/upsertMessages.js.map +1 -1
  210. package/lib/module/store/apis/upsertPoll.js +42 -0
  211. package/lib/module/store/apis/upsertPoll.js.map +1 -0
  212. package/lib/module/store/apis/upsertReads.js +4 -4
  213. package/lib/module/store/apis/upsertReads.js.map +1 -1
  214. package/lib/module/store/apis/upsertUserSyncStatus.js +13 -7
  215. package/lib/module/store/apis/upsertUserSyncStatus.js.map +1 -1
  216. package/lib/module/store/mappers/mapMemberToStorable.js +6 -2
  217. package/lib/module/store/mappers/mapMemberToStorable.js.map +1 -1
  218. package/lib/module/store/mappers/mapReadToStorable.js +3 -1
  219. package/lib/module/store/mappers/mapReadToStorable.js.map +1 -1
  220. package/lib/module/store/mappers/mapStorableToMember.js +5 -1
  221. package/lib/module/store/mappers/mapStorableToMember.js.map +1 -1
  222. package/lib/module/store/mappers/mapStorableToRead.js +3 -1
  223. package/lib/module/store/mappers/mapStorableToRead.js.map +1 -1
  224. package/lib/module/store/mappers/mapStorableToTask.js.map +1 -1
  225. package/lib/module/store/schema.js +2 -0
  226. package/lib/module/store/schema.js.map +1 -1
  227. package/lib/module/utils/addReactionToLocalState.js +62 -81
  228. package/lib/module/utils/addReactionToLocalState.js.map +1 -1
  229. package/lib/module/utils/removeReactionFromLocalState.js +0 -6
  230. package/lib/module/utils/removeReactionFromLocalState.js.map +1 -1
  231. package/lib/module/version.json +1 -1
  232. package/lib/typescript/components/Channel/Channel.d.ts +1 -1
  233. package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
  234. package/lib/typescript/components/Channel/hooks/useCreateThreadContext.d.ts.map +1 -1
  235. package/lib/typescript/components/ChannelList/ChannelList.d.ts.map +1 -1
  236. package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts +1 -1
  237. package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts.map +1 -1
  238. package/lib/typescript/components/ChannelPreview/hooks/useIsChannelMuted.d.ts.map +1 -1
  239. package/lib/typescript/components/Chat/Chat.d.ts.map +1 -1
  240. package/lib/typescript/components/Chat/hooks/useAppSettings.d.ts.map +1 -1
  241. package/lib/typescript/components/Chat/hooks/useSyncDatabase.d.ts +9 -1
  242. package/lib/typescript/components/Chat/hooks/useSyncDatabase.d.ts.map +1 -1
  243. package/lib/typescript/components/MessageMenu/MessageUserReactions.d.ts.map +1 -1
  244. package/lib/typescript/components/MessageMenu/hooks/useFetchReactions.d.ts.map +1 -1
  245. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +1 -1
  246. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts.map +1 -1
  247. package/lib/typescript/hooks/useTranslatedMessage.d.ts.map +1 -1
  248. package/lib/typescript/index.d.ts +1 -0
  249. package/lib/typescript/index.d.ts.map +1 -1
  250. package/lib/typescript/store/OfflineDB.d.ts +112 -0
  251. package/lib/typescript/store/OfflineDB.d.ts.map +1 -0
  252. package/lib/typescript/store/SqliteClient.d.ts +1 -1
  253. package/lib/typescript/store/SqliteClient.d.ts.map +1 -1
  254. package/lib/typescript/store/apis/addPendingTask.d.ts +1 -1
  255. package/lib/typescript/store/apis/addPendingTask.d.ts.map +1 -1
  256. package/lib/typescript/store/apis/channelExists.d.ts +4 -0
  257. package/lib/typescript/store/apis/channelExists.d.ts.map +1 -0
  258. package/lib/typescript/store/apis/deleteChannel.d.ts +2 -2
  259. package/lib/typescript/store/apis/deleteChannel.d.ts.map +1 -1
  260. package/lib/typescript/store/apis/deleteMember.d.ts +2 -2
  261. package/lib/typescript/store/apis/deleteMember.d.ts.map +1 -1
  262. package/lib/typescript/store/apis/deleteMessage.d.ts +3 -3
  263. package/lib/typescript/store/apis/deleteMessage.d.ts.map +1 -1
  264. package/lib/typescript/store/apis/deleteMessagesForChannel.d.ts +4 -3
  265. package/lib/typescript/store/apis/deleteMessagesForChannel.d.ts.map +1 -1
  266. package/lib/typescript/store/apis/deleteReaction.d.ts +7 -6
  267. package/lib/typescript/store/apis/deleteReaction.d.ts.map +1 -1
  268. package/lib/typescript/store/apis/deleteReactions.d.ts +2 -2
  269. package/lib/typescript/store/apis/deleteReactions.d.ts.map +1 -1
  270. package/lib/typescript/store/apis/dropPendingTasks.d.ts +16 -0
  271. package/lib/typescript/store/apis/dropPendingTasks.d.ts.map +1 -0
  272. package/lib/typescript/store/apis/getChannels.d.ts.map +1 -1
  273. package/lib/typescript/store/apis/getLastSyncedAt.d.ts +1 -1
  274. package/lib/typescript/store/apis/getLastSyncedAt.d.ts.map +1 -1
  275. package/lib/typescript/store/apis/getPendingTasks.d.ts +1 -1
  276. package/lib/typescript/store/apis/getPendingTasks.d.ts.map +1 -1
  277. package/lib/typescript/store/apis/getReactionsforFilterSort.d.ts +5 -3
  278. package/lib/typescript/store/apis/getReactionsforFilterSort.d.ts.map +1 -1
  279. package/lib/typescript/store/apis/index.d.ts +10 -1
  280. package/lib/typescript/store/apis/index.d.ts.map +1 -1
  281. package/lib/typescript/store/apis/insertReaction.d.ts +2 -2
  282. package/lib/typescript/store/apis/insertReaction.d.ts.map +1 -1
  283. package/lib/typescript/store/apis/queries/selectReactionsForMessages.d.ts +5 -1
  284. package/lib/typescript/store/apis/queries/selectReactionsForMessages.d.ts.map +1 -1
  285. package/lib/typescript/store/apis/softDeleteMessage.d.ts +5 -0
  286. package/lib/typescript/store/apis/softDeleteMessage.d.ts.map +1 -0
  287. package/lib/typescript/store/apis/updateMessage.d.ts +2 -2
  288. package/lib/typescript/store/apis/updateMessage.d.ts.map +1 -1
  289. package/lib/typescript/store/apis/updateReaction.d.ts +2 -2
  290. package/lib/typescript/store/apis/updateReaction.d.ts.map +1 -1
  291. package/lib/typescript/store/apis/upsertAppSettings.d.ts +3 -3
  292. package/lib/typescript/store/apis/upsertAppSettings.d.ts.map +1 -1
  293. package/lib/typescript/store/apis/upsertChannelData.d.ts +2 -2
  294. package/lib/typescript/store/apis/upsertChannelData.d.ts.map +1 -1
  295. package/lib/typescript/store/apis/upsertChannelDataFromChannel.d.ts +2 -2
  296. package/lib/typescript/store/apis/upsertChannelDataFromChannel.d.ts.map +1 -1
  297. package/lib/typescript/store/apis/upsertChannels.d.ts +3 -5
  298. package/lib/typescript/store/apis/upsertChannels.d.ts.map +1 -1
  299. package/lib/typescript/store/apis/upsertCidsForQuery.d.ts +2 -2
  300. package/lib/typescript/store/apis/upsertCidsForQuery.d.ts.map +1 -1
  301. package/lib/typescript/store/apis/upsertMembers.d.ts +2 -2
  302. package/lib/typescript/store/apis/upsertMembers.d.ts.map +1 -1
  303. package/lib/typescript/store/apis/upsertMessages.d.ts +2 -2
  304. package/lib/typescript/store/apis/upsertMessages.d.ts.map +1 -1
  305. package/lib/typescript/store/apis/upsertPoll.d.ts +7 -0
  306. package/lib/typescript/store/apis/upsertPoll.d.ts.map +1 -0
  307. package/lib/typescript/store/apis/upsertReads.d.ts +2 -2
  308. package/lib/typescript/store/apis/upsertReads.d.ts.map +1 -1
  309. package/lib/typescript/store/apis/upsertUserSyncStatus.d.ts +3 -2
  310. package/lib/typescript/store/apis/upsertUserSyncStatus.d.ts.map +1 -1
  311. package/lib/typescript/store/mappers/mapMemberToStorable.d.ts.map +1 -1
  312. package/lib/typescript/store/mappers/mapReadToStorable.d.ts.map +1 -1
  313. package/lib/typescript/store/mappers/mapStorableToMember.d.ts.map +1 -1
  314. package/lib/typescript/store/mappers/mapStorableToRead.d.ts.map +1 -1
  315. package/lib/typescript/store/mappers/mapStorableToTask.d.ts +2 -1
  316. package/lib/typescript/store/mappers/mapStorableToTask.d.ts.map +1 -1
  317. package/lib/typescript/store/mappers/mapTaskToStorable.d.ts +18 -10
  318. package/lib/typescript/store/mappers/mapTaskToStorable.d.ts.map +1 -1
  319. package/lib/typescript/store/schema.d.ts +3 -2
  320. package/lib/typescript/store/schema.d.ts.map +1 -1
  321. package/lib/typescript/utils/addReactionToLocalState.d.ts +1 -1
  322. package/lib/typescript/utils/addReactionToLocalState.d.ts.map +1 -1
  323. package/lib/typescript/utils/removeReactionFromLocalState.d.ts.map +1 -1
  324. package/package.json +5 -4
  325. package/src/__tests__/offline-support/offline-feature.js +894 -21
  326. package/src/__tests__/offline-support/optimistic-update.js +154 -44
  327. package/src/components/Channel/Channel.tsx +95 -118
  328. package/src/components/ChannelList/ChannelList.tsx +1 -23
  329. package/src/components/ChannelList/hooks/usePaginatedChannels.ts +9 -93
  330. package/src/components/ChannelPreview/hooks/useIsChannelMuted.ts +20 -2
  331. package/src/components/Chat/Chat.tsx +21 -45
  332. package/src/components/Chat/__tests__/Chat.test.js +21 -13
  333. package/src/components/Chat/hooks/useAppSettings.ts +17 -54
  334. package/src/components/Chat/hooks/useSyncDatabase.ts +11 -17
  335. package/src/components/MessageMenu/MessageUserReactions.tsx +7 -1
  336. package/src/components/MessageMenu/hooks/useFetchReactions.ts +68 -35
  337. package/src/contexts/messagesContext/MessagesContext.tsx +1 -1
  338. package/src/index.ts +1 -0
  339. package/src/mock-builders/event/channelVisible.js +7 -0
  340. package/src/mock-builders/event/memberAdded.js +3 -1
  341. package/src/mock-builders/event/memberRemoved.js +1 -0
  342. package/src/mock-builders/event/memberUpdated.js +1 -0
  343. package/src/mock-builders/event/messageNew.js +1 -0
  344. package/src/mock-builders/event/messageRead.js +5 -2
  345. package/src/mock-builders/event/notificationMarkUnread.js +3 -0
  346. package/src/mock-builders/generator/channel.ts +15 -3
  347. package/src/store/OfflineDB.ts +93 -0
  348. package/src/store/SqliteClient.ts +7 -1
  349. package/src/store/apis/addPendingTask.ts +2 -1
  350. package/src/store/apis/channelExists.ts +14 -0
  351. package/src/store/apis/deleteChannel.ts +9 -3
  352. package/src/store/apis/deleteMember.ts +4 -4
  353. package/src/store/apis/deleteMessage.ts +18 -8
  354. package/src/store/apis/deleteMessagesForChannel.ts +12 -8
  355. package/src/store/apis/deleteReaction.ts +39 -19
  356. package/src/store/apis/deleteReactions.ts +4 -4
  357. package/src/store/apis/dropPendingTasks.ts +32 -0
  358. package/src/store/apis/getChannelMessages.ts +1 -1
  359. package/src/store/apis/getChannels.ts +10 -7
  360. package/src/store/apis/getLastSyncedAt.ts +2 -5
  361. package/src/store/apis/getReactionsforFilterSort.ts +8 -7
  362. package/src/store/apis/index.ts +10 -1
  363. package/src/store/apis/insertReaction.ts +4 -4
  364. package/src/store/apis/queries/selectMessagesForChannels.ts +2 -2
  365. package/src/store/apis/queries/selectReactionsForMessages.ts +21 -2
  366. package/src/store/apis/softDeleteMessage.ts +32 -0
  367. package/src/store/apis/updateMessage.ts +3 -10
  368. package/src/store/apis/updateReaction.ts +7 -5
  369. package/src/store/apis/upsertAppSettings.ts +13 -9
  370. package/src/store/apis/upsertChannelData.ts +4 -4
  371. package/src/store/apis/upsertChannelDataFromChannel.ts +3 -3
  372. package/src/store/apis/upsertChannels.ts +14 -24
  373. package/src/store/apis/upsertCidsForQuery.ts +4 -4
  374. package/src/store/apis/upsertMembers.ts +4 -4
  375. package/src/store/apis/upsertMessages.ts +4 -4
  376. package/src/store/apis/upsertPoll.ts +29 -0
  377. package/src/store/apis/upsertReads.ts +4 -4
  378. package/src/store/apis/upsertUserSyncStatus.ts +13 -5
  379. package/src/store/mappers/mapMemberToStorable.ts +4 -0
  380. package/src/store/mappers/mapReadToStorable.ts +2 -1
  381. package/src/store/mappers/mapStorableToMember.ts +4 -0
  382. package/src/store/mappers/mapStorableToRead.ts +2 -1
  383. package/src/store/mappers/mapStorableToTask.ts +3 -1
  384. package/src/store/mappers/mapTaskToStorable.ts +1 -1
  385. package/src/store/schema.ts +5 -3
  386. package/src/utils/addReactionToLocalState.ts +9 -63
  387. package/src/utils/removeReactionFromLocalState.ts +0 -8
  388. package/src/version.json +1 -1
  389. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js +0 -406
  390. package/lib/commonjs/components/Chat/hooks/handleEventToSyncDB.js.map +0 -1
  391. package/lib/commonjs/store/apis/updatePollMessage.js +0 -84
  392. package/lib/commonjs/store/apis/updatePollMessage.js.map +0 -1
  393. package/lib/commonjs/utils/DBSyncManager.js +0 -470
  394. package/lib/commonjs/utils/DBSyncManager.js.map +0 -1
  395. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js +0 -406
  396. package/lib/module/components/Chat/hooks/handleEventToSyncDB.js.map +0 -1
  397. package/lib/module/store/apis/updatePollMessage.js +0 -84
  398. package/lib/module/store/apis/updatePollMessage.js.map +0 -1
  399. package/lib/module/utils/DBSyncManager.js +0 -470
  400. package/lib/module/utils/DBSyncManager.js.map +0 -1
  401. package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts +0 -4
  402. package/lib/typescript/components/Chat/hooks/handleEventToSyncDB.d.ts.map +0 -1
  403. package/lib/typescript/store/apis/updatePollMessage.d.ts +0 -10
  404. package/lib/typescript/store/apis/updatePollMessage.d.ts.map +0 -1
  405. package/lib/typescript/utils/DBSyncManager.d.ts +0 -50
  406. package/lib/typescript/utils/DBSyncManager.d.ts.map +0 -1
  407. package/src/components/Chat/hooks/handleEventToSyncDB.ts +0 -290
  408. package/src/store/apis/updatePollMessage.ts +0 -71
  409. 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 getMembers({ channelIds });
31
- const cidVsReads = await getReads({ channelIds });
32
- const cidVsMessages = await getChannelMessages({
33
- channelIds,
34
- currentUserId,
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<number | undefined> => {
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
- if (typeof result[0]?.lastSyncedAt === 'number') {
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
- currentMessageId,
16
+ messageId,
16
17
  filters,
17
18
  sort,
19
+ limit,
18
20
  }: {
19
- currentMessageId: string;
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([currentMessageId]);
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
- const filteredReactions = reactions.filter((reaction) => reaction.type === filters?.type);
41
-
42
- return getReactions({ reactions: filteredReactions });
43
+ return getReactions({ reactions });
43
44
  };
@@ -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 './updatePollMessage';
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
- flush = true,
10
+ execute = true,
11
11
  message,
12
12
  reaction,
13
13
  }: {
14
14
  message: MessageResponse | LocalMessage;
15
15
  reaction: ReactionResponse;
16
- flush?: boolean;
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
- flush,
37
+ execute,
38
38
  reaction: storableReaction,
39
39
  });
40
40
 
41
- if (flush) {
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 cast(strftime('%s', createdAt) AS INTEGER) DESC
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 cast(strftime('%s', a.createdAt) AS INTEGER) ASC`,
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
- messageIds,
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
- flush = true,
13
+ execute = true,
15
14
  message,
16
15
  }: {
17
16
  message: MessageResponse | LocalMessage;
18
- flush?: boolean;
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 (flush) {
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
- flush = true,
13
+ execute = true,
13
14
  message,
14
15
  reaction,
15
16
  }: {
16
17
  message: MessageResponse | LocalMessage;
17
18
  reaction: ReactionResponse;
18
- flush?: boolean;
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
- createUpdateQuery('reactions', storableReaction, {
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
- flush,
48
+ execute,
47
49
  updatedReaction: storableReaction,
48
50
  updatedReactionGroups,
49
51
  });
50
52
 
51
- if (flush) {
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
- flush = true,
9
+ execute = true,
10
10
  }: {
11
11
  appSettings: AppSettingsAPIResponse;
12
12
  currentUserId: string;
13
- flush?: boolean;
13
+ execute?: boolean;
14
14
  }) => {
15
15
  const storableAppSettings = JSON.stringify(appSettings);
16
- const query = createUpsertQuery('userSyncStatus', {
17
- appSettings: storableAppSettings,
18
- userId: currentUserId,
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
- flush,
25
+ execute,
24
26
  userId: currentUserId,
25
27
  });
26
28
 
27
- if (flush) {
28
- await SqliteClient.executeSql.apply(null, query);
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
- flush = true,
9
+ execute = true,
10
10
  }: {
11
11
  channel: ChannelResponse;
12
- flush?: boolean;
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
- flush,
18
+ execute,
19
19
  });
20
20
 
21
- if (flush) {
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
- flush = true,
9
+ execute = true,
10
10
  }: {
11
11
  channel: Channel;
12
- flush?: boolean;
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 (flush) {
19
+ if (execute) {
20
20
  await SqliteClient.executeSqlBatch([query]);
21
21
  }
22
22
 
@@ -1,6 +1,5 @@
1
- import type { ChannelAPIResponse, ChannelFilters, ChannelSort } from 'stream-chat';
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
- filters,
17
- flush = true,
15
+ execute = true,
18
16
  isLatestMessagesSet,
19
- sort,
20
17
  }: {
21
18
  channels: ChannelAPIResponse[];
22
- filters?: ChannelFilters;
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
- flush: false,
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
- flush: false,
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
- flush: false,
62
+ execute: false,
73
63
  messages,
74
64
  }),
75
65
  );
76
66
  }
77
67
  }
78
68
 
79
- if (flush) {
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
- flush = true,
11
+ execute = true,
12
12
  sort,
13
13
  }: {
14
14
  cids: string[];
15
15
  filters?: ChannelFilters;
16
- flush?: boolean;
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
- flush,
29
+ execute,
30
30
  id,
31
31
  });
32
32
 
33
- if (flush) {
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
- flush = true,
11
+ execute = true,
12
12
  members,
13
13
  }: {
14
14
  cid: string;
15
15
  members: ChannelMemberResponse[];
16
- flush?: boolean;
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
- flush,
37
+ execute,
38
38
  storableMembers,
39
39
  storableUsers,
40
40
  });
41
41
 
42
- if (flush) {
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
- flush = true,
11
+ execute = true,
12
12
  messages,
13
13
  }: {
14
14
  messages: MessageResponse[];
15
- flush?: boolean;
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
- flush,
48
+ execute,
49
49
  messages: storableMessages,
50
50
  polls: storablePolls,
51
51
  reactions: storableReactions,
52
52
  users: storableUsers,
53
53
  });
54
54
 
55
- if (flush) {
55
+ if (execute) {
56
56
  await SqliteClient.executeSqlBatch(finalQueries);
57
57
  }
58
58