chat 1.0.6 → 3.0.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 (318) hide show
  1. package/package.json +2 -96
  2. package/readme.md +1 -201
  3. package/lib/module/ChatContext/index.js +0 -2
  4. package/lib/module/ChatContext/index.js.map +0 -1
  5. package/lib/module/ChatContext/types.js +0 -2
  6. package/lib/module/ChatContext/types.js.map +0 -1
  7. package/lib/module/classes/Chat/index.js +0 -2
  8. package/lib/module/classes/Chat/index.js.map +0 -1
  9. package/lib/module/classes/Chat/types.js +0 -2
  10. package/lib/module/classes/Chat/types.js.map +0 -1
  11. package/lib/module/classes/Inbox/index.js +0 -2
  12. package/lib/module/classes/Inbox/index.js.map +0 -1
  13. package/lib/module/classes/Inbox/types.js +0 -2
  14. package/lib/module/classes/Inbox/types.js.map +0 -1
  15. package/lib/module/classes/Message/index.js +0 -2
  16. package/lib/module/classes/Message/index.js.map +0 -1
  17. package/lib/module/classes/Message/types.js +0 -2
  18. package/lib/module/classes/Message/types.js.map +0 -1
  19. package/lib/module/classes/Reaction/index.js +0 -2
  20. package/lib/module/classes/Reaction/index.js.map +0 -1
  21. package/lib/module/classes/Reaction/types.js +0 -2
  22. package/lib/module/classes/Reaction/types.js.map +0 -1
  23. package/lib/module/classes/Room/index.js +0 -2
  24. package/lib/module/classes/Room/index.js.map +0 -1
  25. package/lib/module/classes/Room/types.js +0 -2
  26. package/lib/module/classes/Room/types.js.map +0 -1
  27. package/lib/module/classes/index.js +0 -2
  28. package/lib/module/classes/index.js.map +0 -1
  29. package/lib/module/components/Avatar/index.js +0 -2
  30. package/lib/module/components/Avatar/index.js.map +0 -1
  31. package/lib/module/components/Chat/Bubble/index.js +0 -2
  32. package/lib/module/components/Chat/Bubble/index.js.map +0 -1
  33. package/lib/module/components/Chat/Composer/Input/index.js +0 -2
  34. package/lib/module/components/Chat/Composer/Input/index.js.map +0 -1
  35. package/lib/module/components/Chat/Composer/Send/index.js +0 -2
  36. package/lib/module/components/Chat/Composer/Send/index.js.map +0 -1
  37. package/lib/module/components/Chat/Composer/index.js +0 -2
  38. package/lib/module/components/Chat/Composer/index.js.map +0 -1
  39. package/lib/module/components/Chat/Media/Image/index.js +0 -2
  40. package/lib/module/components/Chat/Media/Image/index.js.map +0 -1
  41. package/lib/module/components/Chat/Media/index.js +0 -2
  42. package/lib/module/components/Chat/Media/index.js.map +0 -1
  43. package/lib/module/components/Chat/Message/Swiper/Action/index.js +0 -2
  44. package/lib/module/components/Chat/Message/Swiper/Action/index.js.map +0 -1
  45. package/lib/module/components/Chat/Message/Swiper/index.js +0 -2
  46. package/lib/module/components/Chat/Message/Swiper/index.js.map +0 -1
  47. package/lib/module/components/Chat/Message/Touchable/index.js +0 -2
  48. package/lib/module/components/Chat/Message/Touchable/index.js.map +0 -1
  49. package/lib/module/components/Chat/Message/index.js +0 -2
  50. package/lib/module/components/Chat/Message/index.js.map +0 -1
  51. package/lib/module/components/Chat/SystemMessage/index.js +0 -2
  52. package/lib/module/components/Chat/SystemMessage/index.js.map +0 -1
  53. package/lib/module/components/Chat/TypingFooter/index.js +0 -2
  54. package/lib/module/components/Chat/TypingFooter/index.js.map +0 -1
  55. package/lib/module/components/Chat/index.js +0 -2
  56. package/lib/module/components/Chat/index.js.map +0 -1
  57. package/lib/module/components/Chat/types.js +0 -2
  58. package/lib/module/components/Chat/types.js.map +0 -1
  59. package/lib/module/components/Chat-Old/Bubble/index.js +0 -2
  60. package/lib/module/components/Chat-Old/Bubble/index.js.map +0 -1
  61. package/lib/module/components/Chat-Old/Composer/Input/index.js +0 -2
  62. package/lib/module/components/Chat-Old/Composer/Input/index.js.map +0 -1
  63. package/lib/module/components/Chat-Old/Composer/Send/index.js +0 -2
  64. package/lib/module/components/Chat-Old/Composer/Send/index.js.map +0 -1
  65. package/lib/module/components/Chat-Old/Composer/index.js +0 -2
  66. package/lib/module/components/Chat-Old/Composer/index.js.map +0 -1
  67. package/lib/module/components/Chat-Old/Message/index.js +0 -2
  68. package/lib/module/components/Chat-Old/Message/index.js.map +0 -1
  69. package/lib/module/components/Chat-Old/Swiper/Action/index.js +0 -2
  70. package/lib/module/components/Chat-Old/Swiper/Action/index.js.map +0 -1
  71. package/lib/module/components/Chat-Old/Swiper/index.js +0 -2
  72. package/lib/module/components/Chat-Old/Swiper/index.js.map +0 -1
  73. package/lib/module/components/Chat-Old/SystemMessage/index.js +0 -2
  74. package/lib/module/components/Chat-Old/SystemMessage/index.js.map +0 -1
  75. package/lib/module/components/Chat-Old/index.js +0 -2
  76. package/lib/module/components/Chat-Old/index.js.map +0 -1
  77. package/lib/module/components/Chat-Old/types.js +0 -2
  78. package/lib/module/components/Chat-Old/types.js.map +0 -1
  79. package/lib/module/components/ChatProvider/index.js +0 -2
  80. package/lib/module/components/ChatProvider/index.js.map +0 -1
  81. package/lib/module/components/ChatProvider/types.js +0 -2
  82. package/lib/module/components/ChatProvider/types.js.map +0 -1
  83. package/lib/module/components/Inbox/Item/Circle/index.js +0 -2
  84. package/lib/module/components/Inbox/Item/Circle/index.js.map +0 -1
  85. package/lib/module/components/Inbox/Item/Circle/types.js +0 -2
  86. package/lib/module/components/Inbox/Item/Circle/types.js.map +0 -1
  87. package/lib/module/components/Inbox/Item/Initials/index.js +0 -2
  88. package/lib/module/components/Inbox/Item/Initials/index.js.map +0 -1
  89. package/lib/module/components/Inbox/Item/ItemDate/index.js +0 -2
  90. package/lib/module/components/Inbox/Item/ItemDate/index.js.map +0 -1
  91. package/lib/module/components/Inbox/Item/Separator/index.js +0 -2
  92. package/lib/module/components/Inbox/Item/Separator/index.js.map +0 -1
  93. package/lib/module/components/Inbox/Item/Subtitle/index.js +0 -2
  94. package/lib/module/components/Inbox/Item/Subtitle/index.js.map +0 -1
  95. package/lib/module/components/Inbox/Item/Swipeable/index.js +0 -2
  96. package/lib/module/components/Inbox/Item/Swipeable/index.js.map +0 -1
  97. package/lib/module/components/Inbox/Item/Title/index.js +0 -2
  98. package/lib/module/components/Inbox/Item/Title/index.js.map +0 -1
  99. package/lib/module/components/Inbox/Item/UnreadIndicator/index.js +0 -2
  100. package/lib/module/components/Inbox/Item/UnreadIndicator/index.js.map +0 -1
  101. package/lib/module/components/Inbox/Item/index.js +0 -2
  102. package/lib/module/components/Inbox/Item/index.js.map +0 -1
  103. package/lib/module/components/Inbox/index.js +0 -2
  104. package/lib/module/components/Inbox/index.js.map +0 -1
  105. package/lib/module/components/Inbox/question.md +0 -21
  106. package/lib/module/components/Inbox/readme.md +0 -21
  107. package/lib/module/components/Inbox/types.js +0 -2
  108. package/lib/module/components/Inbox/types.js.map +0 -1
  109. package/lib/module/components/RoomCreator/Content/Footer/Button/index.js +0 -2
  110. package/lib/module/components/RoomCreator/Content/Footer/Button/index.js.map +0 -1
  111. package/lib/module/components/RoomCreator/Content/Footer/Input/index.js +0 -2
  112. package/lib/module/components/RoomCreator/Content/Footer/Input/index.js.map +0 -1
  113. package/lib/module/components/RoomCreator/Content/Footer/index.js +0 -2
  114. package/lib/module/components/RoomCreator/Content/Footer/index.js.map +0 -1
  115. package/lib/module/components/RoomCreator/Content/Item/Icon/index.js +0 -2
  116. package/lib/module/components/RoomCreator/Content/Item/Icon/index.js.map +0 -1
  117. package/lib/module/components/RoomCreator/Content/Item/index.js +0 -2
  118. package/lib/module/components/RoomCreator/Content/Item/index.js.map +0 -1
  119. package/lib/module/components/RoomCreator/Content/index.js +0 -2
  120. package/lib/module/components/RoomCreator/Content/index.js.map +0 -1
  121. package/lib/module/components/RoomCreator/Header/index.js +0 -2
  122. package/lib/module/components/RoomCreator/Header/index.js.map +0 -1
  123. package/lib/module/components/RoomCreator/index.js +0 -2
  124. package/lib/module/components/RoomCreator/index.js.map +0 -1
  125. package/lib/module/components/RoomCreator/types.js +0 -2
  126. package/lib/module/components/RoomCreator/types.js.map +0 -1
  127. package/lib/module/components/TypingIndicator/index.js +0 -2
  128. package/lib/module/components/TypingIndicator/index.js.map +0 -1
  129. package/lib/module/components/index.js +0 -2
  130. package/lib/module/components/index.js.map +0 -1
  131. package/lib/module/helpers/getInitials.js +0 -2
  132. package/lib/module/helpers/getInitials.js.map +0 -1
  133. package/lib/module/helpers/sortByAvatar.js +0 -2
  134. package/lib/module/helpers/sortByAvatar.js.map +0 -1
  135. package/lib/module/hooks/index.js +0 -2
  136. package/lib/module/hooks/index.js.map +0 -1
  137. package/lib/module/hooks/useCreateRoom/index.js +0 -2
  138. package/lib/module/hooks/useCreateRoom/index.js.map +0 -1
  139. package/lib/module/hooks/useCreator/index.js +0 -2
  140. package/lib/module/hooks/useCreator/index.js.map +0 -1
  141. package/lib/module/hooks/useInbox/index.js +0 -2
  142. package/lib/module/hooks/useInbox/index.js.map +0 -1
  143. package/lib/module/hooks/useInbox/types.js +0 -2
  144. package/lib/module/hooks/useInbox/types.js.map +0 -1
  145. package/lib/module/hooks/useMessages/index.js +0 -2
  146. package/lib/module/hooks/useMessages/index.js.map +0 -1
  147. package/lib/module/hooks/useMessages/types.js +0 -2
  148. package/lib/module/hooks/useMessages/types.js.map +0 -1
  149. package/lib/module/hooks/useRoom/index.js +0 -2
  150. package/lib/module/hooks/useRoom/index.js.map +0 -1
  151. package/lib/module/hooks/useRoom/types.js +0 -2
  152. package/lib/module/hooks/useRoom/types.js.map +0 -1
  153. package/lib/module/hooks/useSend/useSendToGroup/index.js +0 -2
  154. package/lib/module/hooks/useSend/useSendToGroup/index.js.map +0 -1
  155. package/lib/module/hooks/useSend/useSendToPeople/index.js +0 -2
  156. package/lib/module/hooks/useSend/useSendToPeople/index.js.map +0 -1
  157. package/lib/module/hooks/useTyping/index.js +0 -2
  158. package/lib/module/hooks/useTyping/index.js.map +0 -1
  159. package/lib/module/hooks/useTypingOLD/index.js +0 -2
  160. package/lib/module/hooks/useTypingOLD/index.js.map +0 -1
  161. package/lib/module/hooks/useTypingOLD/types.js +0 -2
  162. package/lib/module/hooks/useTypingOLD/types.js.map +0 -1
  163. package/lib/module/hooks/useViewMessages/index.js +0 -2
  164. package/lib/module/hooks/useViewMessages/index.js.map +0 -1
  165. package/lib/module/hooks/useViewMessages/types.js +0 -2
  166. package/lib/module/hooks/useViewMessages/types.js.map +0 -1
  167. package/lib/module/hooks/useViewMessagesOld/index.js +0 -2
  168. package/lib/module/hooks/useViewMessagesOld/index.js.map +0 -1
  169. package/lib/module/index.js +0 -2
  170. package/lib/module/index.js.map +0 -1
  171. package/lib/typescript/ChatContext/index.d.ts +0 -2
  172. package/lib/typescript/ChatContext/types.d.ts +0 -4
  173. package/lib/typescript/classes/Chat/index.d.ts +0 -14
  174. package/lib/typescript/classes/Chat/types.d.ts +0 -21
  175. package/lib/typescript/classes/Inbox/types.d.ts +0 -2
  176. package/lib/typescript/classes/Message/index.d.ts +0 -47
  177. package/lib/typescript/classes/Message/types.d.ts +0 -66
  178. package/lib/typescript/classes/Reaction/index.d.ts +0 -17
  179. package/lib/typescript/classes/Reaction/types.d.ts +0 -33
  180. package/lib/typescript/classes/Room/index.d.ts +0 -42
  181. package/lib/typescript/classes/Room/types.d.ts +0 -112
  182. package/lib/typescript/classes/index.d.ts +0 -4
  183. package/lib/typescript/components/Avatar/index.d.ts +0 -4
  184. package/lib/typescript/components/Chat/Bubble/index.d.ts +0 -4
  185. package/lib/typescript/components/Chat/Composer/Input/index.d.ts +0 -7
  186. package/lib/typescript/components/Chat/Composer/Send/index.d.ts +0 -4
  187. package/lib/typescript/components/Chat/Composer/index.d.ts +0 -8
  188. package/lib/typescript/components/Chat/Media/Image/index.d.ts +0 -7
  189. package/lib/typescript/components/Chat/Media/index.d.ts +0 -4
  190. package/lib/typescript/components/Chat/Message/Touchable/index.d.ts +0 -4
  191. package/lib/typescript/components/Chat/Message/index.d.ts +0 -8
  192. package/lib/typescript/components/Chat/SystemMessage/index.d.ts +0 -4
  193. package/lib/typescript/components/Chat/TypingFooter/index.d.ts +0 -4
  194. package/lib/typescript/components/Chat/index.d.ts +0 -8
  195. package/lib/typescript/components/Chat/types.d.ts +0 -844
  196. package/lib/typescript/components/ChatProvider/index.d.ts +0 -10
  197. package/lib/typescript/components/ChatProvider/types.d.ts +0 -7
  198. package/lib/typescript/components/Inbox/Item/Initials/index.d.ts +0 -4
  199. package/lib/typescript/components/Inbox/Item/ItemDate/index.d.ts +0 -4
  200. package/lib/typescript/components/Inbox/Item/Separator/index.d.ts +0 -6
  201. package/lib/typescript/components/Inbox/Item/Subtitle/index.d.ts +0 -3
  202. package/lib/typescript/components/Inbox/Item/Swipeable/index.d.ts +0 -4
  203. package/lib/typescript/components/Inbox/Item/Title/index.d.ts +0 -3
  204. package/lib/typescript/components/Inbox/Item/UnreadIndicator/index.d.ts +0 -4
  205. package/lib/typescript/components/Inbox/Item/index.d.ts +0 -6
  206. package/lib/typescript/components/Inbox/index.d.ts +0 -4
  207. package/lib/typescript/components/Inbox/types.d.ts +0 -304
  208. package/lib/typescript/components/RoomCreator/Content/Footer/Button/index.d.ts +0 -4
  209. package/lib/typescript/components/RoomCreator/Content/Footer/Input/index.d.ts +0 -4
  210. package/lib/typescript/components/RoomCreator/Content/Footer/index.d.ts +0 -3
  211. package/lib/typescript/components/RoomCreator/Content/Item/Icon/index.d.ts +0 -4
  212. package/lib/typescript/components/RoomCreator/Content/Item/index.d.ts +0 -4
  213. package/lib/typescript/components/RoomCreator/Content/index.d.ts +0 -4
  214. package/lib/typescript/components/RoomCreator/Header/index.d.ts +0 -4
  215. package/lib/typescript/components/RoomCreator/index.d.ts +0 -4
  216. package/lib/typescript/components/RoomCreator/types.d.ts +0 -208
  217. package/lib/typescript/components/TypingIndicator/index.d.ts +0 -9
  218. package/lib/typescript/components/index.d.ts +0 -12
  219. package/lib/typescript/helpers/getInitials.d.ts +0 -1
  220. package/lib/typescript/hooks/index.d.ts +0 -8
  221. package/lib/typescript/hooks/useCreator/index.d.ts +0 -27
  222. package/lib/typescript/hooks/useInbox/index.d.ts +0 -29
  223. package/lib/typescript/hooks/useInbox/types.d.ts +0 -5
  224. package/lib/typescript/hooks/useMessages/index.d.ts +0 -24
  225. package/lib/typescript/hooks/useMessages/types.d.ts +0 -5
  226. package/lib/typescript/hooks/useRoom/index.d.ts +0 -26
  227. package/lib/typescript/hooks/useRoom/types.d.ts +0 -5
  228. package/lib/typescript/hooks/useSend/useSendToGroup/index.d.ts +0 -6
  229. package/lib/typescript/hooks/useSend/useSendToPeople/index.d.ts +0 -6
  230. package/lib/typescript/hooks/useTyping/index.d.ts +0 -36
  231. package/lib/typescript/hooks/useViewMessages/index.d.ts +0 -18
  232. package/lib/typescript/hooks/useViewMessages/types.d.ts +0 -20
  233. package/lib/typescript/index.d.ts +0 -11
  234. package/src/ChatContext/index.tsx +0 -9
  235. package/src/ChatContext/types.ts +0 -4
  236. package/src/classes/Chat/index.ts +0 -46
  237. package/src/classes/Chat/types.ts +0 -23
  238. package/src/classes/Inbox/index.ts +0 -12
  239. package/src/classes/Inbox/types.ts +0 -3
  240. package/src/classes/Message/index.ts +0 -310
  241. package/src/classes/Message/types.ts +0 -118
  242. package/src/classes/Reaction/index.ts +0 -108
  243. package/src/classes/Reaction/types.ts +0 -37
  244. package/src/classes/Room/index.ts +0 -323
  245. package/src/classes/Room/types.ts +0 -161
  246. package/src/classes/index.ts +0 -4
  247. package/src/components/Avatar/index.tsx +0 -25
  248. package/src/components/Chat/Bubble/index.tsx +0 -139
  249. package/src/components/Chat/Composer/Input/index.tsx +0 -45
  250. package/src/components/Chat/Composer/Send/index.tsx +0 -51
  251. package/src/components/Chat/Composer/index.tsx +0 -184
  252. package/src/components/Chat/Media/Image/index.tsx +0 -26
  253. package/src/components/Chat/Media/index.tsx +0 -11
  254. package/src/components/Chat/Message/Swiper/Action/index.tsx +0 -7
  255. package/src/components/Chat/Message/Swiper/index.tsx +0 -32
  256. package/src/components/Chat/Message/Touchable/index.tsx +0 -60
  257. package/src/components/Chat/Message/index.tsx +0 -328
  258. package/src/components/Chat/SystemMessage/index.tsx +0 -44
  259. package/src/components/Chat/TypingFooter/index.tsx +0 -48
  260. package/src/components/Chat/index.tsx +0 -592
  261. package/src/components/Chat/types.ts +0 -911
  262. package/src/components/Chat-Old/Bubble/index.tsx +0 -58
  263. package/src/components/Chat-Old/Composer/Input/index.tsx +0 -34
  264. package/src/components/Chat-Old/Composer/Send/index.tsx +0 -37
  265. package/src/components/Chat-Old/Composer/index.tsx +0 -131
  266. package/src/components/Chat-Old/Message/index.tsx +0 -160
  267. package/src/components/Chat-Old/Swiper/Action/index.tsx +0 -7
  268. package/src/components/Chat-Old/Swiper/index.tsx +0 -30
  269. package/src/components/Chat-Old/SystemMessage/index.tsx +0 -44
  270. package/src/components/Chat-Old/index.tsx +0 -356
  271. package/src/components/Chat-Old/types.ts +0 -752
  272. package/src/components/ChatProvider/index.tsx +0 -31
  273. package/src/components/ChatProvider/types.ts +0 -8
  274. package/src/components/Inbox/Item/Circle/index.tsx +0 -47
  275. package/src/components/Inbox/Item/Circle/types.ts +0 -8
  276. package/src/components/Inbox/Item/Initials/index.tsx +0 -41
  277. package/src/components/Inbox/Item/ItemDate/index.tsx +0 -26
  278. package/src/components/Inbox/Item/Separator/index.tsx +0 -13
  279. package/src/components/Inbox/Item/Subtitle/index.tsx +0 -23
  280. package/src/components/Inbox/Item/Swipeable/index.tsx +0 -143
  281. package/src/components/Inbox/Item/Title/index.tsx +0 -23
  282. package/src/components/Inbox/Item/UnreadIndicator/index.tsx +0 -84
  283. package/src/components/Inbox/Item/index.tsx +0 -307
  284. package/src/components/Inbox/index.tsx +0 -315
  285. package/src/components/Inbox/question.md +0 -21
  286. package/src/components/Inbox/readme.md +0 -21
  287. package/src/components/Inbox/types.ts +0 -371
  288. package/src/components/RoomCreator/Content/Footer/Button/index.tsx +0 -55
  289. package/src/components/RoomCreator/Content/Footer/Input/index.tsx +0 -27
  290. package/src/components/RoomCreator/Content/Footer/index.tsx +0 -72
  291. package/src/components/RoomCreator/Content/Item/Icon/index.tsx +0 -16
  292. package/src/components/RoomCreator/Content/Item/index.tsx +0 -87
  293. package/src/components/RoomCreator/Content/index.tsx +0 -75
  294. package/src/components/RoomCreator/Header/index.tsx +0 -74
  295. package/src/components/RoomCreator/index.tsx +0 -177
  296. package/src/components/RoomCreator/types.ts +0 -233
  297. package/src/components/TypingIndicator/index.tsx +0 -169
  298. package/src/components/index.ts +0 -18
  299. package/src/helpers/getInitials.ts +0 -11
  300. package/src/helpers/sortByAvatar.ts +0 -1
  301. package/src/hooks/index.ts +0 -8
  302. package/src/hooks/useCreateRoom/index.ts +0 -34
  303. package/src/hooks/useCreator/index.ts +0 -33
  304. package/src/hooks/useInbox/index.ts +0 -76
  305. package/src/hooks/useInbox/types.ts +0 -6
  306. package/src/hooks/useMessages/index.ts +0 -109
  307. package/src/hooks/useMessages/types.ts +0 -6
  308. package/src/hooks/useRoom/index.ts +0 -82
  309. package/src/hooks/useRoom/types.ts +0 -6
  310. package/src/hooks/useSend/useSendToGroup/index.ts +0 -38
  311. package/src/hooks/useSend/useSendToPeople/index.ts +0 -38
  312. package/src/hooks/useTyping/index.ts +0 -154
  313. package/src/hooks/useTypingOLD/index.ts +0 -67
  314. package/src/hooks/useTypingOLD/types.ts +0 -7
  315. package/src/hooks/useViewMessages/index.ts +0 -61
  316. package/src/hooks/useViewMessages/types.ts +0 -22
  317. package/src/hooks/useViewMessagesOld/index.ts +0 -39
  318. package/src/index.ts +0 -13
package/package.json CHANGED
@@ -1,98 +1,4 @@
1
1
  {
2
- "name": "chat",
3
- "description": "The best fully-hosted chat solution for React Native/Expo.",
4
- "version": "1.0.6",
5
- "main": "lib/module/index",
6
- "module": "lib/module/index",
7
- "react-native": "lib/module/index",
8
- "types": "lib/typescript/index",
9
- "homepage": "https://github.com/nandorojo/chatjs",
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/nandorojo/chatjs"
13
- },
14
- "scripts": {
15
- "type-check": "tsc --noEmit",
16
- "type-check:watch": "npm run type-check -- --watch",
17
- "build": "npm run build:types && npm run build:js",
18
- "bundle": "babel src --out-file bundle/index.js --extensions \".ts,.tsx\" --source-maps inline",
19
- "build:tsc": "npm run build:types && npm run build:test",
20
- "build:redash:types": "tsc --noEmit",
21
- "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
22
- "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
23
- "build:test": "rm -R lib && babel src-og --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
24
- "build:babel": "rm -R lib && babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline",
25
- "build:final": "mkdir -p bundle && npm run bundle && npm run build:types",
26
- "prepare": "bob build",
27
- "upload": "yarn prepare && yarn publish",
28
- "docz:dev": "docz dev",
29
- "docz:build": "docz build",
30
- "docz:serve": "docz build && docz serve"
31
- },
32
- "devDependencies": {
33
- "@babel/cli": "^7.2.3",
34
- "@babel/core": "^7.4.0",
35
- "@babel/plugin-proposal-class-properties": "^7.4.0",
36
- "@babel/plugin-proposal-numeric-separator": "^7.2.0",
37
- "@babel/plugin-proposal-object-rest-spread": "^7.4.0",
38
- "@babel/plugin-proposal-optional-chaining": "^7.2.0",
39
- "@babel/preset-env": "^7.4.1",
40
- "@babel/preset-react": "^7.0.0",
41
- "@babel/preset-typescript": "^7.3.3",
42
- "@expo/vector-icons": "^10.0.5",
43
- "@firebase/firestore-types": "^1.4.4",
44
- "@react-native-community/bob": "^0.6.1",
45
- "@types/react": "^16.9.1",
46
- "@types/react-dom": "^16.8.5",
47
- "@types/react-native": "^0.60.4",
48
- "@types/uuid": "^3.4.5",
49
- "@typescript-eslint/eslint-plugin": "^2.1.0",
50
- "@typescript-eslint/parser": "^2.1.0",
51
- "babel-preset-expo": "^8.0.0",
52
- "docz": "^2.2.0",
53
- "eslint": "^6.8.0",
54
- "eslint-config-nando": "^1.0.3",
55
- "eslint-config-prettier": "^6.3.0",
56
- "eslint-config-rallycoding": "^3.2.0",
57
- "eslint-plugin-react": "^7.14.3",
58
- "eslint-plugin-react-hooks": "^1.7.0",
59
- "expo": "^36.0.2",
60
- "firebase": "^6.2.4",
61
- "gatsby-plugin-react-native-web": "^3.0.0-beta.7",
62
- "prettier": "^1.19.1",
63
- "prettier-eslint": "^9.0.0",
64
- "react": "^16.9.0",
65
- "react-art": "^16.12.0",
66
- "react-dom": "^16.12.0",
67
- "react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
68
- "react-native-web": "^0.12.2",
69
- "typescript": "^3.8.3"
70
- },
71
- "dependencies": {
72
- "@nandorojo/fuego": "^0.0.24",
73
- "expo-linear-gradient": "^8.0.0",
74
- "moment": "^2.24.0",
75
- "react-native-gesture-handler": "^1.6.0",
76
- "react-native-iphone-x-helper": "^1.2.1",
77
- "react-native-reanimated": "^1.7.0",
78
- "reanimated-bottom-sheet": "^1.0.0-alpha.13",
79
- "uuid": "^3.3.3"
80
- },
81
- "bugs": {
82
- "url": "https://github.com/nandorojo/chatjs/issues"
83
- },
84
- "author": "Fernando Rojo",
85
- "license": "MIT",
86
- "files": [
87
- "lib",
88
- "src"
89
- ],
90
- "@react-native-community/bob": {
91
- "source": "src",
92
- "output": "lib",
93
- "targets": [
94
- "module",
95
- "typescript"
96
- ]
97
- }
2
+ "name": "chat",
3
+ "version": "3.0.0"
98
4
  }
package/readme.md CHANGED
@@ -1,201 +1 @@
1
- # `chat` 🍹
2
-
3
- ```sh
4
- yarn add chat
5
- ```
6
-
7
- Build production-ready, full-stack chat in minutes. Drop in our pre-made UI components, connect them to your backend our pre-made logic, and you're good to go.
8
-
9
- **Stop worrying about:**
10
-
11
- ✅ Auth
12
-
13
- ✅ Customizable UI
14
-
15
- ✅ Transitions & animations
16
-
17
- ✅ Websockets, data & fallbacks
18
-
19
- ✅ Offline support (beta)
20
-
21
- ✅ 1-on-1 and group chats
22
-
23
- ```javascript
24
- import * as React
25
- import { useMessages, Messages } from 'usechat'
26
-
27
- const ChatScreen = () => {
28
- const { data, send } = useMessages({ id: 'my-first-chat-room' })
29
-
30
- return <Messages onSend={send} messages={data} />
31
- }
32
-
33
- ```
34
-
35
- ## Backend setup for firebase
36
-
37
- If you only want to use this library for the UI components, there is no further setup required.
38
-
39
- However, if you want to connect your firebase/firestore backend, there is are two added steps.
40
-
41
- **1. Install dependencies**
42
-
43
- ```
44
- yarn add firebase @nandorojo/fuego
45
- ```
46
-
47
- **2. Add the provider to the root of your app**
48
-
49
- Initialize `fuego`'s db first. Then, wrap your app with the `ChatProvider`.
50
-
51
- ```jsx
52
- // App.tsx
53
- import * as React from 'react'
54
- import { ChatProvider } from 'chat'
55
- import { Fuego } from '@nandorojo/fuego'
56
-
57
- const fuego = new Fuego({
58
- //...firebase config here
59
- })
60
-
61
- export default () => {
62
- return <ChatProvider fuego={fuego}>{/* Your app goes here*/}</ChatProvider>
63
- }
64
- ```
65
-
66
- [How to find your firebase config](https://support.google.com/firebase/answer/7015592?hl=en#web)
67
-
68
- _Note_: Make sure you've enabled firebase firestore to use this. See [this tutorial](https://blog.expo.io/how-to-build-a-chat-app-with-react-native-3ef8604ebb3c) for more.
69
-
70
- ## Brief Example
71
-
72
- This is all it takes to build a **full-stack** live chat with `chat` in React/React Native (with some abstraction).
73
-
74
- ```jsx
75
- import * as React
76
- import { useNavigation, useNavigationParam } from 'react-navigation'
77
- import { useInbox, Inbox, useMessages, Messages } from 'usechat'
78
-
79
- const InboxScreen = () => {
80
- const { data } = useInbox()
81
- const navigation = useNavigation()
82
-
83
- return <Inbox rooms={data} onPressItem={id => navigation.navigate('Chat', { id })} >
84
- }
85
-
86
- const ChatScreen = () => {
87
- const id = useNavigationParam('id')
88
- const { data, send } = useMessages({ id })
89
-
90
- return <Messages onSend={send} messages={data} />
91
- }
92
-
93
- ```
94
-
95
- ## Highlights
96
-
97
- 😎 Works with `react` and `react native` **(including Expo!)**
98
-
99
- 🚨 Integrates with Firebase auth (and can also work with your custom auth solutions)
100
-
101
- 📣 Integrates with `expo-notifications`
102
-
103
- 🥐 Fully customizable UI components
104
-
105
- 🍇 Production-level animations, transitions, and swipe gestures.
106
-
107
- 👾 Written in TypeScript
108
-
109
- ---
110
-
111
- # Get Started
112
-
113
- Setup is quick and easy. Jump to the setup guide. Then, check out the hello world and example.
114
-
115
- ---
116
-
117
- ## Chat features included out-of-the-box
118
-
119
- ✏️ Typing indicators
120
-
121
- 💯 Unread count
122
-
123
- 😂 Meme search (powered by Memezy)
124
-
125
- 👻 Image & video, **including** uploading logic & content storage
126
-
127
- 🍪 Online status
128
-
129
- 🕺 Realtime inbox
130
-
131
- 🤯 Realtime chat rooms
132
-
133
- 😇 Room-level user permissions
134
-
135
- 🔥 Group chats
136
-
137
- 👴 Customizable system messages (ex: William Buzzelbees changed the group name to "Frankenstein's Friday Squad")
138
-
139
- 👀 Send a message to multiple people, even if a room with those people doesn't exist yet (like an instagram feed-to-DM flow.)
140
-
141
- 🥇 Room names (coming soon)
142
-
143
- ## Customizable components included
144
-
145
- 🧤 `<AuthGate />` wraps your app and gives it customizable auth, powered by firebase.
146
-
147
- 🧢 `<Inbox />` gives you a real-time list of chat rooms.
148
-
149
- 🎩 `<InboxItem />` List item for `<Inbox />`, including customizable swipe gestures.
150
-
151
- ⛑ `<TypingIndicator />` Show typing, with animations, as it happens
152
-
153
- 🍪 `<UnreadIndicator />` Show an iMessage-like unread indicator, with or without the number of unread messages.
154
-
155
- ⚡️ `<Messages />` Like GiftedChat, to the max.
156
-
157
- ## All the logic you'd need for a chat, handled.
158
-
159
- Functions are pre-made for the following:
160
-
161
- 🐻 Create chat room
162
-
163
- 🎃 Leave chat room
164
-
165
- 🤘 Remove users from chat room
166
-
167
- 👮‍♂️ Customizable avatars for chat rooms
168
-
169
- 🏄🏾‍♂️ Add people to a chat room
170
-
171
- ## Auth integration
172
-
173
- ### If you're using Firebase auth
174
-
175
- Chat will automatically integrate into your Firebase auth if you're using it once you've completed the setup.
176
-
177
- ## Aren't there a lot of chat SDKs already? What makes this better than all the others?
178
-
179
- Yes, there are. The motivation for this library comes down to only one concept: **production-ready** chat.
180
-
181
- If you google `react native chat tutorial`, you'll come up with many smart people writing good articles about building your first chat app. Suggestions range from using firebase's highly-customizable serverless database to more opinionated startups that build SDKs for chat only.
182
-
183
- The thing is, none of these options created a production-ready chat that "thinks in React."
184
-
185
- With a custom option like Firebase, you're having to deal with tons of different socket subscriptions, chat schema changes, etc, and building in features like unread count, online status, or typing indicators becomes non-trivial quickly.
186
-
187
- Meanwhile, existing JavaScript chat SDKs aren't made with React's stateful nature in mind. Companies like Pusher, PubNub, and Stream clearly have something good going for them, but they aren't made for React the way a library like `Apollo` is.
188
-
189
- **You should be able to build a customizable, full-stack chat with only a few lines of code.** If Stripe can do that for accepting payments, we can do it for sending words.
190
-
191
- Tutorials for existing chat SDKs have you typing `setState` dozens of times, and you wonder, would this actually look as good as iMessage in production? What if I want to move my component files around? What if I forget to unmount a listener on a certain screen? And if I want to reorganize my component files, do I have to write all that bulky `setState` logic over? What happens if I want to use a state manager like redux?
192
-
193
- With all those questions in mind, I decided I would go feature-by-feature, headache-by-headache, and make my own chat SDK that was made specifically for `react`/`react-native` (and `expo` in particluar).
194
-
195
- Thanks to the introduction of `react hooks` in React 16.8.3 (and in `expo` after SDK v33 🔥), making a react-first chat SDK went from a massive headache to an elegant, scalable experience.
196
-
197
- This chat library relies on two main APIs: `firebase firestore` for the database, `react hooks` for stateful component logic.
198
-
199
- That means that you can build a serverless chat app that is _actually_ ready for production. And when you need extra customizations like unread counts and typing indicators, you just click that you want them in a GUI.
200
-
201
- A final point: most chat SDKs own your messages and data. With us, we just link into your firebase, so you own all the data.
1
+ # chat
@@ -1,2 +0,0 @@
1
- import{createContext}from'react';var context=createContext();context.displayName='ChatJS';export default context;
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.tsx"],"names":["createContext","context","displayName"],"mappings":"AAAA,OAASA,aAAT,KAA8B,OAA9B,CAKA,GAAMC,CAAAA,OAAO,CAAGD,aAAa,EAA7B,CACAC,OAAO,CAACC,WAAR,CAAsB,QAAtB,CAEA,cAAeD,CAAAA,OAAf","sourcesContent":["import { createContext } from 'react'\nimport { ChatContextType } from './types'\n\n// no default necessary with a provider at the top\n// @ts-ignore\nconst context = createContext<ChatContextType>()\ncontext.displayName = 'ChatJS'\n\nexport default context\n"]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,2 +0,0 @@
1
- import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";var Chat=function(){function Chat(){var chat=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};_classCallCheck(this,Chat);this.chat=chat;}_createClass(Chat,[{key:"roomsCollection",get:function get(){return this.chat.roomsCollection||'rooms';}},{key:"messagesCollection",get:function get(){return this.chat.messagesCollection||'messages';}},{key:"httpCallables",get:function get(){return{sendMessageFromFeed:this.chat.httpCallables&&this.chat.httpCallables.sendMessageFromFeed||'sendMessageFromFeed',sendMessageToPeople:this.chat.httpCallables&&this.chat.httpCallables.sendMessageToPeople||'sendMessageToPeople',sendMessageToGroup:this.chat.httpCallables&&this.chat.httpCallables.sendMessageToGroup||'sendMessageToGroup',createRoom:this.chat.httpCallables&&this.chat.httpCallables.createRoom||'createRoom',sendMessageToRooms:this.chat.httpCallables&&this.chat.httpCallables.sendMessageToRooms||'sendMessageToRooms'};}}]);return Chat;}();export{Chat as default};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["Chat","chat","roomsCollection","messagesCollection","sendMessageFromFeed","httpCallables","sendMessageToPeople","sendMessageToGroup","createRoom","sendMessageToRooms"],"mappings":"mIAEqBA,CAAAA,I,YAEpB,eAAmC,IAAvBC,CAAAA,IAAuB,2DAAJ,EAAI,4BAClC,KAAKA,IAAL,CAAYA,IAAZ,CAUA,C,4DACqB,CACrB,MAAO,MAAKA,IAAL,CAAUC,eAAV,EAA6B,OAApC,CACA,C,8CACwB,CACxB,MAAO,MAAKD,IAAL,CAAUE,kBAAV,EAAgC,UAAvC,CACA,C,yCACmB,CACnB,MAAO,CACNC,mBAAmB,CACjB,KAAKH,IAAL,CAAUI,aAAV,EACA,KAAKJ,IAAL,CAAUI,aAAV,CAAwBD,mBADzB,EAEA,qBAJK,CAKNE,mBAAmB,CACjB,KAAKL,IAAL,CAAUI,aAAV,EACA,KAAKJ,IAAL,CAAUI,aAAV,CAAwBC,mBADzB,EAEA,qBARK,CASNC,kBAAkB,CAChB,KAAKN,IAAL,CAAUI,aAAV,EACA,KAAKJ,IAAL,CAAUI,aAAV,CAAwBE,kBADzB,EAEA,oBAZK,CAaNC,UAAU,CACR,KAAKP,IAAL,CAAUI,aAAV,EAA2B,KAAKJ,IAAL,CAAUI,aAAV,CAAwBG,UAApD,EACA,YAfK,CAgBNC,kBAAkB,CAChB,KAAKR,IAAL,CAAUI,aAAV,EACA,KAAKJ,IAAL,CAAUI,aAAV,CAAwBI,kBADzB,EAEA,oBAnBK,CAAP,CAqBA,C,2BA1CmBT,I","sourcesContent":["import { ChatConfig } from './types'\n\nexport default class Chat {\n\tprivate chat: ChatConfig\n\tconstructor(chat: ChatConfig = {}) {\n\t\tthis.chat = chat\n\t\t// this.chat = {\n\t\t// \t...chat,\n\t\t// \thttpCallables: {\n\t\t// \t\tsendMessageFromFeed: 'sendMessageFromFeed',\n\t\t// \t\tsendMessageToPeople: 'sendToPeople',\n\t\t// \t\tsendMessageToGroup: 'sendToGroup',\n\t\t// \t\t...(chat.httpCallables || {})\n\t\t// \t}\n\t\t// }\n\t}\n\tget roomsCollection() {\n\t\treturn this.chat.roomsCollection || 'rooms'\n\t}\n\tget messagesCollection() {\n\t\treturn this.chat.messagesCollection || 'messages'\n\t}\n\tget httpCallables() {\n\t\treturn {\n\t\t\tsendMessageFromFeed:\n\t\t\t\t(this.chat.httpCallables &&\n\t\t\t\t\tthis.chat.httpCallables.sendMessageFromFeed) ||\n\t\t\t\t'sendMessageFromFeed',\n\t\t\tsendMessageToPeople:\n\t\t\t\t(this.chat.httpCallables &&\n\t\t\t\t\tthis.chat.httpCallables.sendMessageToPeople) ||\n\t\t\t\t'sendMessageToPeople',\n\t\t\tsendMessageToGroup:\n\t\t\t\t(this.chat.httpCallables &&\n\t\t\t\t\tthis.chat.httpCallables.sendMessageToGroup) ||\n\t\t\t\t'sendMessageToGroup',\n\t\t\tcreateRoom:\n\t\t\t\t(this.chat.httpCallables && this.chat.httpCallables.createRoom) ||\n\t\t\t\t'createRoom',\n\t\t\tsendMessageToRooms:\n\t\t\t\t(this.chat.httpCallables &&\n\t\t\t\t\tthis.chat.httpCallables.sendMessageToRooms) ||\n\t\t\t\t'sendMessageToRooms'\n\t\t}\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,2 +0,0 @@
1
- import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import{chat}from'../../components/ChatProvider';var _default=function(){function _default(inbox){_classCallCheck(this,_default);this.inbox=inbox;}_createClass(_default,[{key:"path",get:function get(){return chat.messagesCollection;}}]);return _default;}();export{_default as default};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["chat","inbox","messagesCollection"],"mappings":"gIACA,OAASA,IAAT,KAAqB,+BAArB,C,wBAIC,kBAAYC,KAAZ,CAA+B,gCAC9B,KAAKA,KAAL,CAAaA,KAAb,CACA,C,qDACU,CACV,MAAOD,CAAAA,IAAI,CAACE,kBAAZ,CACA,C","sourcesContent":["import { InboxModel } from './types'\nimport { chat } from '../../components/ChatProvider'\n\nexport default class {\n\tprivate inbox: InboxModel\n\tconstructor(inbox: InboxModel) {\n\t\tthis.inbox = inbox\n\t}\n\tget path() {\n\t\treturn chat.messagesCollection\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,2 +0,0 @@
1
- import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _regeneratorRuntime from"@babel/runtime/regenerator";import _defineProperty from"@babel/runtime/helpers/defineProperty";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){_defineProperty(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}import{recipientHasId,recipientHasMembers,isNewMessageModel}from'./types';import{fuego,chat}from'../../components/ChatProvider/index';import Room from'../Room';var _default=function(){function _default(message){_classCallCheck(this,_default);this.message=message;}_createClass(_default,[{key:"sendToRooms",value:function sendToRooms(recipients){var send;return _regeneratorRuntime.async(function sendToRooms$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;send=fuego.firebase.functions().httpsCallable(chat.httpCallables.sendMessageToRooms);if(isNewMessageModel(this.message)){_context.next=4;break;}throw new Error('FAILED TO SEND TO ROOMS: message object is not NewMessageModel');case 4:this.message=_objectSpread({},this.message,{createdAt:fuego.firebase.firestore.FieldValue.serverTimestamp()});return _context.abrupt("return",send({message:this.message,recipients:recipients}));case 8:_context.prev=8;_context.t0=_context["catch"](0);console.error(_context.t0);return _context.abrupt("return",{data:null});case 12:case"end":return _context.stop();}}},null,this,[[0,8]]);}},{key:"sendToPeople",value:function sendToPeople(recipients){var send;return _regeneratorRuntime.async(function sendToPeople$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:send=fuego.firebase.functions().httpsCallable(chat.httpCallables.sendMessageToPeople);_context2.prev=1;if(isNewMessageModel(this.message)){_context2.next=4;break;}throw new Error('FAILED TO SEND TO PEOPLE: message object is not NewMessageModel');case 4:this.message=_objectSpread({},this.message,{createdAt:fuego.firebase.firestore.FieldValue.serverTimestamp()});return _context2.abrupt("return",send({message:this.message,recipients:recipients}));case 8:_context2.prev=8;_context2.t0=_context2["catch"](1);console.error(_context2.t0);return _context2.abrupt("return",{data:null});case 12:case"end":return _context2.stop();}}},null,this,[[1,8]]);}},{key:"sendToGroup",value:function sendToGroup(recipients){var send;return _regeneratorRuntime.async(function sendToGroup$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:send=fuego.firebase.functions().httpsCallable(chat.httpCallables.sendMessageToGroup);_context3.prev=1;if(isNewMessageModel(this.message)){_context3.next=4;break;}throw new Error('FAILED TO SEND TO PEOPLE: message object is not NewMessageModel');case 4:this.message=_objectSpread({},this.message,{createdAt:fuego.firebase.firestore.FieldValue.serverTimestamp()});return _context3.abrupt("return",send({message:this.message,recipients:recipients}));case 8:_context3.prev=8;_context3.t0=_context3["catch"](1);console.error(_context3.t0);return _context3.abrupt("return",{data:null});case 12:case"end":return _context3.stop();}}},null,this,[[1,8]]);}},{key:"sendFromFeed",value:function sendFromFeed(to){var _this=this;var batch=fuego.db.batch();var promises=[];to.forEach(function(room){var _ref=_this.message,id=_ref.id,message=_objectWithoutProperties(_ref,["id"]);if(recipientHasId(room)){var _ref2=new Room({id:room.id}),messagesPath=_ref2.messagesPath;var ref=fuego.db.collection(messagesPath).doc(id);batch.set(ref,message);}else if(recipientHasMembers(room)){var peopleInThisRoomOtherThanMe=room.recipients.slice().sort(function(a,b){return a.id>b.id?1:-1;});var addMessage=fuego.firebase.functions().httpsCallable(chat.httpCallables.sendMessageFromFeed);var newMessage=_objectSpread({},message,{recipients:peopleInThisRoomOtherThanMe});promises.push(addMessage(newMessage));}});return Promise.all([batch.commit()].concat(promises));}},{key:"send",value:function send(roomId){this.addToFirebase(roomId);}},{key:"edit",value:function edit(roomId){return this.updateOnFirebase(roomId);}},{key:"formatForRender",value:function formatForRender(){function isDocList(m){return!!m;}function isDocument(m){return!!m;}try{if(isDocList(this.message)){return this.message.map(function(doc){return _objectSpread({},doc,{id:doc.id,createdAt:doc.createdAt.toDate()});})||[];}if(isDocument(this.message))return _objectSpread({},this.message,{id:this.message.id,createdAt:this.message.createdAt.toDate()});throw new Error('Wrong model here.');}catch(e){console.error('wrong model given to format for render in Message class.',e);return null;}}},{key:"formatForSend",value:function formatForSend(){try{var isNew=function isNew(m){return!!m;};if(isNew(this.message)){this.message=this.message.map(function(message){return _objectSpread({},message,{text:message.text&&message.text.trim()||'',createdAt:fuego.firebase.firestore.FieldValue.serverTimestamp()});});return this;}throw new Error('wrong format for formatting for send');}catch(e){console.error(e);return this;}}},{key:"addToFirebase",value:function addToFirebase(roomId){var messages=this.message;var batch=fuego.db.batch();var updateBatch=function updateBatch(roomId){var addToBatch=function addToBatch(message){try{var _ref3=new Room({id:roomId}),messagesPath=_ref3.messagesPath,roomPath=_ref3.path;var ref=fuego.db.collection(messagesPath).doc(message.id);var id=message.id,messageDoc=_objectWithoutProperties(message,["id"]);batch.set(ref,messageDoc);var _ref4=fuego.auth().currentUser,displayName=_ref4.displayName,uid=_ref4.uid;var roomRef=fuego.db.doc(roomPath);var lastMessage={name:displayName||'Name failed',id:uid,system:false,text:message.text,createdAt:message.createdAt};batch.update(roomRef,{lastMessage:lastMessage});}catch(e){console.error('sending message had an error:',e);}};messages.forEach(addToBatch);};if(Array.isArray(roomId)){;roomId.forEach(updateBatch);}else{updateBatch(roomId);}return batch.commit();}},{key:"updateOnFirebase",value:function updateOnFirebase(roomId){var _ref5=new Room({id:roomId}),path=_ref5.path;var _ref6=this.message,id=_ref6.id,message=_objectWithoutProperties(_ref6,["id"]);return fuego.db.collection(path).doc(this.message.id).set(message,{merge:true});}},{key:"getUsersWhoReacted",value:function getUsersWhoReacted(reaction,_ref7){var roomMembers=_ref7.roomMembers;var users=[];if(!isNewMessageModel(this.message)){console.warn('error getting users who reacted. Needs the new message model passed as an argument, but instead it got this:',this.message);}else if(this.message.reactions){this.message.reactions[reaction].forEach(function(uid){return roomMembers[uid]&&users.push(roomMembers[uid]);});}return users;}}]);return _default;}();export{_default as default};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["recipientHasId","recipientHasMembers","isNewMessageModel","fuego","chat","Room","message","recipients","send","firebase","functions","httpsCallable","httpCallables","sendMessageToRooms","Error","createdAt","firestore","FieldValue","serverTimestamp","console","error","data","sendMessageToPeople","sendMessageToGroup","to","batch","db","promises","forEach","room","id","messagesPath","ref","collection","doc","set","peopleInThisRoomOtherThanMe","slice","sort","a","b","addMessage","sendMessageFromFeed","newMessage","push","Promise","all","commit","roomId","addToFirebase","updateOnFirebase","isDocList","m","isDocument","map","toDate","e","isNew","text","trim","messages","updateBatch","addToBatch","roomPath","path","messageDoc","auth","currentUser","displayName","uid","roomRef","lastMessage","name","system","update","Array","isArray","merge","reaction","roomMembers","users","warn","reactions"],"mappings":"gnCAAA,OAOCA,cAPD,CAQCC,mBARD,CAUCC,iBAVD,KAYO,SAZP,CAaA,OAASC,KAAT,CAAgBC,IAAhB,KAA4B,qCAA5B,CACA,MAAOC,CAAAA,IAAP,KAAiB,SAAjB,C,wBAMC,kBAAYC,OAAZ,CAAmC,gCAClC,KAAKA,OAAL,CAAeA,OAAf,CACA,C,qEAOiBC,U,gJAEVC,I,CAAOL,KAAK,CAACM,QAAN,CACXC,SADW,GAEXC,aAFW,CAEGP,IAAI,CAACQ,aAAL,CAAmBC,kBAFtB,C,IAGRX,iBAAiB,CAAC,KAAKI,OAAN,C,8BACf,IAAIQ,CAAAA,KAAJ,CACL,gEADK,C,QAIP,KAAKR,OAAL,kBACI,KAAKA,OADT,EAECS,SAA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N,EAIA,CALD,IAKO,IAAI,KAAKA,OAAL,CAAa4E,SAAjB,CAA4B,CAClC,KAAK5E,OAAL,CAAa4E,SAAb,CAAuBJ,QAAvB,EAAiClD,OAAjC,CACC,SAAAyC,GAAG,QAAIU,CAAAA,WAAW,CAACV,GAAD,CAAX,EAAoBW,KAAK,CAACpC,IAAN,CAAWmC,WAAW,CAACV,GAAD,CAAtB,CAAxB,EADJ,EAGA,CACD,MAAOW,CAAAA,KAAP,CACA,C","sourcesContent":["import {\n\tMessageModel,\n\tEditMessageModel,\n\tRoomId,\n\tNewMessageModel,\n\tMessageModelDocument,\n\tSendFromFeedRecipients,\n\trecipientHasId,\n\trecipientHasMembers,\n\tSendFromFeedModel,\n\tisNewMessageModel,\n\tNewMessageFormattedForServer\n} from './types'\nimport { fuego, chat } from '../../components/ChatProvider/index'\nimport Room from '../Room'\nimport { LastMessageServer, RoomMembers, RoomMember } from '../Room/types'\nimport { ReactionOption } from '../Reaction/types'\n\nexport default class {\n\tprivate message: MessageModel\n\tconstructor(message: MessageModel) {\n\t\tthis.message = message\n\t}\n\t/**\n\t * A function to send one message to many different existing rooms/group chats separately.\n\t *\n\t * @param recipients An array of rooms ids where this message will be sent to separately\n\t * @returns Promise that returns a room ID if there is only one (or promise that resolves as null if the message object isn't valid)\n\t */\n\tasync sendToRooms(recipients: string[]) {\n\t\ttry {\n\t\t\tconst send = fuego.firebase\n\t\t\t\t.functions()\n\t\t\t\t.httpsCallable(chat.httpCallables.sendMessageToRooms)\n\t\t\tif (!isNewMessageModel(this.message)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'FAILED TO SEND TO ROOMS: message object is not NewMessageModel'\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.message = {\n\t\t\t\t...this.message,\n\t\t\t\tcreatedAt: fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\t\t} as NewMessageFormattedForServer\n\t\t\treturn send({\n\t\t\t\tmessage: this.message,\n\t\t\t\trecipients\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn {\n\t\t\t\tdata: null\n\t\t\t}\n\t\t}\n\t}\n\t/**\n\t * A function to send one message to many different people individually.\n\t * For each recipient, if a room for them doesn't exist, it will get created and the message will be added to it.\n\t * If the room does exist, the message will be added to it.\n\t *\n\t * @param recipients An array of user ids whom this message will be sent to separately\n\t * @returns Promise that returns a room ID (or promise that resolves as null if the message object isn't valid)\n\t */\n\tasync sendToPeople(recipients: string[]) {\n\t\tconst send = fuego.firebase\n\t\t\t.functions()\n\t\t\t.httpsCallable(chat.httpCallables.sendMessageToPeople)\n\t\ttry {\n\t\t\tif (!isNewMessageModel(this.message)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'FAILED TO SEND TO PEOPLE: message object is not NewMessageModel'\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.message = {\n\t\t\t\t...this.message,\n\t\t\t\tcreatedAt: fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\t\t} as NewMessageFormattedForServer\n\t\t\treturn send({\n\t\t\t\tmessage: this.message,\n\t\t\t\trecipients\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn {\n\t\t\t\tdata: null\n\t\t\t}\n\t\t}\n\t}\n\t/**\n\t * Sends message to a group. This is useful when you don't have a room id but do have a list of people you want to send a message to. If you want to send the message to them separately, try sendToPeople instead.\n\t * This function will create a group chat with the specified users if one doesn't exist yet. If it does exist already, then it will add to that existing room.\n\t * @param recipients Array of uids for people in the group this message should send to.\n\t * @returns Promise that returns a room ID (or promise that resolves as null if the message object isn't valid)\n\t */\n\tasync sendToGroup(recipients: string[]) {\n\t\tconst send = fuego.firebase\n\t\t\t.functions()\n\t\t\t.httpsCallable(chat.httpCallables.sendMessageToGroup)\n\t\ttry {\n\t\t\tif (!isNewMessageModel(this.message)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'FAILED TO SEND TO PEOPLE: message object is not NewMessageModel'\n\t\t\t\t)\n\t\t\t}\n\t\t\tthis.message = {\n\t\t\t\t...this.message,\n\t\t\t\tcreatedAt: fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\t\t} as NewMessageFormattedForServer\n\t\t\treturn send({\n\t\t\t\tmessage: this.message,\n\t\t\t\trecipients\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn {\n\t\t\t\tdata: null\n\t\t\t}\n\t\t}\n\t}\n\t/**\n\t * deprecated: fuck this function\n\t */\n\tsendFromFeed(to: SendFromFeedRecipients) {\n\t\tconst batch = fuego.db.batch()\n\t\tconst promises: Promise<firebase.functions.HttpsCallableResult>[] = []\n\n\t\t// the to variable is an array of dictionaries\n\t\t// the dictionaries can be EITHER { id: string } or { recipients: Array<recipient> }\n\t\t// example:\n\t\t// you might send a message to five different places\n\t\t// could be 3 people, and 2 existing rooms\n\t\t// this would be an array of 5 items, 3 with recipients, 2 with id\n\t\t// example of the array:\n\t\t// [\n\t\t// 1) send to a room that has these two users\n\t\t// { recipients: [{id: uid, name: username }, {uid: uid2, name: name2 }]},\n\t\t// 2) send to an already existing room (likely pressing a group)\n\t\t// { id: roomId },\n\t\t// 3) send to one person, unaware if this room exists\n\t\t// { recipients: [{id: uid, name: username }]},\n\t\t// ]\n\n\t\t// now, set of people we're sending this to...\n\t\tto.forEach(room => {\n\t\t\tconst { id, ...message } = this.message as NewMessageModel\n\t\t\tif (recipientHasId(room)) {\n\t\t\t\t// if this recipient is a specified room, then send to that\n\t\t\t\tconst { messagesPath } = new Room({ id: room.id })\n\t\t\t\tconst ref = fuego.db.collection(messagesPath).doc(id)\n\t\t\t\tbatch.set(ref, message)\n\t\t\t} else if (recipientHasMembers(room)) {\n\t\t\t\t// otherwise, if you're just sending to a list of ambigious recipients...\n\t\t\t\t// note: this list will often be one person you're choosing from a feed\n\t\t\t\t// list could be: { recipients: [{ name: string, id: string }, { ...otherRecipient }]}\n\t\t\t\tconst peopleInThisRoomOtherThanMe = room.recipients\n\t\t\t\t\t.slice()\n\t\t\t\t\t.sort((a, b) => (a.id > b.id ? 1 : -1))\n\t\t\t\tconst addMessage = fuego.firebase\n\t\t\t\t\t.functions()\n\t\t\t\t\t.httpsCallable(chat.httpCallables.sendMessageFromFeed)\n\t\t\t\tconst newMessage: SendFromFeedModel = {\n\t\t\t\t\t...(message as NewMessageModel),\n\t\t\t\t\trecipients: peopleInThisRoomOtherThanMe\n\t\t\t\t}\n\t\t\t\tpromises.push(addMessage(newMessage))\n\t\t\t}\n\t\t})\n\n\t\treturn Promise.all<any>([batch.commit(), ...promises])\n\n\t\t// return {\n\t\t// \tbatch: () => batch.commit(),\n\t\t// \ttoRecipients: () => Promise.all(promises)\n\t\t// }\n\t}\n\t/**\n\t * Send message by adding it directly to the backend\n\t * @param roomId The id of the room you want to send this to. Could also be an array of ids, if the same message should go to multiple rooms.\n\t */\n\tsend(roomId: RoomId) {\n\t\tthis.addToFirebase(roomId)\n\t}\n\tedit(roomId: string) {\n\t\treturn this.updateOnFirebase(roomId)\n\t}\n\tformatForRender(): NewMessageModel[] | NewMessageModel | null {\n\t\tfunction isDocList(m: MessageModel): m is MessageModelDocument[] {\n\t\t\treturn !!(m as MessageModelDocument[])\n\t\t}\n\t\tfunction isDocument(m: MessageModel): m is MessageModelDocument {\n\t\t\treturn !!(m as MessageModelDocument)\n\t\t}\n\t\ttry {\n\t\t\tif (isDocList(this.message)) {\n\t\t\t\treturn (\n\t\t\t\t\t(this.message as MessageModelDocument[]).map(\n\t\t\t\t\t\t(doc: MessageModelDocument) => ({\n\t\t\t\t\t\t\t...doc,\n\t\t\t\t\t\t\tid: doc.id,\n\t\t\t\t\t\t\tcreatedAt: doc.createdAt.toDate()\n\t\t\t\t\t\t})\n\t\t\t\t\t) || []\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (isDocument(this.message))\n\t\t\t\treturn {\n\t\t\t\t\t...this.message,\n\t\t\t\t\tid: this.message.id,\n\t\t\t\t\tcreatedAt: this.message.createdAt.toDate()\n\t\t\t\t}\n\n\t\t\tthrow new Error('Wrong model here.')\n\t\t} catch (e) {\n\t\t\tconsole.error(\n\t\t\t\t'wrong model given to format for render in Message class.',\n\t\t\t\te\n\t\t\t)\n\t\t\treturn null\n\t\t}\n\t}\n\tformatForSend() {\n\t\ttry {\n\t\t\tconst isNew = (m: MessageModel): m is NewMessageModel[] =>\n\t\t\t\t!!(m as NewMessageModel[])\n\t\t\tif (isNew(this.message)) {\n\t\t\t\tthis.message = (this.message as NewMessageModel[]).map(message => ({\n\t\t\t\t\t...message,\n\t\t\t\t\ttext: (message.text && message.text.trim()) || '',\n\t\t\t\t\tcreatedAt: fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\t\t\t})) as NewMessageFormattedForServer[]\n\t\t\t\treturn this\n\t\t\t}\n\t\t\tthrow new Error('wrong format for formatting for send')\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn this\n\t\t}\n\t}\n\taddToFirebase(roomId: RoomId) {\n\t\tconst { message: messages } = this\n\n\t\tconst batch = fuego.db.batch()\n\n\t\tconst updateBatch = (roomId: string) => {\n\t\t\t// for each message, add to this batch...\n\t\t\tconst addToBatch = (message: NewMessageFormattedForServer) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst { messagesPath, path: roomPath } = new Room({ id: roomId })\n\t\t\t\t\tconst ref = fuego.db.collection(messagesPath).doc(message.id)\n\n\t\t\t\t\t// remove id from message for single source of truth\n\t\t\t\t\t// it'll be put back again upon format()-ing\n\t\t\t\t\tconst { id, ...messageDoc } = message\n\t\t\t\t\tbatch.set(ref, messageDoc)\n\n\t\t\t\t\t// update the latest message\n\t\t\t\t\tconst { displayName, uid } = fuego.auth().currentUser as firebase.User\n\t\t\t\t\tconst roomRef = fuego.db.doc(roomPath)\n\t\t\t\t\tconst lastMessage: LastMessageServer = {\n\t\t\t\t\t\tname: displayName || 'Name failed',\n\t\t\t\t\t\tid: uid,\n\t\t\t\t\t\tsystem: false,\n\t\t\t\t\t\ttext: message.text,\n\t\t\t\t\t\tcreatedAt: message.createdAt\n\t\t\t\t\t}\n\t\t\t\t\tbatch.update(roomRef, { lastMessage })\n\t\t\t\t} catch (e) {\n\t\t\t\t\tconsole.error('sending message had an error:', e)\n\t\t\t\t}\n\t\t\t}\n\t\t\t;(messages as NewMessageFormattedForServer[]).forEach(addToBatch)\n\t\t}\n\n\t\t// if you're sending these message(s) to multiple rooms, loop through each room...\n\t\tif (Array.isArray(roomId)) {\n\t\t\t;(roomId as string[]).forEach(updateBatch)\n\t\t} else {\n\t\t\t// just send to this room\n\t\t\tupdateBatch(roomId as string)\n\t\t}\n\t\t// once everything has been added to the db batch, commit it\n\t\treturn batch.commit()\n\t}\n\tupdateOnFirebase(roomId: string) {\n\t\tconst { path } = new Room({ id: roomId })\n\t\tconst { id, ...message } = this.message as EditMessageModel\n\t\treturn fuego.db\n\t\t\t.collection(path)\n\t\t\t.doc((this.message as EditMessageModel).id)\n\t\t\t.set(message, { merge: true })\n\t}\n\t// TODO get members through some other method...idk\n\t// eek. what a mess.\n\tgetUsersWhoReacted(\n\t\treaction: ReactionOption,\n\t\t{ roomMembers }: { roomMembers: RoomMembers }\n\t): RoomMember[] {\n\t\tconst users: RoomMember[] = []\n\t\tif (!isNewMessageModel(this.message)) {\n\t\t\tconsole.warn(\n\t\t\t\t'error getting users who reacted. Needs the new message model passed as an argument, but instead it got this:',\n\t\t\t\tthis.message\n\t\t\t)\n\t\t} else if (this.message.reactions) {\n\t\t\tthis.message.reactions[reaction].forEach(\n\t\t\t\tuid => roomMembers[uid] && users.push(roomMembers[uid])\n\t\t\t)\n\t\t}\n\t\treturn users\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
- export function isNewMessageModel(message){return!!message;}export function isNewMessageFormattedForServer(message){return!!message;}export var recipientHasId=function recipientHasId(recipient){return!!recipient;};export var recipientHasMembers=function recipientHasMembers(recipient){return!!recipient;};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["types.ts"],"names":["isNewMessageModel","message","isNewMessageFormattedForServer","recipientHasId","recipient","recipientHasMembers"],"mappings":"AA0DA,MAAO,SAASA,CAAAA,iBAAT,CACNC,OADM,CAEuB,CAC7B,MAAO,CAAC,CAAEA,OAAV,CACA,CAED,MAAO,SAASC,CAAAA,8BAAT,CACND,OADM,CAEoC,CAC1C,MAAO,CAAC,CAAEA,OAAV,CACA,CAoCD,MAAO,IAAME,CAAAA,cAAc,CAAG,QAAjBA,CAAAA,cAAiB,CAC7BC,SAD6B,QAEI,CAAC,CAAEA,SAFP,EAAvB,CAIP,MAAO,IAAMC,CAAAA,mBAAmB,CAAG,QAAtBA,CAAAA,mBAAsB,CAClCD,SADkC,QAGlC,CAAC,CAAEA,SAH+B,EAA5B","sourcesContent":["import { FieldValue } from '@firebase/firestore-types'\nimport { ReactionOption } from '../Reaction/types'\n\nexport interface Message {\n\tid: string\n\t// roomId: string\n}\n\nexport interface NewMessageModel extends Omit<Message, 'roomId'> {\n\ttext: string\n\tcreatedAt: Date\n\tuser: {\n\t\tid: string\n\t\tname: string\n\t\tavatar: string\n\t}\n\t// image?: string\n\t// // You can also add a video prop:\n\t// video?: string\n\tsystem?: boolean\n\tmedia?: MessageMedia\n\treactions?: {\n\t\t[option in ReactionOption]: string[]\n\t}\n\t// Any additional custom parameters are passed through\n}\n\nexport interface MessageMediaWithUrl {\n\turl: string\n\turi?: string\n\theight: number\n\twidth: number\n\tcontentType: 'video' | 'image'\n}\n\nexport interface MessageMediaWithUri {\n\turl: string\n\turi?: string\n\theight: number\n\twidth: number\n\tcontentType: 'video' | 'image'\n}\n\nexport type MessageMedia = MessageMediaWithUrl | MessageMediaWithUri\n\n// export interface MessageMedia {\n// \turl?: string\n// \turi: string\n// \theight: number\n// \twidth: number\n// \tcontentType: 'video' | 'image'\n// }\n\nexport interface NewMessageFormattedForServer\n\textends Omit<NewMessageModel, 'createdAt'> {\n\tcreatedAt: FieldValue\n}\n\nexport function isNewMessageModel(\n\tmessage: MessageModel\n): message is NewMessageModel {\n\treturn !!(message as NewMessageModel)\n}\n\nexport function isNewMessageFormattedForServer(\n\tmessage: MessageModel\n): message is NewMessageFormattedForServer {\n\treturn !!(message as NewMessageFormattedForServer)\n}\n\nexport interface EditMessageModel extends Message {\n\ttext?: string\n}\n\nexport type SendToRecipients = string[]\n\n// you might send a message to multiple rooms\nexport type RoomId = string | string[]\n\n// the message model can be one of them\nexport type MessageModel =\n\t| Message\n\t| NewMessageModel[]\n\t| EditMessageModel\n\t| MessageModelDocument[]\n\t| NewMessageFormattedForServer[]\n\t| NewMessageFormattedForServer\n\nexport interface MessageModelDocument\n\textends Omit<NewMessageModel, 'createdAt'> {\n\tid: string\n\tcreatedAt: firebase.firestore.Timestamp\n}\n\nexport type SendFromFeedRecipient =\n\t| {\n\t\t\tid: string // roomId\n\t }\n\t| SendFromFeedRecipientArray\n\nexport interface SendFromFeedRecipientArray {\n\trecipients: { id: string; name: string }[]\n}\n\nexport const recipientHasId = (\n\trecipient: SendFromFeedRecipient\n): recipient is { id: string } => !!(recipient as { id: string })\n\nexport const recipientHasMembers = (\n\trecipient: SendFromFeedRecipient\n): recipient is SendFromFeedRecipientArray =>\n\t!!(recipient as SendFromFeedRecipientArray)\n\nexport type SendFromFeedRecipients = SendFromFeedRecipient[]\n\nexport interface SendFromFeedModel extends Omit<NewMessageModel, 'id'> {\n\trecipients: SendFromFeedRecipientArray['recipients']\n}\n"]}
@@ -1,2 +0,0 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";import _defineProperty from"@babel/runtime/helpers/defineProperty";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import Room from'../Room';import{fuego}from'../../components/ChatProvider';var _default=function(){function _default(config){_classCallCheck(this,_default);this.config=config;}_createClass(_default,[{key:"verb",value:function verb(){switch(this.config.reaction){case'like':return{add:'liked',remove:'unliked'};case'love':return{add:'loved',remove:'unloved'};default:{console.warn('reaction type is not valid. see reaction class:',this.config.reaction);return{add:'',remove:''};}}}},{key:"add",value:function add(){var _ref,uid,batch,messageRef,_ref2,roomPath,roomRef;return _regeneratorRuntime.async(function add$(_context){while(1){switch(_context.prev=_context.next){case 0:_ref=fuego.auth().currentUser,uid=_ref.uid;batch=fuego.db.batch();messageRef=fuego.db.doc(this.path);batch.update(messageRef,_defineProperty({},"reactions."+this.config.reaction,fuego.firebase.firestore.FieldValue.arrayUnion(uid)));_ref2=new Room({id:this.config.roomId}),roomPath=_ref2.path;roomRef=fuego.db.doc(roomPath);batch.update(roomRef,{lastMessage:this.makeLastMessage({remove:false})});return _context.abrupt("return",batch.commit());case 8:case"end":return _context.stop();}}},null,this);}},{key:"remove",value:function remove(){var _ref3,uid,batch,messageRef,_ref4,roomPath,roomRef;return _regeneratorRuntime.async(function remove$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_ref3=fuego.auth().currentUser,uid=_ref3.uid;batch=fuego.db.batch();messageRef=fuego.db.doc(this.path);batch.update(messageRef,_defineProperty({},"reactions."+this.config.reaction,fuego.firebase.firestore.FieldValue.arrayRemove(uid)));_ref4=new Room({id:this.config.roomId}),roomPath=_ref4.path;roomRef=fuego.db.doc(roomPath);batch.update(roomRef,{lastMessage:this.makeLastMessage({remove:true})});return _context2.abrupt("return",batch.commit());case 8:case"end":return _context2.stop();}}},null,this);}},{key:"makeReactionDescriptionText",value:function makeReactionDescriptionText(remove){if(this.config.descriptionText===null)return'';var _ref5=fuego.auth().currentUser,displayName=_ref5.displayName;var myName=this.config.myName;var name=myName||displayName||'';var verb=remove?this.verb().remove:this.verb().add;if(this.config.descriptionText){if(typeof this.config.descriptionText==='string')return this.config.descriptionText;if(typeof this.config.descriptionText!=='function'){console.error('🍇 Juice Reaction error. The descriptionText property should be either 1) a string or 2) a function that returns a string. Instead, you passed',this.config.descriptionText,' of type ',typeof this.config.descriptionText,'. See the docs or command+hover over the descriptionText property in VS Code to details.');}else{return this.config.descriptionText({reaction:this.config.reaction,name:name||'',text:this.config.text,verb:verb,remove:!!remove});}}var firstName=name&&name.split(' ')[0];var text=firstName+" "+verb+" a message";if(this.config.text){text=firstName+" "+verb+" \""+this.config.text+"\"";}return text;}},{key:"makeLastMessage",value:function makeLastMessage(options){var _ref6=fuego.auth().currentUser,_ref6$displayName=_ref6.displayName,name=_ref6$displayName===void 0?'':_ref6$displayName;return{id:'',createdAt:fuego.firebase.firestore.FieldValue.serverTimestamp(),name:name||'',system:true,text:this.makeReactionDescriptionText(options.remove)};}},{key:"path",get:function get(){var _ref7=new Room({id:this.config.roomId}),messagesPath=_ref7.messagesPath;return messagesPath+"/"+this.config.messageId;}}]);return _default;}();export{_default as default};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["Room","fuego","config","reaction","add","remove","console","warn","auth","currentUser","uid","batch","db","messageRef","doc","path","update","firebase","firestore","FieldValue","arrayUnion","id","roomId","roomPath","roomRef","lastMessage","makeLastMessage","commit","arrayRemove","descriptionText","displayName","myName","name","verb","error","text","firstName","split","options","createdAt","serverTimestamp","system","makeReactionDescriptionText","messagesPath","messageId"],"mappings":"+PACA,MAAOA,CAAAA,IAAP,KAAiB,SAAjB,CACA,OAASC,KAAT,KAAsB,+BAAtB,C,wBAKC,kBAAYC,MAAZ,CAAoC,gCACnC,KAAKA,MAAL,CAAcA,MAAd,CACA,C,wDAKuC,CACvC,OAAQ,KAAKA,MAAL,CAAYC,QAApB,EACC,IAAK,MAAL,CACC,MAAO,CAAEC,GAAG,CAAE,OAAP,CAAgBC,MAAM,CAAE,SAAxB,CAAP,CACD,IAAK,MAAL,CACC,MAAO,CAAED,GAAG,CAAE,OAAP,CAAgBC,MAAM,CAAE,SAAxB,CAAP,CACD,QAAS,CACRC,OAAO,CAACC,IAAR,CACC,iDADD,CAEC,KAAKL,MAAL,CAAYC,QAFb,EAIA,MAAO,CAAEC,GAAG,CAAE,EAAP,CAAWC,MAAM,CAAE,EAAnB,CAAP,CACA,CAXF,CAa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,CAAGJ,IAAI,EAAIA,IAAI,CAACK,KAAL,CAAW,GAAX,EAAgB,CAAhB,CAA1B,CACA,GAAIF,CAAAA,IAAI,CAAMC,SAAN,KAAmBH,IAAnB,aAAR,CACA,GAAI,KAAK/B,MAAL,CAAYiC,IAAhB,CAAsB,CACrBA,IAAI,CAAMC,SAAN,KAAmBH,IAAnB,OAA4B,KAAK/B,MAAL,CAAYiC,IAAxC,KAAJ,CACA,CACD,MAAOA,CAAAA,IAAP,CACA,C,wDACeG,O,CAAkD,WAC9BrC,KAAK,CAACO,IAAN,GAAaC,WADiB,yBACzDqB,WADyD,CAC5CE,IAD4C,4BACrC,EADqC,mBAEjE,MAAO,CACNX,EAAE,CAAE,EADE,CAENkB,SAAS,CAAEtC,KAAK,CAACgB,QAAN,CAAeC,SAAf,CAAyBC,UAAzB,CAAoCqB,eAApC,EAFL,CAGNR,IAAI,CAAEA,IAAI,EAAI,EAHR,CAINS,MAAM,CAAE,IAJF,CAKNN,IAAI,CAAE,KAAKO,2BAAL,CAAiCJ,OAAO,CAACjC,MAAzC,CALA,CAAP,CAOA,C,gCAhGU,WACe,GAAIL,CAAAA,IAAJ,CAAS,CAAEqB,EAAE,CAAE,KAAKnB,MAAL,CAAYoB,MAAlB,CAAT,CADf,CACFqB,YADE,OACFA,YADE,CAEV,MAAUA,CAAAA,YAAV,KAA0B,KAAKzC,MAAL,CAAY0C,SAAtC,CACA,C","sourcesContent":["import { ReactionConfig } from './types'\nimport Room from '../Room'\nimport { fuego } from '../../components/ChatProvider'\nimport { LastMessageServer } from '../Room/types'\n\nexport default class {\n\tprivate config: ReactionConfig\n\tconstructor(config: ReactionConfig) {\n\t\tthis.config = config\n\t}\n\tget path() {\n\t\tconst { messagesPath } = new Room({ id: this.config.roomId })\n\t\treturn `${messagesPath}/${this.config.messageId}`\n\t}\n\tverb(): { add: string; remove: string } {\n\t\tswitch (this.config.reaction) {\n\t\t\tcase 'like':\n\t\t\t\treturn { add: 'liked', remove: 'unliked' }\n\t\t\tcase 'love':\n\t\t\t\treturn { add: 'loved', remove: 'unloved' }\n\t\t\tdefault: {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'reaction type is not valid. see reaction class:',\n\t\t\t\t\tthis.config.reaction\n\t\t\t\t)\n\t\t\t\treturn { add: '', remove: '' }\n\t\t\t}\n\t\t}\n\t}\n\tasync add() {\n\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\t\tconst batch = fuego.db.batch()\n\t\tconst messageRef = fuego.db.doc(this.path)\n\t\tbatch.update(messageRef, {\n\t\t\t[`reactions.${this.config.reaction}`]: fuego.firebase.firestore.FieldValue.arrayUnion(\n\t\t\t\tuid\n\t\t\t)\n\t\t})\n\t\tconst { path: roomPath } = new Room({ id: this.config.roomId })\n\t\tconst roomRef = fuego.db.doc(roomPath)\n\n\t\tbatch.update(roomRef, {\n\t\t\tlastMessage: this.makeLastMessage({ remove: false })\n\t\t})\n\t\treturn batch.commit()\n\t}\n\tasync remove() {\n\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\t\tconst batch = fuego.db.batch()\n\t\tconst messageRef = fuego.db.doc(this.path)\n\t\tbatch.update(messageRef, {\n\t\t\t[`reactions.${this.config.reaction}`]: fuego.firebase.firestore.FieldValue.arrayRemove(\n\t\t\t\tuid\n\t\t\t)\n\t\t})\n\t\tconst { path: roomPath } = new Room({ id: this.config.roomId })\n\t\tconst roomRef = fuego.db.doc(roomPath)\n\n\t\tbatch.update(roomRef, {\n\t\t\tlastMessage: this.makeLastMessage({ remove: true })\n\t\t})\n\t\treturn batch.commit()\n\t}\n\tmakeReactionDescriptionText(remove?: boolean): string {\n\t\tif (this.config.descriptionText === null) return ''\n\t\tconst { displayName } = fuego.auth().currentUser as firebase.User\n\t\tconst { myName } = this.config\n\t\tconst name = myName || displayName || ''\n\t\tconst verb = remove ? this.verb().remove : this.verb().add\n\t\tif (this.config.descriptionText) {\n\t\t\tif (typeof this.config.descriptionText === 'string')\n\t\t\t\treturn this.config.descriptionText\n\t\t\tif (typeof this.config.descriptionText !== 'function') {\n\t\t\t\tconsole.error(\n\t\t\t\t\t'🍇 Juice Reaction error. The descriptionText property should be either 1) a string or 2) a function that returns a string. Instead, you passed',\n\t\t\t\t\tthis.config.descriptionText,\n\t\t\t\t\t' of type ',\n\t\t\t\t\ttypeof this.config.descriptionText,\n\t\t\t\t\t'. See the docs or command+hover over the descriptionText property in VS Code to details.'\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\treturn this.config.descriptionText({\n\t\t\t\t\treaction: this.config.reaction,\n\t\t\t\t\tname: name || '',\n\t\t\t\t\ttext: this.config.text,\n\t\t\t\t\tverb,\n\t\t\t\t\tremove: !!remove\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tconst firstName = name && name.split(' ')[0]\n\t\tlet text = `${firstName} ${verb} a message`\n\t\tif (this.config.text) {\n\t\t\ttext = `${firstName} ${verb} \"${this.config.text}\"`\n\t\t}\n\t\treturn text\n\t}\n\tmakeLastMessage(options: { remove?: boolean }): LastMessageServer {\n\t\tconst { displayName: name = '' } = fuego.auth().currentUser as firebase.User\n\t\treturn {\n\t\t\tid: '',\n\t\t\tcreatedAt: fuego.firebase.firestore.FieldValue.serverTimestamp(),\n\t\t\tname: name || '',\n\t\t\tsystem: true,\n\t\t\ttext: this.makeReactionDescriptionText(options.remove)\n\t\t}\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
@@ -1,2 +0,0 @@
1
- import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _regeneratorRuntime from"@babel/runtime/regenerator";import _defineProperty from"@babel/runtime/helpers/defineProperty";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){_defineProperty(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}import{currentUserExists,roomIsEditModel,roomIsNewModel,roomIsCreateCallable}from'./types';import{fuego,chat}from'../../components/ChatProvider';import{getInitials as _getInitials}from'../../helpers/getInitials';import{firestore}from'firebase';import uuid from'uuid';var _default=function(){function _default(room){_classCallCheck(this,_default);this.room=room;}_createClass(_default,[{key:"getUnreadCount",value:function getUnreadCount(){var _ref=fuego.firebase.auth().currentUser,uid=_ref.uid;try{var member=this.room.members[uid];return member&&member.unreadCount&&member.unreadCount.count||0;}catch(e){console.error("Room getUnreadCount error. Are you sure you initialized the room with the proper members schema?");return 0;}}},{key:"viewMessage",value:function viewMessage(messageId,messageCreatedAt){var _ref$update,ref,_ref2,uid;return _regeneratorRuntime.async(function viewMessage$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;ref=fuego.db.doc(this.path);_ref2=fuego.auth().currentUser,uid=_ref2.uid;return _context.abrupt("return",ref.update((_ref$update={},_defineProperty(_ref$update,"members."+uid+".unreadCount.count",0),_defineProperty(_ref$update,"members."+uid+".unreadCount.lastCleared",fuego.firebase.firestore.FieldValue.serverTimestamp()),_defineProperty(_ref$update,"members."+uid+".unreadCount.lastSeen",{id:messageId,createdAt:messageCreatedAt}),_ref$update)));case 6:_context.prev=6;_context.t0=_context["catch"](0);console.error('Room class: viewMessage() error:',_context.t0);case 9:case"end":return _context.stop();}}},null,this,[[0,6]]);}},{key:"getArrayOfMembersOtherThanMe",value:function getArrayOfMembersOtherThanMe(){var _ref3=this.room,members=_ref3.members;var _ref4=fuego.auth().currentUser,uid=_ref4.uid;return Object.keys(members).filter(function(id){return id!==uid;}).map(function(id){return members[id];});}},{key:"getName",value:function getName(){var _ref5=this.room,members=_ref5.members,name=_ref5.name;if(name)return name;var _ref6=fuego.auth().currentUser,uid=_ref6.uid;var otherPeopleInRoom=Object.keys(members).filter(function(id){return id!==uid;});var namesOfOtherPeopleInRoom=otherPeopleInRoom.map(function(id){return members[id]&&members[id].name&&members[id].name.split(' ')&&members[id].name.split(' ')[0]||'';});if(!namesOfOtherPeopleInRoom.length){console.error('no other members in room',this.room);return'';}if(namesOfOtherPeopleInRoom.length===1)return members[otherPeopleInRoom[0]].name;if(namesOfOtherPeopleInRoom.length===2)return namesOfOtherPeopleInRoom.join(' & ');var commaNames=namesOfOtherPeopleInRoom.slice(0,namesOfOtherPeopleInRoom.length-1).join(', ');var finalName=namesOfOtherPeopleInRoom[namesOfOtherPeopleInRoom.length-1];return commaNames+" & "+finalName;}},{key:"getInitials",value:function getInitials(){var maxNumberOfInitials=arguments.length>0&&arguments[0]!==undefined?arguments[0]:2;var name=this.room.name;if(name)return _getInitials(name);var members=this.getArrayOfMembersOtherThanMe();if(!members.length){console.error('get room initials error: no other members in this room',this.room);return'';}if(members.length===1){return _getInitials(members[0].name,maxNumberOfInitials);}return members.map(function(member){return member.name&&member.name.slice(0,1)||'';}).join('').slice(0,maxNumberOfInitials);}},{key:"leave",value:function leave(){var _ref7,uid;return _regeneratorRuntime.async(function leave$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.prev=0;if(currentUserExists(fuego.auth().currentUser)){_context2.next=3;break;}throw new Error("🚨 Fuego auth error: Tried to leave a room, but there is no valid firebase auth object for this user. \n In order to join a room, the user must exist. If you're just testing around and don't want to have valid users, try await firebase.auth().signInAnonymously().");case 3:_ref7=fuego.auth().currentUser,uid=_ref7.uid;return _context2.abrupt("return",fuego.db.doc(this.path).update(_defineProperty({currentMembers:fuego.firebase.firestore.FieldValue.arrayRemove(uid)},"members."+uid,fuego.firebase.firestore.FieldValue.delete())));case 7:_context2.prev=7;_context2.t0=_context2["catch"](0);console.error(_context2.t0);return _context2.abrupt("return",null);case 11:case"end":return _context2.stop();}}},null,this,[[0,7]]);}},{key:"join",value:function join(){try{var _fuego$db$doc$update2;if(!currentUserExists(fuego.auth().currentUser)){throw new Error("🚨 Fuego auth error: Tried to join a room, but there is no valid firebase auth object for this user. \n In order to join a room, the user must exist. If you're just testing around and don't want to have valid users, try await firebase.auth().signInAnonymously().");}var _ref8=fuego.auth().currentUser,uid=_ref8.uid,displayName=_ref8.displayName;var newMember={name:displayName||'Fredrick Failuretest',exists:true,joinedAt:fuego.firebase.firestore.FieldValue.serverTimestamp()};return fuego.db.doc(this.path).update((_fuego$db$doc$update2={},_defineProperty(_fuego$db$doc$update2,"members."+uid,newMember),_defineProperty(_fuego$db$doc$update2,"currentMembers",fuego.firebase.firestore.FieldValue.arrayUnion(uid)),_fuego$db$doc$update2));}catch(e){console.error(e);return null;}}},{key:"addMembers",value:function addMembers(members){var _firestore$FieldValue;var batch=fuego.db.batch();var ref=fuego.db.doc(this.path);Object.keys(members).forEach(function(uid){return batch.update(ref,_defineProperty({},"members."+uid,members[uid]));});batch.update(ref,{currentMembers:(_firestore$FieldValue=firestore.FieldValue).arrayUnion.apply(_firestore$FieldValue,_toConsumableArray(Object.keys(members)))});return batch.commit();}},{key:"removeMembers",value:function removeMembers(members){var _firestore$FieldValue2;var batch=fuego.db.batch();var ref=fuego.db.doc(this.path);Object.keys(members).forEach(function(uid){return batch.update(ref,_defineProperty({},"members."+uid+".exists",false));});batch.update(ref,{currentMembers:(_firestore$FieldValue2=firestore.FieldValue).arrayRemove.apply(_firestore$FieldValue2,_toConsumableArray(Object.keys(members)))});return batch.commit();}},{key:"create",value:function create(){return _regeneratorRuntime.async(function create$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.prev=0;if(!roomIsNewModel(this.room)){_context3.next=3;break;}return _context3.abrupt("return",this.addToFirebase());case 3:throw new Error('Tried to create room without the proper schema. See NewRoomModel typescript type.');case 6:_context3.prev=6;_context3.t0=_context3["catch"](0);console.error(_context3.t0);return _context3.abrupt("return",null);case 10:case"end":return _context3.stop();}}},null,this,[[0,6]]);}},{key:"createViaCallable",value:function createViaCallable(){var create;return _regeneratorRuntime.async(function createViaCallable$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:_context4.prev=0;if(!roomIsCreateCallable(this.room)){_context4.next=4;break;}create=fuego.firebase.functions().httpsCallable(chat.httpCallables.createRoom);return _context4.abrupt("return",create({recipients:this.room.recipients,name:this.room.name||'',avatar:this.room.avatar||''}));case 4:throw new Error('Error: improper room model for Room.createCallable(). The error comes from config for new Room(config). Make sure schema for config is correct');case 7:_context4.prev=7;_context4.t0=_context4["catch"](0);console.error(_context4.t0);return _context4.abrupt("return",{data:null});case 11:case"end":return _context4.stop();}}},null,this,[[0,7]]);}},{key:"edit",value:function edit(){try{if(roomIsEditModel(this.room))return this.updateOnFirebase();throw new Error('Tried to edit room without the proper schema. See EditRoomModel typescript type.');}catch(e){console.error(e);return null;}}},{key:"getUsersTyping",value:function getUsersTyping(){return this.getArrayOfMembersOtherThanMe().filter(function(member){return member.typing&&member.typing.state==='typing';});}},{key:"updateOnFirebase",value:function updateOnFirebase(){var _ref9=this.room,id=_ref9.id,room=_objectWithoutProperties(_ref9,["id"]);return fuego.db.doc(this.path).update(room);}},{key:"addToFirebase",value:function addToFirebase(){var _ref10=fuego.auth().currentUser,uid=_ref10.uid,displayName=_ref10.displayName,photoURL=_ref10.photoURL;var date=fuego.firebase.firestore.FieldValue.serverTimestamp();var me={name:displayName||'Inexistent Poopnugget',exists:true,avatar:photoURL||'',joinedAt:date};var members=_objectSpread({},this.room.members,_defineProperty({},uid,me));var room={members:members,currentMembers:_toConsumableArray(Object.keys(members)).sort(),createdAt:date,lastEdited:date,lastMessage:{system:true,text:me.name+" started a chat",createdAt:date,id:uuid.v4(),name:me.name}};var ref=fuego.db.collection(chat.roomsCollection).doc();return ref.set(room);}},{key:"path",get:function get(){return chat.roomsCollection+"/"+this.room.id;}},{key:"messagesPath",get:function get(){return this.path+"/"+chat.messagesCollection;}}]);return _default;}();export{_default as default};
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["currentUserExists","roomIsEditModel","roomIsNewModel","roomIsCreateCallable","fuego","chat","getInitials","firestore","uuid","room","firebase","auth","currentUser","uid","member","members","unreadCount","count","e","console","error","messageId","messageCreatedAt","ref","db","doc","path","update","FieldValue","serverTimestamp","id","createdAt","Object","keys","filter","map","name","otherPeopleInRoom","namesOfOtherPeopleInRoom","split","length","join","commaNames","slice","finalName","maxNumberOfInitials","getArrayOfMembersOtherThanMe","Error","currentMembers","arrayRemove","delete","displayName","newMember","exists","joinedAt","arrayUnion","batch","forEach","commit","addToFirebase","create","functions","httpsCallable","httpCallables","createRoom","recipients","avatar","data","updateOnFirebase","typing","state","photoURL","date","me","sort","lastEdited","lastMessage","system","text","v4","collection","roomsCollection","set","messagesCollection"],"mappings":"yrCAAA,OAKCA,iBALD,CAMCC,eAND,CAWCC,cAXD,CAYCC,oBAZD,KAaO,SAbP,CAcA,OAASC,KAAT,CAAgBC,IAAhB,KAA4B,+BAA5B,CACA,OAASC,WAAW,GAAXA,CAAAA,YAAT,KAA4B,2BAA5B,CACA,OAASC,SAAT,KAA0B,UAA1B,CACA,MAAOC,CAAAA,IAAP,KAAiB,MAAjB,C,wBAIC,kBAAYC,IAAZ,CAA6B,gCAC5B,KAAKA,IAAL,CAAYA,IAAZ,CACA,C,4EAOwB,UACRL,KAAK,CAACM,QAAN,CAAeC,IAAf,GAAsBC,WADd,CAChBC,GADgB,MAChBA,GADgB,CAExB,GAAI,CACH,GAAMC,CAAAA,MAAM,CAAI,KAAKL,IAAN,CAAgDM,OAAhD,CACdF,GADc,CAAf,CAIA,M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S,CAAEyC,IAHkB,CAI7BG,UAAU,CAAEH,IAJiB,CAK7BI,WAAW,CAAE,CACZC,MAAM,CAAE,IADI,CAEZC,IAAI,CAAKL,EAAE,CAACrC,IAAR,kBAFQ,CAGZL,SAAS,CAAEyC,IAHC,CAIZ1C,EAAE,CAAEtB,IAAI,CAACuE,EAAL,EAJQ,CAKZ3C,IAAI,CAAEqC,EAAE,CAACrC,IALG,CALgB,CAA9B,CAaA,GAAMb,CAAAA,GAAG,CAAGnB,KAAK,CAACoB,EAAN,CAASwD,UAAT,CAAoB3E,IAAI,CAAC4E,eAAzB,EAA0CxD,GAA1C,EAAZ,CACA,MAAOF,CAAAA,GAAG,CAAC2D,GAAJ,CAAQzE,IAAR,CAAP,CACA,C,gCAzSU,CACV,MAAUJ,CAAAA,IAAI,CAAC4E,eAAf,KAAmC,KAAKxE,IAAN,CAAmCqB,EAArE,CACA,C,wCACkB,CAClB,MAAU,MAAKJ,IAAf,KAAuBrB,IAAI,CAAC8E,kBAA5B,CACA,C","sourcesContent":["import {\n\tNewRoomModel,\n\tRoomModel,\n\tEditRoomModel,\n\tNewRoomMember,\n\tcurrentUserExists,\n\troomIsEditModel,\n\tExistingRoomModel,\n\tRoomMembers,\n\tCreateRoomModel,\n\tRoomPropertiesModel,\n\troomIsNewModel,\n\troomIsCreateCallable\n} from './types'\nimport { fuego, chat } from '../../components/ChatProvider'\nimport { getInitials } from '../../helpers/getInitials'\nimport { firestore } from 'firebase'\nimport uuid from 'uuid'\n\nexport default class {\n\tprivate room: RoomModel\n\tconstructor(room: RoomModel) {\n\t\tthis.room = room\n\t}\n\tget path() {\n\t\treturn `${chat.roomsCollection}/${(this.room as RoomPropertiesModel).id}`\n\t}\n\tget messagesPath() {\n\t\treturn `${this.path}/${chat.messagesCollection}`\n\t}\n\tgetUnreadCount(): number {\n\t\tconst { uid } = fuego.firebase.auth().currentUser as firebase.User\n\t\ttry {\n\t\t\tconst member = (this.room as ExistingRoomModel | NewRoomModel).members[\n\t\t\t\tuid\n\t\t\t]\n\n\t\t\treturn (member && member.unreadCount && member.unreadCount.count) || 0\n\t\t} catch (e) {\n\t\t\tconsole.error(\n\t\t\t\t`Room getUnreadCount error. Are you sure you initialized the room with the proper members schema?`\n\t\t\t)\n\t\t\treturn 0\n\t\t}\n\t}\n\t/**\n\t * Views message function for a room.\n\t *\n\t * To use this in a react component out-of-the-box, I recommend using the [[useViewMessage]] hook. It will handle all this for you.\n\t *\n\t * @param messageId ID of the message you're viewing\n\t * @param messageCreatedAt Timestamp of the message which you're viewing, found in message.createdAt\n\t *\n\t * @remarks\n\t * If you aren't using the useViewMessage hook:\n\t * This function should be used with care. You don't want to send 500 writes if someone views 500 messages.\n\t * You only want to send a read for the most recent message being viewed, assuming it's someone else's message.\n\t * Also, you should be memoizing the last message you sent that you viewed to avoid repeats. Again, this is all handled by useViewMessages.\n\t *\n\t * @returns Promise that only resolves while you're online.\n\t */\n\tasync viewMessage(messageId: string, messageCreatedAt: Date) {\n\t\ttry {\n\t\t\tconst ref = fuego.db.doc(this.path)\n\t\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\n\t\t\treturn ref.update({\n\t\t\t\t[`members.${uid}.unreadCount.count`]: 0,\n\t\t\t\t[`members.${uid}.unreadCount.lastCleared`]: fuego.firebase.firestore.FieldValue.serverTimestamp(),\n\t\t\t\t[`members.${uid}.unreadCount.lastSeen`]: {\n\t\t\t\t\tid: messageId,\n\t\t\t\t\tcreatedAt: messageCreatedAt\n\t\t\t\t}\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error('Room class: viewMessage() error:', e)\n\t\t}\n\t}\n\tgetArrayOfMembersOtherThanMe() {\n\t\tconst { members } = this.room as ExistingRoomModel\n\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\t\treturn Object.keys(members)\n\t\t\t.filter(id => id !== uid)\n\t\t\t.map(id => members[id])\n\t}\n\tgetName(): string {\n\t\tconst { members, name } = this.room as ExistingRoomModel\n\t\tif (name) return name\n\n\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\n\t\tconst otherPeopleInRoom = Object.keys(members).filter(\n\t\t\t(id: string) => id !== uid\n\t\t)\n\t\tconst namesOfOtherPeopleInRoom = otherPeopleInRoom.map(\n\t\t\tid =>\n\t\t\t\t(members[id] &&\n\t\t\t\t\tmembers[id].name &&\n\t\t\t\t\tmembers[id].name.split(' ') &&\n\t\t\t\t\tmembers[id].name.split(' ')[0]) ||\n\t\t\t\t''\n\t\t)\n\t\tif (!namesOfOtherPeopleInRoom.length) {\n\t\t\tconsole.error('no other members in room', this.room)\n\t\t\treturn ''\n\t\t}\n\t\tif (namesOfOtherPeopleInRoom.length === 1)\n\t\t\treturn members[otherPeopleInRoom[0]].name\n\t\tif (namesOfOtherPeopleInRoom.length === 2)\n\t\t\treturn namesOfOtherPeopleInRoom.join(' & ')\n\n\t\tconst commaNames = namesOfOtherPeopleInRoom\n\t\t\t.slice(0, namesOfOtherPeopleInRoom.length - 1)\n\t\t\t.join(', ')\n\t\tconst finalName =\n\t\t\tnamesOfOtherPeopleInRoom[namesOfOtherPeopleInRoom.length - 1]\n\n\t\treturn `${commaNames} & ${finalName}`\n\t}\n\tgetInitials(maxNumberOfInitials = 2): string {\n\t\tconst { name } = this.room\n\t\tif (name) return getInitials(name)\n\n\t\tconst members = this.getArrayOfMembersOtherThanMe()\n\n\t\tif (!members.length) {\n\t\t\tconsole.error(\n\t\t\t\t'get room initials error: no other members in this room',\n\t\t\t\tthis.room\n\t\t\t)\n\t\t\treturn ''\n\t\t}\n\n\t\tif (members.length === 1) {\n\t\t\treturn getInitials(members[0].name, maxNumberOfInitials)\n\t\t}\n\n\t\treturn (\n\t\t\tmembers\n\t\t\t\t// first letter of each person's name\n\t\t\t\t.map(member => (member.name && member.name.slice(0, 1)) || '')\n\t\t\t\t.join('')\n\t\t\t\t// up to two initials\n\t\t\t\t.slice(0, maxNumberOfInitials)\n\t\t)\n\t}\n\t/**\n\t * @returns\n\t * A promise.all array of responses. The first array is for adding a system message; the second is for updating the room object.\n\t */\n\tasync leave() {\n\t\ttry {\n\t\t\tif (!currentUserExists(fuego.auth().currentUser)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"🚨 Fuego auth error: Tried to leave a room, but there is no valid firebase auth object for this user. \\n In order to join a room, the user must exist. If you're just testing around and don't want to have valid users, try await firebase.auth().signInAnonymously().\"\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst { uid } = fuego.auth().currentUser as firebase.User\n\t\t\t// is this even necessary? maybe if people want the option to join or not...\n\t\t\treturn fuego.db.doc(this.path).update({\n\t\t\t\tcurrentMembers: fuego.firebase.firestore.FieldValue.arrayRemove(uid),\n\t\t\t\t[`members.${uid}`]: fuego.firebase.firestore.FieldValue.delete()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn null\n\t\t}\n\t}\n\tjoin() {\n\t\ttry {\n\t\t\tif (!currentUserExists(fuego.auth().currentUser)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"🚨 Fuego auth error: Tried to join a room, but there is no valid firebase auth object for this user. \\n In order to join a room, the user must exist. If you're just testing around and don't want to have valid users, try await firebase.auth().signInAnonymously().\"\n\t\t\t\t)\n\t\t\t}\n\t\t\tconst { uid, displayName } = fuego.auth().currentUser as firebase.User\n\t\t\tconst newMember: NewRoomMember = {\n\t\t\t\tname: displayName || 'Fredrick Failuretest',\n\t\t\t\texists: true,\n\t\t\t\tjoinedAt: fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\t\t}\n\t\t\t// is this even necessary?\n\t\t\t// maybe if people want the option to choose whether they join a room or not...\n\t\t\treturn fuego.db.doc(this.path).update({\n\t\t\t\t[`members.${uid}`]: newMember,\n\t\t\t\tcurrentMembers: fuego.firebase.firestore.FieldValue.arrayUnion(uid)\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn null\n\t\t}\n\t}\n\taddMembers(members: RoomMembers) {\n\t\tconst batch = fuego.db.batch()\n\t\tconst ref = fuego.db.doc(this.path)\n\t\tObject.keys(members).forEach((uid: string) =>\n\t\t\tbatch.update(ref, {\n\t\t\t\t[`members.${uid}`]: members[uid]\n\t\t\t})\n\t\t)\n\n\t\tbatch.update(ref, {\n\t\t\tcurrentMembers: firestore.FieldValue.arrayUnion(...Object.keys(members))\n\t\t})\n\n\t\treturn batch.commit()\n\t}\n\tremoveMembers(members: RoomMembers) {\n\t\tconst batch = fuego.db.batch()\n\t\tconst ref = fuego.db.doc(this.path)\n\n\t\tObject.keys(members).forEach((uid: string) =>\n\t\t\tbatch.update(ref, {\n\t\t\t\t[`members.${uid}.exists`]: false\n\t\t\t})\n\t\t)\n\n\t\tbatch.update(ref, {\n\t\t\tcurrentMembers: firestore.FieldValue.arrayRemove(...Object.keys(members))\n\t\t})\n\n\t\treturn batch.commit()\n\t}\n\tasync create() {\n\t\ttry {\n\t\t\tif (roomIsNewModel(this.room)) return this.addToFirebase()\n\t\t\tthrow new Error(\n\t\t\t\t'Tried to create room without the proper schema. See NewRoomModel typescript type.'\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn null\n\t\t}\n\t}\n\tasync createViaCallable(): Promise<firebase.functions.HttpsCallableResult> {\n\t\ttry {\n\t\t\tif (roomIsCreateCallable(this.room)) {\n\t\t\t\tconst create = fuego.firebase\n\t\t\t\t\t.functions()\n\t\t\t\t\t.httpsCallable(chat.httpCallables.createRoom)\n\t\t\t\treturn create({\n\t\t\t\t\trecipients: this.room.recipients,\n\t\t\t\t\tname: this.room.name || '',\n\t\t\t\t\tavatar: this.room.avatar || ''\n\t\t\t\t})\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t'Error: improper room model for Room.createCallable(). The error comes from config for new Room(config). Make sure schema for config is correct'\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn {\n\t\t\t\tdata: null\n\t\t\t}\n\t\t}\n\t}\n\tedit() {\n\t\ttry {\n\t\t\t// typeguard\n\t\t\tif (roomIsEditModel(this.room)) return this.updateOnFirebase()\n\t\t\tthrow new Error(\n\t\t\t\t'Tried to edit room without the proper schema. See EditRoomModel typescript type.'\n\t\t\t)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\treturn null\n\t\t}\n\t}\n\tgetUsersTyping() {\n\t\treturn this.getArrayOfMembersOtherThanMe().filter(\n\t\t\tmember => member.typing && member.typing.state === 'typing'\n\t\t)\n\n\t\t// return Object.keys((this.room as ExistingRoomModel).members || {})\n\t\t// \t.filter(\n\t\t// \t\t(uid: string) =>\n\t\t// \t\t\tthis.room &&\n\t\t// \t\t\tthis.room.members &&\n\t\t// \t\t\tthis.room.members[uid] &&\n\t\t// \t\t\tthis.room.members[uid].typing\n\t\t// \t)\n\t\t// \t.map(\n\t\t// \t\t(uid: string) =>\n\t\t// \t\t\t(this.room as ExistingRoomModel) &&\n\t\t// \t\t\tthis.room.members &&\n\t\t// \t\t\tthis.room.members[uid]\n\t\t// \t)\n\t}\n\tupdateOnFirebase() {\n\t\tconst { id, ...room } = this.room as EditRoomModel\n\t\treturn fuego.db.doc(this.path).update(room)\n\t}\n\taddToFirebase() {\n\t\tconst { uid, displayName, photoURL } = fuego.auth()\n\t\t\t.currentUser as firebase.User\n\t\tconst date = fuego.firebase.firestore.FieldValue.serverTimestamp()\n\t\tconst me: NewRoomMember = {\n\t\t\tname: displayName || 'Inexistent Poopnugget',\n\t\t\texists: true,\n\t\t\tavatar: photoURL || '',\n\t\t\tjoinedAt: date\n\t\t}\n\t\tconst members: RoomMembers = {\n\t\t\t...(this.room as NewRoomModel).members,\n\t\t\t[uid]: me\n\t\t}\n\t\tconst room: CreateRoomModel = {\n\t\t\tmembers,\n\t\t\tcurrentMembers: [...Object.keys(members)].sort(),\n\t\t\tcreatedAt: date,\n\t\t\tlastEdited: date,\n\t\t\tlastMessage: {\n\t\t\t\tsystem: true,\n\t\t\t\ttext: `${me.name} started a chat`,\n\t\t\t\tcreatedAt: date,\n\t\t\t\tid: uuid.v4(),\n\t\t\t\tname: me.name\n\t\t\t}\n\t\t}\n\t\tconst ref = fuego.db.collection(chat.roomsCollection).doc()\n\t\treturn ref.set(room)\n\t}\n}\n"]}
@@ -1,2 +0,0 @@
1
- export function currentUserExists(user){return!!user;}export function roomIsEditModel(room){return!!room;}export function roomIsNewModel(room){return!!room;}export function roomIsCreateCallable(room){return!!room;}
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["types.ts"],"names":["currentUserExists","user","roomIsEditModel","room","roomIsNewModel","roomIsCreateCallable"],"mappings":"AA8IA,MAAO,SAASA,CAAAA,iBAAT,CACNC,IADM,CAEkB,CACxB,MAAO,CAAC,CAAEA,IAAV,CACA,CAED,MAAO,SAASC,CAAAA,eAAT,CAAyBC,IAAzB,CAAiE,CACvE,MAAO,CAAC,CAAEA,IAAV,CACA,CAED,MAAO,SAASC,CAAAA,cAAT,CAAwBD,IAAxB,CAA+D,CACrE,MAAO,CAAC,CAAEA,IAAV,CACA,CAED,MAAO,SAASE,CAAAA,oBAAT,CACNF,IADM,CAE4B,CAClC,MAAO,CAAC,CAAEA,IAAV,CACA","sourcesContent":["import { FieldValue, Timestamp } from '@firebase/firestore-types'\nimport * as firebase from 'firebase'\n\nexport interface LastMessage {\n\tcreatedAt: Date\n\ttext: string\n\tname: string\n\tsystem: boolean\n\tid: string\n}\n\nexport interface LastMessageServer extends Omit<LastMessage, 'createdAt'> {\n\tcreatedAt: FieldValue\n}\n\n/**\n * Unread count schema in the members dictionary for each room\n */\nexport interface UnreadCount {\n\tcount: number\n\t/**\n\t * The timestamp of the last time you cleared messages.\n\t */\n\tlastCleared: Date\n\t/**\n\t * Details of the last message you saw.\n\t */\n\tlastSeen: {\n\t\tid: string\n\t\tcreatedAt: Date\n\t}\n}\n\nexport interface UnreadCountDocument extends Omit<UnreadCount, 'lastCleared'> {\n\tlastCleared: firebase.firestore.Timestamp\n}\n\nexport interface UnreadCountServer extends Omit<UnreadCount, 'lastCleared'> {\n\tlastCleared: firebase.firestore.FieldValue\n}\n\nexport interface RoomPropertiesModel {\n\tid: string\n\t// avatar url for this room\n\tavatar?: string\n\tmembers?: RoomMembers\n\tname?: string\n}\n\nexport interface Typing {\n\tstate: 'typing' | 'nothing'\n\tlastChanged: typeof firebase.database.ServerValue.TIMESTAMP\n}\n\nexport interface RoomMember {\n\t// typing?: boolean\n\ttyping?: Typing\n\texists: boolean\n\t// we should probably do this one via cloud function\n\tname: string\n\tnickname?: string\n\tavatar?: string\n\tjoinedAt: FieldValue\n\tunreadCount?: UnreadCount\n}\n\nexport interface ExistingRoomMember {\n\t// optional nickname specific to this room\n\tnickname?: string\n\t// url to specific image for this room\n\tavatar?: string\n}\n\nexport interface NewRoomMember extends RoomMember {}\n\n/**\n * Dictionary of members in the room.\n */\nexport interface RoomMembers {\n\t[id: string]: RoomMember\n}\n\n/**\n * Configuration for the room class. Members doesn't need to include me.\n *\n * @example\n * ```\n * const room = new Room(config: NewRoomModel)\n * await room.create()\n * ```\n */\nexport interface NewRoomModel extends Omit<RoomPropertiesModel, 'id'> {\n\tmembers: RoomMembers\n}\n\nexport interface CreateCallableRoomModel extends Partial<RoomPropertiesModel> {\n\trecipients: string[]\n}\n\nexport interface EditRoomModel extends Omit<RoomPropertiesModel, 'members'> {\n\tmembers?: RoomMembers\n\tname?: string\n\tlastMessage?: LastMessage\n}\n\nexport interface ExistingRoomModel extends RoomPropertiesModel {\n\tlastMessage: LastMessage\n\tmembers: RoomMembers\n\tunreadCount?: number\n\tcreatedAt: FieldValue\n\tlastEdited: FieldValue\n\tcurrentMembers: string[]\n}\n\nexport interface CreateRoomModel\n\textends Omit<Omit<ExistingRoomModel, 'id'>, 'lastMessage'> {\n\tlastMessage: LastMessageServer\n}\n\nexport interface CreateRoomCallableModel\n\textends Omit<RoomPropertiesModel, 'id'> {\n\tmembers: RoomMembers\n}\n\ninterface LastMessageDocument extends Omit<LastMessage, 'createdAt'> {\n\tcreatedAt: Timestamp\n}\n\nexport interface ExistingRoomDocument\n\textends Omit<ExistingRoomModel, 'lastMessage'> {\n\tlastMessage: LastMessageDocument\n}\n\nexport type RoomModel =\n\t| RoomPropertiesModel\n\t| NewRoomModel\n\t| ExistingRoomModel\n\t| CreateCallableRoomModel\n\n// typescript type guard functions\n// see: https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards\n\nexport function currentUserExists(\n\tuser: firebase.User | null\n): user is firebase.User {\n\treturn !!(user as firebase.User)\n}\n\nexport function roomIsEditModel(room: RoomModel): room is EditRoomModel {\n\treturn !!(room as EditRoomModel)\n}\n\nexport function roomIsNewModel(room: RoomModel): room is NewRoomModel {\n\treturn !!(room as NewRoomModel)\n}\n\nexport function roomIsCreateCallable(\n\troom: RoomModel\n): room is CreateCallableRoomModel {\n\treturn !!(room as CreateCallableRoomModel)\n}\n"]}
@@ -1,2 +0,0 @@
1
- export{default as Reaction}from'./Reaction';export{default as Message}from'./Message';export{default as Room}from'./Room';export{default as Chat}from'./Chat';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":["default","Reaction","Message","Room","Chat"],"mappings":"AAAA,OAASA,OAAO,GAAIC,CAAAA,QAApB,KAAoC,YAApC,CACA,OAASD,OAAO,GAAIE,CAAAA,OAApB,KAAmC,WAAnC,CACA,OAASF,OAAO,GAAIG,CAAAA,IAApB,KAAgC,QAAhC,CACA,OAASH,OAAO,GAAII,CAAAA,IAApB,KAAgC,QAAhC","sourcesContent":["export { default as Reaction } from './Reaction'\nexport { default as Message } from './Message'\nexport { default as Room } from './Room'\nexport { default as Chat } from './Chat'\n"]}
@@ -1,2 +0,0 @@
1
- import _extends from"@babel/runtime/helpers/extends";var _jsxFileName="/Users/Fernando/Developer/Learning Babel/usechat/src/components/Avatar/index.tsx";import React from'react';import{Image,StyleSheet,View}from'react-native';export default React.memo(function(props){var size=props.size;var borderRadius=size/2;var Img=props.ImageComponent||Image;return React.createElement(View,{style:[styles.container,{borderRadius:borderRadius}],__source:{fileName:_jsxFileName,lineNumber:10}},React.createElement(Img,_extends({style:[{height:size,width:size}],resizeMode:"cover"},props.imageProps||{},{source:{uri:props.avatar},__source:{fileName:_jsxFileName,lineNumber:11}})));});var styles=StyleSheet.create({container:{overflow:'hidden'}});
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.tsx"],"names":["React","Image","StyleSheet","View","memo","props","size","borderRadius","Img","ImageComponent","styles","container","height","width","imageProps","uri","avatar","create","overflow"],"mappings":"yJAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,OAASC,KAAT,CAAgBC,UAAhB,CAA4BC,IAA5B,KAAwC,cAAxC,CAGA,cAAeH,CAAAA,KAAK,CAACI,IAAN,CAAW,SAASC,KAAT,CAA6B,CACtD,GAAMC,CAAAA,IAAI,CAAGD,KAAK,CAACC,IAAnB,CACA,GAAMC,CAAAA,YAAY,CAAGD,IAAI,CAAG,CAA5B,CACA,GAAME,CAAAA,GAAG,CAAGH,KAAK,CAACI,cAAN,EAAwBR,KAApC,CACA,MACC,qBAAC,IAAD,EAAM,KAAK,CAAE,CAACS,MAAM,CAACC,SAAR,CAAmB,CAAEJ,YAAY,CAAZA,YAAF,CAAnB,CAAb,iDACC,oBAAC,GAAD,WACC,KAAK,CAAE,CAAC,CAAEK,MAAM,CAAEN,IAAV,CAAgBO,KAAK,CAAEP,IAAvB,CAAD,CADR,CAEC,UAAU,CAAC,OAFZ,EAGMD,KAAK,CAACS,UAAN,EAAoB,EAH1B,EAIC,MAAM,CAAE,CAAEC,GAAG,CAAEV,KAAK,CAACW,MAAb,CAJT,kDADD,CADD,CAUA,CAdc,CAAf,CAgBA,GAAMN,CAAAA,MAAM,CAAGR,UAAU,CAACe,MAAX,CAAkB,CAChCN,SAAS,CAAE,CACVO,QAAQ,CAAE,QADA,CADqB,CAAlB,CAAf","sourcesContent":["import React from 'react'\nimport { Image, StyleSheet, View } from 'react-native'\nimport { AvatarProps } from '../Inbox/types'\n\nexport default React.memo(function(props: AvatarProps) {\n\tconst size = props.size\n\tconst borderRadius = size / 2\n\tconst Img = props.ImageComponent || Image\n\treturn (\n\t\t<View style={[styles.container, { borderRadius }]}>\n\t\t\t<Img\n\t\t\t\tstyle={[{ height: size, width: size }]}\n\t\t\t\tresizeMode=\"cover\"\n\t\t\t\t{...(props.imageProps || {})}\n\t\t\t\tsource={{ uri: props.avatar }}\n\t\t\t/>\n\t\t</View>\n\t)\n})\n\nconst styles = StyleSheet.create({\n\tcontainer: {\n\t\toverflow: 'hidden'\n\t}\n})\n"]}
@@ -1,2 +0,0 @@
1
- import _extends from"@babel/runtime/helpers/extends";import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";var _jsxFileName="/Users/Fernando/Developer/Learning Babel/usechat/src/components/Chat/Bubble/index.tsx";import React,{useMemo,useCallback}from'react';import{View,Text,StyleSheet}from'react-native';import{LinearGradient}from'expo-linear-gradient';import Media from'../Media';var isValidColor=function isValidColor(color){return /(#(?:[0-9a-f]{ 2 }){ 2,4 }|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[d\.]+%?\)|\b(transparent|black|silver|gray|whitesmoke|maroon|red|purple|fuchsia|green|lime|olivedrab|yellow|navy|blue|teal|aquamarine|orange|aliceblue|antiquewhite|aqua|azure|beige|bisque|blanchedalmond|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|gainsboro|ghostwhite|goldenrod|gold|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavenderblush|lavender|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|limegreen|linen|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|oldlace|olive|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|thistle|tomato|turquoise|violet|wheat|white|yellowgreen|rebeccapurple)\b)/i.test(color);};var Bubble=function Bubble(props){var containerStyles=useMemo(function(){return[styles.container,props.isMe?meStyles.container:otherStyles.container,props.style];},[props.style,props.isMe]);var textStyles=useMemo(function(){var color=props.textColor&&{color:props.textColor}||{};return[styles.text,props.isMe?meStyles.text:otherStyles.text,color,props.textStyle];},[props.textStyle,props.isMe,props.textColor]);var backgroundColor=useMemo(function(){var color=[];if(Array.isArray(props.backgroundColor)){color=props.backgroundColor;}if(typeof props.backgroundColor==='string'){color=[props.backgroundColor,props.backgroundColor];}var invalidColors=_toConsumableArray(Array.from(new Set(color.filter(function(color){return!isValidColor(color);}))));if(invalidColors.length){console.warn("\uD83C\uDF4F Juice warning: The background color value you gave to the Bubble component doesn't seem to be valid. Each color should be a HEX color or CSS color string, matching this format: #abc123, but instead, it got these: "+invalidColors+", which don't match the format. If you gave a valid CSS color and it works, you can ignore this.");}return color||(props.isMe?['#7B16FF','#7114EA']:['#f1f7f8','#f8f8f8']);},[props.backgroundColor,props.isMe]);var propsRenderMedia=props.renderMedia;var renderMedia=useCallback(function(){if(propsRenderMedia===null)return null;if(!props.mediaContentType)return null;var media={url:props.mediaUrl||'',uri:props.mediaUri,height:props.mediaHeight||0,width:props.mediaWidth||0,contentType:props.mediaContentType};if(propsRenderMedia)return propsRenderMedia({media:media});return React.createElement(Media,_extends({},media,{__source:{fileName:_jsxFileName,lineNumber:68}}));},[props.mediaUrl,props.mediaUri,props.mediaHeight,props.mediaWidth,props.mediaContentType,propsRenderMedia]);var text=props.text,propsRenderText=props.renderText;var renderText=useCallback(function(){if(text){if(propsRenderText)return propsRenderText({style:textStyles,text:text});return React.createElement(Text,{style:textStyles,__source:{fileName:_jsxFileName,lineNumber:82}},text);}return null;},[textStyles,text,propsRenderText]);return React.createElement(View,{style:containerStyles,ref:props.bubbleRef,__source:{fileName:_jsxFileName,lineNumber:88}},React.createElement(LinearGradient,{colors:backgroundColor,start:[0.1,0.1],end:[0.9,0.9],style:styles.gradient,__source:{fileName:_jsxFileName,lineNumber:89}},renderMedia(),renderText()));};export default React.memo(Bubble);var styles=StyleSheet.create({container:{maxWidth:'80%',borderRadius:20,overflow:'hidden'},text:{textAlign:'left',fontSize:16,paddingHorizontal:12,paddingVertical:10},gradient:{flex:1}});var meStyles=StyleSheet.create({container:{marginLeft:5},text:{color:'white'}});var otherStyles=StyleSheet.create({container:{marginRight:5},text:{color:'black'}});
2
- //# sourceMappingURL=index.js.map