@sendbird/uikit-utils 2.3.0 → 2.4.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 (52) hide show
  1. package/lib/commonjs/hooks/index.js +38 -1
  2. package/lib/commonjs/hooks/index.js.map +1 -1
  3. package/lib/commonjs/hooks/react-native.js +5 -7
  4. package/lib/commonjs/hooks/react-native.js.map +1 -1
  5. package/lib/commonjs/index.js +25 -1
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/sendbird/channel.js +29 -1
  8. package/lib/commonjs/sendbird/channel.js.map +1 -1
  9. package/lib/commonjs/sendbird/message.js +56 -1
  10. package/lib/commonjs/sendbird/message.js.map +1 -1
  11. package/lib/commonjs/sendbird/user.js +0 -6
  12. package/lib/commonjs/sendbird/user.js.map +1 -1
  13. package/lib/commonjs/shared/index.js +12 -0
  14. package/lib/commonjs/shared/index.js.map +1 -1
  15. package/lib/commonjs/types.js.map +1 -1
  16. package/lib/commonjs/ui-format/openChannel.js +22 -0
  17. package/lib/commonjs/ui-format/openChannel.js.map +1 -0
  18. package/lib/module/hooks/index.js +29 -1
  19. package/lib/module/hooks/index.js.map +1 -1
  20. package/lib/module/hooks/react-native.js +6 -8
  21. package/lib/module/hooks/react-native.js.map +1 -1
  22. package/lib/module/index.js +8 -1
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/sendbird/channel.js +23 -1
  25. package/lib/module/sendbird/channel.js.map +1 -1
  26. package/lib/module/sendbird/message.js +51 -1
  27. package/lib/module/sendbird/message.js.map +1 -1
  28. package/lib/module/sendbird/user.js +0 -4
  29. package/lib/module/sendbird/user.js.map +1 -1
  30. package/lib/module/shared/index.js +10 -0
  31. package/lib/module/shared/index.js.map +1 -1
  32. package/lib/module/types.js.map +1 -1
  33. package/lib/module/ui-format/openChannel.js +10 -0
  34. package/lib/module/ui-format/openChannel.js.map +1 -0
  35. package/lib/typescript/src/hooks/index.d.ts +3 -0
  36. package/lib/typescript/src/index.d.ts +7 -2
  37. package/lib/typescript/src/sendbird/channel.d.ts +10 -1
  38. package/lib/typescript/src/sendbird/message.d.ts +3 -0
  39. package/lib/typescript/src/sendbird/user.d.ts +0 -2
  40. package/lib/typescript/src/shared/index.d.ts +6 -0
  41. package/lib/typescript/src/types.d.ts +8 -3
  42. package/lib/typescript/src/ui-format/openChannel.d.ts +3 -0
  43. package/package.json +4 -4
  44. package/src/hooks/index.ts +31 -1
  45. package/src/hooks/react-native.ts +6 -8
  46. package/src/index.ts +17 -1
  47. package/src/sendbird/channel.ts +33 -2
  48. package/src/sendbird/message.ts +54 -1
  49. package/src/sendbird/user.ts +0 -7
  50. package/src/shared/index.ts +10 -0
  51. package/src/types.ts +17 -2
  52. package/src/ui-format/openChannel.ts +11 -0
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","idPool","useUniqId","key","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useIsFirstMount","isFirstMount","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useIsFirstMount = () => {\n const isFirstMount = useRef(true);\n\n if (isFirstMount.current) {\n isFirstMount.current = false;\n return true;\n }\n\n return isFirstMount.current;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n"],"mappings":"AAAA;AAEA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,eAAjC,EAAkDC,MAAlD,EAA0DC,QAA1D,QAA0E,OAA1E;AAKA,MAAMC,MAAiC,GAAG,EAA1C;AACA,OAAO,MAAMC,SAAS,GAAIC,GAAD,IAAiB;EACxC,OAAOH,QAAQ,CAAC,MAAM;IACpB,IAAI,CAACC,MAAM,CAACE,GAAD,CAAX,EAAkBF,MAAM,CAACE,GAAD,CAAN,GAAc,CAAd;IAClB,OAAOF,MAAM,CAACE,GAAD,CAAN,EAAP;EACD,CAHc,CAAR,CAGJ,CAHI,CAAP;AAID,CALM;AAOP,OAAO,MAAMC,cAAc,GAAG,MAAM;EAClC,MAAM,GAAGC,OAAH,IAAcL,QAAQ,CAAC,CAAD,CAA5B;EACA,OAAOJ,WAAW,CAAC,MAAMS,OAAO,CAAEC,IAAD,IAAUA,IAAI,GAA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B,YAAY,CAACF,OAAjB,EAA0B;IACxBE,YAAY,CAACF,OAAb,GAAuB,KAAvB;IACA,OAAO,IAAP;EACD;;EAED,OAAOE,YAAY,CAACF,OAApB;AACD,CATM;AAWP,OAAO,MAAMG,gBAAgB,GAAuCV,QAApC,IAAuD;EACrF,MAAMW,GAAG,GAAGzB,MAAM,CAAIc,QAAJ,CAAlB;EACAW,GAAG,CAACJ,OAAJ,GAAcP,QAAd;EACA,OAAOjB,WAAW,CAAE;IAAA,OAAa4B,GAAG,CAACJ,OAAJ,CAAY,YAAZ,CAAb;EAAA,CAAF,EAA2C,EAA3C,CAAlB;AACD,CAJM"}
1
+ {"version":3,"names":["useCallback","useEffect","useLayoutEffect","useReducer","useRef","useState","idPool","useUniqId","key","useUniqHandlerId","name","id","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useIsFirstMount","isFirstMount","useFreshCallback","ref","useDebounceEffect","action","delay","timeoutRef","setTimeout","undefined","clearTimeout","usePartialState","initialState","state"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useUniqHandlerId = (name: string) => {\n const id = useUniqId(name);\n return `${name}_${id}`;\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useIsFirstMount = () => {\n const isFirstMount = useRef(true);\n\n if (isFirstMount.current) {\n isFirstMount.current = false;\n return true;\n }\n\n return isFirstMount.current;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n\nexport const useDebounceEffect = (action: () => void, delay: number, deps: DependencyList = []) => {\n const timeoutRef = useRef<NodeJS.Timeout>();\n\n useEffect(() => {\n timeoutRef.current = setTimeout(async () => {\n try {\n await action();\n } finally {\n timeoutRef.current = undefined;\n }\n }, delay);\n\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = undefined;\n }\n };\n }, [delay, ...deps]);\n};\n\nexport const usePartialState = <S>(initialState: S) => {\n return useReducer((prev: S, state: Partial<S>) => ({ ...prev, ...state }), initialState);\n};\n"],"mappings":"AAAA;AAEA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,eAAjC,EAAkDC,UAAlD,EAA8DC,MAA9D,EAAsEC,QAAtE,QAAsF,OAAtF;AAKA,MAAMC,MAAiC,GAAG,EAA1C;AACA,O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D,CAFD,SAEU;QACRE,UAAU,CAACR,OAAX,GAAqBU,SAArB;MACD;IACF,CAN8B,EAM5BH,KAN4B,CAA/B;IAQA,OAAO,MAAM;MACX,IAAIC,UAAU,CAACR,OAAf,EAAwB;QACtBW,YAAY,CAACH,UAAU,CAACR,OAAZ,CAAZ;QACAQ,UAAU,CAACR,OAAX,GAAqBU,SAArB;MACD;IACF,CALD;EAMD,CAfQ,EAeN,CAACH,KAAD,EAAQ,GAAGlB,IAAX,CAfM,CAAT;AAgBD,CAnBM;AAqBP,OAAO,MAAMuB,eAAe,GAAOC,YAAJ,IAAwB;EACrD,OAAOtC,UAAU,CAAC,CAACW,IAAD,EAAU4B,KAAV,MAAiC,EAAE,GAAG5B,IAAL;IAAW,GAAG4B;EAAd,CAAjC,CAAD,EAA0DD,YAA1D,CAAjB;AACD,CAFM"}
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useRef } from 'react';
1
+ import { useEffect, useRef } from 'react';
2
2
  import { AppState } from 'react-native';
3
3
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
4
  const edgePaddingMap = {
@@ -9,13 +9,11 @@ const edgePaddingMap = {
9
9
  };
10
10
  export const useSafeAreaPadding = edges => {
11
11
  const safeAreaInsets = useSafeAreaInsets();
12
- return useMemo(() => {
13
- return edges.reduce((map, edge) => {
14
- const paddingKey = edgePaddingMap[edge];
15
- map[paddingKey] = safeAreaInsets[edge];
16
- return map;
17
- }, {});
18
- }, edges);
12
+ return edges.reduce((map, edge) => {
13
+ const paddingKey = edgePaddingMap[edge];
14
+ map[paddingKey] = safeAreaInsets[edge];
15
+ return map;
16
+ }, {});
19
17
  };
20
18
  export const useAppState = (type, listener) => {
21
19
  const callbackRef = useRef(listener);
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","useMemo","useRef","AppState","useSafeAreaInsets","edgePaddingMap","left","right","top","bottom","useSafeAreaPadding","edges","safeAreaInsets","reduce","map","edge","paddingKey","useAppState","type","listener","callbackRef","current","eventListener","state","subscriber","addEventListener","remove","removeEventListener"],"sources":["react-native.ts"],"sourcesContent":["import { useEffect, useMemo, useRef } from 'react';\nimport { AppState, AppStateEvent, AppStateStatus } from 'react-native';\nimport { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';\n\ntype EdgePaddingMap = {\n left: 'paddingLeft';\n right: 'paddingRight';\n top: 'paddingTop';\n bottom: 'paddingBottom';\n};\nconst edgePaddingMap: EdgePaddingMap = {\n left: 'paddingLeft',\n right: 'paddingRight',\n top: 'paddingTop',\n bottom: 'paddingBottom',\n};\n\nexport const useSafeAreaPadding = <\n T extends keyof EdgeInsets,\n Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },\n>(\n edges: T[],\n): Result => {\n const safeAreaInsets = useSafeAreaInsets();\n return useMemo(() => {\n return edges.reduce((map, edge) => {\n const paddingKey = edgePaddingMap[edge];\n map[paddingKey] = safeAreaInsets[edge];\n return map;\n }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });\n }, edges) as Result;\n};\n\ntype AppStateListener = (status: AppStateStatus) => void;\n\nexport const useAppState = (type: AppStateEvent, listener: AppStateListener) => {\n const callbackRef = useRef<AppStateListener>(listener);\n callbackRef.current = listener;\n\n useEffect(() => {\n const eventListener = (state: AppStateStatus) => callbackRef.current(state);\n const subscriber = AppState.addEventListener(type, eventListener);\n\n return () => {\n // @ts-ignore\n if (subscriber?.remove) {\n subscriber.remove();\n }\n // @ts-ignore\n else if (AppState.removeEventListener) {\n // @ts-ignore\n AppState.removeEventListener(type, eventListener);\n }\n };\n }, []);\n};\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,OAApB,EAA6BC,MAA7B,QAA2C,OAA3C;AACA,SAASC,QAAT,QAAwD,cAAxD;AACA,SAAqBC,iBAArB,QAA8C,gCAA9C;AAQA,MAAMC,cAA8B,GAAG;EACrCC,IAAI,EAAE,aAD+B;EAErCC,KAAK,EAAE,cAF8B;EAGrCC,GAAG,EAAE,YAHgC;EAIrCC,MAAM,EAAE;AAJ6B,CAAvC;AAOA,OAAO,MAAMC,kBAAkB,GAI7BC,KAJgC,IAKrB;EACX,MAAMC,cAAc,GAAGR,iBAAiB,EAAxC;EACA,OAAOH,OAAO,CAAC,MAAM;IACnB,OAAOU,KAAK,CAACE,MAAN,CAAa,CAACC,GAAD,EAAMC,IAAN,KAAe;MACjC,MAAMC,UAAU,GAAGX,cAAc,CAACU,IAAD,CAAjC;MACAD,GAAG,CAACE,UAAD,CAAH,GAAkBJ,cAAc,CAACG,IAAD,CAAhC;MACA,OAAOD,GAAP;IACD,CAJM,EAIJ,EAJI,CAAP;EAKD,CANa,EAMXH,KANW,CAAd;AAOD,CAdM;AAkBP,OAAO,MAAMM,WAAW,GAAG,CAACC,IAAD,EAAsBC,QAAtB,KAAqD;EAC9E,MAAMC,WAAW,GAAGlB,MAAM,CAAmBiB,QAAnB,CAA1B;EACAC,WAAW,CAACC,OAAZ,GAAsBF,QAAtB;EAEAnB,SAAS,CAAC,MAAM;IACd,MAAMsB,aAAa,GAAIC,KAAD,IAA2BH,WAAW,CAACC,OAAZ,CAAoBE,KAApB,CAAjD;;IACA,MAAMC,UAAU,GAAGrB,QAAQ,CAACsB,gBAAT,CAA0BP,IAA1B,EAAgCI,aAAhC,CAAnB;IAEA,OAAO,MAAM;MACX;MACA,IAAIE,UAAJ,aAAIA,UAAJ,eAAIA,UAAU,CAAEE,MAAhB,EAAwB;QACtBF,UAAU,CAACE,MAAX;MACD,CAFD,CAGA;MAHA,KAIK,IAAIvB,QAAQ,CAACwB,mBAAb,EAAkC;QACrC;QACAxB,QAAQ,CAACwB,mBAAT,CAA6BT,IAA7B,EAAmCI,aAAnC;MACD;IACF,CAVD;EAWD,CAfQ,EAeN,EAfM,CAAT;AAgBD,CApBM"}
1
+ {"version":3,"names":["useEffect","useRef","AppState","useSafeAreaInsets","edgePaddingMap","left","right","top","bottom","useSafeAreaPadding","edges","safeAreaInsets","reduce","map","edge","paddingKey","useAppState","type","listener","callbackRef","current","eventListener","state","subscriber","addEventListener","remove","removeEventListener"],"sources":["react-native.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { AppState, AppStateEvent, AppStateStatus } from 'react-native';\nimport { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';\n\ntype EdgePaddingMap = {\n left: 'paddingLeft';\n right: 'paddingRight';\n top: 'paddingTop';\n bottom: 'paddingBottom';\n};\nconst edgePaddingMap: EdgePaddingMap = {\n left: 'paddingLeft',\n right: 'paddingRight',\n top: 'paddingTop',\n bottom: 'paddingBottom',\n};\n\nexport const useSafeAreaPadding = <\n T extends keyof EdgeInsets,\n Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },\n>(\n edges: T[],\n): Result => {\n const safeAreaInsets = useSafeAreaInsets();\n return edges.reduce((map, edge) => {\n const paddingKey = edgePaddingMap[edge];\n map[paddingKey] = safeAreaInsets[edge];\n return map;\n }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] }) as Result;\n};\n\ntype AppStateListener = (status: AppStateStatus) => void;\n\nexport const useAppState = (type: AppStateEvent, listener: AppStateListener) => {\n const callbackRef = useRef<AppStateListener>(listener);\n callbackRef.current = listener;\n\n useEffect(() => {\n const eventListener = (state: AppStateStatus) => callbackRef.current(state);\n const subscriber = AppState.addEventListener(type, eventListener);\n\n return () => {\n // @ts-ignore\n if (subscriber?.remove) {\n subscriber.remove();\n }\n // @ts-ignore\n else if (AppState.removeEventListener) {\n // @ts-ignore\n AppState.removeEventListener(type, eventListener);\n }\n };\n }, []);\n};\n"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AACA,SAASC,QAAT,QAAwD,cAAxD;AACA,SAAqBC,iBAArB,QAA8C,gCAA9C;AAQA,MAAMC,cAA8B,GAAG;EACrCC,IAAI,EAAE,aAD+B;EAErCC,KAAK,EAAE,cAF8B;EAGrCC,GAAG,EAAE,YAHgC;EAIrCC,MAAM,EAAE;AAJ6B,CAAvC;AAOA,OAAO,MAAMC,kBAAkB,GAI7BC,KAJgC,IAKrB;EACX,MAAMC,cAAc,GAAGR,iBAAiB,EAAxC;EACA,OAAOO,KAAK,CAACE,MAAN,CAAa,CAACC,GAAD,EAAMC,IAAN,KAAe;IACjC,MAAMC,UAAU,GAAGX,cAAc,CAACU,IAAD,CAAjC;IACAD,GAAG,CAACE,UAAD,CAAH,GAAkBJ,cAAc,CAACG,IAAD,CAAhC;IACA,OAAOD,GAAP;EACD,CAJM,EAIJ,EAJI,CAAP;AAKD,CAZM;AAgBP,OAAO,MAAMG,WAAW,GAAG,CAACC,IAAD,EAAsBC,QAAtB,KAAqD;EAC9E,MAAMC,WAAW,GAAGlB,MAAM,CAAmBiB,QAAnB,CAA1B;EACAC,WAAW,CAACC,OAAZ,GAAsBF,QAAtB;EAEAlB,SAAS,CAAC,MAAM;IACd,MAAMqB,aAAa,GAAIC,KAAD,IAA2BH,WAAW,CAACC,OAAZ,CAAoBE,KAApB,CAAjD;;IACA,MAAMC,UAAU,GAAGrB,QAAQ,CAACsB,gBAAT,CAA0BP,IAA1B,EAAgCI,aAAhC,CAAnB;IAEA,OAAO,MAAM;MACX;MACA,IAAIE,UAAJ,aAAIA,UAAJ,eAAIA,UAAU,CAAEE,MAAhB,EAAwB;QACtBF,UAAU,CAACE,MAAX;MACD,CAFD,CAGA;MAHA,KAIK,IAAIvB,QAAQ,CAACwB,mBAAb,EAAkC;QACrC;QACAxB,QAAQ,CAACwB,mBAAT,CAA6BT,IAA7B,EAAmCI,aAAnC;MACD;IACF,CAVD;EAWD,CAfQ,EAeN,EAfM,CAAT;AAgBD,CApBM"}
@@ -7,6 +7,7 @@ export * from './shared';
7
7
  export * from './hooks';
8
8
  export * from './hooks/react-native';
9
9
  export * from './ui-format/groupChannel';
10
+ export * from './ui-format/openChannel';
10
11
  export * from './ui-format/common';
11
12
  export * from './sendbird/channel';
12
13
  export * from './sendbird/message';
@@ -17,8 +18,14 @@ export const ASYNC_NOOP = async () => void 0;
17
18
  export const PASS = val => val;
18
19
  export const toMegabyte = byte => byte / 1024 / 1024;
19
20
  export const isFunction = param => typeof param === 'function';
21
+ export function ifThenOr(cond, then, or) {
22
+ if (cond) return then;
23
+ return or;
24
+ }
20
25
  export const SBErrorCode = {
21
- NON_AUTHORIZED: 400108
26
+ NON_AUTHORIZED: 400108,
27
+ CHANNEL_NOT_FOUND_SERVER: 400201,
28
+ CHANNEL_NOT_FOUND_SDK: 900500
22
29
  };
23
30
  export const SBErrorMessage = {
24
31
  ACL: 'Sendbird provides various access control options when using the Chat SDK.\n' + 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\n' + 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\n' + 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.'
@@ -1 +1 @@
1
- {"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","replaceWithRegex","createMentionTemplateRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\n\nexport * from './shared';\n\nexport * from './hooks';\nexport * from './hooks/react-native';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,EAaEC,gBAbF,EAcEC,0BAdF,QAeO,gBAfP;AAgBA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,cAAc,UAAd;AAEA,cAAc,SAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;AACP,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;AAGP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
1
+ {"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","replaceWithRegex","createMentionTemplateRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","ifThenOr","cond","then","or","SBErrorCode","NON_AUTHORIZED","CHANNEL_NOT_FOUND_SERVER","CHANNEL_NOT_FOUND_SDK","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\n\nexport * from './shared';\n\nexport * from './hooks';\nexport * from './hooks/react-native';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/openChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = (param?: unknown): param is Function => typeof param === 'function';\n\nexport function ifThenOr<T>(cond: boolean, then: T): T | undefined;\nexport function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;\nexport function ifThenOr(cond: boolean, then: unknown, or?: unknown) {\n if (cond) return then;\n return or;\n}\n\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n CHANNEL_NOT_FOUND_SERVER: 400201,\n CHANNEL_NOT_FOUND_SDK: 900500,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n OnBeforeHandler,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdOpenChannelListQuery,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n SendbirdOpenChannelUpdateParams,\n SendbirdOpenChannelCreateParams,\n SendbirdParticipant,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,EAaEC,gBAbF,EAcEC,0BAdF,QAeO,gBAfP;AAgBA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,cAAc,UAAd;AAEA,cAAc,SAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,yBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAIC,KAAD,IAAwC,OAAOA,KAAP,KAAiB,UAA5E;AAIP,OAAO,SAASC,QAAT,CAAkBC,IAAlB,EAAiCC,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIF,IAAJ,EAAU,OAAOC,IAAP;EACV,OAAOC,EAAP;AACD;AAED,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE,MADS;EAEzBC,wBAAwB,EAAE,MAFD;EAGzBC,qBAAqB,EAAE;AAHE,CAApB;AAKP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
@@ -11,7 +11,8 @@ export function isDifferentChannel(a, b) {
11
11
  return a.url !== b.url;
12
12
  }
13
13
  export const getGroupChannelChatAvailableState = channel => {
14
- const frozen = channel.isFrozen && channel.myRole !== 'operator';
14
+ const isOperator = channel.myRole === 'operator';
15
+ const frozen = channel.isFrozen && !isOperator;
15
16
  const muted = channel.myMutedState === 'muted';
16
17
  const disabled = frozen || muted;
17
18
  return {
@@ -20,6 +21,17 @@ export const getGroupChannelChatAvailableState = channel => {
20
21
  muted
21
22
  };
22
23
  };
24
+ export const getOpenChannelChatAvailableState = async (channel, userId) => {
25
+ const isOperator = channel.isOperator(userId);
26
+ const frozen = channel.isFrozen && !isOperator;
27
+ const muted = (await channel.getMyMutedInfo()).isMuted;
28
+ const disabled = frozen || muted;
29
+ return {
30
+ disabled,
31
+ frozen,
32
+ muted
33
+ };
34
+ };
23
35
  export const confirmAndMarkAsRead = async channels => {
24
36
  channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));
25
37
  };
@@ -41,4 +53,14 @@ export function getOpenChannels(channels) {
41
53
  export function getChannelUniqId(channel) {
42
54
  return channel.url;
43
55
  }
56
+ export function getDefaultGroupChannelCreateParams(params) {
57
+ const createParams = {
58
+ name: '',
59
+ coverUrl: '',
60
+ isDistinct: false,
61
+ invitedUserIds: params.invitedUserIds
62
+ };
63
+ if (params.currentUserId) createParams.operatorUserIds = [params.currentUserId];
64
+ return createParams;
65
+ }
44
66
  //# sourceMappingURL=channel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","frozen","isFrozen","myRole","muted","myMutedState","disabled","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel","getChannelUniqId"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const frozen = channel.isFrozen && channel.myRole !== 'operator';\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n\nexport function getChannelUniqId(channel: SendbirdChannel) {\n return channel.url;\n}\n"],"mappings":"AAAA,SAASA,eAAT,QAAgC,2BAAhC;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAtD;EACA,MAAMC,KAAK,GAAGJ,OAAO,CAACK,YAAR,KAAyB,OAAvC;EACA,MAAMC,QAAQ,GAAGL,MAAM,IAAIG,KAA3B;EACA,OAAO;IAAEE,QAAF;IAAYL,MAAZ;IAAoBG;EAApB,CAAP;AACD,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AP;AACD;AAED,OAAO,SAASC,gBAAT,CAA0B9B,OAA1B,EAAoD;EACzD,OAAOA,OAAO,CAACF,GAAf;AACD"}
1
+ {"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","isOperator","myRole","frozen","isFrozen","muted","myMutedState","disabled","getOpenChannelChatAvailableState","userId","getMyMutedInfo","isMuted","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","getGroupChannels","c","getOpenChannels","isOpenChannel","getChannelUniqId","getDefaultGroupChannelCreateParams","params","createParams","name","isDistinct","invitedUserIds","operatorUserIds"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type {\n SendbirdBaseChannel,\n SendbirdChannel,\n SendbirdGroupChannel,\n SendbirdGroupChannelCreateParams,\n SendbirdOpenChannel,\n} from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const isOperator = channel.myRole === 'operator';\n const frozen = channel.isFrozen && !isOperator;\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const getOpenChannelChatAvailableState = async (channel: SendbirdOpenChannel, userId: string) => {\n const isOperator = channel.isOperator(userId);\n const frozen = channel.isFrozen && !isOperator;\n const muted = (await channel.getMyMutedInfo()).isMuted;\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n\nexport function getChannelUniqId(channel: SendbirdChannel) {\n return channel.url;\n}\n\nexport function getDefaultGroupChannelCreateParams(params: {\n invitedUserIds: string[];\n currentUserId?: string;\n}): SendbirdGroupChannelCreateParams {\n const createParams: SendbirdGroupChannelCreateParams = {\n name: '',\n coverUrl: '',\n isDistinct: false,\n invitedUserIds: params.invitedUserIds,\n };\n\n if (params.currentUserId) createParams.operatorUserIds = [params.currentUserId];\n\n return createParams;\n}\n"],"mappings":"AAAA,SAASA,eAAT,QAAgC,2BAAhC;;AASA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,UAAU,GAAGD,O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AAE,CAACO,eAAH,EAA3C,EAAiEP,EAAE,CAACjB,GAApE,CAFnB;AAGD,CAJM;AAMP,OAAO,SAASyB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6B1B,OAA7B,EAA4D2B,aAA5D,EAAoF;EACzF,OAAO3B,OAAO,CAAC4B,OAAR,CAAgBd,MAAhB,CAAwBe,CAAD,IAAOA,CAAC,CAACpB,MAAF,KAAakB,aAA3C,CAAP;AACD;AAED,OAAO,SAASG,gBAAT,CAA0BjB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACC,MAAT,CAAiBiB,CAAD,IAAkCA,CAAC,CAACf,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASgB,eAAT,CAAyBnB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACC,MAAT,CAAiBiB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD;AAED,OAAO,SAASC,gBAAT,CAA0BlC,OAA1B,EAAoD;EACzD,OAAOA,OAAO,CAACF,GAAf;AACD;AAED,OAAO,SAASqC,kCAAT,CAA4CC,MAA5C,EAG8B;EACnC,MAAMC,YAA8C,GAAG;IACrDC,IAAI,EAAE,EAD+C;IAErDd,QAAQ,EAAE,EAF2C;IAGrDe,UAAU,EAAE,KAHyC;IAIrDC,cAAc,EAAEJ,MAAM,CAACI;EAJ8B,CAAvD;EAOA,IAAIJ,MAAM,CAACT,aAAX,EAA0BU,YAAY,CAACI,eAAb,GAA+B,CAACL,MAAM,CAACT,aAAR,CAA/B;EAE1B,OAAOU,YAAP;AACD"}
@@ -1,3 +1,4 @@
1
+ import { getFileExtension, getFileType } from '../shared/regex';
1
2
  import { getMessageTimeFormat } from '../ui-format/common';
2
3
  export function isNewMessage(msg, currentUserId) {
3
4
  const myMessage = isMyMessage(msg, currentUserId);
@@ -87,9 +88,58 @@ export function parseSendbirdNotification(dataPayload) {
87
88
  return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
88
89
  }
89
90
  export function shouldRenderReaction(channel, reactionEnabled) {
90
- return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;
91
+ if (channel.isOpenChannel()) {
92
+ return false;
93
+ }
94
+
95
+ if (channel.isGroupChannel()) {
96
+ if (channel.isBroadcast) return false;
97
+ if (channel.isSuper) return false;
98
+ }
99
+
100
+ return reactionEnabled;
91
101
  }
92
102
  export function getReactionCount(reaction) {
93
103
  return reaction.userIds.length;
94
104
  }
105
+ export function getFileTypeFromMessage(message) {
106
+ return getFileType(message.type || getFileExtension(message.name));
107
+ }
108
+ export function getMessageType(message) {
109
+ if (message.isAdminMessage()) {
110
+ return 'admin';
111
+ }
112
+
113
+ if (message.isUserMessage()) {
114
+ if (message.ogMetaData) {
115
+ return 'user.opengraph';
116
+ }
117
+
118
+ return 'user';
119
+ }
120
+
121
+ if (message.isFileMessage()) {
122
+ const fileType = getFileTypeFromMessage(message);
123
+
124
+ switch (fileType) {
125
+ case 'image':
126
+ case 'video':
127
+ {
128
+ return `file.${fileType}`;
129
+ }
130
+
131
+ case 'audio':
132
+ {
133
+ return `file.${fileType}`;
134
+ }
135
+
136
+ default:
137
+ {
138
+ return 'file';
139
+ }
140
+ }
141
+ }
142
+
143
+ return 'unknown';
144
+ }
95
145
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isGroupChannel","isBroadcast","isSuper","getReactionCount","reaction","userIds","length"],"sources":["message.ts"],"sourcesContent":["import type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n"],"mappings":"AASA,SAASA,oBAAT,QAAqC,qBAArC;AAEA,OAAO,SAASC,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAD,EAAMC,aAAN,CAA7B;EACA,IAAIC,SAAJ,EAAe,OAAO,KAAP;EACf,IAAIF,GAAG,CAACI,cAAJ,EAAJ,EAA0B,OAAO,KAAP;EAC1B,OAAOJ,GAAG,CAACK,SAAJ,KAAkB,CAAzB;AACD;AAED,OAAO,SAASC,iBAAT,CAA2BN,GAA3B,EAAyF;EAC9F,OAAOA,GAAG,KAAKO,SAAR,IAAqBP,GAAG,KAAK,IAA7B,IAAqC,mBAAmBA,GAA/D;AACD;AAED,OAAO,SAASG,WAAT,CAAqBH,GAArB,EAAsG;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EAC3G,IAAI,CAACK,iBAAiB,CAACN,GAAD,CAAtB,EAA6B,OAAO,KAAP;EAC7B,OACG,YAAYA,GAAZ,IAAmB,gBAAAA,GAAG,CAACQ,MAAJ,4DAAYC,MAAZ,MAAuBR,aAA3C,IACAD,GAAG,CAACU,aAAJ,KAAsB,SADtB,IAEAV,GAAG,CAACU,aAAJ,KAAsB,QAFtB,IAGAV,GAAG,CAACU,aAAJ,KAAsB,UAJxB;AAMD;AAED,OAAO,SAASC,mBAAT,CAA6BC,OAA7B,EAA+D;EACpE,OAAOC,gBAAgB,CAACD,OAAD,CAAvB;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,iBAAT,CAA2BC,CAA3B,EAA+CC,CAA/C,EAAmE;EACxE,IAAIC,aAAa,GAAG,CAApB;EACA,IAAIC,aAAa,GAAG,CAApB;EAEA,IAAIZ,iBA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AAZ,CAAd;AACD;AAED,OAAO,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD;AAED,OAAO,SAASG,oBAAT,CAA8BC,OAA9B,EAA4DC,eAA5D,EAAsF;EAC3F,OAAOD,OAAO,CAACE,cAAR,MAA4B,CAACF,OAAO,CAACG,WAArC,IAAoD,CAACH,OAAO,CAACI,OAA7D,IAAwEH,eAA/E;AACD;AAED,OAAO,SAASI,gBAAT,CAA0BC,QAA1B,EAAsD;EAC3D,OAAOA,QAAQ,CAACC,OAAT,CAAiBC,MAAxB;AACD"}
1
+ {"version":3,"names":["getFileExtension","getFileType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","getReactionCount","reaction","userIds","length","getFileTypeFromMessage","type","name","getMessageType","ogMetaData","fileType"],"sources":["message.ts"],"sourcesContent":["import { getFileExtension, getFileType } from '../shared/regex';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n if (channel.isOpenChannel()) {\n return false;\n }\n\n if (channel.isGroupChannel()) {\n if (channel.isBroadcast) return false;\n if (channel.isSuper) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\ntype MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio'}`;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage) {\n return getFileType(message.type || getFileExtension(message.name));\n}\n\nexport function getMessageType(message: SendbirdMessage): MessageType {\n if (message.isAdminMessage()) {\n return 'admin';\n }\n\n if (message.isUserMessage()) {\n if (message.ogMetaData) {\n return 'user.opengraph';\n }\n return 'user';\n }\n\n if (message.isFileMessage()) {\n const fileType = getFileTypeFromMessage(message);\n switch (fileType) {\n case 'image':\n case 'video': {\n return `file.${fileType}`;\n }\n case 'audio': {\n return `file.${fileType}`;\n }\n default: {\n return 'file';\n }\n }\n }\n\n return 'unknown';\n}\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,WAA3B,QAA8C,iBAA9C;AAUA,SAASC,oBAAT,QAAqC,qBAArC;AAEA,OAAO,SAASC,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAD,EAAMC,aAAN,CAA7B;EACA,IAAIC,SAAJ,EAAe,OAAO,KAAP;EACf,IAAIF,GAAG,CAACI,cAAJ,EAAJ,EAA0B,OAAO,KAAP;EAC1B,OAAOJ,GAAG,CAACK,SAAJ,KAAkB,CAAzB;AACD;AAED,OAAO,SAASC,iBAAT,CAA2BN,GAA3B,EAAyF;EAC9F,OAAOA,GAAG,KAAKO,SAAR,IAAqBP,GAAG,KAAK,IAA7B,IAAqC,mBAAmBA,GAA/D;AACD;AAED,OAAO,SAASG,WAAT,CAAqBH,GAArB,EAAsG;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EAC3G,IAAI,CAACK,iBAAiB,CAACN,GAAD,CAAtB,EAA6B,OAAO,KAAP;EAC7B,OACG,YAAYA,GAAZ,IAAmB,gBAAAA,GAAG,CAACQ,MAAJ,4DAAYC,MAAZ,MAAuBR,aAA3C,IACAD,GAAG,CAACU,aAAJ,KAAsB,SADtB,IAEAV,GAAG,CAACU,aAAJ,KAAsB,QAFtB,IAGAV,GAAG,CAACU,aAAJ,KAAsB,UAJxB;AAMD;AAED,OAAO,SAASC,mBAAT,CAA6BC,OAA7B,EAA+D;EACpE,OAAOC,g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ACD,OAAO,MAAP;EACD;;EAED,IAAInD,OAAO,CAACoB,aAAR,EAAJ,EAA6B;IAC3B,MAAMgC,QAAQ,GAAGL,sBAAsB,CAAC/C,OAAD,CAAvC;;IACA,QAAQoD,QAAR;MACE,KAAK,OAAL;MACA,KAAK,OAAL;QAAc;UACZ,OAAQ,QAAOA,QAAS,EAAxB;QACD;;MACD,KAAK,OAAL;QAAc;UACZ,OAAQ,QAAOA,QAAS,EAAxB;QACD;;MACD;QAAS;UACP,OAAO,MAAP;QACD;IAVH;EAYD;;EAED,OAAO,SAAP;AACD"}
@@ -2,10 +2,6 @@ export function ifOperator(role, then, or) {
2
2
  if (role === 'operator') return then;
3
3
  return or;
4
4
  }
5
- export function ifMuted(muted, then, or) {
6
- if (muted) return then;
7
- return or;
8
- }
9
5
  export function getUserUniqId(user) {
10
6
  return user.userId;
11
7
  }
@@ -1 +1 @@
1
- {"version":3,"names":["ifOperator","role","then","or","ifMuted","muted","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function ifMuted<T>(muted: boolean, then: T): T | undefined;\nexport function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;\nexport function ifMuted(muted: boolean, then: unknown, or?: unknown) {\n if (muted) return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;AAID,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAiCH,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIE,KAAJ,EAAW,OAAOH,IAAP;EACX,OAAOC,EAAP;AACD;AAED,OAAO,SAASG,aAAT,CAA6CC,IAA7C,EAAsD;EAC3D,OAAOA,IAAI,CAACC,MAAZ;AACD"}
1
+ {"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;AAED,OAAO,SAASC,aAAT,CAA6CC,IAA7C,EAAsD;EAC3D,OAAOA,IAAI,CAACC,MAAZ;AACD"}
@@ -54,4 +54,14 @@ export function shouldCompressImage(filePath) {
54
54
  const extension = getFileExtension(filePath);
55
55
  return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
56
56
  }
57
+ /**
58
+ * Returns the picked data from object.
59
+ * */
60
+
61
+ export function pick(obj, keys) {
62
+ return keys.reduce((pickedObj, key) => {
63
+ pickedObj[key] = obj[key];
64
+ return pickedObj;
65
+ }, {});
66
+ }
57
67
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getFileExtension","getFileType","hash","str","String","Math","abs","split","reduce","a","c","charCodeAt","replace","start","end","text","slice","conditionChaining","conditions","values","idx","findIndex","state","Boolean","length","getDownscaleSize","origin","resizing","ratio","maxWidth","width","maxHeight","height","max","isImage","filePath","mimeType","type","shouldCompressImage","compressionEnabled","extension","match"],"sources":["index.ts"],"sourcesContent":["import { getFileExtension, getFileType } from './regex';\n\n/**\n * Converts a given string to a hashed string.\n * */\nexport function hash(str: string) {\n return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));\n}\n\n/**\n * Replace a specific range of text in the string with another text.\n * */\nexport function replace(str: string, start: number, end: number, text: string) {\n return str.slice(0, start) + text + str.slice(end);\n}\n\n/**\n * Returns the value corresponding to the first true index of a given condition array.\n * */\nexport function conditionChaining<T, V>(conditions: T[], values: V[]) {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n}\n\n/**\n * Calculates the downscale size.\n * */\ntype Size = { width: number; height: number };\nexport function getDownscaleSize(origin: Size, resizing: Partial<Size>) {\n let ratio;\n\n const maxWidth = resizing.width || origin.width,\n maxHeight = resizing.height || origin.height;\n\n if (origin.width <= maxWidth && origin.height <= maxHeight) {\n ratio = 1;\n } else if (origin.width > maxWidth && origin.height <= maxHeight) {\n ratio = maxWidth / origin.width;\n } else if (origin.width <= maxWidth && origin.height > maxHeight) {\n ratio = maxHeight / origin.height;\n } else {\n ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);\n }\n\n return { width: origin.width * ratio, height: origin.height * ratio };\n}\n\nexport function isImage(filePath: string, mimeType?: string) {\n const type = getFileType(mimeType || getFileExtension(filePath));\n return type === 'image';\n}\n\nexport function shouldCompressImage(filePath: string, compressionEnabled = true) {\n const extension = getFileExtension(filePath);\n return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);\n}\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AAEA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAcC,GAAd,EAA2B;EAChC,OAAOC,MAAM,CAACC,IAAI,CAACC,GAAL,CAASH,GAAG,CAACI,KAAJ,CAAU,EAAV,EAAcC,MAAd,CAAqB,CAACC,CAAD,EAAIC,CAAJ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A,IAAIJ,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,GAAgBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGG,SAAS,GAAGL,MAAM,CAACM,MAA3B;EACD,CAFM,MAEA;IACLJ,KAAK,GAAGvB,IAAI,CAAC4B,GAAL,CAASJ,QAAQ,GAAGH,MAAM,CAACI,KAA3B,EAAkCC,SAAS,GAAGL,MAAM,CAACM,MAArD,CAAR;EACD;;EAED,OAAO;IAAEF,KAAK,EAAEJ,MAAM,CAACI,KAAP,GAAeF,KAAxB;IAA+BI,MAAM,EAAEN,MAAM,CAACM,MAAP,GAAgBJ;EAAvD,CAAP;AACD;AAED,OAAO,SAASM,OAAT,CAAiBC,QAAjB,EAAmCC,QAAnC,EAAsD;EAC3D,MAAMC,IAAI,GAAGpC,WAAW,CAACmC,QAAQ,IAAIpC,gBAAgB,CAACmC,QAAD,CAA7B,CAAxB;EACA,OAAOE,IAAI,KAAK,OAAhB;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BH,QAA7B,EAA0E;EAAA,IAA3BI,kBAA2B,uEAAN,IAAM;EAC/E,MAAMC,SAAS,GAAGxC,gBAAgB,CAACmC,QAAD,CAAlC;EACA,OAAOZ,OAAO,CAACiB,SAAS,CAACC,KAAV,CAAgB,eAAhB,KAAoCF,kBAArC,CAAd;AACD"}
1
+ {"version":3,"names":["getFileExtension","getFileType","hash","str","String","Math","abs","split","reduce","a","c","charCodeAt","replace","start","end","text","slice","conditionChaining","conditions","values","idx","findIndex","state","Boolean","length","getDownscaleSize","origin","resizing","ratio","maxWidth","width","maxHeight","height","max","isImage","filePath","mimeType","type","shouldCompressImage","compressionEnabled","extension","match","pick","obj","keys","pickedObj","key"],"sources":["index.ts"],"sourcesContent":["import { getFileExtension, getFileType } from './regex';\n\n/**\n * Converts a given string to a hashed string.\n * */\nexport function hash(str: string) {\n return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));\n}\n\n/**\n * Replace a specific range of text in the string with another text.\n * */\nexport function replace(str: string, start: number, end: number, text: string) {\n return str.slice(0, start) + text + str.slice(end);\n}\n\n/**\n * Returns the value corresponding to the first true index of a given condition array.\n * */\nexport function conditionChaining<T, V>(conditions: T[], values: V[]) {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n}\n\n/**\n * Calculates the downscale size.\n * */\ntype Size = { width: number; height: number };\nexport function getDownscaleSize(origin: Size, resizing: Partial<Size>) {\n let ratio;\n\n const maxWidth = resizing.width || origin.width,\n maxHeight = resizing.height || origin.height;\n\n if (origin.width <= maxWidth && origin.height <= maxHeight) {\n ratio = 1;\n } else if (origin.width > maxWidth && origin.height <= maxHeight) {\n ratio = maxWidth / origin.width;\n } else if (origin.width <= maxWidth && origin.height > maxHeight) {\n ratio = maxHeight / origin.height;\n } else {\n ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);\n }\n\n return { width: origin.width * ratio, height: origin.height * ratio };\n}\n\nexport function isImage(filePath: string, mimeType?: string) {\n const type = getFileType(mimeType || getFileExtension(filePath));\n return type === 'image';\n}\n\nexport function shouldCompressImage(filePath: string, compressionEnabled = true) {\n const extension = getFileExtension(filePath);\n return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);\n}\n\n/**\n * Returns the picked data from object.\n * */\nexport function pick<T extends { [key: string]: unknown }, Keys extends keyof T>(obj: T, keys: Keys[]) {\n return keys.reduce((pickedObj, key) => {\n pickedObj[key] = obj[key];\n return pickedObj;\n }, {} as { [key in Keys]: T[key] });\n}\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AAEA;AACA;AACA;;AACA,OAAO,SAASC,IAAT,CAAcC,GAAd,EAA2B;EAChC,OAAOC,MAAM,CAACC,IAAI,CAACC,GAAL,CAASH,GAAG,CAACI,KAAJ,CAAU,EAAV,EAAcC,MAAd,CAAqB,CAACC,CAAD,E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D,CAFM,MAEA,IAAIJ,MAAM,CAACI,KAAP,IAAgBD,QAAhB,IAA4BH,MAAM,CAACM,MAAP,GAAgBD,SAAhD,EAA2D;IAChEH,KAAK,GAAGG,SAAS,GAAGL,MAAM,CAACM,MAA3B;EACD,CAFM,MAEA;IACLJ,KAAK,GAAGvB,IAAI,CAAC4B,GAAL,CAASJ,QAAQ,GAAGH,MAAM,CAACI,KAA3B,EAAkCC,SAAS,GAAGL,MAAM,CAACM,MAArD,CAAR;EACD;;EAED,OAAO;IAAEF,KAAK,EAAEJ,MAAM,CAACI,KAAP,GAAeF,KAAxB;IAA+BI,MAAM,EAAEN,MAAM,CAACM,MAAP,GAAgBJ;EAAvD,CAAP;AACD;AAED,OAAO,SAASM,OAAT,CAAiBC,QAAjB,EAAmCC,QAAnC,EAAsD;EAC3D,MAAMC,IAAI,GAAGpC,WAAW,CAACmC,QAAQ,IAAIpC,gBAAgB,CAACmC,QAAD,CAA7B,CAAxB;EACA,OAAOE,IAAI,KAAK,OAAhB;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BH,QAA7B,EAA0E;EAAA,IAA3BI,kBAA2B,uEAAN,IAAM;EAC/E,MAAMC,SAAS,GAAGxC,gBAAgB,CAACmC,QAAD,CAAlC;EACA,OAAOZ,OAAO,CAACiB,SAAS,CAACC,KAAV,CAAgB,eAAhB,KAAoCF,kBAArC,CAAd;AACD;AAED;AACA;AACA;;AACA,OAAO,SAASG,IAAT,CAA0EC,GAA1E,EAAkFC,IAAlF,EAAgG;EACrG,OAAOA,IAAI,CAACpC,MAAL,CAAY,CAACqC,SAAD,EAAYC,GAAZ,KAAoB;IACrCD,SAAS,CAACC,GAAD,CAAT,GAAiBH,GAAG,CAACG,GAAD,CAApB;IACA,OAAOD,SAAP;EACD,CAHM,EAGJ,EAHI,CAAP;AAID"}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport type OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
@@ -0,0 +1,10 @@
1
+ export const getOpenChannelTitle = function (channel) {
2
+ let DEFAULT_CHANNEL_NAME = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Open Channel';
3
+ const trimmedChannelName = channel.name.trim();
4
+ if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;
5
+ return trimmedChannelName;
6
+ };
7
+ export const getOpenChannelParticipants = channel => {
8
+ return `${channel.participantCount} participants`;
9
+ };
10
+ //# sourceMappingURL=openChannel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getOpenChannelTitle","channel","DEFAULT_CHANNEL_NAME","trimmedChannelName","name","trim","getOpenChannelParticipants","participantCount"],"sources":["openChannel.ts"],"sourcesContent":["import type { SendbirdOpenChannel } from '../types';\n\nexport const getOpenChannelTitle = (channel: SendbirdOpenChannel, DEFAULT_CHANNEL_NAME = 'Open Channel') => {\n const trimmedChannelName = channel.name.trim();\n if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;\n return trimmedChannelName;\n};\n\nexport const getOpenChannelParticipants = (channel: SendbirdOpenChannel) => {\n return `${channel.participantCount} participants`;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,GAAG,UAACC,OAAD,EAAyE;EAAA,IAA1CC,oBAA0C,uEAAnB,cAAmB;EAC1G,MAAMC,kBAAkB,GAAGF,OAAO,CAACG,IAAR,CAAaC,IAAb,EAA3B;EACA,IAAIF,kBAAkB,KAAK,EAA3B,EAA+B,OAAOD,oBAAP;EAC/B,OAAOC,kBAAP;AACD,CAJM;AAMP,OAAO,MAAMG,0BAA0B,GAAIL,OAAD,IAAkC;EAC1E,OAAQ,GAAEA,OAAO,CAACM,gBAAiB,eAAnC;AACD,CAFM"}
@@ -2,6 +2,7 @@ import type { DependencyList } from 'react';
2
2
  type Destructor = () => void;
3
3
  type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
4
4
  export declare const useUniqId: (key: string) => number;
5
+ export declare const useUniqHandlerId: (name: string) => string;
5
6
  export declare const useForceUpdate: () => () => void;
6
7
  export declare const useAsyncEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
7
8
  export declare const useAsyncLayoutEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
@@ -9,4 +10,6 @@ export declare const useIIFE: <T>(callback: () => T) => T;
9
10
  export declare const useIsMountedRef: () => import("react").MutableRefObject<boolean>;
10
11
  export declare const useIsFirstMount: () => boolean;
11
12
  export declare const useFreshCallback: <T extends (...args: any[]) => any>(callback: T) => T;
13
+ export declare const useDebounceEffect: (action: () => void, delay: number, deps?: DependencyList) => void;
14
+ export declare const usePartialState: <S>(initialState: S) => [S & Partial<S>, import("react").Dispatch<Partial<S>>];
12
15
  export {};
@@ -7,6 +7,7 @@ export * from './shared';
7
7
  export * from './hooks';
8
8
  export * from './hooks/react-native';
9
9
  export * from './ui-format/groupChannel';
10
+ export * from './ui-format/openChannel';
10
11
  export * from './ui-format/common';
11
12
  export * from './sendbird/channel';
12
13
  export * from './sendbird/message';
@@ -16,11 +17,15 @@ export declare const NOOP: () => void;
16
17
  export declare const ASYNC_NOOP: () => Promise<undefined>;
17
18
  export declare const PASS: <T>(val: T) => T;
18
19
  export declare const toMegabyte: (byte: number) => number;
19
- export declare const isFunction: <T>(param?: T | undefined) => param is NonNullable<T>;
20
+ export declare const isFunction: (param?: unknown) => param is Function;
21
+ export declare function ifThenOr<T>(cond: boolean, then: T): T | undefined;
22
+ export declare function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;
20
23
  export declare const SBErrorCode: {
21
24
  NON_AUTHORIZED: number;
25
+ CHANNEL_NOT_FOUND_SERVER: number;
26
+ CHANNEL_NOT_FOUND_SDK: number;
22
27
  };
23
28
  export declare const SBErrorMessage: {
24
29
  ACL: string;
25
30
  };
26
- export type { UserStruct, FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelCreateParams, SendbirdFileMessageCreateParams, SendbirdUserMessageCreateParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, SendbirdPreviousMessageListQuery, SendbirdSendableMessage, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, SendbirdRestrictedUser, SendbirdReaction, SendbirdEmojiContainer, SendbirdEmoji, SendbirdEmojiCategory, } from './types';
31
+ export type { UserStruct, FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, OnBeforeHandler, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelCreateParams, SendbirdFileMessageCreateParams, SendbirdUserMessageCreateParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, SendbirdPreviousMessageListQuery, SendbirdSendableMessage, SendbirdOpenChannelListQuery, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, SendbirdRestrictedUser, SendbirdReaction, SendbirdEmojiContainer, SendbirdEmoji, SendbirdEmojiCategory, SendbirdOpenChannelUpdateParams, SendbirdOpenChannelCreateParams, SendbirdParticipant, } from './types';
@@ -1,4 +1,4 @@
1
- import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
1
+ import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdGroupChannelCreateParams, SendbirdOpenChannel } from '../types';
2
2
  /**
3
3
  * Diff utils for channel
4
4
  * @param {SendbirdBaseChannel} [a]
@@ -11,6 +11,11 @@ export declare const getGroupChannelChatAvailableState: (channel: SendbirdGroupC
11
11
  frozen: boolean;
12
12
  muted: boolean;
13
13
  };
14
+ export declare const getOpenChannelChatAvailableState: (channel: SendbirdOpenChannel, userId: string) => Promise<{
15
+ disabled: boolean;
16
+ frozen: boolean;
17
+ muted: boolean;
18
+ }>;
14
19
  export declare const confirmAndMarkAsRead: (channels: SendbirdBaseChannel[]) => Promise<void>;
15
20
  export declare const confirmAndMarkAsDelivered: (channels: SendbirdBaseChannel[]) => Promise<void>;
16
21
  export declare function isDefaultCoverImage(coverUrl: string): boolean;
@@ -18,3 +23,7 @@ export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, curre
18
23
  export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
19
24
  export declare function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[];
20
25
  export declare function getChannelUniqId(channel: SendbirdChannel): string;
26
+ export declare function getDefaultGroupChannelCreateParams(params: {
27
+ invitedUserIds: string[];
28
+ currentUserId?: string;
29
+ }): SendbirdGroupChannelCreateParams;
@@ -20,4 +20,7 @@ export declare function isSendbirdNotification(dataPayload?: {
20
20
  export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
21
21
  export declare function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean): boolean;
22
22
  export declare function getReactionCount(reaction: SendbirdReaction): number;
23
+ type MessageType = 'user' | 'admin' | 'file' | 'unknown' | `user.${'opengraph'}` | `file.${'image' | 'video' | 'audio'}`;
24
+ export declare function getFileTypeFromMessage(message: SendbirdFileMessage): "video" | "audio" | "image" | "file";
25
+ export declare function getMessageType(message: SendbirdMessage): MessageType;
23
26
  export {};
@@ -2,6 +2,4 @@ import type { Role } from '@sendbird/chat';
2
2
  import type { UserStruct } from '../types';
3
3
  export declare function ifOperator<T>(role: Role, then: T): T | undefined;
4
4
  export declare function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
5
- export declare function ifMuted<T>(muted: boolean, then: T): T | undefined;
6
- export declare function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
7
5
  export declare function getUserUniqId<T extends UserStruct>(user: T): string;
@@ -23,4 +23,10 @@ export declare function getDownscaleSize(origin: Size, resizing: Partial<Size>):
23
23
  };
24
24
  export declare function isImage(filePath: string, mimeType?: string): boolean;
25
25
  export declare function shouldCompressImage(filePath: string, compressionEnabled?: boolean): boolean;
26
+ /**
27
+ * Returns the picked data from object.
28
+ * */
29
+ export declare function pick<T extends {
30
+ [key: string]: unknown;
31
+ }, Keys extends keyof T>(obj: T, keys: Keys[]): { [key in Keys]: T[key]; };
26
32
  export {};
@@ -1,10 +1,10 @@
1
1
  import type React from 'react';
2
2
  import type SendbirdChat from '@sendbird/chat';
3
- import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
3
+ import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, Participant, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
4
4
  import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
5
- import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
5
+ import type { ModuleNamespaces, OpenChannelCreateParams, OpenChannelUpdateParams, SendableMessage } from '@sendbird/chat/lib/__definition';
6
6
  import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
7
- import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
7
+ import type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';
8
8
  export type FilterByValueType<T extends object, Type> = {
9
9
  [K in keyof T as T[K] extends Type ? K : never]: T[K];
10
10
  };
@@ -18,6 +18,7 @@ export type PartialNullable<T> = {
18
18
  };
19
19
  export type Optional<T> = T | undefined;
20
20
  export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
21
+ export type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
21
22
  export interface UserStruct {
22
23
  userId: string;
23
24
  }
@@ -35,10 +36,13 @@ export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
35
36
  export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
36
37
  export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
37
38
  export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
39
+ export type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;
40
+ export type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;
38
41
  export type SendbirdUserUpdateParams = UserUpdateParams;
39
42
  export type SendbirdUser = User;
40
43
  export type SendbirdRestrictedUser = RestrictedUser;
41
44
  export type SendbirdMember = Member;
45
+ export type SendbirdParticipant = Participant;
42
46
  export type SendbirdGroupChannel = GroupChannel;
43
47
  export type SendbirdBaseChannel = BaseChannel;
44
48
  export type SendbirdOpenChannel = OpenChannel;
@@ -48,6 +52,7 @@ export type SendbirdEmojiCategory = EmojiCategory;
48
52
  export type SendbirdEmojiContainer = EmojiContainer;
49
53
  export type SendbirdGroupChannelCollection = GroupChannelCollection;
50
54
  export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
55
+ export type SendbirdOpenChannelListQuery = OpenChannelListQuery;
51
56
  export type SendbirdMessageCollection = MessageCollection;
52
57
  export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
53
58
  export type SendbirdError = SBError;
@@ -0,0 +1,3 @@
1
+ import type { SendbirdOpenChannel } from '../types';
2
+ export declare const getOpenChannelTitle: (channel: SendbirdOpenChannel, DEFAULT_CHANNEL_NAME?: string) => string;
3
+ export declare const getOpenChannelParticipants: (channel: SendbirdOpenChannel) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendbird/uikit-utils",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "UIKit utilities",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -45,12 +45,12 @@
45
45
  "@types/react": "*",
46
46
  "@types/react-native": "*",
47
47
  "react": "17.0.2",
48
- "react-native": "0.67.4",
48
+ "react-native": "0.67.5",
49
49
  "react-native-builder-bob": "^0.18.0",
50
50
  "typescript": "4.9.4"
51
51
  },
52
52
  "peerDependencies": {
53
- "@sendbird/chat": "^4.0.13",
53
+ "@sendbird/chat": "^4.3.0",
54
54
  "react": ">=16.13.1"
55
55
  },
56
56
  "peerDependenciesMeta": {
@@ -77,5 +77,5 @@
77
77
  "readmeFile": "./README.md",
78
78
  "displayName": "@sendbird/uikit-utils"
79
79
  },
80
- "gitHead": "a9bf41fd7919436db99f6cc3bacd0f8d791b7729"
80
+ "gitHead": "05ec076e3a2433089586870c9a7e7bf7639b06be"
81
81
  }