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