stream-chat-react-native-core 4.9.0 → 4.10.1-beta.1

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 (98) hide show
  1. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js +7 -3
  2. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js.map +1 -1
  3. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
  4. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  5. package/lib/commonjs/components/Chat/Chat.js +9 -5
  6. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  7. package/lib/commonjs/components/ImageGallery/ImageGallery.js +25 -22
  8. package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
  9. package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
  10. package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
  11. package/lib/commonjs/components/Message/Message.js +12 -8
  12. package/lib/commonjs/components/Message/Message.js.map +1 -1
  13. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js +7 -4
  14. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  15. package/lib/commonjs/components/MessageList/MessageList.js +130 -70
  16. package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
  17. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +16 -10
  18. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  19. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
  20. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  21. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +15 -13
  22. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  23. package/lib/commonjs/contexts/translationContext/TranslationContext.js +8 -4
  24. package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
  25. package/lib/commonjs/hooks/useStreami18n.js.map +1 -1
  26. package/lib/commonjs/hooks/useTranslatedMessage.js +34 -0
  27. package/lib/commonjs/hooks/useTranslatedMessage.js.map +1 -0
  28. package/lib/commonjs/mock-builders/api/getOrCreateChannel.js.map +1 -1
  29. package/lib/commonjs/mock-builders/generator/channel.js +8 -4
  30. package/lib/commonjs/mock-builders/generator/channel.js.map +1 -1
  31. package/lib/commonjs/version.json +1 -1
  32. package/lib/module/components/ChannelPreview/ChannelPreview.js +7 -3
  33. package/lib/module/components/ChannelPreview/ChannelPreview.js.map +1 -1
  34. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
  35. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  36. package/lib/module/components/Chat/Chat.js +9 -5
  37. package/lib/module/components/Chat/Chat.js.map +1 -1
  38. package/lib/module/components/ImageGallery/ImageGallery.js +25 -22
  39. package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
  40. package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
  41. package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
  42. package/lib/module/components/Message/Message.js +12 -8
  43. package/lib/module/components/Message/Message.js.map +1 -1
  44. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js +7 -4
  45. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  46. package/lib/module/components/MessageList/MessageList.js +130 -70
  47. package/lib/module/components/MessageList/MessageList.js.map +1 -1
  48. package/lib/module/contexts/messageInputContext/MessageInputContext.js +16 -10
  49. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  50. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
  51. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  52. package/lib/module/contexts/overlayContext/OverlayProvider.js +15 -13
  53. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  54. package/lib/module/contexts/translationContext/TranslationContext.js +8 -4
  55. package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
  56. package/lib/module/hooks/useStreami18n.js.map +1 -1
  57. package/lib/module/hooks/useTranslatedMessage.js +34 -0
  58. package/lib/module/hooks/useTranslatedMessage.js.map +1 -0
  59. package/lib/module/mock-builders/api/getOrCreateChannel.js.map +1 -1
  60. package/lib/module/mock-builders/generator/channel.js +8 -4
  61. package/lib/module/mock-builders/generator/channel.js.map +1 -1
  62. package/lib/module/version.json +1 -1
  63. package/lib/typescript/components/ChannelPreview/__tests__/ChannelPreview.test.d.ts +1 -0
  64. package/lib/typescript/components/Message/MessageSimple/__tests__/MessageTextContainer.test.d.ts +1 -0
  65. package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts +2 -1
  66. package/lib/typescript/contexts/translationContext/TranslationContext.d.ts +7 -2
  67. package/lib/typescript/hooks/__tests__/useTranslatedMessage.test.d.ts +1 -0
  68. package/lib/typescript/hooks/useStreami18n.d.ts +2 -2
  69. package/lib/typescript/hooks/useTranslatedMessage.d.ts +3 -0
  70. package/lib/typescript/mock-builders/api/getOrCreateChannel.d.ts +13 -1
  71. package/lib/typescript/mock-builders/event/messageNew.d.ts +2 -0
  72. package/lib/typescript/mock-builders/event/messageRead.d.ts +8 -0
  73. package/lib/typescript/mock-builders/generator/channel.d.ts +19 -15
  74. package/package.json +3 -3
  75. package/src/components/ChannelPreview/ChannelPreview.tsx +7 -1
  76. package/src/components/ChannelPreview/__tests__/{ChannelPreview.test.js → ChannelPreview.test.tsx} +79 -41
  77. package/src/components/ChannelPreview/hooks/__tests__/useLatestMessagePreview.test.tsx +56 -21
  78. package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +4 -1
  79. package/src/components/Chat/Chat.tsx +6 -3
  80. package/src/components/ImageGallery/ImageGallery.tsx +10 -6
  81. package/src/components/ImageGallery/components/ImageGalleryFooter.tsx +2 -1
  82. package/src/components/Message/Message.tsx +3 -0
  83. package/src/components/Message/MessageSimple/MessageTextContainer.tsx +7 -1
  84. package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.tsx +108 -0
  85. package/src/components/Message/MessageSimple/__tests__/__snapshots__/{MessageTextContainer.test.js.snap → MessageTextContainer.test.tsx.snap} +0 -0
  86. package/src/components/MessageList/MessageList.tsx +8 -10
  87. package/src/contexts/messageInputContext/MessageInputContext.tsx +7 -0
  88. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +4 -0
  89. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +2 -1
  90. package/src/contexts/overlayContext/OverlayProvider.tsx +4 -3
  91. package/src/contexts/translationContext/TranslationContext.tsx +10 -1
  92. package/src/hooks/__tests__/useTranslatedMessage.test.tsx +106 -0
  93. package/src/hooks/useStreami18n.ts +2 -2
  94. package/src/hooks/useTranslatedMessage.ts +30 -0
  95. package/src/mock-builders/api/{getOrCreateChannel.js → getOrCreateChannel.ts} +8 -1
  96. package/src/mock-builders/generator/{channel.js → channel.ts} +19 -10
  97. package/src/version.json +1 -1
  98. package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.js +0 -65
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.withTranslationContext = exports.useTranslationContext = exports.isDayOrMoment = exports.TranslationProvider = exports.TranslationContext = void 0;
8
+ exports.withTranslationContext = exports.useTranslationContext = exports.isDayOrMoment = exports.TranslationProvider = exports.TranslationContext = exports.DEFAULT_USER_LANGUAGE = void 0;
9
9
 
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
 
@@ -24,6 +24,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
24
24
 
25
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
26
 
27
+ var DEFAULT_USER_LANGUAGE = 'en';
28
+ exports.DEFAULT_USER_LANGUAGE = DEFAULT_USER_LANGUAGE;
29
+
27
30
  var isDayOrMoment = function isDayOrMoment(output) {
28
31
  return output.isSame != null;
29
32
  };
@@ -35,7 +38,8 @@ var defaultTranslationContextValue = {
35
38
  },
36
39
  tDateTimeParser: function tDateTimeParser(input) {
37
40
  return (0, _dayjs["default"])(input);
38
- }
41
+ },
42
+ userLanguage: DEFAULT_USER_LANGUAGE
39
43
  };
40
44
 
41
45
  var TranslationContext = _react["default"].createContext(defaultTranslationContextValue);
@@ -50,7 +54,7 @@ var TranslationProvider = function TranslationProvider(_ref) {
50
54
  __self: _this,
51
55
  __source: {
52
56
  fileName: _jsxFileName,
53
- lineNumber: 38,
57
+ lineNumber: 47,
54
58
  columnNumber: 3
55
59
  }
56
60
  }, children);
@@ -77,7 +81,7 @@ var withTranslationContext = function withTranslationContext(Component) {
77
81
  __self: _this,
78
82
  __source: {
79
83
  fileName: _jsxFileName,
80
- lineNumber: 63,
84
+ lineNumber: 72,
81
85
  columnNumber: 12
82
86
  }
83
87
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["TranslationContext.tsx"],"names":["isDayOrMoment","output","isSame","defaultTranslationContextValue","t","key","tDateTimeParser","input","TranslationContext","React","createContext","TranslationProvider","children","value","useTranslationContext","contextValue","Error","withTranslationContext","Component","WithTranslationContextComponent","props","translationContext","displayName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,EAAAA,+BAA+B,CAACG,WAAhC,8BAAuE,oCACrEJ,SADqE,CAAvE;AAGA,SAAOC,+BAAP;AACD,CAhBM","sourcesContent":["import React, { useContext } from 'react';\n\nimport Dayjs from 'dayjs';\n\nimport type { TFunction } from 'i18next';\nimport type { Moment } from 'moment';\n\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport const isDayOrMoment = (output: TDateTimeParserOutput): output is Dayjs.Dayjs | Moment =>\n (output as Dayjs.Dayjs | Moment).isSame != null;\n\nexport type TDateTimeParserInput = string | number | Date;\n\nexport type TDateTimeParserOutput = string | number | Date | Dayjs.Dayjs | Moment;\n\nexport type TDateTimeParser = (input?: TDateTimeParserInput) => TDateTimeParserOutput;\n\nexport type TranslationContextValue = {\n t: TFunction | ((key: string) => string);\n tDateTimeParser: TDateTimeParser;\n};\n\nconst defaultTranslationContextValue: TranslationContextValue = {\n t: (key: string) => key,\n tDateTimeParser: (input) => Dayjs(input),\n};\n\nexport const TranslationContext = React.createContext<TranslationContextValue>(\n defaultTranslationContextValue,\n);\n\nexport const TranslationProvider: React.FC<{\n value: TranslationContextValue;\n}> = ({ children, value }) => (\n <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>\n);\n\nexport const useTranslationContext = () => {\n const contextValue = useContext(TranslationContext);\n\n if (contextValue === defaultTranslationContextValue && !isTestEnvironment()) {\n throw new Error(\n `The useTranslationContext hook was called outside the TranslationContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider)(https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withTranslationContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<StreamChatGenerics>,\n): React.FC<Omit<StreamChatGenerics, keyof TranslationContextValue>> => {\n const WithTranslationContextComponent = (\n props: Omit<StreamChatGenerics, keyof TranslationContextValue>,\n ) => {\n const translationContext = useTranslationContext();\n\n return <Component {...(props as StreamChatGenerics)} {...translationContext} />;\n };\n WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(\n Component as React.ComponentType,\n )}`;\n return WithTranslationContextComponent;\n};\n"]}
1
+ {"version":3,"sources":["TranslationContext.tsx"],"names":["DEFAULT_USER_LANGUAGE","isDayOrMoment","output","isSame","defaultTranslationContextValue","t","key","tDateTimeParser","input","userLanguage","TranslationContext","React","createContext","TranslationProvider","children","value","useTranslationContext","contextValue","Error","withTranslationContext","Component","WithTranslationContextComponent","props","translationContext","displayName"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAQA;;AACA;;;;;;;;;AAEO,IAAMA,qBAA2C,GAAG,IAApD;;;AAEA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,MAAD;AAAA,SAC1BA,MAAD,CAAiCC,MAAjC,IAA2C,IADhB;AAAA,CAAtB;;;AAkBP,IAAMC,8BAAuD,GAAG;AAC9DC,EAAAA,CAAC,EAAE,WAACC,GAAD;AAAA,WAAiBA,GAAjB;AAAA,GAD2D;AAE9DC,EAAAA,eAAe,EAAE,yBAACC,KAAD;AAAA,WAAW,uBAAMA,KAAN,CAAX;AAAA,GAF6C;AAG9DC,EAAAA,YAAY,EAAET;AAHgD,CAAhE;;AAMO,IAAMU,kBAAkB,GAAGC,kBAAMC,aAAN,CAChCR,8BADgC,CAA3B;;;;AAIA,IAAMS,mBAEX,GAAG,SAFQA,mBAER;AAAA,MAAGC,QAAH,QAAGA,QAAH;AAAA,MAAaC,KAAb,QAAaA,KAAb;AAAA,SACH,gCAAC,kBAAD,CAAoB,QAApB;AAA6B,IAAA,KAAK,EAAEA,KAApC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAA4CD,QAA5C,CADG;AAAA,CAFE;;;;AAMA,IAAME,qBAAqB,GAAG,SAAxBA,qBAAwB,GAAM;AACzC,MAAMC,YAAY,GAAG,uBAAWP,kBAAX,CAArB;;AAEA,MAAIO,YAAY,KAAKb,8BAAjB,IAAmD,CAAC,2CAAxD,EAA6E;AAC3E,UAAM,IAAIc,KAAJ,+UAAN;AAGD;;AAED,SAAOD,YAAP;AACD,CAVM;;;;AAYA,IAAME,sBAAsB,GAAG,SAAzBA,sBAAyB,CAGpCC,SAHoC,EAIkC;AACtE,MAAMC,+BAA+B,GAAG,SAAlCA,+BAAkC,CACtCC,KADsC,EAEnC;AACH,QAAMC,kBAAkB,GAAGP,qBAAqB,EAAhD;AAEA,WAAO,gCAAC,SAAD,gCAAgBM,KAAhB,EAAkDC,kBAAlD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAP;AACD,GAND;;AAOAF,EAAAA,+BAA+B,CAACG,WAAhC,8BAAuE,oCACrEJ,SADqE,CAAvE;AAGA,SAAOC,+BAAP;AACD,CAhBM","sourcesContent":["import React, { useContext } from 'react';\n\nimport Dayjs from 'dayjs';\n\nimport type { TFunction } from 'i18next';\nimport type { Moment } from 'moment';\n\nimport type { TranslationLanguages } from 'stream-chat';\n\nimport type { DefaultStreamChatGenerics } from '../../types/types';\nimport { getDisplayName } from '../utils/getDisplayName';\nimport { isTestEnvironment } from '../utils/isTestEnvironment';\n\nexport const DEFAULT_USER_LANGUAGE: TranslationLanguages = 'en';\n\nexport const isDayOrMoment = (output: TDateTimeParserOutput): output is Dayjs.Dayjs | Moment =>\n (output as Dayjs.Dayjs | Moment).isSame != null;\n\nexport type TDateTimeParserInput = string | number | Date;\n\nexport type TDateTimeParserOutput = string | number | Date | Dayjs.Dayjs | Moment;\n\nexport type TDateTimeParser = (input?: TDateTimeParserInput) => TDateTimeParserOutput;\n\nexport type TranslatorFunctions = {\n t: TFunction | ((key: string) => string);\n tDateTimeParser: TDateTimeParser;\n};\n\nexport type TranslationContextValue = TranslatorFunctions & {\n userLanguage: TranslationLanguages;\n};\n\nconst defaultTranslationContextValue: TranslationContextValue = {\n t: (key: string) => key,\n tDateTimeParser: (input) => Dayjs(input),\n userLanguage: DEFAULT_USER_LANGUAGE,\n};\n\nexport const TranslationContext = React.createContext<TranslationContextValue>(\n defaultTranslationContextValue,\n);\n\nexport const TranslationProvider: React.FC<{\n value: TranslationContextValue;\n}> = ({ children, value }) => (\n <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>\n);\n\nexport const useTranslationContext = () => {\n const contextValue = useContext(TranslationContext);\n\n if (contextValue === defaultTranslationContextValue && !isTestEnvironment()) {\n throw new Error(\n `The useTranslationContext hook was called outside the TranslationContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider)(https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,\n );\n }\n\n return contextValue;\n};\n\nexport const withTranslationContext = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n Component: React.ComponentType<StreamChatGenerics>,\n): React.FC<Omit<StreamChatGenerics, keyof TranslationContextValue>> => {\n const WithTranslationContextComponent = (\n props: Omit<StreamChatGenerics, keyof TranslationContextValue>,\n ) => {\n const translationContext = useTranslationContext();\n\n return <Component {...(props as StreamChatGenerics)} {...translationContext} />;\n };\n WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(\n Component as React.ComponentType,\n )}`;\n return WithTranslationContextComponent;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["useStreami18n.ts"],"names":["useStreami18n","i18nInstance","setTranslators","loadingTranslators","setLoadingTranslators","isMounted","i18nInstanceExists","streami18n","Streami18n","language","registerSetLanguageCallback","t","prevTranslator","getTranslators","then","translator","current"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAGA;;AAEO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,OAMvB;AAAA,MALJC,YAKI,QALJA,YAKI;AAAA,MAJJC,cAII,QAJJA,cAII;;AACJ,kBAAoD,qBAAS,IAAT,CAApD;AAAA;AAAA,MAAOC,kBAAP;AAAA,MAA2BC,qBAA3B;;AACA,MAAMC,SAAS,GAAG,uCAAlB;AACA,MAAMC,kBAAkB,GAAG,CAAC,CAACL,YAA7B;AACA,wBAAU,YAAM;AACd,QAAIM,UAAJ;;AAEA,QAAIN,YAAY,YAAYO,sBAA5B,EAAwC;AACtCD,MAAAA,UAAU,GAAGN,YAAb;AACD,KAFD,MAEO;AACLM,MAAAA,UAAU,GAAG,IAAIC,sBAAJ,CAAe;AAAEC,QAAAA,QAAQ,EAAE;AAAZ,OAAf,CAAb;AACD;;AAEDF,IAAAA,UAAU,CAACG,2BAAX,CAAuC,UAACC,CAAD;AAAA,aACrCT,cAAc,CAAC,UAACU,cAAD;AAAA,6CAA0BA,cAA1B;AAA0CD,UAAAA,CAAC,EAADA;AAA1C;AAAA,OAAD,CADuB;AAAA,KAAvC;AAGAJ,IAAAA,UAAU,CAACM,cAAX,GAA4BC,IAA5B,CAAiC,UAACC,UAAD,EAAgB;AAC/C,UAAIA,UAAU,IAAIV,SAAS,CAACW,OAA5B,EAAqCd,cAAc,CAACa,UAAD,CAAd;AACtC,KAFD;AAIAX,IAAAA,qBAAqB,CAAC,KAAD,CAArB;AACD,GAjBD,EAiBG,CAACE,kBAAD,EAAqBL,YAArB,CAjBH;AAmBA,SAAOE,kBAAP;AACD,CA9BM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useIsMountedRef } from './useIsMountedRef';\n\nimport type { TranslationContextValue } from '../contexts/translationContext/TranslationContext';\nimport { Streami18n } from '../utils/Streami18n';\n\nexport const useStreami18n = ({\n i18nInstance,\n setTranslators,\n}: {\n setTranslators: React.Dispatch<React.SetStateAction<TranslationContextValue>>;\n i18nInstance?: Streami18n;\n}) => {\n const [loadingTranslators, setLoadingTranslators] = useState(true);\n const isMounted = useIsMountedRef();\n const i18nInstanceExists = !!i18nInstance;\n useEffect(() => {\n let streami18n: Streami18n;\n\n if (i18nInstance instanceof Streami18n) {\n streami18n = i18nInstance;\n } else {\n streami18n = new Streami18n({ language: 'en' });\n }\n\n streami18n.registerSetLanguageCallback((t: (key: string) => string) =>\n setTranslators((prevTranslator) => ({ ...prevTranslator, t })),\n );\n streami18n.getTranslators().then((translator) => {\n if (translator && isMounted.current) setTranslators(translator);\n });\n\n setLoadingTranslators(false);\n }, [i18nInstanceExists, i18nInstance]);\n\n return loadingTranslators;\n};\n"]}
1
+ {"version":3,"sources":["useStreami18n.ts"],"names":["useStreami18n","i18nInstance","setTranslators","loadingTranslators","setLoadingTranslators","isMounted","i18nInstanceExists","streami18n","Streami18n","language","registerSetLanguageCallback","t","prevTranslator","getTranslators","then","translator","current"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AAGA;;AAEO,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,OAMvB;AAAA,MALJC,YAKI,QALJA,YAKI;AAAA,MAJJC,cAII,QAJJA,cAII;;AACJ,kBAAoD,qBAAS,IAAT,CAApD;AAAA;AAAA,MAAOC,kBAAP;AAAA,MAA2BC,qBAA3B;;AACA,MAAMC,SAAS,GAAG,uCAAlB;AACA,MAAMC,kBAAkB,GAAG,CAAC,CAACL,YAA7B;AACA,wBAAU,YAAM;AACd,QAAIM,UAAJ;;AAEA,QAAIN,YAAY,YAAYO,sBAA5B,EAAwC;AACtCD,MAAAA,UAAU,GAAGN,YAAb;AACD,KAFD,MAEO;AACLM,MAAAA,UAAU,GAAG,IAAIC,sBAAJ,CAAe;AAAEC,QAAAA,QAAQ,EAAE;AAAZ,OAAf,CAAb;AACD;;AAEDF,IAAAA,UAAU,CAACG,2BAAX,CAAuC,UAACC,CAAD;AAAA,aACrCT,cAAc,CAAC,UAACU,cAAD;AAAA,6CAA0BA,cAA1B;AAA0CD,UAAAA,CAAC,EAADA;AAA1C;AAAA,OAAD,CADuB;AAAA,KAAvC;AAGAJ,IAAAA,UAAU,CAACM,cAAX,GAA4BC,IAA5B,CAAiC,UAACC,UAAD,EAAgB;AAC/C,UAAIA,UAAU,IAAIV,SAAS,CAACW,OAA5B,EAAqCd,cAAc,CAACa,UAAD,CAAd;AACtC,KAFD;AAIAX,IAAAA,qBAAqB,CAAC,KAAD,CAArB;AACD,GAjBD,EAiBG,CAACE,kBAAD,EAAqBL,YAArB,CAjBH;AAmBA,SAAOE,kBAAP;AACD,CA9BM","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useIsMountedRef } from './useIsMountedRef';\n\nimport type { TranslatorFunctions } from '../contexts/translationContext/TranslationContext';\nimport { Streami18n } from '../utils/Streami18n';\n\nexport const useStreami18n = ({\n i18nInstance,\n setTranslators,\n}: {\n setTranslators: React.Dispatch<React.SetStateAction<TranslatorFunctions>>;\n i18nInstance?: Streami18n;\n}) => {\n const [loadingTranslators, setLoadingTranslators] = useState(true);\n const isMounted = useIsMountedRef();\n const i18nInstanceExists = !!i18nInstance;\n useEffect(() => {\n let streami18n: Streami18n;\n\n if (i18nInstance instanceof Streami18n) {\n streami18n = i18nInstance;\n } else {\n streami18n = new Streami18n({ language: 'en' });\n }\n\n streami18n.registerSetLanguageCallback((t: (key: string) => string) =>\n setTranslators((prevTranslator) => ({ ...prevTranslator, t })),\n );\n streami18n.getTranslators().then((translator) => {\n if (translator && isMounted.current) setTranslators(translator);\n });\n\n setLoadingTranslators(false);\n }, [i18nInstanceExists, i18nInstance]);\n\n return loadingTranslators;\n};\n"]}
@@ -0,0 +1,34 @@
1
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTranslatedMessage = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _MessageOverlayContext = require("../contexts/messageOverlayContext/MessageOverlayContext");
11
+
12
+ var _TranslationContext = require("../contexts/translationContext/TranslationContext");
13
+
14
+ var useTranslatedMessage = function useTranslatedMessage(message) {
15
+ var _messageOverlayContex;
16
+
17
+ var _useTranslationContex = (0, _TranslationContext.useTranslationContext)(),
18
+ translationContextUserLanguage = _useTranslationContex.userLanguage;
19
+
20
+ var messageOverlayContextValue = (0, _MessageOverlayContext.useMessageOverlayContext)();
21
+ var userLanguage = ((_messageOverlayContex = messageOverlayContextValue.data) == null ? void 0 : _messageOverlayContex.userLanguage) || translationContextUserLanguage;
22
+ var translationKey = userLanguage + "_text";
23
+
24
+ if (message.i18n && translationKey in message.i18n) {
25
+ return (0, _extends2["default"])({}, message, {
26
+ text: message.i18n[translationKey]
27
+ });
28
+ }
29
+
30
+ return (0, _extends2["default"])({}, message);
31
+ };
32
+
33
+ exports.useTranslatedMessage = useTranslatedMessage;
34
+ //# sourceMappingURL=useTranslatedMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useTranslatedMessage.ts"],"names":["useTranslatedMessage","message","translationContextUserLanguage","userLanguage","messageOverlayContextValue","data","translationKey","i18n","text"],"mappings":";;;;;;;;;AAEA;;AACA;;AAKO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAuB,CAGlCC,OAHkC,EAI/B;AAAA;;AACH,8BAAyD,gDAAzD;AAAA,MAAsBC,8BAAtB,yBAAQC,YAAR;;AACA,MAAMC,0BAA0B,GAAG,sDAAnC;AAEA,MAAMD,YAAY,GAChB,0BAAAC,0BAA0B,CAACC,IAA3B,2CAAiCF,YAAjC,KAAiDD,8BADnD;AAGA,MAAMI,cAA8B,GAAMH,YAAN,UAApC;;AAEA,MAAIF,OAAO,CAACM,IAAR,IAAgBD,cAAc,IAAIL,OAAO,CAACM,IAA9C,EAAoD;AAClD,yCACKN,OADL;AAEEO,MAAAA,IAAI,EAAEP,OAAO,CAACM,IAAR,CAAaD,cAAb;AAFR;AAID;;AAED,uCAAYL,OAAZ;AACD,CArBM","sourcesContent":["import type { FormatMessageResponse, MessageResponse, TranslationLanguages } from 'stream-chat';\n\nimport { useMessageOverlayContext } from '../contexts/messageOverlayContext/MessageOverlayContext';\nimport { useTranslationContext } from '../contexts/translationContext/TranslationContext';\nimport type { DefaultStreamChatGenerics } from '../types/types';\n\ntype TranslationKey = `${TranslationLanguages}_text`;\n\nexport const useTranslatedMessage = <\n StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,\n>(\n message: MessageResponse<StreamChatGenerics> | FormatMessageResponse<StreamChatGenerics>,\n) => {\n const { userLanguage: translationContextUserLanguage } = useTranslationContext();\n const messageOverlayContextValue = useMessageOverlayContext<StreamChatGenerics>();\n\n const userLanguage =\n messageOverlayContextValue.data?.userLanguage || translationContextUserLanguage;\n\n const translationKey: TranslationKey = `${userLanguage}_text`;\n\n if (message.i18n && translationKey in message.i18n) {\n return {\n ...message,\n text: message.i18n[translationKey],\n };\n }\n\n return { ...message };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["getOrCreateChannel.js"],"names":["getOrCreateChannelApi","channel","members","messages","result","duration"],"mappings":";;;;;AAAA;;AASO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,GAMhC;AAAA,MALHC,OAKG,uEALO;AACRA,IAAAA,OAAO,EAAE,EADD;AAERC,IAAAA,OAAO,EAAE,EAFD;AAGRC,IAAAA,QAAQ,EAAE;AAHF,GAKP;AACH,MAAMC,MAAM,GAAG;AACbH,IAAAA,OAAO,EAAEA,OAAO,CAACA,OADJ;AAEbI,IAAAA,QAAQ,EAAE,IAFG;AAGbH,IAAAA,OAAO,EAAED,OAAO,CAACC,OAHJ;AAIbC,IAAAA,QAAQ,EAAEF,OAAO,CAACE;AAJL,GAAf;AAOA,SAAO,8BAAkBC,MAAlB,EAA0B,MAA1B,CAAP;AACD,CAfM","sourcesContent":["import { mockedApiResponse } from './utils';\n\n/**\n * Returns the api response for queryChannel api.\n *\n * api - /channels/{type}/{id}/query\n *\n * @param {*} channel\n */\nexport const getOrCreateChannelApi = (\n channel = {\n channel: {},\n members: [],\n messages: [],\n },\n) => {\n const result = {\n channel: channel.channel,\n duration: 0.01,\n members: channel.members,\n messages: channel.messages,\n };\n\n return mockedApiResponse(result, 'post');\n};\n"]}
1
+ {"version":3,"sources":["getOrCreateChannel.ts"],"names":["getOrCreateChannelApi","channel","members","messages","result","duration"],"mappings":";;;;;AACA;;AAeO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,GAMhC;AAAA,MALHC,OAKG,uEALoC;AACrCA,IAAAA,OAAO,EAAE,EAD4B;AAErCC,IAAAA,OAAO,EAAE,EAF4B;AAGrCC,IAAAA,QAAQ,EAAE;AAH2B,GAKpC;AACH,MAAMC,MAAM,GAAG;AACbH,IAAAA,OAAO,EAAEA,OAAO,CAACA,OADJ;AAEbI,IAAAA,QAAQ,EAAE,IAFG;AAGbH,IAAAA,OAAO,EAAED,OAAO,CAACC,OAHJ;AAIbC,IAAAA,QAAQ,EAAEF,OAAO,CAACE;AAJL,GAAf;AAOA,SAAO,8BAAkBC,MAAlB,EAA0B,MAA1B,CAAP;AACD,CAfM","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { mockedApiResponse } from './utils';\n\nexport type GetOrCreateChannelApiParams = {\n channel?: Record<string, any>;\n members?: Record<string, any>[];\n messages?: Record<string, any>[];\n};\n\n/**\n * Returns the api response for queryChannel api.\n *\n * api - /channels/{type}/{id}/query\n *\n * @param {*} channel\n */\nexport const getOrCreateChannelApi = (\n channel: GetOrCreateChannelApiParams = {\n channel: {},\n members: [],\n messages: [],\n },\n) => {\n const result = {\n channel: channel.channel,\n duration: 0.01,\n members: channel.members,\n messages: channel.messages,\n };\n\n return mockedApiResponse(result, 'post');\n};\n"]}
@@ -17,7 +17,7 @@ var _uuid = require("uuid");
17
17
 
18
18
  var _user = require("./user");
19
19
 
20
- var _excluded = ["id", "type", "channel"];
20
+ var _excluded = ["id", "messages", "type", "channel"];
21
21
  var defaultCapabilities = ['ban-channel-members', 'delete-any-message', 'delete-own-message', 'flag-message', 'mute-channel', 'pin-message', 'quote-message', 'read-events', 'send-links', 'send-message', 'send-reaction', 'send-reply', 'typing-events', 'update-any-message', 'update-own-message', 'upload-file'];
22
22
  var defaultConfig = {
23
23
  automod: 'disabled',
@@ -81,8 +81,9 @@ var getChannelDefaults = function getChannelDefaults() {
81
81
 
82
82
  var generateChannel = function generateChannel(customValues) {
83
83
  return Object.keys(customValues).reduce(function (accumulated, current) {
84
- if (Object.prototype.hasOwnProperty.call(accumulated, current)) {
85
- accumulated[current] = (0, _typeof2["default"])(accumulated[current]) === 'object' ? (0, _extends3["default"])({}, accumulated[current], customValues[current]) : accumulated[current] = customValues[current];
84
+ if (current in accumulated) {
85
+ var _key = current;
86
+ accumulated[_key] = (0, _typeof2["default"])(accumulated[_key]) === 'object' ? (0, _extends3["default"])({}, accumulated[_key], customValues[_key]) : accumulated[_key] = customValues[_key];
86
87
  return accumulated;
87
88
  }
88
89
 
@@ -96,10 +97,13 @@ var generateChannelResponse = function generateChannelResponse() {
96
97
  var customValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
97
98
  channel: {},
98
99
  id: (0, _uuid.v4)(),
100
+ messages: [],
99
101
  type: 'messaging'
100
102
  };
101
103
  var _customValues$id = customValues.id,
102
104
  id = _customValues$id === void 0 ? (0, _uuid.v4)() : _customValues$id,
105
+ _customValues$message = customValues.messages,
106
+ messages = _customValues$message === void 0 ? [] : _customValues$message,
103
107
  _customValues$type = customValues.type,
104
108
  type = _customValues$type === void 0 ? 'messaging' : _customValues$type,
105
109
  _customValues$channel = customValues.channel,
@@ -115,7 +119,7 @@ var generateChannelResponse = function generateChannelResponse() {
115
119
  user: (0, _user.generateUser)()
116
120
  })),
117
121
  members: [],
118
- messages: []
122
+ messages: messages
119
123
  }, rest);
120
124
  };
121
125
 
@@ -1 +1 @@
1
- {"version":3,"sources":["channel.js"],"names":["defaultCapabilities","defaultConfig","automod","automod_behavior","commands","args","description","name","set","connect_events","created_at","max_message_length","message_retention","mutes","reactions","read_events","replies","search","typing_events","updated_at","uploads","url_enrichment","defaultState","members","messages","setIsUpToDate","jest","fn","getChannelDefaults","id","type","_client","data","cid","config","created_by","frozen","own_capabilities","state","generateChannel","customValues","Object","keys","reduce","accumulated","current","prototype","hasOwnProperty","call","generateChannelResponse","channel","rest","defaults","user"],"mappings":";;;;;;;;;;;;;;;AAAA;;AAEA;;;AAEA,IAAMA,mBAAmB,GAAG,CAC1B,qBAD0B,EAE1B,oBAF0B,EAG1B,oBAH0B,EAI1B,cAJ0B,EAK1B,cAL0B,EAM1B,aAN0B,EAO1B,eAP0B,EAQ1B,aAR0B,EAS1B,YAT0B,EAU1B,cAV0B,EAW1B,eAX0B,EAY1B,YAZ0B,EAa1B,eAb0B,EAc1B,oBAd0B,EAe1B,oBAf0B,EAgB1B,aAhB0B,CAA5B;AAmBA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,OAAO,EAAE,UADW;AAEpBC,EAAAA,gBAAgB,EAAE,MAFE;AAGpBC,EAAAA,QAAQ,EAAE,CACR;AACEC,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,WAAW,EAAE,kCAFf;AAGEC,IAAAA,IAAI,EAAE,OAHR;AAIEC,IAAAA,GAAG,EAAE;AAJP,GADQ,CAHU;AAWpBC,EAAAA,cAAc,EAAE,IAXI;AAYpBC,EAAAA,UAAU,EAAE,gCAZQ;AAapBC,EAAAA,kBAAkB,EAAE,IAbA;AAcpBC,EAAAA,iBAAiB,EAAE,UAdC;AAepBC,EAAAA,KAAK,EAAE,IAfa;AAgBpBN,EAAAA,IAAI,EAAE,WAhBc;AAiBpBO,EAAAA,SAAS,EAAE,IAjBS;AAkBpBC,EAAAA,WAAW,EAAE,IAlBO;AAmBpBC,EAAAA,OAAO,EAAE,IAnBW;AAoBpBC,EAAAA,MAAM,EAAE,IApBY;AAqBpBC,EAAAA,aAAa,EAAE,IArBK;AAsBpBC,EAAAA,UAAU,EAAE,gCAtBQ;AAuBpBC,EAAAA,OAAO,EAAE,IAvBW;AAwBpBC,EAAAA,cAAc,EAAE;AAxBI,CAAtB;AA0B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D,MAAAA,WAAW,CAACC,OAAD,CAAX,GACE,yBAAOD,WAAW,CAACC,OAAD,CAAlB,MAAgC,QAAhC,iCACSD,WAAW,CAACC,OAAD,CADpB,EACkCL,YAAY,CAACK,OAAD,CAD9C,IAEKD,WAAW,CAACC,OAAD,CAAX,GAAuBL,YAAY,CAACK,OAAD,CAH1C;AAIA,aAAOD,WAAP;AACD;;AACD,yCAAYA,WAAZ,uCAA0BC,OAA1B,EAAoCL,YAAY,CAACK,OAAD,CAAhD;AACD,GATD,EASGjB,kBAAkB,EATrB,CAD6B;AAAA,CAAxB;;;;AAYA,IAAMqB,uBAAuB,GAAG,SAA1BA,uBAA0B,GAElC;AAAA,MADHT,YACG,uEADY;AAAEU,IAAAA,OAAO,EAAE,EAAX;AAAerB,IAAAA,EAAE,EAAE,eAAnB;AAA6BC,IAAAA,IAAI,EAAE;AAAnC,GACZ;AACH,yBAAqEU,YAArE,CAAQX,EAAR;AAAA,MAAQA,EAAR,iCAAa,eAAb;AAAA,2BAAqEW,YAArE,CAAuBV,IAAvB;AAAA,MAAuBA,IAAvB,mCAA8B,WAA9B;AAAA,8BAAqEU,YAArE,CAA2CU,OAA3C;AAAA,MAA2CA,OAA3C,sCAAqD,EAArD;AAAA,MAA4DC,IAA5D,6CAAqEX,YAArE;AAEA,MAAMY,QAAQ,GAAGxB,kBAAkB,EAAnC;AACA;AACEsB,IAAAA,OAAO,gCACFE,QAAQ,CAACpB,IADP;AAGHC,MAAAA,GAAG,EAAKH,IAAL,SAAaD;AAHb,OAIAqB,OAJA;AAKHrB,MAAAA,EAAE,EAAFA,EALG;AAMHC,MAAAA,IAAI,EAAJA,IANG;AAOHuB,MAAAA,IAAI,EAAE;AAPH,OADT;AAWE9B,IAAAA,OAAO,EAAE,EAXX;AAYEC,IAAAA,QAAQ,EAAE;AAZZ,KAaK2B,IAbL;AAeD,CArBM","sourcesContent":["import { v4 as uuidv4 } from 'uuid';\n\nimport { generateUser, getUserDefaults } from './user';\n\nconst defaultCapabilities = [\n 'ban-channel-members',\n 'delete-any-message',\n 'delete-own-message',\n 'flag-message',\n 'mute-channel',\n 'pin-message',\n 'quote-message',\n 'read-events',\n 'send-links',\n 'send-message',\n 'send-reaction',\n 'send-reply',\n 'typing-events',\n 'update-any-message',\n 'update-own-message',\n 'upload-file',\n];\n\nconst defaultConfig = {\n automod: 'disabled',\n automod_behavior: 'flag',\n commands: [\n {\n args: '[text]',\n description: 'Post a random gif to the channel',\n name: 'giphy',\n set: 'fun_set',\n },\n ],\n connect_events: true,\n created_at: '2020-04-24T11:36:43.859020368Z',\n max_message_length: 5000,\n message_retention: 'infinite',\n mutes: true,\n name: 'messaging',\n reactions: true,\n read_events: true,\n replies: true,\n search: true,\n typing_events: true,\n updated_at: '2020-04-24T11:36:43.859022903Z',\n uploads: true,\n url_enrichment: true,\n};\nconst defaultState = {\n members: {},\n messages: [],\n setIsUpToDate: jest.fn(),\n};\n\nconst getChannelDefaults = ({ id, type } = { id: uuidv4(), type: 'messaging' }) => ({\n _client: {},\n data: {\n cid: `${type}:${id}`,\n config: {\n ...defaultConfig,\n name: type,\n type,\n },\n created_at: '2020-04-28T11:20:48.578147Z',\n created_by: getUserDefaults(),\n frozen: false,\n id,\n own_capabilities: defaultCapabilities,\n type,\n updated_at: '2020-04-28T11:20:48.578147Z',\n },\n id,\n state: defaultState,\n type,\n});\n\nexport const generateChannel = (customValues) =>\n Object.keys(customValues).reduce((accumulated, current) => {\n if (Object.prototype.hasOwnProperty.call(accumulated, current)) {\n accumulated[current] =\n typeof accumulated[current] === 'object'\n ? { ...accumulated[current], ...customValues[current] }\n : (accumulated[current] = customValues[current]);\n return accumulated;\n }\n return { ...accumulated, [current]: customValues[current] };\n }, getChannelDefaults());\n\nexport const generateChannelResponse = (\n customValues = { channel: {}, id: uuidv4(), type: 'messaging' },\n) => {\n const { id = uuidv4(), type = 'messaging', channel = {}, ...rest } = customValues;\n\n const defaults = getChannelDefaults();\n return {\n channel: {\n ...defaults.data,\n ...{\n cid: `${type}:${id}`,\n ...channel,\n id,\n type,\n user: generateUser(),\n },\n },\n members: [],\n messages: [],\n ...rest,\n };\n};\n"]}
1
+ {"version":3,"sources":["channel.ts"],"names":["defaultCapabilities","defaultConfig","automod","automod_behavior","commands","args","description","name","set","connect_events","created_at","max_message_length","message_retention","mutes","reactions","read_events","replies","search","typing_events","updated_at","uploads","url_enrichment","defaultState","members","messages","setIsUpToDate","jest","fn","getChannelDefaults","id","type","_client","data","cid","config","created_by","frozen","own_capabilities","state","generateChannel","customValues","Object","keys","reduce","accumulated","current","key","generateChannelResponse","channel","rest","defaults","user"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;;AAEA,IAAMA,mBAAmB,GAAG,CAC1B,qBAD0B,EAE1B,oBAF0B,EAG1B,oBAH0B,EAI1B,cAJ0B,EAK1B,cAL0B,EAM1B,aAN0B,EAO1B,eAP0B,EAQ1B,aAR0B,EAS1B,YAT0B,EAU1B,cAV0B,EAW1B,eAX0B,EAY1B,YAZ0B,EAa1B,eAb0B,EAc1B,oBAd0B,EAe1B,oBAf0B,EAgB1B,aAhB0B,CAA5B;AAmBA,IAAMC,aAAa,GAAG;AACpBC,EAAAA,OAAO,EAAE,UADW;AAEpBC,EAAAA,gBAAgB,EAAE,MAFE;AAGpBC,EAAAA,QAAQ,EAAE,CACR;AACEC,IAAAA,IAAI,EAAE,QADR;AAEEC,IAAAA,WAAW,EAAE,kCAFf;AAGEC,IAAAA,IAAI,EAAE,OAHR;AAIEC,IAAAA,GAAG,EAAE;AAJP,GADQ,CAHU;AAWpBC,EAAAA,cAAc,EAAE,IAXI;AAYpBC,EAAAA,UAAU,EAAE,gCAZQ;AAapBC,EAAAA,kBAAkB,EAAE,IAbA;AAcpBC,EAAAA,iBAAiB,EAAE,UAdC;AAepBC,EAAAA,KAAK,EAAE,IAfa;AAgBpBN,EAAAA,IAAI,EAAE,WAhBc;AAiBpBO,EAAAA,SAAS,EAAE,IAjBS;AAkBpBC,EAAAA,WAAW,EAA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,SAAaD;AAHb,OAIAmB,OAJA;AAKHnB,MAAAA,EAAE,EAAFA,EALG;AAMHC,MAAAA,IAAI,EAAJA,IANG;AAOHqB,MAAAA,IAAI,EAAE;AAPH,OADT;AAWE5B,IAAAA,OAAO,EAAE,EAXX;AAYEC,IAAAA,QAAQ,EAARA;AAZF,KAaKyB,IAbL;AAeD,CA1BM","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { generateUser, getUserDefaults } from './user';\n\nconst defaultCapabilities = [\n 'ban-channel-members',\n 'delete-any-message',\n 'delete-own-message',\n 'flag-message',\n 'mute-channel',\n 'pin-message',\n 'quote-message',\n 'read-events',\n 'send-links',\n 'send-message',\n 'send-reaction',\n 'send-reply',\n 'typing-events',\n 'update-any-message',\n 'update-own-message',\n 'upload-file',\n];\n\nconst defaultConfig = {\n automod: 'disabled',\n automod_behavior: 'flag',\n commands: [\n {\n args: '[text]',\n description: 'Post a random gif to the channel',\n name: 'giphy',\n set: 'fun_set',\n },\n ],\n connect_events: true,\n created_at: '2020-04-24T11:36:43.859020368Z',\n max_message_length: 5000,\n message_retention: 'infinite',\n mutes: true,\n name: 'messaging',\n reactions: true,\n read_events: true,\n replies: true,\n search: true,\n typing_events: true,\n updated_at: '2020-04-24T11:36:43.859022903Z',\n uploads: true,\n url_enrichment: true,\n};\nconst defaultState = {\n members: {},\n messages: [],\n setIsUpToDate: jest.fn(),\n};\n\nconst getChannelDefaults = (\n { id, type }: { [key: string]: any } = { id: uuidv4(), type: 'messaging' },\n) => ({\n _client: {},\n data: {\n cid: `${type}:${id}`,\n config: {\n ...defaultConfig,\n name: type,\n type,\n },\n created_at: '2020-04-28T11:20:48.578147Z',\n created_by: getUserDefaults(),\n frozen: false,\n id,\n own_capabilities: defaultCapabilities,\n type,\n updated_at: '2020-04-28T11:20:48.578147Z',\n },\n id,\n state: defaultState,\n type,\n});\n\nexport const generateChannel = (customValues: { [key: string]: any }) =>\n Object.keys(customValues).reduce((accumulated, current) => {\n if (current in accumulated) {\n const key = current as keyof typeof accumulated;\n accumulated[key] =\n typeof accumulated[key] === 'object'\n ? { ...accumulated[key], ...customValues[key] }\n : (accumulated[key] = customValues[key]);\n return accumulated;\n }\n return { ...accumulated, [current]: customValues[current] };\n }, getChannelDefaults());\n\nexport const generateChannelResponse = (\n customValues: {\n channel?: Record<string, any>;\n id?: string;\n messages?: Record<string, any>[];\n type?: string;\n } = { channel: {}, id: uuidv4(), messages: [], type: 'messaging' },\n) => {\n const { id = uuidv4(), messages = [], type = 'messaging', channel = {}, ...rest } = customValues;\n\n const defaults = getChannelDefaults();\n return {\n channel: {\n ...defaults.data,\n ...{\n cid: `${type}:${id}`,\n ...channel,\n id,\n type,\n user: generateUser(),\n },\n },\n members: [],\n messages,\n ...rest,\n };\n};\n"]}
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.9.0"
2
+ "version": "4.10.1-beta.1"
3
3
  }
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-native/extend-expect';
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren } from 'react';
2
- import type { Attachment } from 'stream-chat';
2
+ import type { Attachment, TranslationLanguages } from 'stream-chat';
3
3
  import type { GroupType, MessageType } from '../../components/MessageList/hooks/useMessageList';
4
4
  import type { MessageActionListProps } from '../../components/MessageOverlay/MessageActionList';
5
5
  import type { MessageActionListItemProps, MessageActionType } from '../../components/MessageOverlay/MessageActionListItem';
@@ -29,6 +29,7 @@ export declare type MessageOverlayData<StreamChatGenerics extends DefaultStreamC
29
29
  ownCapabilities?: OwnCapabilitiesContextValue;
30
30
  supportedReactions?: ReactionData[];
31
31
  threadList?: boolean;
32
+ userLanguage?: TranslationLanguages;
32
33
  videos?: Attachment<StreamChatGenerics>[];
33
34
  };
34
35
  export declare type MessageOverlayContextValue<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = {
@@ -2,18 +2,23 @@ import React from 'react';
2
2
  import Dayjs from 'dayjs';
3
3
  import type { TFunction } from 'i18next';
4
4
  import type { Moment } from 'moment';
5
+ import type { TranslationLanguages } from 'stream-chat';
5
6
  import type { DefaultStreamChatGenerics } from '../../types/types';
7
+ export declare const DEFAULT_USER_LANGUAGE: TranslationLanguages;
6
8
  export declare const isDayOrMoment: (output: TDateTimeParserOutput) => output is Dayjs.Dayjs | Moment;
7
9
  export declare type TDateTimeParserInput = string | number | Date;
8
10
  export declare type TDateTimeParserOutput = string | number | Date | Dayjs.Dayjs | Moment;
9
11
  export declare type TDateTimeParser = (input?: TDateTimeParserInput) => TDateTimeParserOutput;
10
- export declare type TranslationContextValue = {
12
+ export declare type TranslatorFunctions = {
11
13
  t: TFunction | ((key: string) => string);
12
14
  tDateTimeParser: TDateTimeParser;
13
15
  };
16
+ export declare type TranslationContextValue = TranslatorFunctions & {
17
+ userLanguage: TranslationLanguages;
18
+ };
14
19
  export declare const TranslationContext: React.Context<TranslationContextValue>;
15
20
  export declare const TranslationProvider: React.FC<{
16
21
  value: TranslationContextValue;
17
22
  }>;
18
23
  export declare const useTranslationContext: () => TranslationContextValue;
19
- export declare const withTranslationContext: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(Component: React.ComponentType<StreamChatGenerics>) => React.FC<Omit<StreamChatGenerics, keyof TranslationContextValue>>;
24
+ export declare const withTranslationContext: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(Component: React.ComponentType<StreamChatGenerics>) => React.FC<Omit<StreamChatGenerics, "userLanguage" | keyof TranslatorFunctions>>;
@@ -1,6 +1,6 @@
1
- import type { TranslationContextValue } from '../contexts/translationContext/TranslationContext';
1
+ import type { TranslatorFunctions } from '../contexts/translationContext/TranslationContext';
2
2
  import { Streami18n } from '../utils/Streami18n';
3
3
  export declare const useStreami18n: ({ i18nInstance, setTranslators, }: {
4
- setTranslators: React.Dispatch<React.SetStateAction<TranslationContextValue>>;
4
+ setTranslators: React.Dispatch<React.SetStateAction<TranslatorFunctions>>;
5
5
  i18nInstance?: Streami18n | undefined;
6
6
  }) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { FormatMessageResponse, MessageResponse } from 'stream-chat';
2
+ import type { DefaultStreamChatGenerics } from '../types/types';
3
+ export declare const useTranslatedMessage: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(message: MessageResponse<StreamChatGenerics> | FormatMessageResponse<StreamChatGenerics>) => MessageResponse<StreamChatGenerics> | FormatMessageResponse<StreamChatGenerics>;
@@ -1,4 +1,16 @@
1
- export function getOrCreateChannelApi(channel?: any): {
1
+ export declare type GetOrCreateChannelApiParams = {
2
+ channel?: Record<string, any>;
3
+ members?: Record<string, any>[];
4
+ messages?: Record<string, any>[];
5
+ };
6
+ /**
7
+ * Returns the api response for queryChannel api.
8
+ *
9
+ * api - /channels/{type}/{id}/query
10
+ *
11
+ * @param {*} channel
12
+ */
13
+ export declare const getOrCreateChannelApi: (channel?: GetOrCreateChannelApiParams) => {
2
14
  response: {
3
15
  data: any;
4
16
  status: number;
@@ -0,0 +1,2 @@
1
+ declare function _default(client: any, newMessage: any, channel?: {}): void;
2
+ export default _default;
@@ -0,0 +1,8 @@
1
+ declare function _default(client: any, user: any, channel?: {}): {
2
+ channel: {};
3
+ cid: any;
4
+ received_at: Date;
5
+ type: string;
6
+ user: any;
7
+ };
8
+ export default _default;
@@ -1,10 +1,13 @@
1
- export function generateChannel(customValues: any): {
1
+ /// <reference types="jest" />
2
+ export declare const generateChannel: (customValues: {
3
+ [key: string]: any;
4
+ }) => {
2
5
  _client: {};
3
6
  data: {
4
7
  cid: string;
5
8
  config: {
6
- name: string;
7
- type: string;
9
+ name: any;
10
+ type: any;
8
11
  automod: string;
9
12
  automod_behavior: string;
10
13
  commands: {
@@ -39,24 +42,25 @@ export function generateChannel(customValues: any): {
39
42
  updated_at: string;
40
43
  };
41
44
  frozen: boolean;
42
- id: string;
45
+ id: any;
43
46
  own_capabilities: string[];
44
- type: string;
47
+ type: any;
45
48
  updated_at: string;
46
49
  };
47
- id: string;
50
+ id: any;
48
51
  state: {
49
52
  members: {};
50
53
  messages: never[];
51
54
  setIsUpToDate: jest.Mock<any, any>;
52
55
  };
53
- type: string;
56
+ type: any;
54
57
  };
55
- export function generateChannelResponse(customValues?: {
56
- channel: {};
57
- id: string;
58
- type: string;
59
- }): {
58
+ export declare const generateChannelResponse: (customValues?: {
59
+ channel?: Record<string, any>;
60
+ id?: string;
61
+ messages?: Record<string, any>[];
62
+ type?: string;
63
+ }) => {
60
64
  channel: {
61
65
  id: string;
62
66
  type: string;
@@ -72,8 +76,8 @@ export function generateChannelResponse(customValues?: {
72
76
  };
73
77
  cid: string;
74
78
  config: {
75
- name: string;
76
- type: string;
79
+ name: any;
80
+ type: any;
77
81
  automod: string;
78
82
  automod_behavior: string;
79
83
  commands: {
@@ -112,5 +116,5 @@ export function generateChannelResponse(customValues?: {
112
116
  updated_at: string;
113
117
  };
114
118
  members: never[];
115
- messages: never[];
119
+ messages: Record<string, any>[];
116
120
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stream-chat-react-native-core",
3
3
  "description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
4
- "version": "4.9.0",
4
+ "version": "4.10.1-beta.1",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "dependencies": {
71
71
  "@babel/runtime": "^7.12.5",
72
- "@gorhom/bottom-sheet": "4.1.5",
72
+ "@gorhom/bottom-sheet": "^4.1.6",
73
73
  "dayjs": "1.10.5",
74
74
  "file-loader": "6.2.0",
75
75
  "i18next": "20.2.4",
@@ -143,7 +143,7 @@
143
143
  "react-native-web": "0.15.0",
144
144
  "react-test-renderer": "17.0.2",
145
145
  "typescript": "4.4.3",
146
- "uuid": "8.3.2",
146
+ "uuid": "^8.3.2",
147
147
  "webpack": "4.44.2"
148
148
  }
149
149
  }
@@ -10,6 +10,7 @@ import {
10
10
  } from '../../contexts/channelsContext/ChannelsContext';
11
11
  import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext';
12
12
 
13
+ import { useTranslatedMessage } from '../../hooks/useTranslatedMessage';
13
14
  import type { DefaultStreamChatGenerics } from '../../types/types';
14
15
 
15
16
  export type ChannelPreviewPropsWithContext<
@@ -38,10 +39,15 @@ const ChannelPreviewWithContext = <
38
39
  | MessageResponse<StreamChatGenerics>
39
40
  | undefined
40
41
  >(channel.state.messages[channel.state.messages.length - 1]);
42
+
43
+ const translatedLastMessage = useTranslatedMessage<StreamChatGenerics>(
44
+ lastMessage || ({} as MessageResponse<StreamChatGenerics>),
45
+ );
46
+
41
47
  const [forceUpdate, setForceUpdate] = useState(0);
42
48
  const [unread, setUnread] = useState(channel.countUnread());
43
49
 
44
- const latestMessagePreview = useLatestMessagePreview(channel, forceUpdate, lastMessage);
50
+ const latestMessagePreview = useLatestMessagePreview(channel, forceUpdate, translatedLastMessage);
45
51
 
46
52
  const channelLastMessage = channel.lastMessage();
47
53
  const channelLastMessageString = `${channelLastMessage?.id}${channelLastMessage?.updated_at}`;