@sendbird/uikit-utils 2.4.2 → 2.5.0-rc.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.
- package/lib/commonjs/hooks/index.js +9 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/index.js +16 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/message.js +10 -0
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui-format/common.js +57 -1
- package/lib/commonjs/ui-format/common.js.map +1 -1
- package/lib/commonjs/ui-format/groupChannel.js +2 -33
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -1
- package/lib/module/hooks/index.js +7 -0
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/index.js +5 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/message.js +9 -0
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui-format/common.js +54 -1
- package/lib/module/ui-format/common.js.map +1 -1
- package/lib/module/ui-format/groupChannel.js +3 -34
- package/lib/module/ui-format/groupChannel.js.map +1 -1
- package/lib/typescript/src/hooks/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts +5 -4
- package/lib/typescript/src/sendbird/message.d.ts +8 -1
- package/lib/typescript/src/types.d.ts +2 -1
- package/lib/typescript/src/ui-format/common.d.ts +13 -0
- package/lib/typescript/src/ui-format/groupChannel.d.ts +1 -1
- package/package.json +2 -3
- package/src/hooks/index.ts +10 -0
- package/src/index.ts +5 -52
- package/src/sendbird/message.ts +12 -0
- package/src/types.ts +2 -0
- package/src/ui-format/common.ts +53 -1
- package/src/ui-format/groupChannel.ts +4 -30
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useUniqId = exports.useUniqHandlerId = exports.usePartialState = exports.useIsMountedRef = exports.useIsFirstMount = exports.useIIFE = exports.useFreshCallback = exports.useForceUpdate = exports.useDebounceEffect = exports.useAsyncLayoutEffect = exports.useAsyncEffect = void 0;
|
|
6
|
+
exports.useUniqId = exports.useUniqHandlerId = exports.useRefTracker = exports.usePartialState = exports.useIsMountedRef = exports.useIsFirstMount = exports.useIIFE = exports.useFreshCallback = exports.useForceUpdate = exports.useDebounceEffect = exports.useAsyncLayoutEffect = exports.useAsyncEffect = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
9
|
|
|
@@ -106,4 +106,12 @@ const usePartialState = initialState => {
|
|
|
106
106
|
}), initialState);
|
|
107
107
|
};
|
|
108
108
|
exports.usePartialState = usePartialState;
|
|
109
|
+
const useRefTracker = target => {
|
|
110
|
+
const ref = (0, _react.useRef)(target);
|
|
111
|
+
(0, _react.useLayoutEffect)(() => {
|
|
112
|
+
ref.current = target;
|
|
113
|
+
});
|
|
114
|
+
return ref;
|
|
115
|
+
};
|
|
116
|
+
exports.useRefTracker = useRefTracker;
|
|
109
117
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","idPool","useUniqId","key","useState","exports","useUniqHandlerId","name","id","useForceUpdate","updater","useCallback","prev","useAsyncEffect","asyncEffect","deps","useEffect","createAsyncEffectCallback","useAsyncLayoutEffect","useLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","useRef","current","useIsFirstMount","isFirstMount","useFreshCallback","ref","arguments","useDebounceEffect","action","delay","length","undefined","timeoutRef","setTimeout","clearTimeout","usePartialState","initialState","useReducer","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":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAFA;;AAOA,MAAMC,MAAiC,GAAG,CAAC,CAAC;AACrC,MAAMC,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAO,IAAAC,eAAQ,EAAC,MAAM;IACpB,IAAI,CAACH,MAAM,CAACE,GAAG,CAAC,EAAEF,MAAM,CAACE,GAAG,CAAC,GAAG,CAAC;IACjC,OAAOF,MAAM,CAACE,GAAG,CAAC,EAAE;EACtB,CAAC,CAAC,CAAC,CAAC,CAAC;AACP,CAAC;AAACE,OAAA,CAAAH,SAAA,GAAAA,SAAA;AAEK,MAAMI,gBAAgB,GAAIC,IAAY,IAAK;EAChD,MAAMC,EAAE,GAAGN,SAAS,CAACK,IAAI,CAAC;EAC1B,OAAQ,GAAEA,IAAK,IAAGC,EAAG,EAAC;AACxB,CAAC;AAACH,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEK,MAAMG,cAAc,GAAGA,CAAA,KAAM;EAClC,MAAM,GAAGC,OAAO,CAAC,GAAG,IAAAN,eAAQ,EAAC,CAAC,CAAC;EAC/B,OAAO,IAAAO,kBAAW,EAAC,MAAMD,OAAO,CAAEE,IAAI,IAAKA,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3D,CAAC;AAACP,OAAA,CAAAI,cAAA,GAAAA,cAAA;AAEK,MAAMI,cAAc,GAAGA,CAACC,WAAgC,EAAEC,IAAqB,KAAK;EACzF,IAAAC,gBAAS,EAACC,yBAAyB,CAACH,WAAW,CAAC,EAAEC,IAAI,CAAC;AACzD,CAAC;AAACV,OAAA,CAAAQ,cAAA,GAAAA,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,MAAM;IAAE,GAAGlC,IAAI;IAAE,GAAGkC;EAAM,CAAC,CAAC,EAAEF,YAAY,CAAC;AAC1F,CAAC;AAACvC,OAAA,CAAAsC,eAAA,GAAAA,eAAA"}
|
|
1
|
+
{"version":3,"names":["_react","require","idPool","useUniqId","key","useState","exports","useUniqHandlerId","name","id","useForceUpdate","updater","useCallback","prev","useAsyncEffect","asyncEffect","deps","useEffect","createAsyncEffectCallback","useAsyncLayoutEffect","useLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","useRef","current","useIsFirstMount","isFirstMount","useFreshCallback","ref","arguments","useDebounceEffect","action","delay","length","undefined","timeoutRef","setTimeout","clearTimeout","usePartialState","initialState","useReducer","state","useRefTracker","target"],"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\nexport const useRefTracker = <T>(target: T) => {\n const ref = useRef(target);\n\n useLayoutEffect(() => {\n ref.current = target;\n });\n\n return ref;\n};\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAFA;;AAOA,MAAMC,MAAiC,GAAG,CAAC,CAAC;AACrC,MAAMC,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAO,IAAAC,eAAQ,EAAC,MAAM;IACpB,IAAI,CAACH,MAAM,CAACE,GAAG,CAAC,EAAEF,MAAM,CAACE,GAAG,CAAC,GAAG,CAAC;IACjC,OAAOF,MAAM,CAACE,GAAG,CAAC,EAAE;EACtB,C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});
|
|
199
|
+
var _types = require("./types");
|
|
200
|
+
Object.keys(_types).forEach(function (key) {
|
|
201
|
+
if (key === "default" || key === "__esModule") return;
|
|
202
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
203
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
204
|
+
Object.defineProperty(exports, key, {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () {
|
|
207
|
+
return _types[key];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
199
211
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
200
212
|
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; }
|
|
201
213
|
const NOOP = () => void 0;
|
|
@@ -213,9 +225,10 @@ function ifThenOr(cond, then, or) {
|
|
|
213
225
|
return or;
|
|
214
226
|
}
|
|
215
227
|
const SBErrorCode = {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
228
|
+
UNAUTHORIZED_REQUEST: 400108,
|
|
229
|
+
RESOURCE_NOT_FOUND: 400201,
|
|
230
|
+
BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: 900100,
|
|
231
|
+
CHANNEL_NOT_FOUND: 900500
|
|
219
232
|
};
|
|
220
233
|
exports.SBErrorCode = SBErrorCode;
|
|
221
234
|
const SBErrorMessage = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_logger","require","_arrayToMap","_interopRequireWildcard","_regex","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_bufferedRequest","_file","_shared","_hooks","_reactNative","_groupChannel","_openChannel","_common","_channel","_message","_attrs","_user","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","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 * from './shared/regex';\nexport * from './shared/bufferedRequest';\nexport * from './shared/file';\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,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA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B,OAAOA,KAAK,KAAK,UAAU;AAACtC,OAAA,CAAAqC,UAAA,GAAAA,UAAA;AAIvF,SAASE,QAAQA,CAACC,IAAa,EAAEC,IAAa,EAAEC,EAAY,EAAE;EACnE,IAAIF,IAAI,EAAE,OAAOC,IAAI;EACrB,OAAOC,EAAE;AACX;AAEO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE,MAAM;EACtBC,wBAAwB,EAAE,MAAM;EAChCC,qBAAqB,EAAE;AACzB,CAAC;AAAC9C,OAAA,CAAA2C,WAAA,GAAAA,WAAA;AACK,MAAMI,cAAc,GAAG;EAC5BC,GAAG,EACD,6EAA6E,GAC7E,yGAAyG,GACzG,0GAA0G,GAC1G;AACJ,CAAC;AAAChD,OAAA,CAAA+C,cAAA,GAAAA,cAAA"}
|
|
1
|
+
{"version":3,"names":["_logger","require","_arrayToMap","_interopRequireWildcard","_regex","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_bufferedRequest","_file","_shared","_hooks","_reactNative","_groupChannel","_openChannel","_common","_channel","_message","_attrs","_user","_types","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","ifThenOr","cond","then","or","SBErrorCode","UNAUTHORIZED_REQUEST","RESOURCE_NOT_FOUND","BANNED_USER_SEND_MESSAGE_NOT_ALLOWED","CHANNEL_NOT_FOUND","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport * from './shared/regex';\nexport * from './shared/bufferedRequest';\nexport * from './shared/file';\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 UNAUTHORIZED_REQUEST: 400108,\n RESOURCE_NOT_FOUND: 400201,\n BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: 900100,\n CHANNEL_NOT_FOUND: 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 * from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UA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I,GAAG,IAAI,GAAG,IAAI;AAACrC,OAAA,CAAAoC,UAAA,GAAAA,UAAA;AACxD,MAAME,UAAU,GAAIC,KAAe,IAAwB,OAAOA,KAAK,KAAK,UAAU;AAACvC,OAAA,CAAAsC,UAAA,GAAAA,UAAA;AAIvF,SAASE,QAAQA,CAACC,IAAa,EAAEC,IAAa,EAAEC,EAAY,EAAE;EACnE,IAAIF,IAAI,EAAE,OAAOC,IAAI;EACrB,OAAOC,EAAE;AACX;AAEO,MAAMC,WAAW,GAAG;EACzBC,oBAAoB,EAAE,MAAM;EAC5BC,kBAAkB,EAAE,MAAM;EAC1BC,oCAAoC,EAAE,MAAM;EAC5CC,iBAAiB,EAAE;AACrB,CAAC;AAAChD,OAAA,CAAA4C,WAAA,GAAAA,WAAA;AACK,MAAMK,cAAc,GAAG;EAC5BC,GAAG,EACD,6EAA6E,GAC7E,yGAAyG,GACzG,0GAA0G,GAC1G;AACJ,CAAC;AAAClD,OAAA,CAAAiD,cAAA,GAAAA,cAAA"}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.calcMessageGrouping = calcMessageGrouping;
|
|
7
7
|
exports.getAvailableUriFromFileMessage = getAvailableUriFromFileMessage;
|
|
8
|
+
exports.getDefaultMessageSearchQueryParams = getDefaultMessageSearchQueryParams;
|
|
8
9
|
exports.getFileTypeFromMessage = getFileTypeFromMessage;
|
|
9
10
|
exports.getMessageType = getMessageType;
|
|
10
11
|
exports.getMessageUniqId = getMessageUniqId;
|
|
@@ -18,6 +19,7 @@ exports.messageComparator = messageComparator;
|
|
|
18
19
|
exports.messageKeyExtractor = messageKeyExtractor;
|
|
19
20
|
exports.parseSendbirdNotification = parseSendbirdNotification;
|
|
20
21
|
exports.shouldRenderReaction = shouldRenderReaction;
|
|
22
|
+
var _message = require("@sendbird/chat/message");
|
|
21
23
|
var _file = require("../shared/file");
|
|
22
24
|
var _common = require("../ui-format/common");
|
|
23
25
|
function isNewMessage(msg, currentUserId) {
|
|
@@ -148,4 +150,12 @@ function getMessageType(message) {
|
|
|
148
150
|
}
|
|
149
151
|
return 'unknown';
|
|
150
152
|
}
|
|
153
|
+
function getDefaultMessageSearchQueryParams(channel, keyword) {
|
|
154
|
+
return {
|
|
155
|
+
keyword,
|
|
156
|
+
channelUrl: channel.url,
|
|
157
|
+
messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),
|
|
158
|
+
order: _message.MessageSearchOrder.TIMESTAMP
|
|
159
|
+
};
|
|
160
|
+
}
|
|
151
161
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_file","require","_common","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","getMessageTimeFormat","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","getFileTypeFromMessage","getFileType","type","getFileExtension","name","getMessageType","ogMetaData","fileType"],"sources":["message.ts"],"sourcesContent":["import { getFileExtension, getFileType } from '../shared/file';\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,IAAAA,KAAA,GAAAC,OAAA;AAUA,IAAAC,OAAA,GAAAD,OAAA;AAEO,SAASE,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEO,SAASG,WAAWA,CAACH,GAA4B,EAAqD;EAAA,IAAAQ,WAAA;EAAA,IAAnDP,aAAa,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,iCAAiC;EACzG,IAAI,CAACH,iBAAiB,CAACN,GAAG,CAAC,EAAE,OAAO,KAAK;EACzC,OACG,QAAQ,IAAIA,GAAG,IAAI,EAAAQ,WAAA,GAAAR,GAAG,CAACW,MAAM,cAAAH,WAAA,uBAAVA,WAAA,CAAYI,MAAM,MAAKX,aAAa,IACxDD,GAAG,CAACa,aAAa,KAAK,SAAS,IAC/Bb,GAAG,CAACa,aAAa,KAAK,QAAQ,IAC9Bb,GAAG,CAACa,aAAa,KAAK,UAAU;AAEpC;AAEO,SAASC,mBAAmBA,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AAU,EAAE;MACtB,OAAO,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAIvD,OAAO,CAACuB,aAAa,EAAE,EAAE;IAC3B,MAAMiC,QAAQ,GAAGP,sBAAsB,CAACjD,OAAO,CAAC;IAChD,QAAQwD,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB"}
|
|
1
|
+
{"version":3,"names":["_message","require","_file","_common","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","getMessageTimeFormat","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","getFileTypeFromMessage","getFileType","type","getFileExtension","name","getMessageType","ogMetaData","fileType","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","MessageSearchOrder","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,OAAA,GAAAF,OAAA;AAEO,SAASG,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEO,SAASG,WAAWA,CAACH,GAA4B,EAAqD;EAAA,IAAAQ,WAAA;EAAA,IAAnDP,aAAa,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,iCAAiC;E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SAASsD,sBAAsBA,CAACjD,OAA4B,EAAE;EACnE,OAAO,IAAAkD,iBAAW,EAAClD,OAAO,CAACmD,IAAI,IAAI,IAAAC,sBAAgB,EAACpD,OAAO,CAACqD,IAAI,CAAC,CAAC;AACpE;AAEO,SAASC,cAAcA,CAACtD,OAAwB,EAAe;EACpE,IAAIA,OAAO,CAACX,cAAc,EAAE,EAAE;IAC5B,OAAO,OAAO;EAChB;EAEA,IAAIW,OAAO,CAACsB,aAAa,EAAE,EAAE;IAC3B,IAAItB,OAAO,CAACuD,UAAU,EAAE;MACtB,OAAO,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAIvD,OAAO,CAACuB,aAAa,EAAE,EAAE;IAC3B,MAAMiC,QAAQ,GAAGP,sBAAsB,CAACjD,OAAO,CAAC;IAChD,QAAQwD,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB;AAEO,SAASC,kCAAkCA,CAACjB,OAA6B,EAAEkB,OAAe,EAAE;EACjG,OAAO;IACLA,OAAO;IACPC,UAAU,EAAEnB,OAAO,CAACZ,GAAG;IACvBgC,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAACtB,OAAO,CAACuB,QAAQ,EAAEvB,OAAO,CAACwB,SAAS,CAAC;IACnEC,KAAK,EAAEC,2BAAkB,CAACC;EAC5B,CAAC;AACH"}
|
|
@@ -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 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":""}
|
|
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 MessageSearchQuery,\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;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\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":""}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.truncatedCount = exports.truncate = exports.getMessageTimeFormat = exports.getDateSeparatorFormat = void 0;
|
|
6
|
+
exports.truncatedCount = exports.truncate = exports.getMessageTimeFormat = exports.getMessagePreviewTitle = exports.getMessagePreviewTime = exports.getMessagePreviewBody = exports.getDateSeparatorFormat = void 0;
|
|
7
7
|
var _dateFns = require("date-fns");
|
|
8
8
|
const defaultOpts = {
|
|
9
9
|
mode: 'mid',
|
|
@@ -93,5 +93,61 @@ const getMessageTimeFormat = (date, locale) => {
|
|
|
93
93
|
locale
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Message preview title text
|
|
99
|
+
* */
|
|
96
100
|
exports.getMessageTimeFormat = getMessageTimeFormat;
|
|
101
|
+
const getMessagePreviewTitle = function (message) {
|
|
102
|
+
let EMPTY_USERNAME = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '(No name)';
|
|
103
|
+
if (message.isFileMessage() || message.isUserMessage()) {
|
|
104
|
+
return message.sender.nickname || EMPTY_USERNAME;
|
|
105
|
+
}
|
|
106
|
+
if (message.isAdminMessage()) {
|
|
107
|
+
return 'Admin';
|
|
108
|
+
}
|
|
109
|
+
return EMPTY_USERNAME;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Message preview body text
|
|
114
|
+
* */
|
|
115
|
+
exports.getMessagePreviewTitle = getMessagePreviewTitle;
|
|
116
|
+
const getMessagePreviewBody = function (message) {
|
|
117
|
+
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
118
|
+
if (message.isFileMessage()) {
|
|
119
|
+
const extIdx = message.name.lastIndexOf('.');
|
|
120
|
+
if (extIdx > -1) {
|
|
121
|
+
const file = message.name.slice(0, extIdx);
|
|
122
|
+
const ext = message.name.slice(extIdx);
|
|
123
|
+
return file + ext;
|
|
124
|
+
}
|
|
125
|
+
return message.name;
|
|
126
|
+
}
|
|
127
|
+
if (message.isUserMessage()) {
|
|
128
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
129
|
+
}
|
|
130
|
+
if (message.isAdminMessage()) {
|
|
131
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
132
|
+
}
|
|
133
|
+
return EMPTY_MESSAGE;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Message preview time format
|
|
138
|
+
* */
|
|
139
|
+
exports.getMessagePreviewBody = getMessagePreviewBody;
|
|
140
|
+
const getMessagePreviewTime = (timestamp, locale) => {
|
|
141
|
+
if ((0, _dateFns.isToday)(timestamp)) return (0, _dateFns.format)(timestamp, 'p', {
|
|
142
|
+
locale
|
|
143
|
+
});
|
|
144
|
+
if ((0, _dateFns.isYesterday)(timestamp)) return 'Yesterday';
|
|
145
|
+
if ((0, _dateFns.isThisYear)(timestamp)) return (0, _dateFns.format)(timestamp, 'MMM dd', {
|
|
146
|
+
locale
|
|
147
|
+
});
|
|
148
|
+
return (0, _dateFns.format)(timestamp, 'yyyy/MM/dd', {
|
|
149
|
+
locale
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
exports.getMessagePreviewTime = getMessagePreviewTime;
|
|
97
153
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dateFns","require","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","exports","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","isThisYear","format","getMessageTimeFormat"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear } from 'date-fns';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;
|
|
1
|
+
{"version":3,"names":["_dateFns","require","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","exports","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","isThisYear","format","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp","isToday","isYesterday"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/dd', { locale });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAMA,MAAMC,WAA2B,GAAG;EAAEC,IAAI,EAAE,KAAK;EAAEC,MAAM,EAAE,EAAE;EAAEC,SAAS,EAAE;AAAM,CAAC;;AAEjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,GAAG,SAAAA,CAACC,GAAW,EAA0D;EAAA,IAAxDC,IAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGP,WAAW;EAC/E,MAAMU,OAAO,GAAG;IAAE,GAAGV,WAAW;IAAE,GAAGM;EAAK,CAAC;EAC3C,MAAM;IAAEJ,MAAM;IAAED,IAAI;IAAEE;EAAU,CAAC,GAAGO,OAAO;EAE3C,IAAIL,GAAG,CAACG,MAAM,IAAIN,MAAM,EAAE,OAAOG,GAAG;EAEpC,IAAIJ,IAAI,KAAK,MAAM,EAAE;IACnB,OAAOE,SAAS,GAAGE,GAAG,CAACM,KAAK,CAAC,CAACT,MAAM,CAAC;EACvC;EAEA,IAAID,IAAI,KAAK,KAAK,EAAE;IAClB,MAAMW,IAAI,GAAGC,IAAI,CAACC,IAAI,CAACZ,MAAM,GAA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G,IAAI,GAAGC,GAAG;IACnB;IAEA,OAAOb,OAAO,CAACU,IAAI;EACrB;EAEA,IAAIV,OAAO,CAACG,aAAa,EAAE,EAAE;IAC3B,OAAOH,OAAO,CAACA,OAAO,IAAIQ,aAAa;EACzC;EAEA,IAAIR,OAAO,CAACM,cAAc,EAAE,EAAE;IAC5B,OAAON,OAAO,CAACA,OAAO,IAAIQ,aAAa;EACzC;EAEA,OAAOA,aAAa;AACtB,CAAC;;AAED;AACA;AACA;AAFApB,OAAA,CAAAmB,qBAAA,GAAAA,qBAAA;AAGO,MAAMO,qBAAqB,GAAGA,CAACC,SAAiB,EAAEpB,MAAe,KAAK;EAC3E,IAAI,IAAAqB,gBAAO,EAACD,SAAS,CAAC,EAAE,OAAO,IAAAlB,eAAM,EAACkB,SAAS,EAAE,GAAG,EAAE;IAAEpB;EAAO,CAAC,CAAC;EACjE,IAAI,IAAAsB,oBAAW,EAACF,SAAS,CAAC,EAAE,OAAO,WAAW;EAC9C,IAAI,IAAAnB,mBAAU,EAACmB,SAAS,CAAC,EAAE,OAAO,IAAAlB,eAAM,EAACkB,SAAS,EAAE,QAAQ,EAAE;IAAEpB;EAAO,CAAC,CAAC;EAEzE,OAAO,IAAAE,eAAM,EAACkB,SAAS,EAAE,YAAY,EAAE;IAAEpB;EAAO,CAAC,CAAC;AACpD,CAAC;AAACP,OAAA,CAAA0B,qBAAA,GAAAA,qBAAA"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getGroupChannelTitle = exports.getGroupChannelPreviewTime = exports.getGroupChannelLastMessage = void 0;
|
|
7
|
-
var _dateFns = require("date-fns");
|
|
8
7
|
var _common = require("./common");
|
|
9
8
|
const getGroupChannelTitle = function (currentUserId, channel) {
|
|
10
9
|
let EMPTY_USERNAME = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(No name)';
|
|
@@ -27,44 +26,14 @@ const getGroupChannelTitle = function (currentUserId, channel) {
|
|
|
27
26
|
exports.getGroupChannelTitle = getGroupChannelTitle;
|
|
28
27
|
const getGroupChannelPreviewTime = (channel, locale) => {
|
|
29
28
|
var _channel$lastMessage;
|
|
30
|
-
|
|
31
|
-
if ((0, _dateFns.isToday)(timestamp)) return (0, _dateFns.format)(timestamp, 'p', {
|
|
32
|
-
locale
|
|
33
|
-
});
|
|
34
|
-
if ((0, _dateFns.isYesterday)(timestamp)) return 'Yesterday';
|
|
35
|
-
if ((0, _dateFns.isThisYear)(timestamp)) return (0, _dateFns.format)(timestamp, 'MMM dd', {
|
|
36
|
-
locale
|
|
37
|
-
});
|
|
38
|
-
return (0, _dateFns.format)(timestamp, 'yyyy/MM/dd', {
|
|
39
|
-
locale
|
|
40
|
-
});
|
|
29
|
+
return (0, _common.getMessagePreviewTime)(((_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.createdAt) || channel.joinedAt * 1000 || channel.createdAt, locale);
|
|
41
30
|
};
|
|
42
31
|
exports.getGroupChannelPreviewTime = getGroupChannelPreviewTime;
|
|
43
32
|
const getGroupChannelLastMessage = function (channel) {
|
|
44
33
|
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
45
|
-
let MAX_LEN = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 15;
|
|
46
34
|
const message = channel.lastMessage;
|
|
47
35
|
if (!message) return EMPTY_MESSAGE;
|
|
48
|
-
|
|
49
|
-
const extIdx = message.name.lastIndexOf('.');
|
|
50
|
-
if (extIdx > -1) {
|
|
51
|
-
const file = message.name.slice(0, extIdx);
|
|
52
|
-
const ext = message.name.slice(extIdx);
|
|
53
|
-
return (0, _common.truncate)(file, {
|
|
54
|
-
maxLen: MAX_LEN
|
|
55
|
-
}) + ext;
|
|
56
|
-
}
|
|
57
|
-
return (0, _common.truncate)(message.name, {
|
|
58
|
-
maxLen: MAX_LEN
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (message.isUserMessage()) {
|
|
62
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
63
|
-
}
|
|
64
|
-
if (message.isAdminMessage()) {
|
|
65
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
66
|
-
}
|
|
67
|
-
return EMPTY_MESSAGE;
|
|
36
|
+
return (0, _common.getMessagePreviewBody)(message, EMPTY_MESSAGE);
|
|
68
37
|
};
|
|
69
38
|
exports.getGroupChannelLastMessage = getGroupChannelLastMessage;
|
|
70
39
|
//# sourceMappingURL=groupChannel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_common","require","getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","arguments","length","undefined","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","_ref","userId","map","_ref2","nickname","join","exports","getGroupChannelPreviewTime","locale","_channel$lastMessage","getMessagePreviewTime","lastMessage","createdAt","joinedAt","getGroupChannelLastMessage","EMPTY_MESSAGE","message","getMessagePreviewBody"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { getMessagePreviewBody, getMessagePreviewTime } from './common';\n\nexport const getGroupChannelTitle = (\n currentUserId: string,\n channel: SendbirdGroupChannel,\n EMPTY_USERNAME = '(No name)',\n NO_MEMBERS = '(No members)',\n DEFAULT_CHANNEL_NAME = 'Group Channel',\n) => {\n if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;\n if (channel.memberCount === 1) return NO_MEMBERS;\n return channel.members\n .filter(({ userId }) => userId !== currentUserId)\n .map(({ nickname }) => nickname || EMPTY_USERNAME)\n .join(', ');\n};\n\nexport const getGroupChannelPreviewTime = (channel: SendbirdGroupChannel, locale?: Locale) => {\n return getMessagePreviewTime(channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt, locale);\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '') => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\n return getMessagePreviewBody(message, EMPTY_MESSAGE);\n};\n"],"mappings":";;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAEO,MAAMC,oBAAoB,GAAG,SAAAA,CAClCC,aAAqB,EACrBC,OAA6B,EAI1B;EAAA,IAHHC,cAAc,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,WAAW;EAAA,IAC5BG,UAAU,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,cAAc;EAAA,IAC3BI,oBAAoB,GAAAJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,eAAe;EAEtC,IAAIF,OAAO,CAACO,IAAI,KAAKD,oBAAoB,IAAIN,OAAO,CAACO,IAAI,KAAK,EAAE,EAAE,OAAOP,OAAO,CAACO,IAAI;EACrF,IAAIP,OAAO,CAACQ,WAAW,KAAK,CAAC,EAAE,OAAOH,UAAU;EAChD,OAAOL,OAAO,CAACS,OAAO,CACnBC,MAAM,CAACC,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAKC,MAAM,KAAKb,aAAa;EAAA,EAAC,CAChDc,GAAG,CAACC,KAAA;IAAA,IAAC;MAAEC;IAAS,CAAC,GAAAD,KAAA;IAAA,OAAKC,QAAQ,IAAId,cAAc;EAAA,EAAC,CACjDe,IAAI,CAAC,IAAI,CAAC;AACf,CAAC;AAACC,OAAA,CAAAnB,oBAAA,GAAAA,oBAAA;AAEK,MAAMoB,0BAA0B,GAAGA,CAAClB,OAA6B,EAAEmB,MAAe,KAAK;EAAA,IAAAC,oBAAA;EAC5F,OAAO,IAAAC,6BAAqB,EAAC,EAAAD,oBAAA,GAAApB,OAAO,CAACsB,WAAW,cAAAF,oBAAA,uBAAnBA,oBAAA,CAAqBG,SAAS,KAAIvB,OAAO,CAACwB,QAAQ,GAAG,IAAI,IAAIxB,OAAO,CAACuB,SAAS,EAAEJ,MAAM,CAAC;AACtH,CAAC;AAACF,OAAA,CAAAC,0BAAA,GAAAA,0BAAA;AAEK,MAAMO,0BAA0B,GAAG,SAAAA,CAACzB,OAA6B,EAAyB;EAAA,IAAvB0B,aAAa,GAAAxB,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC1F,MAAMyB,OAAO,GAAG3B,OAAO,CAACsB,WAAW;EACnC,IAAI,CAACK,OAAO,EAAE,OAAOD,aAAa;EAElC,OAAO,IAAAE,6BAAqB,EAACD,OAAO,EAAED,aAAa,CAAC;AACtD,CAAC;AAACT,OAAA,CAAAQ,0BAAA,GAAAA,0BAAA"}
|
|
@@ -89,4 +89,11 @@ export const usePartialState = initialState => {
|
|
|
89
89
|
...state
|
|
90
90
|
}), initialState);
|
|
91
91
|
};
|
|
92
|
+
export const useRefTracker = target => {
|
|
93
|
+
const ref = useRef(target);
|
|
94
|
+
useLayoutEffect(() => {
|
|
95
|
+
ref.current = target;
|
|
96
|
+
});
|
|
97
|
+
return ref;
|
|
98
|
+
};
|
|
92
99
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
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","arguments","useDebounceEffect","action","delay","length","undefined","timeoutRef","setTimeout","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,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAK7F,MAAMC,MAAiC,GAAG,CAAC,CAAC;AAC5C,OAAO,MAAMC,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAOH,QAAQ,CAAC,MAAM;IACpB,IAAI,CAACC,MAAM,CAACE,GAAG,CAAC,EAAEF,MAAM,CAACE,GAAG,CAAC,GAAG,CAAC;IACjC,OAAOF,MAAM,CAACE,GAAG,CAAC,EAAE;EACtB,CAAC,CAAC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,OAAO,MAAMC,gBAAgB,GAAIC,IAAY,IAAK;EAChD,MAAMC,EAAE,GAAGJ,SAAS,CAACG,IAAI,CAAC;EAC1B,OAAQ,GAAEA,IAAK,IAAGC,EAAG,EAAC;AACxB,CAAC;AAED,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,MAAM,GAAGC,OAAO,CAAC,GAAGR,QAAQ,CAAC,CAAC,CAAC;EAC/B,OAAOL,WAAW,CAAC,MAAMa,OAAO,CAAEC,IAAI,IAAKA,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3D,CAAC;AAED,OAAO,MAAMC,cAAc,GAAGA,CAACC,WAAgC,EAAEC,IAAqB,KAAK;EACzFhB,SAAS,CAACiB,yBAAyB,CAACF,WAAW,CAAC,EAAEC,IAAI,CAA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W,IAAQ;EACrF,MAAMW,GAAG,GAAG5B,MAAM,CAAIiB,QAAQ,CAAC;EAC/BW,GAAG,CAACJ,OAAO,GAAGP,QAAQ;EACtB,OAAOrB,WAAW,CAAE;IAAA,OAAagC,GAAG,CAACJ,OAAO,CAAC,GAAAK,SAAO,CAAC;EAAA,GAAQ,EAAE,CAAC;AAClE,CAAC;AAED,OAAO,MAAMC,iBAAiB,GAAG,SAAAA,CAACC,MAAkB,EAAEC,KAAa,EAAgC;EAAA,IAA9BnB,IAAoB,GAAAgB,SAAA,CAAAI,MAAA,QAAAJ,SAAA,QAAAK,SAAA,GAAAL,SAAA,MAAG,EAAE;EAC5F,MAAMM,UAAU,GAAGnC,MAAM,EAAkB;EAE3CH,SAAS,CAAC,MAAM;IACdsC,UAAU,CAACX,OAAO,GAAGY,UAAU,CAAC,YAAY;MAC1C,IAAI;QACF,MAAML,MAAM,EAAE;MAChB,CAAC,SAAS;QACRI,UAAU,CAACX,OAAO,GAAGU,SAAS;MAChC;IACF,CAAC,EAAEF,KAAK,CAAC;IAET,OAAO,MAAM;MACX,IAAIG,UAAU,CAACX,OAAO,EAAE;QACtBa,YAAY,CAACF,UAAU,CAACX,OAAO,CAAC;QAChCW,UAAU,CAACX,OAAO,GAAGU,SAAS;MAChC;IACF,CAAC;EACH,CAAC,EAAE,CAACF,KAAK,EAAE,GAAGnB,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,OAAO,MAAMyB,eAAe,GAAOC,YAAe,IAAK;EACrD,OAAOxC,UAAU,CAAC,CAACW,IAAO,EAAE8B,KAAiB,MAAM;IAAE,GAAG9B,IAAI;IAAE,GAAG8B;EAAM,CAAC,CAAC,EAAED,YAAY,CAAC;AAC1F,CAAC"}
|
|
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","arguments","useDebounceEffect","action","delay","length","undefined","timeoutRef","setTimeout","clearTimeout","usePartialState","initialState","state","useRefTracker","target"],"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\nexport const useRefTracker = <T>(target: T) => {\n const ref = useRef(target);\n\n useLayoutEffect(() => {\n ref.current = target;\n });\n\n return ref;\n};\n"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAK7F,MAAMC,MAAiC,GAAG,CAAC,CAAC;AAC5C,OAAO,MAAMC,SAAS,GAAIC,GAAW,IAAK;EACxC,OAAOH,QAAQ,CAAC,MAAM;IACpB,IAAI,CAACC,MAAM,CAACE,GAAG,CAAC,EAAEF,MAAM,CAACE,GAAG,CAAC,GAAG,CAAC;IACjC,OAAOF,MAAM,CAACE,GAAG,CAAC,EAAE;EACtB,CAAC,CAAC,CAAC,CAAC,CAAC;AACP,CAAC;AAED,OAAO,MAAMC,gBAAgB,GAAIC,IAAY,IAAK;EAChD,MAAMC,EAAE,GAAGJ,SAAS,CAACG,IAAI,CAAC;EAC1B,OAAQ,GAAEA,IAAK,IAAGC,EAAG,EAAC;AACxB,CAAC;AAED,OAAO,MAAMC,cAAc,GAAGA,CAAA,KAAM;EAClC,M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AOxC,UAAU,CAAC,CAACW,IAAO,EAAE8B,KAAiB,MAAM;IAAE,GAAG9B,IAAI;IAAE,GAAG8B;EAAM,CAAC,CAAC,EAAED,YAAY,CAAC;AAC1F,CAAC;AAED,OAAO,MAAME,aAAa,GAAOC,MAAS,IAAK;EAC7C,MAAMd,GAAG,GAAG5B,MAAM,CAAC0C,MAAM,CAAC;EAE1B5C,eAAe,CAAC,MAAM;IACpB8B,GAAG,CAACJ,OAAO,GAAGkB,MAAM;EACtB,CAAC,CAAC;EAEF,OAAOd,GAAG;AACZ,CAAC"}
|
package/lib/module/index.js
CHANGED
|
@@ -23,11 +23,13 @@ export function ifThenOr(cond, then, or) {
|
|
|
23
23
|
return or;
|
|
24
24
|
}
|
|
25
25
|
export const SBErrorCode = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
UNAUTHORIZED_REQUEST: 400108,
|
|
27
|
+
RESOURCE_NOT_FOUND: 400201,
|
|
28
|
+
BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: 900100,
|
|
29
|
+
CHANNEL_NOT_FOUND: 900500
|
|
29
30
|
};
|
|
30
31
|
export const SBErrorMessage = {
|
|
31
32
|
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.'
|
|
32
33
|
};
|
|
34
|
+
export * from './types';
|
|
33
35
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","ifThenOr","cond","then","or","SBErrorCode","
|
|
1
|
+
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","ifThenOr","cond","then","or","SBErrorCode","UNAUTHORIZED_REQUEST","RESOURCE_NOT_FOUND","BANNED_USER_SEND_MESSAGE_NOT_ALLOWED","CHANNEL_NOT_FOUND","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport * from './shared/regex';\nexport * from './shared/bufferedRequest';\nexport * from './shared/file';\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 UNAUTHORIZED_REQUEST: 400108,\n RESOURCE_NOT_FOUND: 400201,\n BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: 900100,\n CHANNEL_NOT_FOUND: 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 * from './types';\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AACxC,SAASC,OAAO,IAAIC,UAAU,EAAEC,oBAAoB,QAAQ,qBAAqB;AACjF,cAAc,gBAAgB;AAC9B,cAAc,0BAA0B;AACxC,cAAc,eAAe;AAC7B,cAAc,UAAU;AAExB,cAAc,SAAS;AACvB,cAAc,sBAAsB;AACpC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,kBAAkB;AAChC,cAAc,iBAAiB;AAE/B,OAAO,MAAMC,IAAgB,GAAGA,CAAA,KAAM,KAAK,CAAC;AAC5C,OAAO,MAAMC,UAAU,GAAG,MAAAA,CAAA,KAAY,KAAK,CAAC;AAC5C,OAAO,MAAMC,IAAI,GAAOC,GAAM,IAAKA,GAAG;AACtC,OAAO,MAAMC,UAAU,GAAIC,IAAY,IAAKA,IAAI,GAAG,IAAI,GAAG,IAAI;AAC9D,OAAO,MAAMC,UAAU,GAAIC,KAAe,IAAwB,OAAOA,KAAK,KAAK,UAAU;AAI7F,OAAO,SAASC,QAAQA,CAACC,IAAa,EAAEC,IAAa,EAAEC,EAAY,EAAE;EACnE,IAAIF,IAAI,EAAE,OAAOC,IAAI;EACrB,OAAOC,EAAE;AACX;AAEA,OAAO,MAAMC,WAAW,GAAG;EACzBC,oBAAoB,EAAE,MAAM;EAC5BC,kBAAkB,EAAE,MAAM;EAC1BC,oCAAoC,EAAE,MAAM;EAC5CC,iBAAiB,EAAE;AACrB,CAAC;AACD,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,6EAA6E,GAC7E,yGAAyG,GACzG,0GAA0G,GAC1G;AACJ,CAAC;AAED,cAAc,SAAS"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageSearchOrder } from '@sendbird/chat/message';
|
|
1
2
|
import { getFileExtension, getFileType } from '../shared/file';
|
|
2
3
|
import { getMessageTimeFormat } from '../ui-format/common';
|
|
3
4
|
export function isNewMessage(msg, currentUserId) {
|
|
@@ -128,4 +129,12 @@ export function getMessageType(message) {
|
|
|
128
129
|
}
|
|
129
130
|
return 'unknown';
|
|
130
131
|
}
|
|
132
|
+
export function getDefaultMessageSearchQueryParams(channel, keyword) {
|
|
133
|
+
return {
|
|
134
|
+
keyword,
|
|
135
|
+
channelUrl: channel.url,
|
|
136
|
+
messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),
|
|
137
|
+
order: MessageSearchOrder.TIMESTAMP
|
|
138
|
+
};
|
|
139
|
+
}
|
|
131
140
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getFileExtension","getFileType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","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","getFileTypeFromMessage","type","name","getMessageType","ogMetaData","fileType"],"sources":["message.ts"],"sourcesContent":["import { getFileExtension, getFileType } from '../shared/file';\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,gBAAgB,EAAEC,WAAW,QAAQ,gBAAgB;AAU9D,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,OAAO,SAASC,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEA,OAAO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEA,OAAO,SAASG,WAAWA,CAACH,GAA4B,EAAqD;EAAA,IAAAQ,WAAA;EAAA,IAAnDP,aAAa,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,iCAAiC;EACzG,IAAI,CAACH,iBAAiB,CAACN,GAAG,CAAC,EAAE,OAAO,KAAK;EACzC,OACG,QAAQ,IAAIA,GAAG,IAAI,EAAAQ,WAAA,GAAAR,GAAG,CAACW,MAAM,cAAAH,WAAA,uBAAVA,WAAA,CAAYI,MAAM,MAAKX,aAAa,IACxDD,GAAG,CAACa,aAAa,KAAK,SAAS,IAC/Bb,GAAG,CAACa,aAAa,KAAK,QAAQ,IAC9Bb,GAAG,CAACa,aAAa,KAAK,UAAU;AAEpC;AAEA,OAAO,SAASC,mBAAmBA,CAACC,OAAwB,EAAU;EACpE,OAAOC,gBAAgB,CAACD,OAAO,CAAC;AACl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O,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAIpD,OAAO,CAACsB,aAAa,EAAE,EAAE;IAC3B,MAAM+B,QAAQ,GAAGL,sBAAsB,CAAChD,OAAO,CAAC;IAChD,QAAQqD,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB"}
|
|
1
|
+
{"version":3,"names":["MessageSearchOrder","getFileExtension","getFileType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","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","getFileTypeFromMessage","type","name","getMessageType","ogMetaData","fileType","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,SAASC,gBAAgB,EAAEC,WAAW,QAAQ,gBAAgB;AAW9D,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,OAAO,SAASC,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEA,OAAO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEA,OAAO,SAASG,WAAWA,CAACH,GAA4B,EAAqD;EAAA,IAAAQ,WAAA;EAAA,IAAnDP,aAAa,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,iCAAiC;EACzG,IAAI,C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ACC,OAAO,CAACpD,MAAM;AAChC;AAUA,OAAO,SAASqD,sBAAsBA,CAAChD,OAA4B,EAAE;EACnE,OAAOlB,WAAW,CAACkB,OAAO,CAACiD,IAAI,IAAIpE,gBAAgB,CAACmB,OAAO,CAACkD,IAAI,CAAC,CAAC;AACpE;AAEA,OAAO,SAASC,cAAcA,CAACnD,OAAwB,EAAe;EACpE,IAAIA,OAAO,CAACX,cAAc,EAAE,EAAE;IAC5B,OAAO,OAAO;EAChB;EAEA,IAAIW,OAAO,CAACqB,aAAa,EAAE,EAAE;IAC3B,IAAIrB,OAAO,CAACoD,UAAU,EAAE;MACtB,OAAO,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAIpD,OAAO,CAACsB,aAAa,EAAE,EAAE;IAC3B,MAAM+B,QAAQ,GAAGL,sBAAsB,CAAChD,OAAO,CAAC;IAChD,QAAQqD,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB;AAEA,OAAO,SAASC,kCAAkCA,CAACf,OAA6B,EAAEgB,OAAe,EAAE;EACjG,OAAO;IACLA,OAAO;IACPC,UAAU,EAAEjB,OAAO,CAACZ,GAAG;IACvB8B,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAACpB,OAAO,CAACqB,QAAQ,EAAErB,OAAO,CAACsB,SAAS,CAAC;IACnEC,KAAK,EAAElF,kBAAkB,CAACmF;EAC5B,CAAC;AACH"}
|
package/lib/module/types.js.map
CHANGED
|
@@ -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 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":""}
|
|
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 MessageSearchQuery,\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;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\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,4 +1,4 @@
|
|
|
1
|
-
import { format, isThisYear } from 'date-fns';
|
|
1
|
+
import { format, isThisYear, isToday, isYesterday } from 'date-fns';
|
|
2
2
|
const defaultOpts = {
|
|
3
3
|
mode: 'mid',
|
|
4
4
|
maxLen: 40,
|
|
@@ -84,4 +84,57 @@ export const getMessageTimeFormat = (date, locale) => {
|
|
|
84
84
|
locale
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Message preview title text
|
|
90
|
+
* */
|
|
91
|
+
export const getMessagePreviewTitle = function (message) {
|
|
92
|
+
let EMPTY_USERNAME = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '(No name)';
|
|
93
|
+
if (message.isFileMessage() || message.isUserMessage()) {
|
|
94
|
+
return message.sender.nickname || EMPTY_USERNAME;
|
|
95
|
+
}
|
|
96
|
+
if (message.isAdminMessage()) {
|
|
97
|
+
return 'Admin';
|
|
98
|
+
}
|
|
99
|
+
return EMPTY_USERNAME;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Message preview body text
|
|
104
|
+
* */
|
|
105
|
+
export const getMessagePreviewBody = function (message) {
|
|
106
|
+
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
107
|
+
if (message.isFileMessage()) {
|
|
108
|
+
const extIdx = message.name.lastIndexOf('.');
|
|
109
|
+
if (extIdx > -1) {
|
|
110
|
+
const file = message.name.slice(0, extIdx);
|
|
111
|
+
const ext = message.name.slice(extIdx);
|
|
112
|
+
return file + ext;
|
|
113
|
+
}
|
|
114
|
+
return message.name;
|
|
115
|
+
}
|
|
116
|
+
if (message.isUserMessage()) {
|
|
117
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
118
|
+
}
|
|
119
|
+
if (message.isAdminMessage()) {
|
|
120
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
121
|
+
}
|
|
122
|
+
return EMPTY_MESSAGE;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Message preview time format
|
|
127
|
+
* */
|
|
128
|
+
export const getMessagePreviewTime = (timestamp, locale) => {
|
|
129
|
+
if (isToday(timestamp)) return format(timestamp, 'p', {
|
|
130
|
+
locale
|
|
131
|
+
});
|
|
132
|
+
if (isYesterday(timestamp)) return 'Yesterday';
|
|
133
|
+
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', {
|
|
134
|
+
locale
|
|
135
|
+
});
|
|
136
|
+
return format(timestamp, 'yyyy/MM/dd', {
|
|
137
|
+
locale
|
|
138
|
+
});
|
|
139
|
+
};
|
|
87
140
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["format","isThisYear","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","getMessageTimeFormat"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear } from 'date-fns';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n"],"mappings":"AACA,SAASA,MAAM,EAAEC,UAAU,QAAQ,UAAU;
|
|
1
|
+
{"version":3,"names":["format","isThisYear","isToday","isYesterday","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)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AW;EAC9C,IAAI7C,UAAU,CAAC6C,SAAS,CAAC,EAAE,OAAO9C,MAAM,CAAC8C,SAAS,EAAE,QAAQ,EAAE;IAAElB;EAAO,CAAC,CAAC;EAEzE,OAAO5B,MAAM,CAAC8C,SAAS,EAAE,YAAY,EAAE;IAAElB;EAAO,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { truncate } from './common';
|
|
1
|
+
import { getMessagePreviewBody, getMessagePreviewTime } from './common';
|
|
3
2
|
export const getGroupChannelTitle = function (currentUserId, channel) {
|
|
4
3
|
let EMPTY_USERNAME = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(No name)';
|
|
5
4
|
let NO_MEMBERS = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '(No members)';
|
|
@@ -20,42 +19,12 @@ export const getGroupChannelTitle = function (currentUserId, channel) {
|
|
|
20
19
|
};
|
|
21
20
|
export const getGroupChannelPreviewTime = (channel, locale) => {
|
|
22
21
|
var _channel$lastMessage;
|
|
23
|
-
|
|
24
|
-
if (isToday(timestamp)) return format(timestamp, 'p', {
|
|
25
|
-
locale
|
|
26
|
-
});
|
|
27
|
-
if (isYesterday(timestamp)) return 'Yesterday';
|
|
28
|
-
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', {
|
|
29
|
-
locale
|
|
30
|
-
});
|
|
31
|
-
return format(timestamp, 'yyyy/MM/dd', {
|
|
32
|
-
locale
|
|
33
|
-
});
|
|
22
|
+
return getMessagePreviewTime(((_channel$lastMessage = channel.lastMessage) === null || _channel$lastMessage === void 0 ? void 0 : _channel$lastMessage.createdAt) || channel.joinedAt * 1000 || channel.createdAt, locale);
|
|
34
23
|
};
|
|
35
24
|
export const getGroupChannelLastMessage = function (channel) {
|
|
36
25
|
let EMPTY_MESSAGE = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
37
|
-
let MAX_LEN = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 15;
|
|
38
26
|
const message = channel.lastMessage;
|
|
39
27
|
if (!message) return EMPTY_MESSAGE;
|
|
40
|
-
|
|
41
|
-
const extIdx = message.name.lastIndexOf('.');
|
|
42
|
-
if (extIdx > -1) {
|
|
43
|
-
const file = message.name.slice(0, extIdx);
|
|
44
|
-
const ext = message.name.slice(extIdx);
|
|
45
|
-
return truncate(file, {
|
|
46
|
-
maxLen: MAX_LEN
|
|
47
|
-
}) + ext;
|
|
48
|
-
}
|
|
49
|
-
return truncate(message.name, {
|
|
50
|
-
maxLen: MAX_LEN
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (message.isUserMessage()) {
|
|
54
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
55
|
-
}
|
|
56
|
-
if (message.isAdminMessage()) {
|
|
57
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
58
|
-
}
|
|
59
|
-
return EMPTY_MESSAGE;
|
|
28
|
+
return getMessagePreviewBody(message, EMPTY_MESSAGE);
|
|
60
29
|
};
|
|
61
30
|
//# sourceMappingURL=groupChannel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["getMessagePreviewBody","getMessagePreviewTime","getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","arguments","length","undefined","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","_ref","userId","map","_ref2","nickname","join","getGroupChannelPreviewTime","locale","_channel$lastMessage","lastMessage","createdAt","joinedAt","getGroupChannelLastMessage","EMPTY_MESSAGE","message"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { getMessagePreviewBody, getMessagePreviewTime } from './common';\n\nexport const getGroupChannelTitle = (\n currentUserId: string,\n channel: SendbirdGroupChannel,\n EMPTY_USERNAME = '(No name)',\n NO_MEMBERS = '(No members)',\n DEFAULT_CHANNEL_NAME = 'Group Channel',\n) => {\n if (channel.name !== DEFAULT_CHANNEL_NAME && channel.name !== '') return channel.name;\n if (channel.memberCount === 1) return NO_MEMBERS;\n return channel.members\n .filter(({ userId }) => userId !== currentUserId)\n .map(({ nickname }) => nickname || EMPTY_USERNAME)\n .join(', ');\n};\n\nexport const getGroupChannelPreviewTime = (channel: SendbirdGroupChannel, locale?: Locale) => {\n return getMessagePreviewTime(channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt, locale);\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '') => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\n return getMessagePreviewBody(message, EMPTY_MESSAGE);\n};\n"],"mappings":"AAGA,SAASA,qBAAqB,EAAEC,qBAAqB,QAAQ,UAAU;AAEvE,OAAO,MAAMC,oBAAoB,GAAG,SAAAA,CAClCC,aAAqB,EACrBC,OAA6B,EAI1B;EAAA,IAHHC,cAAc,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,WAAW;EAAA,IAC5BG,UAAU,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,cAAc;EAAA,IAC3BI,oBAAoB,GAAAJ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,eAAe;EAEtC,IAAIF,OAAO,CAACO,IAAI,KAAKD,oBAAoB,IAAIN,OAAO,CAACO,IAAI,KAAK,EAAE,EAAE,OAAOP,OAAO,CAACO,IAAI;EACrF,IAAIP,OAAO,CAACQ,WAAW,KAAK,CAAC,EAAE,OAAOH,UAAU;EAChD,OAAOL,OAAO,CAACS,OAAO,CACnBC,MAAM,CAACC,IAAA;IAAA,IAAC;MAAEC;IAAO,CAAC,GAAAD,IAAA;IAAA,OAAKC,MAAM,KAAKb,aAAa;EAAA,EAAC,CAChDc,GAAG,CAACC,KAAA;IAAA,IAAC;MAAEC;IAAS,CAAC,GAAAD,KAAA;IAAA,OAAKC,QAAQ,IAAId,cAAc;EAAA,EAAC,CACjDe,IAAI,CAAC,IAAI,CAAC;AACf,CAAC;AAED,OAAO,MAAMC,0BAA0B,GAAGA,CAACjB,OAA6B,EAAEkB,MAAe,KAAK;EAAA,IAAAC,oBAAA;EAC5F,OAAOtB,qBAAqB,CAAC,EAAAsB,oBAAA,GAAAnB,OAAO,CAACoB,WAAW,cAAAD,oBAAA,uBAAnBA,oBAAA,CAAqBE,SAAS,KAAIrB,OAAO,CAACsB,QAAQ,GAAG,IAAI,IAAItB,OAAO,CAACqB,SAAS,EAAEH,MAAM,CAAC;AACtH,CAAC;AAED,OAAO,MAAMK,0BAA0B,GAAG,SAAAA,CAACvB,OAA6B,EAAyB;EAAA,IAAvBwB,aAAa,GAAAtB,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,EAAE;EAC1F,MAAMuB,OAAO,GAAGzB,OAAO,CAACoB,WAAW;EACnC,IAAI,CAACK,OAAO,EAAE,OAAOD,aAAa;EAElC,OAAO5B,qBAAqB,CAAC6B,OAAO,EAAED,aAAa,CAAC;AACtD,CAAC"}
|
|
@@ -12,4 +12,5 @@ export declare const useIsFirstMount: () => boolean;
|
|
|
12
12
|
export declare const useFreshCallback: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
13
13
|
export declare const useDebounceEffect: (action: () => void, delay: number, deps?: DependencyList) => void;
|
|
14
14
|
export declare const usePartialState: <S>(initialState: S) => [S & Partial<S>, import("react").Dispatch<Partial<S>>];
|
|
15
|
+
export declare const useRefTracker: <T>(target: T) => import("react").MutableRefObject<T>;
|
|
15
16
|
export {};
|
|
@@ -21,11 +21,12 @@ export declare const isFunction: (param?: unknown) => param is Function;
|
|
|
21
21
|
export declare function ifThenOr<T>(cond: boolean, then: T): T | undefined;
|
|
22
22
|
export declare function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;
|
|
23
23
|
export declare const SBErrorCode: {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
UNAUTHORIZED_REQUEST: number;
|
|
25
|
+
RESOURCE_NOT_FOUND: number;
|
|
26
|
+
BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: number;
|
|
27
|
+
CHANNEL_NOT_FOUND: number;
|
|
27
28
|
};
|
|
28
29
|
export declare const SBErrorMessage: {
|
|
29
30
|
ACL: string;
|
|
30
31
|
};
|
|
31
|
-
export
|
|
32
|
+
export * from './types';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MessageSearchOrder } from '@sendbird/chat/message';
|
|
2
|
+
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdGroupChannel, SendbirdMessage, SendbirdReaction, SendbirdSendableMessage } from '../types';
|
|
2
3
|
export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
3
4
|
export declare function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage;
|
|
4
5
|
export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string): boolean;
|
|
@@ -23,4 +24,10 @@ export declare function getReactionCount(reaction: SendbirdReaction): number;
|
|
|
23
24
|
type MessageType = 'user' | 'admin' | 'file' | 'unknown' | `user.${'opengraph'}` | `file.${'image' | 'video' | 'audio'}`;
|
|
24
25
|
export declare function getFileTypeFromMessage(message: SendbirdFileMessage): "video" | "audio" | "image" | "file";
|
|
25
26
|
export declare function getMessageType(message: SendbirdMessage): MessageType;
|
|
27
|
+
export declare function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string): {
|
|
28
|
+
keyword: string;
|
|
29
|
+
channelUrl: string;
|
|
30
|
+
messageTimestampFrom: number;
|
|
31
|
+
order: MessageSearchOrder;
|
|
32
|
+
};
|
|
26
33
|
export {};
|
|
@@ -3,7 +3,7 @@ import type SendbirdChat from '@sendbird/chat';
|
|
|
3
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
5
|
import type { ModuleNamespaces, OpenChannelCreateParams, OpenChannelUpdateParams, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
|
-
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
6
|
+
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, MessageSearchQuery, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
7
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];
|
|
@@ -55,6 +55,7 @@ export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
|
55
55
|
export type SendbirdOpenChannelListQuery = OpenChannelListQuery;
|
|
56
56
|
export type SendbirdMessageCollection = MessageCollection;
|
|
57
57
|
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
58
|
+
export type SendbirdMessageSearchQuery = MessageSearchQuery;
|
|
58
59
|
export type SendbirdError = SBError;
|
|
59
60
|
export interface SendbirdDataPayload {
|
|
60
61
|
app_id: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
+
import type { SendbirdBaseMessage } from '../types';
|
|
2
3
|
type TruncateMode = 'head' | 'mid' | 'tail';
|
|
3
4
|
type TruncateOption = {
|
|
4
5
|
mode: TruncateMode;
|
|
@@ -41,4 +42,16 @@ export declare const getDateSeparatorFormat: (date: Date, locale?: Locale) => st
|
|
|
41
42
|
* @returns {string}
|
|
42
43
|
* */
|
|
43
44
|
export declare const getMessageTimeFormat: (date: Date, locale?: Locale) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Message preview title text
|
|
47
|
+
* */
|
|
48
|
+
export declare const getMessagePreviewTitle: (message: SendbirdBaseMessage, EMPTY_USERNAME?: string) => string;
|
|
49
|
+
/**
|
|
50
|
+
* Message preview body text
|
|
51
|
+
* */
|
|
52
|
+
export declare const getMessagePreviewBody: (message: SendbirdBaseMessage, EMPTY_MESSAGE?: string) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Message preview time format
|
|
55
|
+
* */
|
|
56
|
+
export declare const getMessagePreviewTime: (timestamp: number, locale?: Locale) => string;
|
|
44
57
|
export {};
|
|
@@ -2,4 +2,4 @@ import type { Locale } from 'date-fns';
|
|
|
2
2
|
import type { SendbirdGroupChannel } from '../types';
|
|
3
3
|
export declare const getGroupChannelTitle: (currentUserId: string, channel: SendbirdGroupChannel, EMPTY_USERNAME?: string, NO_MEMBERS?: string, DEFAULT_CHANNEL_NAME?: string) => string;
|
|
4
4
|
export declare const getGroupChannelPreviewTime: (channel: SendbirdGroupChannel, locale?: Locale) => string;
|
|
5
|
-
export declare const getGroupChannelLastMessage: (channel: SendbirdGroupChannel, EMPTY_MESSAGE?: string
|
|
5
|
+
export declare const getGroupChannelLastMessage: (channel: SendbirdGroupChannel, EMPTY_MESSAGE?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-rc.1",
|
|
4
4
|
"description": "A collection of utility functions and constants for building chat UI components with Sendbird UIKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sendbird",
|
|
@@ -80,6 +80,5 @@
|
|
|
80
80
|
"entryPoint": "./src/index.ts",
|
|
81
81
|
"readmeFile": "./README.md",
|
|
82
82
|
"displayName": "@sendbird/uikit-utils"
|
|
83
|
-
}
|
|
84
|
-
"gitHead": "ae9e60edc60cdd4f6e9b0e4019e84584e807bc2c"
|
|
83
|
+
}
|
|
85
84
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -102,3 +102,13 @@ export const useDebounceEffect = (action: () => void, delay: number, deps: Depen
|
|
|
102
102
|
export const usePartialState = <S>(initialState: S) => {
|
|
103
103
|
return useReducer((prev: S, state: Partial<S>) => ({ ...prev, ...state }), initialState);
|
|
104
104
|
};
|
|
105
|
+
|
|
106
|
+
export const useRefTracker = <T>(target: T) => {
|
|
107
|
+
const ref = useRef(target);
|
|
108
|
+
|
|
109
|
+
useLayoutEffect(() => {
|
|
110
|
+
ref.current = target;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return ref;
|
|
114
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -29,9 +29,10 @@ export function ifThenOr(cond: boolean, then: unknown, or?: unknown) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export const SBErrorCode = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
UNAUTHORIZED_REQUEST: 400108,
|
|
33
|
+
RESOURCE_NOT_FOUND: 400201,
|
|
34
|
+
BANNED_USER_SEND_MESSAGE_NOT_ALLOWED: 900100,
|
|
35
|
+
CHANNEL_NOT_FOUND: 900500,
|
|
35
36
|
};
|
|
36
37
|
export const SBErrorMessage = {
|
|
37
38
|
ACL:
|
|
@@ -41,52 +42,4 @@ export const SBErrorMessage = {
|
|
|
41
42
|
'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
export
|
|
45
|
-
UserStruct,
|
|
46
|
-
FilterByValueType,
|
|
47
|
-
UnionToIntersection,
|
|
48
|
-
OmittedValues,
|
|
49
|
-
PartialDeep,
|
|
50
|
-
Optional,
|
|
51
|
-
ContextValue,
|
|
52
|
-
OnBeforeHandler,
|
|
53
|
-
SendbirdMessage,
|
|
54
|
-
SendbirdChatSDK,
|
|
55
|
-
SendbirdChannel,
|
|
56
|
-
SendbirdBaseChannel,
|
|
57
|
-
SendbirdGroupChannel,
|
|
58
|
-
SendbirdOpenChannel,
|
|
59
|
-
SendbirdUser,
|
|
60
|
-
SendbirdMember,
|
|
61
|
-
SendbirdBaseMessage,
|
|
62
|
-
SendbirdUserMessage,
|
|
63
|
-
SendbirdFileMessage,
|
|
64
|
-
SendbirdAdminMessage,
|
|
65
|
-
SendbirdGroupChannelCreateParams,
|
|
66
|
-
SendbirdFileMessageCreateParams,
|
|
67
|
-
SendbirdUserMessageCreateParams,
|
|
68
|
-
SendbirdError,
|
|
69
|
-
SendbirdMessageCollection,
|
|
70
|
-
SendbirdGroupChannelCollection,
|
|
71
|
-
NotificationFiles,
|
|
72
|
-
NotificationMentionedUsers,
|
|
73
|
-
NotificationTranslations,
|
|
74
|
-
PartialNullable,
|
|
75
|
-
SendbirdDataPayload,
|
|
76
|
-
SendbirdPreviousMessageListQuery,
|
|
77
|
-
SendbirdSendableMessage,
|
|
78
|
-
SendbirdOpenChannelListQuery,
|
|
79
|
-
SendbirdGroupChannelListQuery,
|
|
80
|
-
SendbirdGroupChannelUpdateParams,
|
|
81
|
-
SendbirdUserMessageUpdateParams,
|
|
82
|
-
SendbirdFileMessageUpdateParams,
|
|
83
|
-
SendbirdUserUpdateParams,
|
|
84
|
-
SendbirdRestrictedUser,
|
|
85
|
-
SendbirdReaction,
|
|
86
|
-
SendbirdEmojiContainer,
|
|
87
|
-
SendbirdEmoji,
|
|
88
|
-
SendbirdEmojiCategory,
|
|
89
|
-
SendbirdOpenChannelUpdateParams,
|
|
90
|
-
SendbirdOpenChannelCreateParams,
|
|
91
|
-
SendbirdParticipant,
|
|
92
|
-
} from './types';
|
|
45
|
+
export * from './types';
|
package/src/sendbird/message.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { MessageSearchOrder } from '@sendbird/chat/message';
|
|
2
|
+
|
|
1
3
|
import { getFileExtension, getFileType } from '../shared/file';
|
|
2
4
|
import type {
|
|
3
5
|
SendbirdBaseChannel,
|
|
4
6
|
SendbirdBaseMessage,
|
|
5
7
|
SendbirdDataPayload,
|
|
6
8
|
SendbirdFileMessage,
|
|
9
|
+
SendbirdGroupChannel,
|
|
7
10
|
SendbirdMessage,
|
|
8
11
|
SendbirdReaction,
|
|
9
12
|
SendbirdSendableMessage,
|
|
@@ -173,3 +176,12 @@ export function getMessageType(message: SendbirdMessage): MessageType {
|
|
|
173
176
|
|
|
174
177
|
return 'unknown';
|
|
175
178
|
}
|
|
179
|
+
|
|
180
|
+
export function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {
|
|
181
|
+
return {
|
|
182
|
+
keyword,
|
|
183
|
+
channelUrl: channel.url,
|
|
184
|
+
messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),
|
|
185
|
+
order: MessageSearchOrder.TIMESTAMP,
|
|
186
|
+
};
|
|
187
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -37,6 +37,7 @@ import type {
|
|
|
37
37
|
FileMessage,
|
|
38
38
|
FileMessageCreateParams,
|
|
39
39
|
FileMessageUpdateParams,
|
|
40
|
+
MessageSearchQuery,
|
|
40
41
|
PreviousMessageListQuery,
|
|
41
42
|
Reaction,
|
|
42
43
|
UserMessage,
|
|
@@ -115,6 +116,7 @@ export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
|
115
116
|
export type SendbirdOpenChannelListQuery = OpenChannelListQuery;
|
|
116
117
|
export type SendbirdMessageCollection = MessageCollection;
|
|
117
118
|
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
119
|
+
export type SendbirdMessageSearchQuery = MessageSearchQuery;
|
|
118
120
|
|
|
119
121
|
export type SendbirdError = SBError;
|
|
120
122
|
|
package/src/ui-format/common.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
import { format, isThisYear } from 'date-fns';
|
|
2
|
+
import { format, isThisYear, isToday, isYesterday } from 'date-fns';
|
|
3
|
+
|
|
4
|
+
import type { SendbirdBaseMessage } from '../types';
|
|
3
5
|
|
|
4
6
|
type TruncateMode = 'head' | 'mid' | 'tail';
|
|
5
7
|
type TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };
|
|
@@ -73,3 +75,53 @@ export const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {
|
|
|
73
75
|
export const getMessageTimeFormat = (date: Date, locale?: Locale): string => {
|
|
74
76
|
return format(date, 'p', { locale });
|
|
75
77
|
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Message preview title text
|
|
81
|
+
* */
|
|
82
|
+
export const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {
|
|
83
|
+
if (message.isFileMessage() || message.isUserMessage()) {
|
|
84
|
+
return message.sender.nickname || EMPTY_USERNAME;
|
|
85
|
+
}
|
|
86
|
+
if (message.isAdminMessage()) {
|
|
87
|
+
return 'Admin';
|
|
88
|
+
}
|
|
89
|
+
return EMPTY_USERNAME;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Message preview body text
|
|
94
|
+
* */
|
|
95
|
+
export const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {
|
|
96
|
+
if (message.isFileMessage()) {
|
|
97
|
+
const extIdx = message.name.lastIndexOf('.');
|
|
98
|
+
if (extIdx > -1) {
|
|
99
|
+
const file = message.name.slice(0, extIdx);
|
|
100
|
+
const ext = message.name.slice(extIdx);
|
|
101
|
+
return file + ext;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return message.name;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (message.isUserMessage()) {
|
|
108
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (message.isAdminMessage()) {
|
|
112
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return EMPTY_MESSAGE;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Message preview time format
|
|
120
|
+
* */
|
|
121
|
+
export const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {
|
|
122
|
+
if (isToday(timestamp)) return format(timestamp, 'p', { locale });
|
|
123
|
+
if (isYesterday(timestamp)) return 'Yesterday';
|
|
124
|
+
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });
|
|
125
|
+
|
|
126
|
+
return format(timestamp, 'yyyy/MM/dd', { locale });
|
|
127
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { Locale } from 'date-fns';
|
|
2
|
-
import { format, isThisYear, isToday, isYesterday } from 'date-fns';
|
|
3
2
|
|
|
4
3
|
import type { SendbirdGroupChannel } from '../types';
|
|
5
|
-
import {
|
|
4
|
+
import { getMessagePreviewBody, getMessagePreviewTime } from './common';
|
|
6
5
|
|
|
7
6
|
export const getGroupChannelTitle = (
|
|
8
7
|
currentUserId: string,
|
|
@@ -20,37 +19,12 @@ export const getGroupChannelTitle = (
|
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
export const getGroupChannelPreviewTime = (channel: SendbirdGroupChannel, locale?: Locale) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (isToday(timestamp)) return format(timestamp, 'p', { locale });
|
|
26
|
-
if (isYesterday(timestamp)) return 'Yesterday';
|
|
27
|
-
if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });
|
|
28
|
-
|
|
29
|
-
return format(timestamp, 'yyyy/MM/dd', { locale });
|
|
22
|
+
return getMessagePreviewTime(channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt, locale);
|
|
30
23
|
};
|
|
31
24
|
|
|
32
|
-
export const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = ''
|
|
25
|
+
export const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '') => {
|
|
33
26
|
const message = channel.lastMessage;
|
|
34
27
|
if (!message) return EMPTY_MESSAGE;
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
const extIdx = message.name.lastIndexOf('.');
|
|
38
|
-
if (extIdx > -1) {
|
|
39
|
-
const file = message.name.slice(0, extIdx);
|
|
40
|
-
const ext = message.name.slice(extIdx);
|
|
41
|
-
return truncate(file, { maxLen: MAX_LEN }) + ext;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return truncate(message.name, { maxLen: MAX_LEN });
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (message.isUserMessage()) {
|
|
48
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (message.isAdminMessage()) {
|
|
52
|
-
return message.message ?? EMPTY_MESSAGE;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return EMPTY_MESSAGE;
|
|
29
|
+
return getMessagePreviewBody(message, EMPTY_MESSAGE);
|
|
56
30
|
};
|