@ethora/chat-component-rn 26.8.1 → 26.8.2

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 (604) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/README.md +43 -10
  3. package/lib/commonjs/assets/icons.js +7 -2
  4. package/lib/commonjs/assets/icons.js.map +1 -1
  5. package/lib/commonjs/components/AuthForms/Login.js +4 -4
  6. package/lib/commonjs/components/AuthForms/Login.js.map +1 -1
  7. package/lib/commonjs/components/Header/HeaderRoomList.js +29 -8
  8. package/lib/commonjs/components/Header/HeaderRoomList.js.map +1 -1
  9. package/lib/commonjs/components/MainComponents/ChatHeader.js +9 -3
  10. package/lib/commonjs/components/MainComponents/ChatHeader.js.map +1 -1
  11. package/lib/commonjs/components/MainComponents/ChatRoom.js +150 -14
  12. package/lib/commonjs/components/MainComponents/ChatRoom.js.map +1 -1
  13. package/lib/commonjs/components/MainComponents/ChatWrapper.js +34 -13
  14. package/lib/commonjs/components/MainComponents/ChatWrapper.js.map +1 -1
  15. package/lib/commonjs/components/MainComponents/LoginWrapper.js +2 -1
  16. package/lib/commonjs/components/MainComponents/LoginWrapper.js.map +1 -1
  17. package/lib/commonjs/components/MainComponents/MediaMessage.js +29 -9
  18. package/lib/commonjs/components/MainComponents/MediaMessage.js.map +1 -1
  19. package/lib/commonjs/components/MainComponents/MessageContainer.js +5 -1
  20. package/lib/commonjs/components/MainComponents/MessageContainer.js.map +1 -1
  21. package/lib/commonjs/components/MainComponents/MessageList.js +13 -5
  22. package/lib/commonjs/components/MainComponents/MessageList.js.map +1 -1
  23. package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js +14 -13
  24. package/lib/commonjs/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
  25. package/lib/commonjs/components/MainComponents/RoomList.js +208 -35
  26. package/lib/commonjs/components/MainComponents/RoomList.js.map +1 -1
  27. package/lib/commonjs/components/Menu/HeaderRoomListMenu.js +317 -98
  28. package/lib/commonjs/components/Menu/HeaderRoomListMenu.js.map +1 -1
  29. package/lib/commonjs/components/Modals/AttachSheet/AttachSheet.js +322 -110
  30. package/lib/commonjs/components/Modals/AttachSheet/AttachSheet.js.map +1 -1
  31. package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js +546 -203
  32. package/lib/commonjs/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
  33. package/lib/commonjs/components/Modals/ChatProfileModal/ReportChatModal.js +226 -0
  34. package/lib/commonjs/components/Modals/ChatProfileModal/ReportChatModal.js.map +1 -0
  35. package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js +69 -27
  36. package/lib/commonjs/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
  37. package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js +2 -1
  38. package/lib/commonjs/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
  39. package/lib/commonjs/components/Modals/Modal/Modal.js +8 -0
  40. package/lib/commonjs/components/Modals/Modal/Modal.js.map +1 -1
  41. package/lib/commonjs/components/Modals/NewChatModal/ModalContent.js +2 -1
  42. package/lib/commonjs/components/Modals/NewChatModal/ModalContent.js.map +1 -1
  43. package/lib/commonjs/components/Modals/NewChatModal/NewChatModal.js +202 -106
  44. package/lib/commonjs/components/Modals/NewChatModal/NewChatModal.js.map +1 -1
  45. package/lib/commonjs/components/Modals/NewChatModal/UpdNewChatModal.js +8 -0
  46. package/lib/commonjs/components/Modals/NewChatModal/UpdNewChatModal.js.map +1 -1
  47. package/lib/commonjs/components/Modals/ProfileHeader/ProfileHeader.js +563 -0
  48. package/lib/commonjs/components/Modals/ProfileHeader/ProfileHeader.js.map +1 -0
  49. package/lib/commonjs/components/Modals/ProfileHeader/ProfileMenu.js +210 -0
  50. package/lib/commonjs/components/Modals/ProfileHeader/ProfileMenu.js.map +1 -0
  51. package/lib/commonjs/components/Modals/SelectUsersModal/SelectUsersModal.js +4 -2
  52. package/lib/commonjs/components/Modals/SelectUsersModal/SelectUsersModal.js.map +1 -1
  53. package/lib/commonjs/components/Modals/UserProfileModal/EditUserModal.js +7 -21
  54. package/lib/commonjs/components/Modals/UserProfileModal/EditUserModal.js.map +1 -1
  55. package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js +507 -244
  56. package/lib/commonjs/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
  57. package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js +74 -46
  58. package/lib/commonjs/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
  59. package/lib/commonjs/components/Modals/styledModalComponents.js +9 -2
  60. package/lib/commonjs/components/Modals/styledModalComponents.js.map +1 -1
  61. package/lib/commonjs/components/RoomComponents/ChatRoomItem.js +21 -7
  62. package/lib/commonjs/components/RoomComponents/ChatRoomItem.js.map +1 -1
  63. package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js +22 -3
  64. package/lib/commonjs/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
  65. package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js +17 -3
  66. package/lib/commonjs/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
  67. package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js +17 -3
  68. package/lib/commonjs/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
  69. package/lib/commonjs/components/VideoCalls/VideoCallSession.js +6 -3
  70. package/lib/commonjs/components/VideoCalls/VideoCallSession.js.map +1 -1
  71. package/lib/commonjs/components/styled/AudioMessage.js +2 -1
  72. package/lib/commonjs/components/styled/AudioMessage.js.map +1 -1
  73. package/lib/commonjs/components/styled/MessageImage.js +37 -9
  74. package/lib/commonjs/components/styled/MessageImage.js.map +1 -1
  75. package/lib/commonjs/components/styled/SendInput.js +80 -11
  76. package/lib/commonjs/components/styled/SendInput.js.map +1 -1
  77. package/lib/commonjs/components/styled/StyledComponents.js +9 -3
  78. package/lib/commonjs/components/styled/StyledComponents.js.map +1 -1
  79. package/lib/commonjs/components/styled/StyledInputComponents/StyledInputComponents.js +11 -4
  80. package/lib/commonjs/components/styled/StyledInputComponents/StyledInputComponents.js.map +1 -1
  81. package/lib/commonjs/components/styled/UnsupportedType.js +14 -4
  82. package/lib/commonjs/components/styled/UnsupportedType.js.map +1 -1
  83. package/lib/commonjs/components/styled/VideoMessage.js +119 -61
  84. package/lib/commonjs/components/styled/VideoMessage.js.map +1 -1
  85. package/lib/commonjs/context/xmppProvider.js +184 -59
  86. package/lib/commonjs/context/xmppProvider.js.map +1 -1
  87. package/lib/commonjs/helpers/createMessageFromXml.js +19 -1
  88. package/lib/commonjs/helpers/createMessageFromXml.js.map +1 -1
  89. package/lib/commonjs/helpers/ensureScopedChatCache.js +2 -2
  90. package/lib/commonjs/helpers/ensureScopedChatCache.js.map +1 -1
  91. package/lib/commonjs/helpers/getChatBackground.js +23 -0
  92. package/lib/commonjs/helpers/getChatBackground.js.map +1 -0
  93. package/lib/commonjs/helpers/getDisplayFileName.js +79 -0
  94. package/lib/commonjs/helpers/getDisplayFileName.js.map +1 -0
  95. package/lib/commonjs/helpers/getServerReadTimestamp.js +188 -0
  96. package/lib/commonjs/helpers/getServerReadTimestamp.js.map +1 -0
  97. package/lib/commonjs/helpers/historyPreloadScheduler.js +65 -2
  98. package/lib/commonjs/helpers/historyPreloadScheduler.js.map +1 -1
  99. package/lib/commonjs/helpers/initXmppRooms.js +14 -8
  100. package/lib/commonjs/helpers/initXmppRooms.js.map +1 -1
  101. package/lib/commonjs/helpers/insertMessageWithDelimiter.js +51 -9
  102. package/lib/commonjs/helpers/insertMessageWithDelimiter.js.map +1 -1
  103. package/lib/commonjs/helpers/isOwnMessage.js +75 -0
  104. package/lib/commonjs/helpers/isOwnMessage.js.map +1 -0
  105. package/lib/commonjs/helpers/keyboardLayout.js +12 -2
  106. package/lib/commonjs/helpers/keyboardLayout.js.map +1 -1
  107. package/lib/commonjs/helpers/mediaLibraryRuntime.js +31 -0
  108. package/lib/commonjs/helpers/mediaLibraryRuntime.js.map +1 -0
  109. package/lib/commonjs/helpers/mimeToExtension.js +6 -14
  110. package/lib/commonjs/helpers/mimeToExtension.js.map +1 -1
  111. package/lib/commonjs/helpers/msgSortableMs.js +37 -0
  112. package/lib/commonjs/helpers/msgSortableMs.js.map +1 -0
  113. package/lib/commonjs/helpers/persistCrypto.js +122 -0
  114. package/lib/commonjs/helpers/persistCrypto.js.map +1 -0
  115. package/lib/commonjs/helpers/pickImageAsset.js +68 -0
  116. package/lib/commonjs/helpers/pickImageAsset.js.map +1 -0
  117. package/lib/commonjs/helpers/pushPayload.js +71 -0
  118. package/lib/commonjs/helpers/pushPayload.js.map +1 -0
  119. package/lib/commonjs/helpers/resolveInitBeforeLoadUser.js +130 -17
  120. package/lib/commonjs/helpers/resolveInitBeforeLoadUser.js.map +1 -1
  121. package/lib/commonjs/helpers/secureFileUrl.js +101 -0
  122. package/lib/commonjs/helpers/secureFileUrl.js.map +1 -0
  123. package/lib/commonjs/helpers/secureKeyValue.js +83 -0
  124. package/lib/commonjs/helpers/secureKeyValue.js.map +1 -0
  125. package/lib/commonjs/helpers/secureStoreRuntime.js +59 -0
  126. package/lib/commonjs/helpers/secureStoreRuntime.js.map +1 -0
  127. package/lib/commonjs/helpers/secureUserStorage.js +75 -0
  128. package/lib/commonjs/helpers/secureUserStorage.js.map +1 -0
  129. package/lib/commonjs/helpers/shallowEqual.js +36 -0
  130. package/lib/commonjs/helpers/shallowEqual.js.map +1 -0
  131. package/lib/commonjs/helpers/sheetGestures.js +32 -0
  132. package/lib/commonjs/helpers/sheetGestures.js.map +1 -0
  133. package/lib/commonjs/hooks/useChatRoomFocus.js +45 -12
  134. package/lib/commonjs/hooks/useChatRoomFocus.js.map +1 -1
  135. package/lib/commonjs/hooks/useChatWrapperInit.js +30 -10
  136. package/lib/commonjs/hooks/useChatWrapperInit.js.map +1 -1
  137. package/lib/commonjs/hooks/useComposing.js +27 -0
  138. package/lib/commonjs/hooks/useComposing.js.map +1 -1
  139. package/lib/commonjs/hooks/useFileToken.js +10 -0
  140. package/lib/commonjs/hooks/useFileToken.js.map +1 -0
  141. package/lib/commonjs/hooks/useLogout.js +23 -7
  142. package/lib/commonjs/hooks/useLogout.js.map +1 -1
  143. package/lib/commonjs/hooks/usePendingNotification.js +8 -11
  144. package/lib/commonjs/hooks/usePendingNotification.js.map +1 -1
  145. package/lib/commonjs/hooks/useSendMessage.js +50 -14
  146. package/lib/commonjs/hooks/useSendMessage.js.map +1 -1
  147. package/lib/commonjs/hooks/useUnreadMessagesCounter.js +6 -1
  148. package/lib/commonjs/hooks/useUnreadMessagesCounter.js.map +1 -1
  149. package/lib/commonjs/i18n/strings.js +145 -37
  150. package/lib/commonjs/i18n/strings.js.map +1 -1
  151. package/lib/commonjs/main.js +44 -0
  152. package/lib/commonjs/main.js.map +1 -1
  153. package/lib/commonjs/networking/api-requests/auth.api.js +134 -60
  154. package/lib/commonjs/networking/api-requests/auth.api.js.map +1 -1
  155. package/lib/commonjs/networking/api-requests/roomMembers.api.js +1 -1
  156. package/lib/commonjs/networking/api-requests/roomMembers.api.js.map +1 -1
  157. package/lib/commonjs/networking/api-requests/rooms.api.js +9 -9
  158. package/lib/commonjs/networking/api-requests/rooms.api.js.map +1 -1
  159. package/lib/commonjs/networking/api-requests/user.api.js +68 -9
  160. package/lib/commonjs/networking/api-requests/user.api.js.map +1 -1
  161. package/lib/commonjs/networking/apiClient.js +62 -112
  162. package/lib/commonjs/networking/apiClient.js.map +1 -1
  163. package/lib/commonjs/networking/authRefresh.js +332 -0
  164. package/lib/commonjs/networking/authRefresh.js.map +1 -0
  165. package/lib/commonjs/networking/stanzaHandlers.js +41 -28
  166. package/lib/commonjs/networking/stanzaHandlers.js.map +1 -1
  167. package/lib/commonjs/networking/xmpp/flushLastViewedToPrivateStore.js +46 -8
  168. package/lib/commonjs/networking/xmpp/flushLastViewedToPrivateStore.js.map +1 -1
  169. package/lib/commonjs/networking/xmpp/presenceInRoom.xmpp.js +8 -1
  170. package/lib/commonjs/networking/xmpp/presenceInRoom.xmpp.js.map +1 -1
  171. package/lib/commonjs/networking/xmpp/subscribeToRoomMessages.xmpp.js +5 -1
  172. package/lib/commonjs/networking/xmpp/subscribeToRoomMessages.xmpp.js.map +1 -1
  173. package/lib/commonjs/networking/xmppClient.js +124 -8
  174. package/lib/commonjs/networking/xmppClient.js.map +1 -1
  175. package/lib/commonjs/roomStore/chatSettingsSlice.js +26 -7
  176. package/lib/commonjs/roomStore/chatSettingsSlice.js.map +1 -1
  177. package/lib/commonjs/roomStore/index.js +35 -2
  178. package/lib/commonjs/roomStore/index.js.map +1 -1
  179. package/lib/commonjs/roomStore/persistence.js +226 -23
  180. package/lib/commonjs/roomStore/persistence.js.map +1 -1
  181. package/lib/commonjs/roomStore/roomsSlice.js +151 -38
  182. package/lib/commonjs/roomStore/roomsSlice.js.map +1 -1
  183. package/lib/commonjs/services/pushSubscriptionService.js +15 -13
  184. package/lib/commonjs/services/pushSubscriptionService.js.map +1 -1
  185. package/lib/commonjs/version.js +1 -1
  186. package/lib/module/assets/icons.js +6 -1
  187. package/lib/module/assets/icons.js.map +1 -1
  188. package/lib/module/components/AuthForms/Login.js +4 -4
  189. package/lib/module/components/AuthForms/Login.js.map +1 -1
  190. package/lib/module/components/Header/HeaderRoomList.js +29 -8
  191. package/lib/module/components/Header/HeaderRoomList.js.map +1 -1
  192. package/lib/module/components/MainComponents/ChatHeader.js +9 -3
  193. package/lib/module/components/MainComponents/ChatHeader.js.map +1 -1
  194. package/lib/module/components/MainComponents/ChatRoom.js +152 -16
  195. package/lib/module/components/MainComponents/ChatRoom.js.map +1 -1
  196. package/lib/module/components/MainComponents/ChatWrapper.js +35 -14
  197. package/lib/module/components/MainComponents/ChatWrapper.js.map +1 -1
  198. package/lib/module/components/MainComponents/LoginWrapper.js +2 -1
  199. package/lib/module/components/MainComponents/LoginWrapper.js.map +1 -1
  200. package/lib/module/components/MainComponents/MediaMessage.js +30 -10
  201. package/lib/module/components/MainComponents/MediaMessage.js.map +1 -1
  202. package/lib/module/components/MainComponents/MessageContainer.js +5 -1
  203. package/lib/module/components/MainComponents/MessageContainer.js.map +1 -1
  204. package/lib/module/components/MainComponents/MessageList.js +13 -5
  205. package/lib/module/components/MainComponents/MessageList.js.map +1 -1
  206. package/lib/module/components/MainComponents/ProfileImagePlaceholder.js +14 -13
  207. package/lib/module/components/MainComponents/ProfileImagePlaceholder.js.map +1 -1
  208. package/lib/module/components/MainComponents/RoomList.js +207 -35
  209. package/lib/module/components/MainComponents/RoomList.js.map +1 -1
  210. package/lib/module/components/Menu/HeaderRoomListMenu.js +319 -101
  211. package/lib/module/components/Menu/HeaderRoomListMenu.js.map +1 -1
  212. package/lib/module/components/Modals/AttachSheet/AttachSheet.js +313 -113
  213. package/lib/module/components/Modals/AttachSheet/AttachSheet.js.map +1 -1
  214. package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js +549 -207
  215. package/lib/module/components/Modals/ChatProfileModal/ChatProfileModal.js.map +1 -1
  216. package/lib/module/components/Modals/ChatProfileModal/ReportChatModal.js +223 -0
  217. package/lib/module/components/Modals/ChatProfileModal/ReportChatModal.js.map +1 -0
  218. package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js +70 -28
  219. package/lib/module/components/Modals/FilePreviewModal/FilePreviewModal.js.map +1 -1
  220. package/lib/module/components/Modals/FilePreviewModal/PdfView.js +2 -1
  221. package/lib/module/components/Modals/FilePreviewModal/PdfView.js.map +1 -1
  222. package/lib/module/components/Modals/Modal/Modal.js +9 -1
  223. package/lib/module/components/Modals/Modal/Modal.js.map +1 -1
  224. package/lib/module/components/Modals/NewChatModal/ModalContent.js +2 -1
  225. package/lib/module/components/Modals/NewChatModal/ModalContent.js.map +1 -1
  226. package/lib/module/components/Modals/NewChatModal/NewChatModal.js +205 -108
  227. package/lib/module/components/Modals/NewChatModal/NewChatModal.js.map +1 -1
  228. package/lib/module/components/Modals/NewChatModal/UpdNewChatModal.js +8 -0
  229. package/lib/module/components/Modals/NewChatModal/UpdNewChatModal.js.map +1 -1
  230. package/lib/module/components/Modals/ProfileHeader/ProfileHeader.js +555 -0
  231. package/lib/module/components/Modals/ProfileHeader/ProfileHeader.js.map +1 -0
  232. package/lib/module/components/Modals/ProfileHeader/ProfileMenu.js +205 -0
  233. package/lib/module/components/Modals/ProfileHeader/ProfileMenu.js.map +1 -0
  234. package/lib/module/components/Modals/SelectUsersModal/SelectUsersModal.js +4 -2
  235. package/lib/module/components/Modals/SelectUsersModal/SelectUsersModal.js.map +1 -1
  236. package/lib/module/components/Modals/UserProfileModal/EditUserModal.js +9 -23
  237. package/lib/module/components/Modals/UserProfileModal/EditUserModal.js.map +1 -1
  238. package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js +509 -248
  239. package/lib/module/components/Modals/UserProfileModal/UserProfileModal.js.map +1 -1
  240. package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js +76 -48
  241. package/lib/module/components/Modals/UserSettingsModal/UserSettingsModal.js.map +1 -1
  242. package/lib/module/components/Modals/styledModalComponents.js +9 -2
  243. package/lib/module/components/Modals/styledModalComponents.js.map +1 -1
  244. package/lib/module/components/RoomComponents/ChatRoomItem.js +21 -7
  245. package/lib/module/components/RoomComponents/ChatRoomItem.js.map +1 -1
  246. package/lib/module/components/RoomComponents/styled/LastMessageFile.js +22 -3
  247. package/lib/module/components/RoomComponents/styled/LastMessageFile.js.map +1 -1
  248. package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js +17 -3
  249. package/lib/module/components/RoomComponents/styled/LastMessagePhoto.js.map +1 -1
  250. package/lib/module/components/RoomComponents/styled/LastMessageVideo.js +17 -3
  251. package/lib/module/components/RoomComponents/styled/LastMessageVideo.js.map +1 -1
  252. package/lib/module/components/VideoCalls/VideoCallSession.js +6 -3
  253. package/lib/module/components/VideoCalls/VideoCallSession.js.map +1 -1
  254. package/lib/module/components/styled/AudioMessage.js +2 -1
  255. package/lib/module/components/styled/AudioMessage.js.map +1 -1
  256. package/lib/module/components/styled/MessageImage.js +37 -9
  257. package/lib/module/components/styled/MessageImage.js.map +1 -1
  258. package/lib/module/components/styled/SendInput.js +81 -12
  259. package/lib/module/components/styled/SendInput.js.map +1 -1
  260. package/lib/module/components/styled/StyledComponents.js +9 -3
  261. package/lib/module/components/styled/StyledComponents.js.map +1 -1
  262. package/lib/module/components/styled/StyledInputComponents/StyledInputComponents.js +11 -4
  263. package/lib/module/components/styled/StyledInputComponents/StyledInputComponents.js.map +1 -1
  264. package/lib/module/components/styled/UnsupportedType.js +14 -4
  265. package/lib/module/components/styled/UnsupportedType.js.map +1 -1
  266. package/lib/module/components/styled/VideoMessage.js +120 -62
  267. package/lib/module/components/styled/VideoMessage.js.map +1 -1
  268. package/lib/module/context/xmppProvider.js +184 -60
  269. package/lib/module/context/xmppProvider.js.map +1 -1
  270. package/lib/module/helpers/createMessageFromXml.js +19 -1
  271. package/lib/module/helpers/createMessageFromXml.js.map +1 -1
  272. package/lib/module/helpers/ensureScopedChatCache.js +2 -2
  273. package/lib/module/helpers/ensureScopedChatCache.js.map +1 -1
  274. package/lib/module/helpers/getChatBackground.js +18 -0
  275. package/lib/module/helpers/getChatBackground.js.map +1 -0
  276. package/lib/module/helpers/getDisplayFileName.js +73 -0
  277. package/lib/module/helpers/getDisplayFileName.js.map +1 -0
  278. package/lib/module/helpers/getServerReadTimestamp.js +181 -0
  279. package/lib/module/helpers/getServerReadTimestamp.js.map +1 -0
  280. package/lib/module/helpers/historyPreloadScheduler.js +66 -3
  281. package/lib/module/helpers/historyPreloadScheduler.js.map +1 -1
  282. package/lib/module/helpers/initXmppRooms.js +14 -8
  283. package/lib/module/helpers/initXmppRooms.js.map +1 -1
  284. package/lib/module/helpers/insertMessageWithDelimiter.js +52 -9
  285. package/lib/module/helpers/insertMessageWithDelimiter.js.map +1 -1
  286. package/lib/module/helpers/isOwnMessage.js +70 -0
  287. package/lib/module/helpers/isOwnMessage.js.map +1 -0
  288. package/lib/module/helpers/keyboardLayout.js +12 -2
  289. package/lib/module/helpers/keyboardLayout.js.map +1 -1
  290. package/lib/module/helpers/mediaLibraryRuntime.js +25 -0
  291. package/lib/module/helpers/mediaLibraryRuntime.js.map +1 -0
  292. package/lib/module/helpers/mimeToExtension.js +6 -13
  293. package/lib/module/helpers/mimeToExtension.js.map +1 -1
  294. package/lib/module/helpers/msgSortableMs.js +32 -0
  295. package/lib/module/helpers/msgSortableMs.js.map +1 -0
  296. package/lib/module/helpers/persistCrypto.js +115 -0
  297. package/lib/module/helpers/persistCrypto.js.map +1 -0
  298. package/lib/module/helpers/pickImageAsset.js +63 -0
  299. package/lib/module/helpers/pickImageAsset.js.map +1 -0
  300. package/lib/module/helpers/pushPayload.js +63 -0
  301. package/lib/module/helpers/pushPayload.js.map +1 -0
  302. package/lib/module/helpers/resolveInitBeforeLoadUser.js +130 -16
  303. package/lib/module/helpers/resolveInitBeforeLoadUser.js.map +1 -1
  304. package/lib/module/helpers/secureFileUrl.js +91 -0
  305. package/lib/module/helpers/secureFileUrl.js.map +1 -0
  306. package/lib/module/helpers/secureKeyValue.js +75 -0
  307. package/lib/module/helpers/secureKeyValue.js.map +1 -0
  308. package/lib/module/helpers/secureStoreRuntime.js +52 -0
  309. package/lib/module/helpers/secureStoreRuntime.js.map +1 -0
  310. package/lib/module/helpers/secureUserStorage.js +72 -0
  311. package/lib/module/helpers/secureUserStorage.js.map +1 -0
  312. package/lib/module/helpers/shallowEqual.js +31 -0
  313. package/lib/module/helpers/shallowEqual.js.map +1 -0
  314. package/lib/module/helpers/sheetGestures.js +26 -0
  315. package/lib/module/helpers/sheetGestures.js.map +1 -0
  316. package/lib/module/hooks/useChatRoomFocus.js +46 -13
  317. package/lib/module/hooks/useChatRoomFocus.js.map +1 -1
  318. package/lib/module/hooks/useChatWrapperInit.js +30 -10
  319. package/lib/module/hooks/useChatWrapperInit.js.map +1 -1
  320. package/lib/module/hooks/useComposing.js +28 -1
  321. package/lib/module/hooks/useComposing.js.map +1 -1
  322. package/lib/module/hooks/useFileToken.js +5 -0
  323. package/lib/module/hooks/useFileToken.js.map +1 -0
  324. package/lib/module/hooks/useLogout.js +23 -7
  325. package/lib/module/hooks/useLogout.js.map +1 -1
  326. package/lib/module/hooks/usePendingNotification.js +8 -11
  327. package/lib/module/hooks/usePendingNotification.js.map +1 -1
  328. package/lib/module/hooks/useSendMessage.js +52 -16
  329. package/lib/module/hooks/useSendMessage.js.map +1 -1
  330. package/lib/module/hooks/useUnreadMessagesCounter.js +6 -1
  331. package/lib/module/hooks/useUnreadMessagesCounter.js.map +1 -1
  332. package/lib/module/i18n/strings.js +145 -37
  333. package/lib/module/i18n/strings.js.map +1 -1
  334. package/lib/module/main.js +14 -2
  335. package/lib/module/main.js.map +1 -1
  336. package/lib/module/networking/api-requests/auth.api.js +131 -59
  337. package/lib/module/networking/api-requests/auth.api.js.map +1 -1
  338. package/lib/module/networking/api-requests/roomMembers.api.js +1 -1
  339. package/lib/module/networking/api-requests/roomMembers.api.js.map +1 -1
  340. package/lib/module/networking/api-requests/rooms.api.js +9 -9
  341. package/lib/module/networking/api-requests/rooms.api.js.map +1 -1
  342. package/lib/module/networking/api-requests/user.api.js +64 -7
  343. package/lib/module/networking/api-requests/user.api.js.map +1 -1
  344. package/lib/module/networking/apiClient.js +61 -113
  345. package/lib/module/networking/apiClient.js.map +1 -1
  346. package/lib/module/networking/authRefresh.js +321 -0
  347. package/lib/module/networking/authRefresh.js.map +1 -0
  348. package/lib/module/networking/stanzaHandlers.js +41 -28
  349. package/lib/module/networking/stanzaHandlers.js.map +1 -1
  350. package/lib/module/networking/xmpp/flushLastViewedToPrivateStore.js +46 -8
  351. package/lib/module/networking/xmpp/flushLastViewedToPrivateStore.js.map +1 -1
  352. package/lib/module/networking/xmpp/presenceInRoom.xmpp.js +8 -1
  353. package/lib/module/networking/xmpp/presenceInRoom.xmpp.js.map +1 -1
  354. package/lib/module/networking/xmpp/subscribeToRoomMessages.xmpp.js +5 -1
  355. package/lib/module/networking/xmpp/subscribeToRoomMessages.xmpp.js.map +1 -1
  356. package/lib/module/networking/xmppClient.js +124 -8
  357. package/lib/module/networking/xmppClient.js.map +1 -1
  358. package/lib/module/roomStore/chatSettingsSlice.js +26 -7
  359. package/lib/module/roomStore/chatSettingsSlice.js.map +1 -1
  360. package/lib/module/roomStore/index.js +37 -4
  361. package/lib/module/roomStore/index.js.map +1 -1
  362. package/lib/module/roomStore/persistence.js +223 -22
  363. package/lib/module/roomStore/persistence.js.map +1 -1
  364. package/lib/module/roomStore/roomsSlice.js +139 -34
  365. package/lib/module/roomStore/roomsSlice.js.map +1 -1
  366. package/lib/module/services/pushSubscriptionService.js +15 -13
  367. package/lib/module/services/pushSubscriptionService.js.map +1 -1
  368. package/lib/module/version.js +1 -1
  369. package/lib/typescript/assets/icons.d.ts +16 -0
  370. package/lib/typescript/assets/icons.d.ts.map +1 -1
  371. package/lib/typescript/components/AuthForms/Login.d.ts.map +1 -1
  372. package/lib/typescript/components/Header/HeaderRoomList.d.ts.map +1 -1
  373. package/lib/typescript/components/MainComponents/ChatHeader.d.ts.map +1 -1
  374. package/lib/typescript/components/MainComponents/ChatRoom.d.ts.map +1 -1
  375. package/lib/typescript/components/MainComponents/ChatWrapper.d.ts.map +1 -1
  376. package/lib/typescript/components/MainComponents/LoginWrapper.d.ts.map +1 -1
  377. package/lib/typescript/components/MainComponents/MediaMessage.d.ts.map +1 -1
  378. package/lib/typescript/components/MainComponents/MessageContainer.d.ts.map +1 -1
  379. package/lib/typescript/components/MainComponents/MessageList.d.ts +10 -1
  380. package/lib/typescript/components/MainComponents/MessageList.d.ts.map +1 -1
  381. package/lib/typescript/components/MainComponents/ProfileImagePlaceholder.d.ts.map +1 -1
  382. package/lib/typescript/components/MainComponents/RoomList.d.ts +7 -0
  383. package/lib/typescript/components/MainComponents/RoomList.d.ts.map +1 -1
  384. package/lib/typescript/components/Menu/HeaderRoomListMenu.d.ts +3 -0
  385. package/lib/typescript/components/Menu/HeaderRoomListMenu.d.ts.map +1 -1
  386. package/lib/typescript/components/Modals/AttachSheet/AttachSheet.d.ts +9 -0
  387. package/lib/typescript/components/Modals/AttachSheet/AttachSheet.d.ts.map +1 -1
  388. package/lib/typescript/components/Modals/ChatProfileModal/ChatProfileModal.d.ts +10 -0
  389. package/lib/typescript/components/Modals/ChatProfileModal/ChatProfileModal.d.ts.map +1 -1
  390. package/lib/typescript/components/Modals/ChatProfileModal/ReportChatModal.d.ts +9 -0
  391. package/lib/typescript/components/Modals/ChatProfileModal/ReportChatModal.d.ts.map +1 -0
  392. package/lib/typescript/components/Modals/FilePreviewModal/FilePreviewModal.d.ts.map +1 -1
  393. package/lib/typescript/components/Modals/FilePreviewModal/PdfView.d.ts.map +1 -1
  394. package/lib/typescript/components/Modals/Modal/Modal.d.ts.map +1 -1
  395. package/lib/typescript/components/Modals/NewChatModal/ModalContent.d.ts +4 -2
  396. package/lib/typescript/components/Modals/NewChatModal/ModalContent.d.ts.map +1 -1
  397. package/lib/typescript/components/Modals/NewChatModal/NewChatModal.d.ts +1 -1
  398. package/lib/typescript/components/Modals/NewChatModal/NewChatModal.d.ts.map +1 -1
  399. package/lib/typescript/components/Modals/NewChatModal/UpdNewChatModal.d.ts.map +1 -1
  400. package/lib/typescript/components/Modals/ProfileHeader/ProfileHeader.d.ts +75 -0
  401. package/lib/typescript/components/Modals/ProfileHeader/ProfileHeader.d.ts.map +1 -0
  402. package/lib/typescript/components/Modals/ProfileHeader/ProfileMenu.d.ts +25 -0
  403. package/lib/typescript/components/Modals/ProfileHeader/ProfileMenu.d.ts.map +1 -0
  404. package/lib/typescript/components/Modals/SelectUsersModal/SelectUsersModal.d.ts +6 -1
  405. package/lib/typescript/components/Modals/SelectUsersModal/SelectUsersModal.d.ts.map +1 -1
  406. package/lib/typescript/components/Modals/UserProfileModal/EditUserModal.d.ts.map +1 -1
  407. package/lib/typescript/components/Modals/UserProfileModal/UserProfileModal.d.ts +16 -0
  408. package/lib/typescript/components/Modals/UserProfileModal/UserProfileModal.d.ts.map +1 -1
  409. package/lib/typescript/components/Modals/UserSettingsModal/UserSettingsModal.d.ts +1 -0
  410. package/lib/typescript/components/Modals/UserSettingsModal/UserSettingsModal.d.ts.map +1 -1
  411. package/lib/typescript/components/Modals/styledModalComponents.d.ts.map +1 -1
  412. package/lib/typescript/components/RoomComponents/ChatRoomItem.d.ts.map +1 -1
  413. package/lib/typescript/components/RoomComponents/styled/LastMessageFile.d.ts +1 -1
  414. package/lib/typescript/components/RoomComponents/styled/LastMessageFile.d.ts.map +1 -1
  415. package/lib/typescript/components/RoomComponents/styled/LastMessagePhoto.d.ts +1 -1
  416. package/lib/typescript/components/RoomComponents/styled/LastMessagePhoto.d.ts.map +1 -1
  417. package/lib/typescript/components/RoomComponents/styled/LastMessageVideo.d.ts +1 -1
  418. package/lib/typescript/components/RoomComponents/styled/LastMessageVideo.d.ts.map +1 -1
  419. package/lib/typescript/components/VideoCalls/VideoCallSession.d.ts.map +1 -1
  420. package/lib/typescript/components/styled/AudioMessage.d.ts.map +1 -1
  421. package/lib/typescript/components/styled/MessageImage.d.ts +14 -0
  422. package/lib/typescript/components/styled/MessageImage.d.ts.map +1 -1
  423. package/lib/typescript/components/styled/SendInput.d.ts.map +1 -1
  424. package/lib/typescript/components/styled/StyledComponents.d.ts.map +1 -1
  425. package/lib/typescript/components/styled/StyledInputComponents/StyledInputComponents.d.ts.map +1 -1
  426. package/lib/typescript/components/styled/UnsupportedType.d.ts.map +1 -1
  427. package/lib/typescript/components/styled/VideoMessage.d.ts +8 -0
  428. package/lib/typescript/components/styled/VideoMessage.d.ts.map +1 -1
  429. package/lib/typescript/context/xmppProvider.d.ts.map +1 -1
  430. package/lib/typescript/helpers/createMessageFromXml.d.ts.map +1 -1
  431. package/lib/typescript/helpers/getChatBackground.d.ts +15 -0
  432. package/lib/typescript/helpers/getChatBackground.d.ts.map +1 -0
  433. package/lib/typescript/helpers/getDisplayFileName.d.ts +49 -0
  434. package/lib/typescript/helpers/getDisplayFileName.d.ts.map +1 -0
  435. package/lib/typescript/helpers/getServerReadTimestamp.d.ts +108 -0
  436. package/lib/typescript/helpers/getServerReadTimestamp.d.ts.map +1 -0
  437. package/lib/typescript/helpers/historyPreloadScheduler.d.ts.map +1 -1
  438. package/lib/typescript/helpers/initXmppRooms.d.ts.map +1 -1
  439. package/lib/typescript/helpers/insertMessageWithDelimiter.d.ts +1 -1
  440. package/lib/typescript/helpers/insertMessageWithDelimiter.d.ts.map +1 -1
  441. package/lib/typescript/helpers/isOwnMessage.d.ts +36 -0
  442. package/lib/typescript/helpers/isOwnMessage.d.ts.map +1 -0
  443. package/lib/typescript/helpers/keyboardLayout.d.ts +5 -1
  444. package/lib/typescript/helpers/keyboardLayout.d.ts.map +1 -1
  445. package/lib/typescript/helpers/mediaLibraryRuntime.d.ts +3 -0
  446. package/lib/typescript/helpers/mediaLibraryRuntime.d.ts.map +1 -0
  447. package/lib/typescript/helpers/mimeToExtension.d.ts +0 -15
  448. package/lib/typescript/helpers/mimeToExtension.d.ts.map +1 -1
  449. package/lib/typescript/helpers/msgSortableMs.d.ts +2 -0
  450. package/lib/typescript/helpers/msgSortableMs.d.ts.map +1 -0
  451. package/lib/typescript/helpers/persistCrypto.d.ts +13 -0
  452. package/lib/typescript/helpers/persistCrypto.d.ts.map +1 -0
  453. package/lib/typescript/helpers/pickImageAsset.d.ts +27 -0
  454. package/lib/typescript/helpers/pickImageAsset.d.ts.map +1 -0
  455. package/lib/typescript/helpers/pushPayload.d.ts +7 -0
  456. package/lib/typescript/helpers/pushPayload.d.ts.map +1 -0
  457. package/lib/typescript/helpers/resolveInitBeforeLoadUser.d.ts.map +1 -1
  458. package/lib/typescript/helpers/secureFileUrl.d.ts +7 -0
  459. package/lib/typescript/helpers/secureFileUrl.d.ts.map +1 -0
  460. package/lib/typescript/helpers/secureKeyValue.d.ts +13 -0
  461. package/lib/typescript/helpers/secureKeyValue.d.ts.map +1 -0
  462. package/lib/typescript/helpers/secureStoreRuntime.d.ts +29 -0
  463. package/lib/typescript/helpers/secureStoreRuntime.d.ts.map +1 -0
  464. package/lib/typescript/helpers/secureUserStorage.d.ts +23 -0
  465. package/lib/typescript/helpers/secureUserStorage.d.ts.map +1 -0
  466. package/lib/typescript/helpers/shallowEqual.d.ts +11 -0
  467. package/lib/typescript/helpers/shallowEqual.d.ts.map +1 -0
  468. package/lib/typescript/helpers/sheetGestures.d.ts +20 -0
  469. package/lib/typescript/helpers/sheetGestures.d.ts.map +1 -0
  470. package/lib/typescript/hooks/useChatRoomFocus.d.ts +4 -1
  471. package/lib/typescript/hooks/useChatRoomFocus.d.ts.map +1 -1
  472. package/lib/typescript/hooks/useChatWrapperInit.d.ts.map +1 -1
  473. package/lib/typescript/hooks/useComposing.d.ts.map +1 -1
  474. package/lib/typescript/hooks/useFileToken.d.ts +2 -0
  475. package/lib/typescript/hooks/useFileToken.d.ts.map +1 -0
  476. package/lib/typescript/hooks/useLogout.d.ts.map +1 -1
  477. package/lib/typescript/hooks/usePendingNotification.d.ts.map +1 -1
  478. package/lib/typescript/hooks/useSendMessage.d.ts.map +1 -1
  479. package/lib/typescript/hooks/useUnreadMessagesCounter.d.ts +1 -0
  480. package/lib/typescript/hooks/useUnreadMessagesCounter.d.ts.map +1 -1
  481. package/lib/typescript/i18n/strings.d.ts.map +1 -1
  482. package/lib/typescript/main.d.ts +9 -2
  483. package/lib/typescript/main.d.ts.map +1 -1
  484. package/lib/typescript/networking/api-requests/auth.api.d.ts +3 -1
  485. package/lib/typescript/networking/api-requests/auth.api.d.ts.map +1 -1
  486. package/lib/typescript/networking/api-requests/user.api.d.ts +27 -0
  487. package/lib/typescript/networking/api-requests/user.api.d.ts.map +1 -1
  488. package/lib/typescript/networking/apiClient.d.ts +12 -6
  489. package/lib/typescript/networking/apiClient.d.ts.map +1 -1
  490. package/lib/typescript/networking/authRefresh.d.ts +95 -0
  491. package/lib/typescript/networking/authRefresh.d.ts.map +1 -0
  492. package/lib/typescript/networking/stanzaHandlers.d.ts.map +1 -1
  493. package/lib/typescript/networking/xmpp/flushLastViewedToPrivateStore.d.ts +10 -2
  494. package/lib/typescript/networking/xmpp/flushLastViewedToPrivateStore.d.ts.map +1 -1
  495. package/lib/typescript/networking/xmpp/presenceInRoom.xmpp.d.ts.map +1 -1
  496. package/lib/typescript/networking/xmpp/subscribeToRoomMessages.xmpp.d.ts.map +1 -1
  497. package/lib/typescript/networking/xmppClient.d.ts +14 -0
  498. package/lib/typescript/networking/xmppClient.d.ts.map +1 -1
  499. package/lib/typescript/roomStore/chatSettingsSlice.d.ts +16 -0
  500. package/lib/typescript/roomStore/chatSettingsSlice.d.ts.map +1 -1
  501. package/lib/typescript/roomStore/index.d.ts.map +1 -1
  502. package/lib/typescript/roomStore/persistence.d.ts +18 -1
  503. package/lib/typescript/roomStore/persistence.d.ts.map +1 -1
  504. package/lib/typescript/roomStore/roomsSlice.d.ts +43 -3
  505. package/lib/typescript/roomStore/roomsSlice.d.ts.map +1 -1
  506. package/lib/typescript/services/pushSubscriptionService.d.ts +1 -1
  507. package/lib/typescript/services/pushSubscriptionService.d.ts.map +1 -1
  508. package/lib/typescript/types/types.d.ts +50 -5
  509. package/lib/typescript/types/types.d.ts.map +1 -1
  510. package/lib/typescript/version.d.ts +1 -1
  511. package/package.json +41 -28
  512. package/src/assets/icons.tsx +48 -9
  513. package/src/components/AuthForms/Login.tsx +3 -3
  514. package/src/components/Header/HeaderRoomList.tsx +29 -7
  515. package/src/components/MainComponents/ChatHeader.tsx +9 -3
  516. package/src/components/MainComponents/ChatRoom.tsx +161 -15
  517. package/src/components/MainComponents/ChatWrapper.tsx +36 -20
  518. package/src/components/MainComponents/LoginWrapper.tsx +1 -0
  519. package/src/components/MainComponents/MediaMessage.tsx +26 -8
  520. package/src/components/MainComponents/MessageContainer.tsx +5 -1
  521. package/src/components/MainComponents/MessageList.tsx +23 -4
  522. package/src/components/MainComponents/ProfileImagePlaceholder.tsx +21 -14
  523. package/src/components/MainComponents/RoomList.tsx +236 -39
  524. package/src/components/Menu/HeaderRoomListMenu.tsx +328 -75
  525. package/src/components/Modals/AttachSheet/AttachSheet.tsx +333 -97
  526. package/src/components/Modals/ChatProfileModal/ChatProfileModal.tsx +600 -282
  527. package/src/components/Modals/ChatProfileModal/ReportChatModal.tsx +244 -0
  528. package/src/components/Modals/FilePreviewModal/FilePreviewModal.tsx +79 -38
  529. package/src/components/Modals/FilePreviewModal/PdfView.tsx +2 -1
  530. package/src/components/Modals/Modal/Modal.tsx +7 -0
  531. package/src/components/Modals/NewChatModal/ModalContent.tsx +6 -3
  532. package/src/components/Modals/NewChatModal/NewChatModal.tsx +219 -119
  533. package/src/components/Modals/NewChatModal/UpdNewChatModal.tsx +12 -1
  534. package/src/components/Modals/ProfileHeader/ProfileHeader.tsx +624 -0
  535. package/src/components/Modals/ProfileHeader/ProfileMenu.tsx +217 -0
  536. package/src/components/Modals/SelectUsersModal/SelectUsersModal.tsx +14 -4
  537. package/src/components/Modals/UserProfileModal/EditUserModal.tsx +9 -25
  538. package/src/components/Modals/UserProfileModal/UserProfileModal.tsx +617 -307
  539. package/src/components/Modals/UserSettingsModal/UserSettingsModal.tsx +75 -58
  540. package/src/components/Modals/styledModalComponents.tsx +9 -2
  541. package/src/components/RoomComponents/ChatRoomItem.tsx +18 -3
  542. package/src/components/RoomComponents/styled/LastMessageFile.tsx +28 -4
  543. package/src/components/RoomComponents/styled/LastMessagePhoto.tsx +18 -3
  544. package/src/components/RoomComponents/styled/LastMessageVideo.tsx +18 -3
  545. package/src/components/VideoCalls/VideoCallSession.tsx +8 -3
  546. package/src/components/styled/AudioMessage.tsx +2 -1
  547. package/src/components/styled/MessageImage.tsx +53 -7
  548. package/src/components/styled/SendInput.tsx +83 -12
  549. package/src/components/styled/StyledComponents.ts +9 -3
  550. package/src/components/styled/StyledInputComponents/StyledInputComponents.tsx +11 -4
  551. package/src/components/styled/UnsupportedType.tsx +14 -4
  552. package/src/components/styled/VideoMessage.tsx +131 -54
  553. package/src/context/xmppProvider.tsx +216 -57
  554. package/src/helpers/createMessageFromXml.ts +20 -1
  555. package/src/helpers/ensureScopedChatCache.ts +2 -2
  556. package/src/helpers/getChatBackground.ts +18 -0
  557. package/src/helpers/getDisplayFileName.ts +87 -0
  558. package/src/helpers/getServerReadTimestamp.ts +197 -0
  559. package/src/helpers/historyPreloadScheduler.ts +80 -3
  560. package/src/helpers/initXmppRooms.tsx +14 -10
  561. package/src/helpers/insertMessageWithDelimiter.ts +55 -19
  562. package/src/helpers/isOwnMessage.ts +90 -0
  563. package/src/helpers/keyboardLayout.ts +23 -2
  564. package/src/helpers/mediaLibraryRuntime.ts +25 -0
  565. package/src/helpers/mimeToExtension.ts +6 -22
  566. package/src/helpers/msgSortableMs.ts +25 -0
  567. package/src/helpers/persistCrypto.ts +127 -0
  568. package/src/helpers/pickImageAsset.ts +68 -0
  569. package/src/helpers/pushPayload.ts +62 -0
  570. package/src/helpers/resolveInitBeforeLoadUser.ts +125 -18
  571. package/src/helpers/secureFileUrl.ts +103 -0
  572. package/src/helpers/secureKeyValue.ts +80 -0
  573. package/src/helpers/secureStoreRuntime.ts +62 -0
  574. package/src/helpers/secureUserStorage.ts +80 -0
  575. package/src/helpers/shallowEqual.ts +33 -0
  576. package/src/helpers/sheetGestures.ts +25 -0
  577. package/src/hooks/useChatRoomFocus.ts +49 -9
  578. package/src/hooks/useChatWrapperInit.ts +30 -10
  579. package/src/hooks/useComposing.tsx +37 -1
  580. package/src/hooks/useFileToken.ts +7 -0
  581. package/src/hooks/useLogout.tsx +29 -9
  582. package/src/hooks/usePendingNotification.ts +5 -11
  583. package/src/hooks/useSendMessage.tsx +60 -15
  584. package/src/hooks/useUnreadMessagesCounter.ts +11 -0
  585. package/src/i18n/strings.ts +145 -37
  586. package/src/main.ts +26 -2
  587. package/src/networking/api-requests/auth.api.ts +156 -48
  588. package/src/networking/api-requests/roomMembers.api.ts +1 -1
  589. package/src/networking/api-requests/rooms.api.ts +9 -9
  590. package/src/networking/api-requests/user.api.ts +79 -7
  591. package/src/networking/apiClient.ts +68 -123
  592. package/src/networking/authRefresh.ts +451 -0
  593. package/src/networking/stanzaHandlers.ts +44 -28
  594. package/src/networking/xmpp/flushLastViewedToPrivateStore.ts +71 -10
  595. package/src/networking/xmpp/presenceInRoom.xmpp.ts +6 -1
  596. package/src/networking/xmpp/subscribeToRoomMessages.xmpp.ts +12 -1
  597. package/src/networking/xmppClient.ts +141 -9
  598. package/src/roomStore/chatSettingsSlice.ts +34 -10
  599. package/src/roomStore/index.ts +40 -4
  600. package/src/roomStore/persistence.ts +234 -24
  601. package/src/roomStore/roomsSlice.ts +161 -29
  602. package/src/services/pushSubscriptionService.ts +18 -13
  603. package/src/types/types.ts +72 -5
  604. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["http","store","getMyUser","options","token","getState","chatSettingStore","user","endpoint","response","get","headers","Authorization","data","getDocuments","walletAddress","getExportMyData","responseType","deleteDocument","fileId","delete","deleteMe","updateMe","put","updateProfile","fd","error","Error"],"sourceRoot":"../../../../src","sources":["networking/api-requests/user.api.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,cAAc;AAC/B,SAASC,KAAK,QAAQ,iBAAiB;AAQvC,OAAO,eAAeC,SAASA,CAACC,OAA0B,EAAiB;EACzE,MAAMC,KAAK,GACTD,OAAO,EAAEC,KAAK,IAAIH,KAAK,CAACI,QAAQ,CAAC,CAAC,CAACC,gBAAgB,CAACC,IAAI,CAACH,KAAK,IAAI,EAAE;EACtE,MAAMI,QAAQ,GAAGL,OAAO,EAAEK,QAAQ,IAAI,WAAW;EAEjD,MAAMC,QAAQ,GAAG,MAAMT,IAAI,CAACU,GAAG,CAACF,QAAQ,EAAE;IACxCG,OAAO,EAAE;MAAEC,aAAa,EAAER;IAAM;EAClC,CAAC,CAAC;EAEF,IAAIK,QAAQ,EAAEI,IAAI,EAAEN,IAAI,EAAE;IACxB,OAAOE,QAAQ,CAACI,IAAI,CAACN,IAAI;EAC3B;EACA,OAAOE,QAAQ,CAACI,IAAI;AACtB;AAEA,OAAO,SAASC,YAA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ACF,MAAMK,QAAQ,GAAG,MAAMT,IAAI,CAACuB,GAAG,CAAC,QAAQ,EAAEE,EAAE,EAAE;MAC5Cd,OAAO,EAAE;QACPC,aAAa,EAAER,KAAK;QACpB,cAAc,EAAE;MAClB;IACF,CAAC,CAAC;IACF,OAAOK,QAAQ,CAACI,IAAI;EACtB,CAAC,CAAC,OAAOa,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;EAC3C;AACF","ignoreList":[]}
1
+ {"version":3,"names":["http","normalizeApiPath","store","getMyUser","options","token","getState","chatSettingStore","user","endpoint","response","get","headers","Authorization","data","getDocuments","walletAddress","getExportMyData","responseType","deleteDocument","fileId","delete","deleteMe","updateMe","put","updateProfile","fd","error","Error","getUserFiles","params","limit","offset","payload","rows","results","items","map","row","url","location","locations","id","String","_id","name","originalname","filename","documentName","split","pop","mimetype","mimeType","type","createdAt","updatedAt","size","undefined","filter","Boolean","isMediaFile","file","mime","toLowerCase","startsWith","test"],"sourceRoot":"../../../../src","sources":["networking/api-requests/user.api.ts"],"mappings":";;AAAA,OAAOA,IAAI,MAAM,cAAc;AAC/B,SAASC,gBAAgB,QAAQ,cAAc;AAC/C,SAASC,KAAK,QAAQ,iBAAiB;AAQvC,OAAO,eAAeC,SAASA,CAACC,OAA0B,EAAiB;EACzE,MAAMC,KAAK,GACTD,OAAO,EAAEC,KAAK,IAAIH,KAAK,CAACI,QAAQ,CAAC,CAAC,CAACC,gBAAgB,CAACC,IAAI,CAACH,KAAK,IAAI,EAAE;EACtE,MAAMI,QAAQ,GAAGR,gBAAgB,CAACG,OAAO,EAAEK,QAAQ,CAAC,IAAI,cAAc;EAEtE,MAAMC,QAAQ,GAAG,MAAMV,IAAI,CAACW,GAAG,CAACF,QAAQ,EAAE;IACxCG,OAAO,EAAE;MAAEC,aAAa,EAAER;IAAM;EAClC,CAAC,CAAC;EAEF,IAAIK,QAAQ,EAAEI,IAAI,EAAEN,IAAI,EAAE;IACxB,OAAOE,Q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AG,EAAE;MAAC,OAAO,IAAI;IAAC;IACvB,OAAO;MACLG,EAAE,EAAEC,MAAM,CAACL,GAAG,EAAEM,GAAG,IAAIN,GAAG,EAAEI,EAAE,IAAIH,GAAG,CAAC;MACtCM,IAAI,EACFP,GAAG,EAAEQ,YAAY,IACjBR,GAAG,EAAES,QAAQ,IACbT,GAAG,EAAEU,YAAY,IACjBV,GAAG,EAAEO,IAAI,IACTN,GAAG,CAACU,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC,IACpB,MAAM;MACRX,GAAG;MACHY,QAAQ,EAAEb,GAAG,EAAEa,QAAQ,IAAIb,GAAG,EAAEc,QAAQ,IAAId,GAAG,EAAEe,IAAI,IAAI,EAAE;MAC3DC,SAAS,EAAEhB,GAAG,EAAEgB,SAAS,IAAIhB,GAAG,EAAEiB,SAAS;MAC3CC,IAAI,EAAE,OAAOlB,GAAG,EAAEkB,IAAI,KAAK,QAAQ,GAAGlB,GAAG,CAACkB,IAAI,GAAGC;IACnD,CAAC;EACH,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;AACpB;;AAEA;AACA,OAAO,MAAMC,WAAW,GAAIC,IAAc,IAAc;EACtD,MAAMC,IAAI,GAAG,CAACD,IAAI,CAACV,QAAQ,IAAI,EAAE,EAAEY,WAAW,CAAC,CAAC;EAChD,IAAID,IAAI,CAACE,UAAU,CAAC,QAAQ,CAAC,IAAIF,IAAI,CAACE,UAAU,CAAC,QAAQ,CAAC,EAAE;IAAC,OAAO,IAAI;EAAC;EACzE,IAAIF,IAAI,EAAE;IAAC,OAAO,KAAK;EAAC;EACxB;EACA,OAAO,4DAA4D,CAACG,IAAI,CACtEJ,IAAI,CAAChB,IACP,CAAC;AACH,CAAC","ignoreList":[]}
@@ -2,8 +2,9 @@
2
2
 
3
3
  import axios from 'axios';
4
4
  import { store } from '../roomStore';
5
- import { logout, refreshTokens } from '../roomStore/chatSettingsSlice';
5
+ import { logout } from '../roomStore/chatSettingsSlice';
6
6
  import { installAxiosCapture } from '../utils/devLogger';
7
+ import { refreshAuthTokens, isRefreshFatalError } from './authRefresh';
7
8
 
8
9
  // Per product-code-policy: no compiled-in Ethora endpoints or tokens.
9
10
  // Consumers must call `setBaseURL(baseUrl, appToken)` (or pass
@@ -19,10 +20,24 @@ const http = axios.create({
19
20
  // Dev-logger hook: capture every request + response on the shared
20
21
  // `http` instance.
21
22
  installAxiosCapture(http);
23
+ const stripApiVersion = baseUrl => baseUrl.replace(/\/+$/, '').replace(/\/v\d+$/, '');
24
+ export const normalizeApiPath = path => {
25
+ if (!path) {
26
+ return path;
27
+ }
28
+ if (/^https?:\/\//i.test(path)) {
29
+ return path;
30
+ }
31
+ if (/^\/v\d+\//.test(path)) {
32
+ return path;
33
+ }
34
+ return `/v1${path.startsWith('/') ? '' : '/'}${path}`;
35
+ };
22
36
  export function setBaseURL(baseUrl, appToken) {
23
- if (baseUrl && baseUrl !== currentBaseURL) {
24
- currentBaseURL = baseUrl;
25
- http.defaults.baseURL = baseUrl;
37
+ const normalized = baseUrl ? stripApiVersion(baseUrl) : baseUrl;
38
+ if (normalized && normalized !== currentBaseURL) {
39
+ currentBaseURL = normalized;
40
+ http.defaults.baseURL = normalized;
26
41
  }
27
42
  if (appToken && appToken !== currentAppToken) {
28
43
  currentAppToken = appToken;
@@ -34,132 +49,65 @@ export function getCurrentAppToken() {
34
49
  export function getCurrentBaseURL() {
35
50
  return currentBaseURL;
36
51
  }
52
+
53
+ /**
54
+ * @deprecated Import `refreshAuthTokens` from `./authRefresh` instead.
55
+ *
56
+ * Kept as a thin forwarder so existing call sites keep working while
57
+ * they migrate. Declared as a function (not `const refresh =
58
+ * refreshAuthTokens`) on purpose: this module and `authRefresh` import
59
+ * each other, and a const would capture the binding before the other
60
+ * module finished evaluating.
61
+ */
37
62
  export function refresh() {
38
- return new Promise((resolve, reject) => {
39
- const user = store.getState().chatSettingStore.user;
40
- try {
41
- http.post('/users/login/refresh', {}, {
42
- headers: {
43
- Authorization: user.refreshToken
44
- }
45
- }).then(response => {
46
- store.dispatch(refreshTokens({
47
- token: response.data.token,
48
- refreshToken: response.data.refreshToken
49
- }));
50
- // BUGFIX: previously the `.then` only dispatched and never
51
- // resolved, so every `await refresh()` callsite hung forever
52
- // on the happy path. Resolve with the axios response shape so
53
- // the interceptor can read `tokens.data.token` to retry.
54
- resolve(response);
55
- }).catch(error => {
56
- reject(error);
57
- });
58
- } catch (error) {
59
- // BUGFIX: previously the outer-try catch dispatched logout but
60
- // never rejected, so a synchronous throw from `http.post` (e.g.
61
- // a bad URL) would hang the promise. Reject explicitly.
62
- console.log('errr');
63
- store.dispatch(logout());
64
- reject(error);
65
- }
66
- });
63
+ return refreshAuthTokens();
67
64
  }
68
- let isRefreshing = false;
69
- let failedQueue = [];
70
- const addRequestToQueue = config => {
71
- return new Promise((resolve, reject) => {
72
- failedQueue.push({
73
- resolve,
74
- reject,
75
- config
76
- });
77
- });
78
- };
79
- const processQueue = newAccessToken => {
80
- for (const request of failedQueue) {
81
- if (newAccessToken) {
82
- request.config.headers.Authorization = newAccessToken;
83
- }
84
- request.resolve(http(request.config));
85
- }
86
- failedQueue = [];
87
- };
88
65
  http.interceptors.response.use(response => response, async error => {
89
- // BUGFIX: the original condition was `if (!enabled)` — inverted, so
90
- // turning `refreshTokens.enabled: true` actually DISABLED the refresh
91
- // path on 401. Use the correct sense.
92
- if (!store.getState().chatSettingStore?.config?.refreshTokens?.enabled) {
93
- // BUGFIX: previously this branch fell off the end of the async
94
- // function and returned `undefined`, which axios treats as a
95
- // resolved-with-undefined response. Callers expecting an error
96
- // got `undefined` instead, silently swallowing every failure
97
- // when the refresh path isn't configured. Re-reject so the
98
- // original error reaches the caller.
99
- return Promise.reject(error);
100
- }
101
66
  const originalRequest = error.config;
102
67
  const status = error.response?.status;
103
68
 
104
69
  // Refresh paths only fire on 401. Anything else passes through.
105
- if (!error.response || status !== 401) {
70
+ if (!error.response || status !== 401 || !originalRequest) {
106
71
  return Promise.reject(error);
107
72
  }
108
- if (store.getState().chatSettingStore?.config?.refreshTokens?.refreshFunction) {
109
- // Consumer-supplied refresh function. Call it, dispatch the new
110
- // tokens, retry the original request.
111
- try {
112
- const fn = store.getState().chatSettingStore?.config?.refreshTokens?.refreshFunction;
113
- if (!fn) return Promise.reject(error);
114
- const result = await fn();
115
- const {
116
- refreshToken: newRefreshToken,
117
- accessToken
118
- } = result || {
119
- refreshToken: '',
120
- accessToken: ''
121
- };
122
- store.dispatch(refreshTokens({
123
- token: accessToken,
124
- refreshToken: newRefreshToken || ''
125
- }));
126
- // BUGFIX: previously this branch returned `undefined` after
127
- // dispatching, so the original request was never retried and
128
- // the caller resolved with undefined. Stamp the new token on
129
- // the original config and replay.
130
- if (originalRequest?.headers) {
131
- originalRequest.headers.Authorization = accessToken;
132
- }
133
- return http(originalRequest);
134
- } catch (refreshErr) {
135
- return Promise.reject(refreshErr);
136
- }
73
+
74
+ // Never retry twice, and never touch the auth endpoints themselves —
75
+ // both would recurse. (`_retry` was set but never checked before,
76
+ // so a request could bounce between 401 and replay indefinitely.)
77
+ if (originalRequest._retry || originalRequest.url === '/v1/users/login/refresh' || originalRequest.url === '/v1/users/login') {
78
+ return Promise.reject(error);
137
79
  }
80
+ const refreshConfig = store.getState().chatSettingStore?.config?.refreshTokens;
138
81
 
139
- // Built-in `/users/login/refresh` path. Skip if the failing request
140
- // IS the refresh / login itself — otherwise we'd loop forever.
141
- if (originalRequest.url === '/users/login/refresh' || originalRequest.url === '/users/login') {
82
+ // BUGFIX (kept): the original condition here was inverted, so
83
+ // `refreshTokens.enabled: true` actually DISABLED the refresh path.
84
+ if (!refreshConfig?.enabled) {
142
85
  return Promise.reject(error);
143
86
  }
144
- originalRequest._retry = true;
145
- if (isRefreshing) {
146
- const retryOriginalRequest = addRequestToQueue(originalRequest);
147
- return retryOriginalRequest;
87
+
88
+ // Nothing to rotate with — reject rather than firing a doomed
89
+ // refresh that would look like a bad-token event to the backend.
90
+ const hasRefreshableSession = Boolean(refreshConfig.refreshFunction || store.getState().chatSettingStore.user?.refreshToken);
91
+ if (!hasRefreshableSession) {
92
+ return Promise.reject(error);
148
93
  }
149
- isRefreshing = true;
94
+ originalRequest._retry = true;
150
95
  try {
151
- const tokens = await refresh();
152
- // (was: console.log('tokens', tokens) — dumped the full response
153
- // incl. access/refresh/ws tokens on every refresh; removed.)
154
- isRefreshing = false;
155
- originalRequest.headers.Authorization = tokens.data.token;
156
- processQueue(tokens.data.token);
96
+ // One shared rotation for every 401 in flight — `refreshAuthTokens`
97
+ // dedupes internally, which replaces the old isRefreshing/
98
+ // failedQueue machinery entirely.
99
+ const tokens = await refreshAuthTokens();
100
+ originalRequest.headers = originalRequest.headers || {};
101
+ originalRequest.headers.Authorization = tokens.token;
157
102
  return http(originalRequest);
158
103
  } catch (refreshErr) {
159
- isRefreshing = false;
160
- // BUGFIX: previously this returned the error (resolving the
161
- // promise with the error as value) instead of rejecting, so
162
- // axios callers got the error as a "successful" response body.
104
+ // Only a genuinely dead session logs the user out. A network
105
+ // blip, a 5xx, or a REFRESH_IN_PROGRESS race must leave the
106
+ // session alone — logging out on those is exactly the mass-logout
107
+ // failure mode the new backend scheme would otherwise cause.
108
+ if (isRefreshFatalError(refreshErr)) {
109
+ store.dispatch(logout());
110
+ }
163
111
  return Promise.reject(refreshErr);
164
112
  }
165
113
  });
@@ -1 +1 @@
1
- {"version":3,"names":["axios","store","logout","refreshTokens","installAxiosCapture","DEFAULT_BASE_URL","currentBaseURL","currentAppToken","http","create","baseURL","setBaseURL","baseUrl","appToken","defaults","getCurrentAppToken","getCurrentBaseURL","refresh","Promise","resolve","reject","user","getState","chatSettingStore","post","headers","Authorization","refreshToken","then","response","dispatch","token","data","catch","error","console","log","isRefreshing","failedQueue","addRequestToQueue","config","push","processQueue","newAccessToken","request","interceptors","use","enabled","originalRequest","status","refreshFunction","fn","result","newRefreshToken","accessToken","refreshErr","url","_retry","retryOriginalRequest","tokens"],"sourceRoot":"../../../src","sources":["networking/apiClient.ts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IAC9B,CAAC,CAAC,OAAOO,UAAU,EAAE;MACnB,OAAOrC,OAAO,CAACE,MAAM,CAACmC,UAAU,CAAC;IACnC;EACF;;EAEA;EACA;EACA,IACEP,eAAe,CAACQ,GAAG,KAAK,sBAAsB,IAC9CR,eAAe,CAACQ,GAAG,KAAK,cAAc,EACtC;IACA,OAAOtC,OAAO,CAACE,MAAM,CAACc,KAAK,CAAC;EAC9B;EAEAc,eAAe,CAACS,MAAM,GAAG,IAAI;EAE7B,IAAIpB,YAAY,EAAE;IAChB,MAAMqB,oBAAoB,GAAGnB,iBAAiB,CAACS,eAAe,CAAC;IAC/D,OAAOU,oBAAoB;EAC7B;EAEArB,YAAY,GAAG,IAAI;EACnB,IAAI;IACF,MAAMsB,MAAM,GAAG,MAAM1C,OAAO,CAAC,CAAC;IAC9B;IACA;IACAoB,YAAY,GAAG,KAAK;IACpBW,eAAe,CAACvB,OAAO,CAACC,aAAa,GAAGiC,MAAM,CAAC3B,IAAI,CAACD,KAAK;IACzDW,YAAY,CAACiB,MAAM,CAAC3B,IAAI,CAACD,KAAK,CAAC;IAC/B,OAAOvB,IAAI,CAACwC,eAAe,CAAC;EAC9B,CAAC,CAAC,OAAOO,UAAU,EAAE;IACnBlB,YAAY,GAAG,KAAK;IACpB;IACA;IACA;IACA,OAAOnB,OAAO,CAACE,MAAM,CAACmC,UAAU,CAAC;EACnC;AACF,CACF,CAAC;AAED,eAAe/C,IAAI","ignoreList":[]}
1
+ {"version":3,"names":["axios","store","logout","installAxiosCapture","refreshAuthTokens","isRefreshFatalError","DEFAULT_BASE_URL","currentBaseURL","currentAppToken","http","create","baseURL","stripApiVersion","baseUrl","replace","normalizeApiPath","path","test","startsWith","setBaseURL","appToken","normalized","defaults","getCurrentAppToken","getCurrentBaseURL","refresh","interceptors","response","use","error","originalRequest","config","status","Promise","reject","_retry","url","refreshConfig","getState","chatSettingStore","refreshTokens","enabled","hasRefreshableSession","Boolean","refreshFunction","user","refreshToken","tokens","headers","Authorization","token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Ae,IAC3B3C,KAAK,CAACqC,QAAQ,CAAC,CAAC,CAACC,gBAAgB,CAACM,IAAI,EAAEC,YAC5C,CAAC;EACD,IAAI,CAACJ,qBAAqB,EAAE;IAC1B,OAAOT,OAAO,CAACC,MAAM,CAACL,KAAK,CAAC;EAC9B;EAEAC,eAAe,CAACK,MAAM,GAAG,IAAI;EAE7B,IAAI;IACF;IACA;IACA;IACA,MAAMY,MAAM,GAAG,MAAM3C,iBAAiB,CAAC,CAAC;IACxC0B,eAAe,CAACkB,OAAO,GAAGlB,eAAe,CAACkB,OAAO,IAAI,CAAC,CAAC;IACvDlB,eAAe,CAACkB,OAAO,CAACC,aAAa,GAAGF,MAAM,CAACG,KAAK;IACpD,OAAOzC,IAAI,CAACqB,eAAe,CAAC;EAC9B,CAAC,CAAC,OAAOqB,UAAU,EAAE;IACnB;IACA;IACA;IACA;IACA,IAAI9C,mBAAmB,CAAC8C,UAAU,CAAC,EAAE;MACnClD,KAAK,CAACmD,QAAQ,CAAClD,MAAM,CAAC,CAAC,CAAC;IAC1B;IACA,OAAO+B,OAAO,CAACC,MAAM,CAACiB,UAAU,CAAC;EACnC;AACF,CACF,CAAC;AAED,eAAe1C,IAAI","ignoreList":[]}
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+
3
+ import http from './apiClient';
4
+ import { store } from '../roomStore';
5
+ import { refreshTokens } from '../roomStore/chatSettingsSlice';
6
+ import { secureUserStorage } from '../helpers/secureUserStorage';
7
+ import { pushLog } from '../utils/devLogger';
8
+
9
+ /**
10
+ * THE single refresh-token rotation point for the SDK.
11
+ *
12
+ * The backend now runs refresh-token ROTATION with REUSE DETECTION:
13
+ * every successful `/users/login/refresh` burns the presented refresh
14
+ * token and issues a new one. Presenting an already-rotated token is
15
+ * indistinguishable, server-side, from a stolen token — so it is
16
+ * treated as theft and (once the backend leaves monitor mode and
17
+ * enables enforcing mode) kills the whole token family.
18
+ *
19
+ * That puts three hard obligations on the client:
20
+ *
21
+ * 1. Persist the NEW refreshToken from every response, immediately,
22
+ * before any other logic can throw and drop it on the floor.
23
+ * 2. Never rotate concurrently. Two parallel refreshes both start
24
+ * from the same token; the loser presents a burned one and looks
25
+ * like an attacker. React Native is single-process, so a shared
26
+ * in-flight promise is the whole lock — no Web Locks needed (the
27
+ * web build of this component does need them, see its own
28
+ * `authRefresh.ts`).
29
+ * 3. Route EVERY refresh path through here. One "side" refresh
30
+ * elsewhere in the codebase breaks the scheme for everyone.
31
+ *
32
+ * Callers must also stop treating 401 as "log out". Two of the four
33
+ * refresh error codes are race signals, not auth failures — see
34
+ * `RefreshErrorCode` below and `RefreshFatalError`.
35
+ */
36
+
37
+ /**
38
+ * Thrown when the session is genuinely dead and the caller must do a
39
+ * hard logout (clear storage, drop XMPP, send the user to login).
40
+ *
41
+ * Anything else this module rejects with — network errors, 5xx, an
42
+ * unrecognised 401 — is NOT fatal and must NOT trigger a logout.
43
+ */
44
+ export class RefreshFatalError extends Error {
45
+ constructor(code, message) {
46
+ super(message || `Refresh failed: ${code}`);
47
+ this.name = 'RefreshFatalError';
48
+ this.code = code;
49
+ // Required for `instanceof` to survive TS's ES5 class-extends-builtin
50
+ // downlevelling, which RN's babel preset still applies.
51
+ Object.setPrototypeOf(this, RefreshFatalError.prototype);
52
+ }
53
+ }
54
+ export const isRefreshFatalError = error => error instanceof RefreshFatalError || error?.name === 'RefreshFatalError';
55
+ const REFRESH_ENDPOINT = '/v1/users/login/refresh';
56
+
57
+ /** `REFRESH_IN_PROGRESS` retry budget, per backend guidance (~300ms x 2-3). */
58
+ const IN_PROGRESS_MAX_ATTEMPTS = 3;
59
+ const IN_PROGRESS_BASE_DELAY_MS = 300;
60
+ /**
61
+ * Jitter matters: after a network blip every client in the app retries
62
+ * on the same schedule and would hammer the rotation mutex in lockstep.
63
+ */
64
+ const IN_PROGRESS_JITTER_MS = 150;
65
+ const KNOWN_CODES = ['REFRESH_IN_PROGRESS', 'REFRESH_TOKEN_ALREADY_ROTATED', 'REFRESH_TOKEN_REUSE_DETECTED', 'REFRESH_TOKEN_NOT_FOUND'];
66
+ const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
67
+ const inProgressDelay = attempt => IN_PROGRESS_BASE_DELAY_MS * attempt + Math.floor(Math.random() * IN_PROGRESS_JITTER_MS);
68
+
69
+ /**
70
+ * All four codes come back as HTTP 401, so the status alone tells us
71
+ * nothing — the code in the body is the only signal.
72
+ *
73
+ * TODO(backend-confirm): the exact location of `code` in the payload is
74
+ * not documented yet. Until it is, probe every shape the API uses
75
+ * elsewhere and take the first hit. Once confirmed, collapse this to
76
+ * the single real path.
77
+ */
78
+ export const parseRefreshErrorCode = error => {
79
+ const response = error?.response;
80
+ if (!response) {
81
+ return null;
82
+ }
83
+ const data = response.data;
84
+ const candidates = [data?.code, data?.error?.code, data?.errors?.[0]?.code, data?.error, data?.message, response.headers?.['x-error-code']];
85
+ for (const candidate of candidates) {
86
+ if (typeof candidate !== 'string') {
87
+ continue;
88
+ }
89
+ const match = KNOWN_CODES.find(code => candidate.includes(code));
90
+ if (match) {
91
+ return match;
92
+ }
93
+ }
94
+ return null;
95
+ };
96
+ const getStoreUser = () => store.getState().chatSettingStore?.user || {};
97
+
98
+ /**
99
+ * The refresh token as of RIGHT NOW. Read at the moment of use, never
100
+ * captured ahead of time — that is the single-process equivalent of the
101
+ * web build's "re-read inside the lock".
102
+ *
103
+ * Redux is the source of truth in RN (one process, one store);
104
+ * AsyncStorage is only consulted as a cold-start fallback, before
105
+ * `resolveInitBeforeLoadUser` has hydrated the store.
106
+ */
107
+ const readCurrentRefreshToken = async () => {
108
+ const fromStore = getStoreUser().refreshToken;
109
+ if (fromStore) {
110
+ return fromStore;
111
+ }
112
+ const stored = await secureUserStorage().get();
113
+ return stored?.refreshToken || '';
114
+ };
115
+
116
+ /**
117
+ * Persist BEFORE resolving. The dispatch updates redux (and, until
118
+ * phase 6 lands, fires its own best-effort AsyncStorage write); the
119
+ * awaited write below is the one that actually guarantees the rotated
120
+ * token survives the app being killed a moment later. Losing it means
121
+ * the next launch presents a burned token — i.e. looks like theft.
122
+ */
123
+ const persistTokens = async result => {
124
+ store.dispatch(refreshTokens({
125
+ token: result.token,
126
+ refreshToken: result.refreshToken,
127
+ xmppPassword: result.xmppPassword,
128
+ fileToken: result.fileToken
129
+ }));
130
+ try {
131
+ // Write the post-dispatch snapshot rather than a read-modify-write
132
+ // merge, so this can't race the reducer's own write back to a
133
+ // stale copy of the surrounding user fields.
134
+ await secureUserStorage().set(store.getState().chatSettingStore.user);
135
+ } catch (error) {
136
+ pushLog('warn', 'authRefresh: failed to persist rotated tokens', error);
137
+ }
138
+ };
139
+
140
+ /**
141
+ * A rotation that happened somewhere we didn't drive — currently only
142
+ * reachable via the ALREADY_ROTATED recovery path, kept separate so the
143
+ * web build and this one stay structurally identical.
144
+ */
145
+ const adoptStoredTokens = async () => {
146
+ const stored = await secureUserStorage().get();
147
+ if (!stored?.refreshToken || !stored?.token) {
148
+ return null;
149
+ }
150
+ const user = getStoreUser();
151
+ if (user.refreshToken !== stored.refreshToken) {
152
+ store.dispatch(refreshTokens({
153
+ token: stored.token,
154
+ refreshToken: stored.refreshToken
155
+ }));
156
+ }
157
+ return {
158
+ token: stored.token,
159
+ refreshToken: stored.refreshToken,
160
+ xmppPassword: stored.xmppPassword,
161
+ fileToken: stored.fileToken
162
+ };
163
+ };
164
+
165
+ /** Host-supplied rotation, mirrors `IConfig['refreshTokens']['refreshFunction']`. */
166
+
167
+ const runConsumerRefresh = async refreshFunction => {
168
+ const refreshed = await refreshFunction();
169
+ if (!refreshed?.accessToken) {
170
+ throw new Error('Custom refresh function did not return an access token');
171
+ }
172
+ if (!refreshed.refreshToken) {
173
+ // Not fatal — some hosts still run non-rotating backends — but on a
174
+ // rotating one this silently keeps a burned token around, which is
175
+ // exactly the failure the new scheme punishes.
176
+ pushLog('warn', 'authRefresh: custom refreshFunction returned no refreshToken; ' + 'keeping the existing one. On a rotating backend this will be ' + 'seen as token reuse.');
177
+ }
178
+ const result = {
179
+ token: refreshed.accessToken,
180
+ refreshToken: refreshed.refreshToken || (await readCurrentRefreshToken()) || '',
181
+ xmppPassword: refreshed.xmppPassword,
182
+ fileToken: refreshed.fileToken
183
+ };
184
+ await persistTokens(result);
185
+ return result;
186
+ };
187
+ const requestRotation = async refreshToken => {
188
+ const response = await http.post(REFRESH_ENDPOINT, {}, {
189
+ headers: {
190
+ Authorization: refreshToken
191
+ }
192
+ });
193
+ const result = {
194
+ token: response?.data?.token || '',
195
+ refreshToken: response?.data?.refreshToken || '',
196
+ wsToken: response?.data?.wsToken,
197
+ xmppPassword: response?.data?.xmppPassword,
198
+ fileToken: response?.data?.fileToken
199
+ };
200
+ if (!result.token || !result.refreshToken) {
201
+ throw new Error('Refresh response did not contain both tokens');
202
+ }
203
+
204
+ // Persist first, resolve second. Every early return between here and
205
+ // the caller is a chance to lose the rotation.
206
+ await persistTokens(result);
207
+ return result;
208
+ };
209
+ const performRefresh = async overrideToken => {
210
+ const consumerRefresh = store.getState().chatSettingStore?.config?.refreshTokens?.refreshFunction;
211
+ if (consumerRefresh) {
212
+ // A configured host function wins unconditionally — including over
213
+ // an explicit bootstrap token. Hosts that embed this SDK often own
214
+ // the Ethora refresh token themselves (their own storage, their own
215
+ // rotation) and only hand us a copy; rotating it here would burn
216
+ // THEIR token behind their back and leave them holding a dead one.
217
+ //
218
+ // It still has to be serialised — it hits the same backend mutex —
219
+ // hence running it inside the shared in-flight promise.
220
+ return runConsumerRefresh(consumerRefresh);
221
+ }
222
+ for (let attempt = 1; attempt <= IN_PROGRESS_MAX_ATTEMPTS; attempt++) {
223
+ const refreshToken = overrideToken || (await readCurrentRefreshToken());
224
+ if (!refreshToken) {
225
+ // Deliberately NOT fatal: a missing token mid-bootstrap must not
226
+ // nuke a session that is still being hydrated.
227
+ throw new Error('Refresh token is missing');
228
+ }
229
+ try {
230
+ return await requestRotation(refreshToken);
231
+ } catch (error) {
232
+ const code = parseRefreshErrorCode(error);
233
+ if (code === 'REFRESH_IN_PROGRESS') {
234
+ if (attempt < IN_PROGRESS_MAX_ATTEMPTS) {
235
+ await sleep(inProgressDelay(attempt));
236
+ continue;
237
+ }
238
+ // Budget spent. Whoever holds the mutex has very likely
239
+ // finished and written a newer token — take it if so. Skipped
240
+ // for an explicit token: it may belong to a different session
241
+ // than whatever is currently in storage.
242
+ const adopted = overrideToken ? null : await adoptStoredTokens();
243
+ if (adopted && adopted.refreshToken !== refreshToken) {
244
+ return adopted;
245
+ }
246
+ throw error;
247
+ }
248
+ if (code === 'REFRESH_TOKEN_ALREADY_ROTATED') {
249
+ // Our copy is stale. If something already wrote a newer token,
250
+ // this is a benign race — use it. Otherwise the session really
251
+ // is unrecoverable.
252
+ const adopted = overrideToken ? null : await adoptStoredTokens();
253
+ if (adopted && adopted.refreshToken !== refreshToken) {
254
+ return adopted;
255
+ }
256
+ throw new RefreshFatalError(code);
257
+ }
258
+ if (code === 'REFRESH_TOKEN_REUSE_DETECTED' || code === 'REFRESH_TOKEN_NOT_FOUND') {
259
+ throw new RefreshFatalError(code);
260
+ }
261
+
262
+ // Network error, 5xx, plain 401 without a code — pass through
263
+ // untouched. The caller must not log out on these.
264
+ throw error;
265
+ }
266
+ }
267
+
268
+ // Unreachable: the loop either returns or throws.
269
+ throw new Error('Refresh attempts exhausted');
270
+ };
271
+ let inflight = null;
272
+ let lastRotationAt = 0;
273
+ const QUIET_ROTATION_MIN_INTERVAL_MS = 5 * 60 * 1000;
274
+
275
+ /**
276
+ * Rotate the tokens. Concurrent callers share ONE request — this is the
277
+ * lock the new backend scheme requires.
278
+ *
279
+ * Rejects with `RefreshFatalError` when the session is dead (caller
280
+ * should hard-logout) and with a plain error otherwise (caller should
281
+ * surface the failure and leave the session alone).
282
+ */
283
+ export function refreshAuthTokens(options) {
284
+ if (inflight) {
285
+ // Whatever that rotation produces is at least as fresh as anything
286
+ // this caller could have asked for.
287
+ return inflight;
288
+ }
289
+ inflight = performRefresh(options?.refreshToken).then(result => {
290
+ lastRotationAt = Date.now();
291
+ return result;
292
+ }).finally(() => {
293
+ inflight = null;
294
+ });
295
+ return inflight;
296
+ }
297
+
298
+ /**
299
+ * Fire-and-forget variant for call sites that only want "make sure the
300
+ * tokens are fresh" and have no meaningful error handling — chat
301
+ * bootstrap, XMPP reconnect. Never rejects.
302
+ */
303
+
304
+ export async function refreshAuthTokensQuietly(options) {
305
+ if (!options?.force && Date.now() - lastRotationAt < QUIET_ROTATION_MIN_INTERVAL_MS) {
306
+ return null;
307
+ }
308
+ try {
309
+ return await refreshAuthTokens();
310
+ } catch (error) {
311
+ pushLog(isRefreshFatalError(error) ? 'error' : 'warn', 'authRefresh: background refresh failed', error);
312
+ return null;
313
+ }
314
+ }
315
+
316
+ /** Test seam — drops any shared in-flight promise between cases. */
317
+ export function __resetAuthRefreshStateForTests() {
318
+ inflight = null;
319
+ lastRotationAt = 0;
320
+ }
321
+ //# sourceMappingURL=authRefresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["http","store","refreshTokens","secureUserStorage","pushLog","RefreshFatalError","Error","constructor","code","message","name","Object","setPrototypeOf","prototype","isRefreshFatalError","error","REFRESH_ENDPOINT","IN_PROGRESS_MAX_ATTEMPTS","IN_PROGRESS_BASE_DELAY_MS","IN_PROGRESS_JITTER_MS","KNOWN_CODES","sleep","ms","Promise","resolve","setTimeout","inProgressDelay","attempt","Math","floor","random","parseRefreshErrorCode","response","data","candidates","errors","headers","candidate","match","find","includes","getStoreUser","getState","chatSettingStore","user","readCurrentRefreshToken","fromStore","refreshToken","stored","get","persistTokens","result","dispatch","token","xmppPassword","fileToken","set","adoptStoredTokens","runConsumerRefresh","refreshFunction","refreshed","accessToken","requestRotation","post","Authorization","wsToken","performRefresh","overrideToken","consumerRefresh","config","adopted","inflight","lastRotationAt","QUIET_ROTATION_MIN_INTERVAL_MS","refreshAuthTokens","options","then","Date","now","finally","refreshAuthTokensQuietly","force","__resetAuthRefreshStateForTests"],"sourceRoot":"../../../src","sources":["networking/authRefresh.ts"],"mappings":";;A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