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
@@ -3,7 +3,6 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { LocalMessage, ReactionResponse, ReactionSort } from 'stream-chat';
4
4
 
5
5
  import { useChatContext } from '../../../contexts/chatContext/ChatContext';
6
- import { getReactionsForFilterSort } from '../../../store/apis/getReactionsforFilterSort';
7
6
 
8
7
  export type UseFetchReactionParams = {
9
8
  limit?: number;
@@ -28,25 +27,10 @@ export const useFetchReactions = ({
28
27
  const sortString = useMemo(() => JSON.stringify(sort), [sort]);
29
28
 
30
29
  const fetchReactions = useCallback(async () => {
31
- const loadOfflineReactions = async () => {
32
- if (!messageId) {
33
- return;
34
- }
35
- const reactionsFromDB = await getReactionsForFilterSort({
36
- currentMessageId: messageId,
37
- filters: reactionType ? { type: reactionType } : {},
38
- sort,
39
- });
40
- if (reactionsFromDB) {
41
- setReactions(reactionsFromDB);
42
- setLoading(false);
43
- }
44
- };
45
-
46
- const loadOnlineReactions = async () => {
47
- if (!messageId) {
48
- return;
49
- }
30
+ if (!messageId) {
31
+ return;
32
+ }
33
+ try {
50
34
  const response = await client.queryReactions(
51
35
  messageId,
52
36
  reactionType ? { type: reactionType } : {},
@@ -54,38 +38,87 @@ export const useFetchReactions = ({
54
38
  { limit, next },
55
39
  );
56
40
  if (response) {
41
+ setReactions((prevReactions) =>
42
+ next ? [...prevReactions, ...response.reactions] : response.reactions,
43
+ );
57
44
  setNext(response.next);
58
- setReactions((prevReactions) => [...prevReactions, ...response.reactions]);
59
45
  setLoading(false);
60
46
  }
61
- };
62
-
63
- try {
64
- // TODO: Threads are not supported for the offline use case as we don't store the thread messages currently, and this will change in the future.
65
- if (enableOfflineSupport && !message?.parent_id) {
66
- await loadOfflineReactions();
67
- } else {
68
- await loadOnlineReactions();
69
- }
70
47
  } catch (error) {
71
48
  console.log('Error fetching reactions: ', error);
72
49
  }
73
50
  // eslint-disable-next-line react-hooks/exhaustive-deps
74
- }, [client, messageId, reactionType, sortString, next, enableOfflineSupport]);
51
+ }, [client, messageId, reactionType, sortString, next, limit, enableOfflineSupport]);
75
52
 
76
53
  const loadNextPage = useCallback(async () => {
77
54
  if (next) {
78
55
  await fetchReactions();
79
56
  }
80
- // eslint-disable-next-line react-hooks/exhaustive-deps
81
- }, [fetchReactions]);
57
+ }, [fetchReactions, next]);
82
58
 
83
59
  useEffect(() => {
84
60
  setReactions([]);
85
61
  setNext(undefined);
86
62
  fetchReactions();
87
- // eslint-disable-next-line react-hooks/exhaustive-deps
88
- }, [messageId, reactionType, sortString]);
63
+ }, [fetchReactions, messageId, reactionType, sortString]);
64
+
65
+ useEffect(() => {
66
+ const listeners: ReturnType<typeof client.on>[] = [];
67
+ listeners.push(
68
+ client.on('offline_reactions.queried', (event) => {
69
+ const { offlineReactions } = event;
70
+ if (offlineReactions) {
71
+ setReactions(offlineReactions);
72
+ setLoading(false);
73
+ setNext(undefined);
74
+ }
75
+ }),
76
+ );
77
+
78
+ listeners.push(
79
+ client.on('reaction.new', (event) => {
80
+ const { reaction } = event;
81
+
82
+ if (reaction && reaction.type === reactionType) {
83
+ setReactions((prevReactions) => [reaction, ...prevReactions]);
84
+ }
85
+ }),
86
+ );
87
+
88
+ listeners.push(
89
+ client.on('reaction.updated', (event) => {
90
+ const { reaction } = event;
91
+
92
+ if (reaction) {
93
+ if (reaction.type === reactionType) {
94
+ setReactions((prevReactions) => [reaction, ...prevReactions]);
95
+ } else {
96
+ setReactions((prevReactions) =>
97
+ prevReactions.filter((r) => r.user_id !== reaction.user_id),
98
+ );
99
+ }
100
+ }
101
+ }),
102
+ );
103
+
104
+ listeners.push(
105
+ client.on('reaction.deleted', (event) => {
106
+ const { reaction } = event;
107
+
108
+ if (reaction && reaction.type === reactionType) {
109
+ setReactions((prevReactions) =>
110
+ prevReactions.filter((r) => r.user_id !== reaction.user_id),
111
+ );
112
+ }
113
+ }),
114
+ );
115
+
116
+ return () => {
117
+ listeners.forEach((listener) => {
118
+ listener?.unsubscribe();
119
+ });
120
+ };
121
+ }, [client, reactionType]);
89
122
 
90
123
  return { loading, loadNextPage, reactions };
91
124
  };
@@ -107,7 +107,7 @@ export type MessagesContextValue = Pick<MessageContextValue, 'isMessageAIGenerat
107
107
  * Defaults to: [DateHeader](https://github.com/GetStream/stream-chat-react-native/blob/main/package/src/components/MessageList/DateHeader.tsx)
108
108
  **/
109
109
  DateHeader: React.ComponentType<DateHeaderProps>;
110
- deleteMessage: (message: LocalMessage) => Promise<void>;
110
+ deleteMessage: (message: LocalMessage, hardDelete?: boolean) => Promise<void>;
111
111
  deleteReaction: (type: string, messageId: string) => Promise<void>;
112
112
 
113
113
  /** Should keyboard be dismissed when messaged is touched */
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export { default as trTranslations } from './i18n/tr.json';
29
29
  export { default as heTranslations } from './i18n/he.json';
30
30
 
31
31
  export { SqliteClient } from './store/SqliteClient';
32
+ export { OfflineDB } from './store/OfflineDB';
32
33
  export { version } from './version.json';
33
34
 
34
35
  import { NativeHandlers } from './native';
@@ -0,0 +1,7 @@
1
+ export default (client, channel = {}) => {
2
+ client.dispatchEvent({
3
+ channel,
4
+ cid: channel.cid,
5
+ type: 'channel.visible',
6
+ });
7
+ };
@@ -1,8 +1,10 @@
1
1
  export default (client, member, channel = {}) => {
2
2
  client.dispatchEvent({
3
- channel,
3
+ channel_id: channel.id,
4
+ channel_type: channel.type,
4
5
  cid: channel.cid,
5
6
  member,
6
7
  type: 'member.added',
8
+ user: member.user,
7
9
  });
8
10
  };
@@ -4,5 +4,6 @@ export default (client, member, channel = {}) => {
4
4
  cid: channel.cid,
5
5
  member,
6
6
  type: 'member.removed',
7
+ user: member.user,
7
8
  });
8
9
  };
@@ -4,5 +4,6 @@ export default (client, member, channel = {}) => {
4
4
  cid: channel.cid,
5
5
  member,
6
6
  type: 'member.updated',
7
+ user: member.user,
7
8
  });
8
9
  };
@@ -6,5 +6,6 @@ export default (client, newMessage, channel = {}) => {
6
6
  cid: channel.cid,
7
7
  message: newMessage,
8
8
  type: 'message.new',
9
+ ...(newMessage.user ? { user: newMessage.user } : {}),
9
10
  });
10
11
  };
@@ -1,10 +1,13 @@
1
- export default (client, user, channel = {}) => {
1
+ export default (client, user, channel = {}, payload = {}) => {
2
+ const newDate = new Date();
2
3
  const event = {
3
4
  channel,
4
5
  cid: channel.cid,
5
- received_at: new Date(),
6
+ created_at: newDate,
7
+ received_at: newDate,
6
8
  type: 'message.read',
7
9
  user,
10
+ ...payload,
8
11
  };
9
12
  client.dispatchEvent(event);
10
13
 
@@ -1,7 +1,10 @@
1
1
  export default (client, channel = {}, payload = {}, user = {}) => {
2
+ const newDate = new Date();
2
3
  client.dispatchEvent({
3
4
  channel,
4
5
  cid: channel.cid,
6
+ created_at: newDate,
7
+ received_at: newDate,
5
8
  type: 'notification.mark_unread',
6
9
  user,
7
10
  ...payload,
@@ -97,10 +97,20 @@ export const generateChannelResponse = (
97
97
  channel?: Record<string, any>;
98
98
  id?: string;
99
99
  messages?: Record<string, any>[];
100
+ members?: Record<string, any>[];
101
+ read?: Record<string, any>[];
100
102
  type?: string;
101
- } = { channel: {}, id: uuidv4(), messages: [], type: 'messaging' },
103
+ } = { channel: {}, id: uuidv4(), members: [], messages: [], read: [], type: 'messaging' },
102
104
  ) => {
103
- const { channel = {}, id = uuidv4(), messages = [], type = 'messaging', ...rest } = customValues;
105
+ const {
106
+ channel = {},
107
+ id = uuidv4(),
108
+ messages = [],
109
+ members = [],
110
+ read,
111
+ type = 'messaging',
112
+ ...rest
113
+ } = customValues;
104
114
 
105
115
  const defaults = getChannelDefaults();
106
116
  return {
@@ -110,12 +120,14 @@ export const generateChannelResponse = (
110
120
  cid: `${type}:${id}`,
111
121
  ...channel,
112
122
  id,
123
+ member_count: members.length,
113
124
  type,
114
125
  user: generateUser(),
115
126
  },
116
127
  },
117
- members: [],
128
+ members,
118
129
  messages,
130
+ read,
119
131
  ...rest,
120
132
  };
121
133
  };
@@ -0,0 +1,93 @@
1
+ import { AbstractOfflineDB, StreamChat } from 'stream-chat';
2
+ import type {
3
+ DBGetAppSettingsType,
4
+ DBGetChannelsForQueryType,
5
+ DBGetChannelsType,
6
+ DBGetLastSyncedAtType,
7
+ DBUpsertAppSettingsType,
8
+ DBUpsertUserSyncStatusType,
9
+ } from 'stream-chat';
10
+
11
+ import * as api from './apis';
12
+ import { SqliteClient } from './SqliteClient';
13
+
14
+ export class OfflineDB extends AbstractOfflineDB {
15
+ constructor({ client }: { client: StreamChat }) {
16
+ super({ client });
17
+ }
18
+
19
+ upsertCidsForQuery = api.upsertCidsForQuery;
20
+
21
+ upsertChannels = api.upsertChannels;
22
+
23
+ // TODO: Rename currentUserId -> userId in the next major version as it is technically breaking.
24
+ upsertUserSyncStatus = ({ userId, lastSyncedAt, execute }: DBUpsertUserSyncStatusType) =>
25
+ api.upsertUserSyncStatus({ currentUserId: userId, execute, lastSyncedAt });
26
+
27
+ // TODO: Rename currentUserId -> userId in the next major version as it is technically breaking.
28
+ upsertAppSettings = ({ appSettings, userId, execute }: DBUpsertAppSettingsType) =>
29
+ api.upsertAppSettings({ appSettings, currentUserId: userId, execute });
30
+
31
+ upsertPoll = api.upsertPoll;
32
+
33
+ upsertChannelData = api.upsertChannelData;
34
+
35
+ upsertReads = api.upsertReads;
36
+
37
+ upsertMessages = api.upsertMessages;
38
+
39
+ upsertMembers = api.upsertMembers;
40
+
41
+ updateMessage = api.updateMessage;
42
+
43
+ // TODO: Rename currentUserId -> userId in the next major version as it is technically breaking.
44
+ getChannels = ({ cids, userId }: DBGetChannelsType) =>
45
+ api.getChannels({ channelIds: cids, currentUserId: userId });
46
+
47
+ // TODO: Rename currentUserId -> userId in the next major version as it is technically breaking.
48
+ getChannelsForQuery = ({ userId, filters, sort }: DBGetChannelsForQueryType) =>
49
+ api.getChannelsForFilterSort({ currentUserId: userId, filters, sort });
50
+
51
+ getAllChannelCids = api.getAllChannelIds;
52
+
53
+ // TODO: Rename currentUserId -> userId in the next major version as it is technically breaking.
54
+ getLastSyncedAt = ({ userId }: DBGetLastSyncedAtType) =>
55
+ api.getLastSyncedAt({ currentUserId: userId });
56
+
57
+ getAppSettings = ({ userId }: DBGetAppSettingsType) =>
58
+ api.getAppSettings({ currentUserId: userId });
59
+
60
+ getReactions = api.getReactionsForFilterSort;
61
+
62
+ addPendingTask = api.addPendingTask;
63
+
64
+ deletePendingTask = api.deletePendingTask;
65
+
66
+ deleteReaction = api.deleteReaction;
67
+
68
+ deleteMember = api.deleteMember;
69
+
70
+ deleteChannel = api.deleteChannel;
71
+
72
+ deleteMessagesForChannel = api.deleteMessagesForChannel;
73
+
74
+ dropPendingTasks = api.dropPendingTasks;
75
+
76
+ hardDeleteMessage = api.deleteMessage;
77
+
78
+ softDeleteMessage = api.softDeleteMessage;
79
+
80
+ getPendingTasks = api.getPendingTasks;
81
+
82
+ updateReaction = api.updateReaction;
83
+
84
+ insertReaction = api.insertReaction;
85
+
86
+ channelExists = api.channelExists;
87
+
88
+ resetDB = SqliteClient.resetDB;
89
+
90
+ executeSqlBatch = SqliteClient.executeSqlBatch;
91
+
92
+ initializeDB = SqliteClient.initializeDatabase;
93
+ }
@@ -28,7 +28,7 @@ import type { PreparedBatchQueries, PreparedQueries, Scalar, Table } from './typ
28
28
  * This way usage @op-engineering/op-sqlite package is scoped to a single class/file.
29
29
  */
30
30
  export class SqliteClient {
31
- static dbVersion = 8;
31
+ static dbVersion = 9;
32
32
 
33
33
  static dbName = DB_NAME;
34
34
  static dbLocation = DB_LOCATION;
@@ -96,6 +96,7 @@ export class SqliteClient {
96
96
  });
97
97
  await this.db.executeBatch(finalQueries);
98
98
  } catch (e) {
99
+ this.db?.execute('ROLLBACK');
99
100
  this.logger?.('error', 'SqlBatch queries failed', {
100
101
  error: e,
101
102
  queries,
@@ -164,6 +165,7 @@ export class SqliteClient {
164
165
  await SqliteClient.dropTables();
165
166
  await SqliteClient.updateUserPragmaVersion(SqliteClient.dbVersion);
166
167
  }
168
+
167
169
  SqliteClient.logger?.('info', 'create tables if not exists', {
168
170
  tables: Object.keys(tables),
169
171
  });
@@ -176,6 +178,8 @@ export class SqliteClient {
176
178
  );
177
179
 
178
180
  await SqliteClient.executeSqlBatch(q);
181
+
182
+ return true;
179
183
  } catch (e) {
180
184
  console.log('Error initializing DB', e);
181
185
  this.logger?.('error', 'Error initializing DB', {
@@ -183,6 +187,8 @@ export class SqliteClient {
183
187
  dbname: SqliteClient.dbName,
184
188
  error: e,
185
189
  });
190
+
191
+ return false;
186
192
  }
187
193
  };
188
194
 
@@ -1,8 +1,9 @@
1
+ import type { PendingTask } from 'stream-chat';
2
+
1
3
  import { mapTaskToStorable } from '../mappers/mapTaskToStorable';
2
4
  import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
3
5
  import { createUpsertQuery } from '../sqlite-utils/createUpsertQuery';
4
6
  import { SqliteClient } from '../SqliteClient';
5
- import type { PendingTask } from '../types';
6
7
 
7
8
  /*
8
9
  * addPendingTask - Adds a pending task to the database
@@ -0,0 +1,14 @@
1
+ import { SqliteClient } from '../SqliteClient';
2
+
3
+ export const channelExists = async ({ cid }: { cid: string }) => {
4
+ const channels = await SqliteClient.executeSql(
5
+ 'SELECT EXISTS(SELECT 1 FROM channels WHERE cid = ?)',
6
+ [cid],
7
+ );
8
+
9
+ SqliteClient.logger?.('info', 'channelExists', {
10
+ cid,
11
+ });
12
+
13
+ return channels.length > 0;
14
+ };
@@ -1,17 +1,23 @@
1
1
  import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
2
2
  import { SqliteClient } from '../SqliteClient';
3
3
 
4
- export const deleteChannel = async ({ cid, flush = true }: { cid: string; flush?: boolean }) => {
4
+ export const deleteChannel = async ({
5
+ cid,
6
+ execute = true,
7
+ }: {
8
+ cid: string;
9
+ execute?: boolean;
10
+ }) => {
5
11
  const query = createDeleteQuery('channels', {
6
12
  cid,
7
13
  });
8
14
 
9
15
  SqliteClient.logger?.('info', 'deleteChannel', {
10
16
  cid,
11
- flush,
17
+ execute,
12
18
  });
13
19
 
14
- if (flush) {
20
+ if (execute) {
15
21
  await SqliteClient.executeSql.apply(null, query);
16
22
  }
17
23
 
@@ -5,12 +5,12 @@ import { SqliteClient } from '../SqliteClient';
5
5
 
6
6
  export const deleteMember = async ({
7
7
  cid,
8
- flush = true,
8
+ execute = true,
9
9
  member,
10
10
  }: {
11
11
  cid: string;
12
12
  member: ChannelMemberResponse;
13
- flush?: boolean;
13
+ execute?: boolean;
14
14
  }) => {
15
15
  const query = createDeleteQuery('members', {
16
16
  cid,
@@ -19,11 +19,11 @@ export const deleteMember = async ({
19
19
 
20
20
  SqliteClient.logger?.('info', 'deleteMember', {
21
21
  cid,
22
- flush,
22
+ execute,
23
23
  userId: member.user_id,
24
24
  });
25
25
 
26
- if (flush) {
26
+ if (execute) {
27
27
  await SqliteClient.executeSql.apply(null, query);
28
28
  }
29
29
 
@@ -1,19 +1,29 @@
1
1
  import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
2
2
  import { SqliteClient } from '../SqliteClient';
3
3
 
4
- export const deleteMessage = async ({ flush = true, id }: { id: string; flush?: boolean }) => {
5
- const query = createDeleteQuery('messages', {
6
- id,
7
- });
4
+ export const deleteMessage = async ({ execute = true, id }: { id: string; execute?: boolean }) => {
5
+ const queries = [];
6
+
7
+ queries.push(
8
+ createDeleteQuery('reactions', {
9
+ messageId: id,
10
+ }),
11
+ );
12
+
13
+ queries.push(
14
+ createDeleteQuery('messages', {
15
+ id,
16
+ }),
17
+ );
8
18
 
9
19
  SqliteClient.logger?.('info', 'deleteMessage', {
10
- flush,
20
+ execute,
11
21
  id,
12
22
  });
13
23
 
14
- if (flush) {
15
- await SqliteClient.executeSql.apply(null, query);
24
+ if (execute) {
25
+ await SqliteClient.executeSqlBatch(queries);
16
26
  }
17
27
 
18
- return [query];
28
+ return queries;
19
29
  };
@@ -1,23 +1,27 @@
1
- import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
2
1
  import { SqliteClient } from '../SqliteClient';
3
2
 
4
3
  export const deleteMessagesForChannel = async ({
5
4
  cid,
6
- flush = true,
5
+ truncated_at,
6
+ execute = true,
7
7
  }: {
8
8
  cid: string;
9
- flush?: boolean;
9
+ truncated_at?: string;
10
+ execute?: boolean;
10
11
  }) => {
11
- const query = createDeleteQuery('messages', {
12
- cid,
13
- });
12
+ const timestamp = truncated_at ? new Date(truncated_at).toISOString() : new Date().toISOString();
13
+ const query: [string, (string | number)[]] = [
14
+ `DELETE FROM messages WHERE cid = ? AND createdAt <= ?`,
15
+ [cid, timestamp],
16
+ ];
14
17
 
15
18
  SqliteClient.logger?.('info', 'deleteMessagesForChannel', {
16
19
  cid,
17
- flush,
20
+ execute,
21
+ truncated_at,
18
22
  });
19
23
 
20
- if (flush) {
24
+ if (execute) {
21
25
  await SqliteClient.executeSql.apply(null, query);
22
26
  }
23
27
 
@@ -1,32 +1,52 @@
1
+ import { FormatMessageResponse, MessageResponse, ReactionResponse } from 'stream-chat';
2
+
1
3
  import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
4
+ import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
2
5
  import { SqliteClient } from '../SqliteClient';
6
+ import { PreparedQueries } from '../types';
3
7
 
4
8
  export const deleteReaction = async ({
5
- flush = true,
6
- messageId,
7
- reactionType,
8
- userId,
9
+ execute = true,
10
+ message,
11
+ reaction,
9
12
  }: {
10
- messageId: string;
11
- reactionType: string;
12
- userId: string;
13
- flush?: boolean;
13
+ reaction: ReactionResponse;
14
+ message?: MessageResponse | FormatMessageResponse;
15
+ execute?: boolean;
14
16
  }) => {
15
- const query = createDeleteQuery('reactions', {
16
- messageId,
17
- type: reactionType,
18
- userId,
19
- });
17
+ const queries: PreparedQueries[] = [];
18
+
19
+ if (!message) {
20
+ return [];
21
+ }
22
+
23
+ queries.push(
24
+ createDeleteQuery('reactions', {
25
+ messageId: reaction.message_id,
26
+ type: reaction.type,
27
+ userId: reaction.user_id,
28
+ }),
29
+ );
30
+
31
+ const stringifiedNewReactionGroups = JSON.stringify(message.reaction_groups);
32
+
33
+ queries.push(
34
+ createUpdateQuery(
35
+ 'messages',
36
+ {
37
+ reactionGroups: stringifiedNewReactionGroups,
38
+ },
39
+ { id: message.id },
40
+ ),
41
+ );
20
42
 
21
43
  SqliteClient.logger?.('info', 'deleteReaction', {
22
- messageId,
23
- type: reactionType,
24
- userId,
44
+ reaction,
25
45
  });
26
46
 
27
- if (flush) {
28
- await SqliteClient.executeSql.apply(null, query);
47
+ if (execute) {
48
+ await SqliteClient.executeSqlBatch(queries);
29
49
  }
30
50
 
31
- return [query];
51
+ return queries;
32
52
  };
@@ -2,20 +2,20 @@ import { createDeleteQuery } from '../sqlite-utils/createDeleteQuery';
2
2
  import { SqliteClient } from '../SqliteClient';
3
3
 
4
4
  export const deleteReactionsForMessage = async ({
5
- flush = true,
5
+ execute = true,
6
6
  messageId,
7
7
  }: {
8
8
  messageId: string;
9
- flush?: boolean;
9
+ execute?: boolean;
10
10
  }) => {
11
11
  const query = createDeleteQuery('reactions', {
12
12
  messageId,
13
13
  });
14
14
  console.log('deleteReactionsForMessage', {
15
- flush,
15
+ execute,
16
16
  messageId,
17
17
  });
18
- if (flush) {
18
+ if (execute) {
19
19
  await SqliteClient.executeSql.apply(null, query);
20
20
  }
21
21