@sendbird/uikit-utils 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/hooks/index.js +1 -3
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/index.js +22 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +19 -3
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/sendbird/message.js +9 -4
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/shared/arrayToMap.js.map +1 -1
- package/lib/commonjs/types.js +1 -3
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui-format/groupChannel.js +9 -1
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -1
- package/lib/module/hooks/index.js +1 -3
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +10 -1
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/sendbird/message.js +7 -4
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/shared/arrayToMap.js.map +1 -1
- package/lib/module/types.js +4 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui-format/groupChannel.js +9 -1
- package/lib/module/ui-format/groupChannel.js.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/sendbird/channel.d.ts +5 -3
- package/lib/typescript/src/sendbird/message.d.ts +4 -3
- package/lib/typescript/src/shared/arrayToMap.d.ts +1 -1
- package/lib/typescript/src/types.d.ts +32 -19
- package/package.json +6 -6
- package/src/hooks/index.ts +1 -3
- package/src/index.ts +13 -3
- package/src/sendbird/channel.ts +19 -2
- package/src/sendbird/message.ts +17 -7
- package/src/shared/arrayToMap.ts +1 -4
- package/src/types.ts +55 -24
- package/src/ui-format/groupChannel.ts +9 -1
|
@@ -76,9 +76,7 @@ exports.useIsMountedRef = useIsMountedRef;
|
|
|
76
76
|
|
|
77
77
|
const useFreshCallback = callback => {
|
|
78
78
|
const ref = (0, _react.useRef)(callback);
|
|
79
|
-
|
|
80
|
-
ref.current = callback;
|
|
81
|
-
});
|
|
79
|
+
ref.current = callback;
|
|
82
80
|
return (0, _react.useCallback)(function () {
|
|
83
81
|
return ref.current(...arguments);
|
|
84
82
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["idPool","useUniqId","key","useState","useForceUpdate","updater","useCallback","prev","useAsyncEffect","asyncEffect","deps","useEffect","createAsyncEffectCallback","useAsyncLayoutEffect","useLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","useRef","current","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n
|
|
1
|
+
{"version":3,"names":["idPool","useUniqId","key","useState","useForceUpdate","updater","useCallback","prev","useAsyncEffect","asyncEffect","deps","useEffect","createAsyncEffectCallback","useAsyncLayoutEffect","useLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","useRef","current","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n"],"mappings":";;;;;;;AAEA;;AAFA;AAOA,MAAMA,MAAiC,GAAG,EAA1C;;AACO,MAAMC,SAAS,GAAIC,GAAD,IAAiB;EACxC,OAAO,IAAAC,eAAA,EAAS,MAAM;IACpB,IAAI,CAACH,MAAM,CAACE,GAAD,CAAX,EAAkBF,MAAM,CAACE,GAAD,CAAN,GAAc,CAAd;IAClB,OAAOF,MAAM,CAACE,GAAD,CAAN,EAAP;EACD,CAHM,EAGJ,CAHI,CAAP;AAID,CALM;;;;AAOA,MAAME,cAAc,GAAG,MAAM;EAClC,MAAM,GAAGC,OAAH,IAAc,IAAAF,eAAA,EAAS,CAAT,CAApB;EACA,OAAO,IAAAG,kBAAA,EAAY,MAAMD,OAAO,CAAEE,IAAD,IAAUA,IAAI,GAAG,CAAlB,CAAzB,EAA+C,EAA/C,CAAP;AACD,CAHM;;;;AAKA,MAAMC,cAAc,GAAG,CAACC,WAAD,EAAmCC,IAAnC,KAA6D;EACzF,IAAAC,gBAAA,EAAUC,yBAAyB,CAACH,WAAD,CAAnC,EAAkDC,IAAlD;AACD,CAFM;;;;AAGA,MAAMG,oBAAoB,GAAG,CAACJ,WAAD,EAAmCC,IAAnC,KAA6D;EAC/F,IAAAI,sBAAA,EAAgBF,yBAAyB,CAACH,WAAD,CAAzC,EAAwDC,IAAxD;AACD,CAFM;;;;AAGA,MAAMK,OAAO,GAAOC,QAAJ,IAA0B;EAC/C,OAAOC,IAAI,CAACD,QAAD,CAAX;AACD,CAFM;;;;AAGP,MAAMC,IAAI,GAAuCD,QAApC,IAAmEA,QAAQ,EAAxF;;AACA,MAAMJ,yBAAyB,GAAIH,WAAD,IAAsC,MAAM;EAC5E,MAAMS,UAAU,GAAGD,IAAI,CAACR,WAAD,CAAvB;EACA,OAAO,MAAM;IACX,IAAI,CAACS,UAAL,EAAiB;;IAEjB,IAAIA,UAAU,YAAYC,OAA1B,EAAmC;MACjCF,IAAI,CAAC,YAAY;QACf,MAAMG,iBAAiB,GAAG,MAAMF,UAAhC;QACA,IAAIE,iBAAJ,EAAuBA,iBAAiB;MACzC,CAHG,CAAJ;IAID,CALD,MAKO;MACLH,IAAI,CAACC,UAAD,CAAJ;IACD;EACF,CAXD;AAYD,CAdD;;AAgBO,MAAMG,eAAe,GAAG,MAAM;EACnC,MAAMC,SAAS,GAAG,IAAAC,aAAA,EAAO,IAAP,CAAlB;EAEA,IAAAZ,gBAAA,EAAU,MAAM;IACd,OAAO,MAAM;MACXW,SAAS,CAACE,OAAV,GAAoB,KAApB;IACD,CAFD;EAGD,CAJD,EAIG,EAJH;EAMA,OAAOF,SAAP;AACD,CAVM;;;;AAYA,MAAMG,gBAAgB,GAAuCT,QAApC,IAAuD;EACrF,MAAMU,GAAG,GAAG,IAAAH,aAAA,EAAUP,QAAV,CAAZ;EACAU,GAAG,CAACF,OAAJ,GAAcR,QAAd;EACA,OAAO,IAAAV,kBAAA,EAAa;IAAA,OAAaoB,GAAG,CAACF,OAAJ,CAAY,YAAZ,CAAb;EAAA,CAAb,EAAsD,EAAtD,CAAP;AACD,CAJM"}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -21,7 +21,10 @@ var _exportNames = {
|
|
|
21
21
|
imageExtRegex: true,
|
|
22
22
|
getFileType: true,
|
|
23
23
|
getFileExtension: true,
|
|
24
|
-
replaceUrlAsComponents: true
|
|
24
|
+
replaceUrlAsComponents: true,
|
|
25
|
+
normalizeFileName: true,
|
|
26
|
+
emailRegex: true,
|
|
27
|
+
phoneRegex: true
|
|
25
28
|
};
|
|
26
29
|
exports.ASYNC_NOOP = void 0;
|
|
27
30
|
Object.defineProperty(exports, "Logger", {
|
|
@@ -61,6 +64,12 @@ Object.defineProperty(exports, "createPubSub", {
|
|
|
61
64
|
return _pubsub.createPubSub;
|
|
62
65
|
}
|
|
63
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "emailRegex", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _regex.emailRegex;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
64
73
|
Object.defineProperty(exports, "getFileExtension", {
|
|
65
74
|
enumerable: true,
|
|
66
75
|
get: function () {
|
|
@@ -85,6 +94,18 @@ Object.defineProperty(exports, "newLineRegex", {
|
|
|
85
94
|
return _regex.newLineRegex;
|
|
86
95
|
}
|
|
87
96
|
});
|
|
97
|
+
Object.defineProperty(exports, "normalizeFileName", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return _regex.normalizeFileName;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "phoneRegex", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _regex.phoneRegex;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
88
109
|
Object.defineProperty(exports, "replaceUrlAsComponents", {
|
|
89
110
|
enumerable: true,
|
|
90
111
|
get: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { default as conditionChaining } from './shared/conditionChaining';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n} from './shared/regex';\n\nexport * from './hooks';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\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;\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n
|
|
1
|
+
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { default as conditionChaining } from './shared/conditionChaining';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n} from './shared/regex';\n\nexport * from './hooks';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\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;\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAeA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;;;;;;;AAEO,MAAMA,IAAgB,GAAG,MAAM,KAAK,CAApC;;;;AACA,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;;;;AACA,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;;;;AACA,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD"}
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.confirmAndMarkAsRead = exports.confirmAndMarkAsDelivered = void 0;
|
|
6
7
|
exports.getGroupChannels = getGroupChannels;
|
|
7
8
|
exports.getMembersExcludeMe = getMembersExcludeMe;
|
|
8
9
|
exports.getOpenChannels = getOpenChannels;
|
|
9
|
-
exports.groupChannelChatUnavailable = void 0;
|
|
10
10
|
exports.isDefaultCoverImage = isDefaultCoverImage;
|
|
11
11
|
exports.isDifferentChannel = isDifferentChannel;
|
|
12
|
+
exports.isGroupChannelChatUnavailable = void 0;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Diff utils for channel
|
|
@@ -21,11 +22,26 @@ function isDifferentChannel(a, b) {
|
|
|
21
22
|
return a.url !== b.url;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
+
const isGroupChannelChatUnavailable = channel => {
|
|
25
26
|
return channel.myMutedState === 'muted' || channel.isFrozen && channel.myRole !== 'operator';
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
exports.
|
|
29
|
+
exports.isGroupChannelChatUnavailable = isGroupChannelChatUnavailable;
|
|
30
|
+
|
|
31
|
+
const confirmAndMarkAsRead = async (sdk, channels) => {
|
|
32
|
+
const channelUrls = channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).map(it => it.url);
|
|
33
|
+
await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.confirmAndMarkAsRead = confirmAndMarkAsRead;
|
|
37
|
+
|
|
38
|
+
const confirmAndMarkAsDelivered = async (sdk, channel) => {
|
|
39
|
+
if (channel.isGroupChannel() && channel.unreadMessageCount > 0) {
|
|
40
|
+
await sdk.groupChannel.markAsDelivered(channel.url);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.confirmAndMarkAsDelivered = confirmAndMarkAsDelivered;
|
|
29
45
|
|
|
30
46
|
function isDefaultCoverImage(coverUrl) {
|
|
31
47
|
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isDifferentChannel","a","b","url","
|
|
1
|
+
{"version":3,"names":["isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","confirmAndMarkAsRead","sdk","channels","channelUrls","filter","it","isGroupChannel","unreadMessageCount","map","groupChannel","markAsReadWithChannelUrls","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import type {\n SendbirdBaseChannel,\n SendbirdChannel,\n SendbirdChatSDK,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n} from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\n};\n\nexport const confirmAndMarkAsRead = async (sdk: SendbirdChatSDK, channels: SendbirdBaseChannel[]) => {\n const channelUrls = channels.filter((it) => it.isGroupChannel() && it.unreadMessageCount > 0).map((it) => it.url);\n await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);\n};\n\nexport const confirmAndMarkAsDelivered = async (sdk: SendbirdChatSDK, channel: SendbirdBaseChannel) => {\n if (channel.isGroupChannel() && channel.unreadMessageCount > 0) {\n await sdk.groupChannel.markAsDelivered(channel.url);\n }\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":";;;;;;;;;;;;;AAQA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;;AAEM,MAAMC,6BAA6B,GAAIC,OAAD,IAAmC;EAC9E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;;;;AAIA,MAAMC,oBAAoB,GAAG,OAAOC,GAAP,EAA6BC,QAA7B,KAAiE;EACnG,MAAMC,WAAW,GAAGD,QAAQ,CAACE,MAAT,CAAiBC,EAAD,IAAQA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAAvE,EAA0EC,GAA1E,CAA+EH,EAAD,IAAQA,EAAE,CAACX,GAAzF,CAApB;EACA,MAAMO,GAAG,CAACQ,YAAJ,CAAiBC,yBAAjB,CAA2CP,WAA3C,CAAN;AACD,CAHM;;;;AAKA,MAAMQ,yBAAyB,GAAG,OAAOV,GAAP,EAA6BL,OAA7B,KAA8D;EACrG,IAAIA,OAAO,CAACU,cAAR,MAA4BV,OAAO,CAACW,kBAAR,GAA6B,CAA7D,EAAgE;IAC9D,MAAMN,GAAG,CAACQ,YAAJ,CAAiBG,eAAjB,CAAiChB,OAAO,CAACF,GAAzC,CAAN;EACD;AACF,CAJM;;;;AAMA,SAASmB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BpB,OAA7B,EAA4DqB,aAA5D,EAAoF;EACzF,OAAOrB,OAAO,CAACsB,OAAR,CAAgBd,MAAhB,CAAwBe,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaH,aAA3C,CAAP;AACD;;AAEM,SAASI,gBAAT,CAA0BnB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACE,MAAT,CAAiBkB,CAAD,IAAkCA,CAAC,CAAChB,cAAF,EAAlD,CAAP;AACD;;AAEM,SAASiB,eAAT,CAAyBrB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACE,MAAT,CAAiBkB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD"}
|
|
@@ -9,6 +9,7 @@ exports.getMessageUniqId = getMessageUniqId;
|
|
|
9
9
|
exports.hasSameSender = hasSameSender;
|
|
10
10
|
exports.isMyMessage = isMyMessage;
|
|
11
11
|
exports.isNewMessage = isNewMessage;
|
|
12
|
+
exports.isSendableMessage = isSendableMessage;
|
|
12
13
|
exports.isSendbirdNotification = isSendbirdNotification;
|
|
13
14
|
exports.messageComparator = messageComparator;
|
|
14
15
|
exports.messageKeyExtractor = messageKeyExtractor;
|
|
@@ -23,11 +24,15 @@ function isNewMessage(msg, currentUserId) {
|
|
|
23
24
|
return msg.updatedAt === 0;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
function isSendableMessage(msg) {
|
|
28
|
+
return msg !== undefined && msg !== null && 'sendingStatus' in msg;
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
function isMyMessage(msg) {
|
|
27
32
|
var _msg$sender;
|
|
28
33
|
|
|
29
34
|
let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
|
|
30
|
-
if (!msg) return false;
|
|
35
|
+
if (!isSendableMessage(msg)) return false;
|
|
31
36
|
return 'sender' in msg && ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId || msg.sendingStatus === 'pending' || msg.sendingStatus === 'failed' || msg.sendingStatus === 'canceled';
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -46,8 +51,8 @@ function messageKeyExtractor(message) {
|
|
|
46
51
|
function messageComparator(a, b) {
|
|
47
52
|
let aStatusOffset = 0;
|
|
48
53
|
let bStatusOffset = 0;
|
|
49
|
-
if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
50
|
-
if (b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
54
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
55
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
51
56
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
52
57
|
}
|
|
53
58
|
|
|
@@ -94,7 +99,7 @@ function getMessageUniqId(msg) {
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
function getAvailableUriFromFileMessage(message) {
|
|
97
|
-
if (!message.url && message.messageParams && 'uri' in message.messageParams.file) {
|
|
102
|
+
if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {
|
|
98
103
|
return message.messageParams.file.uri;
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","messageTime","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"names":["isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","messageTime","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type {\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdSendableMessage,\n} from '../types';\nimport { messageTime } 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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(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"],"mappings":";;;;;;;;;;;;;;;;;AAOA;;AAEO,SAASA,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAD,EAAMC,aAAN,CAA7B;EACA,IAAIC,SAAJ,EAAe,OAAO,KAAP;EACf,IAAIF,GAAG,CAACI,cAAJ,EAAJ,EAA0B,OAAO,KAAP;EAC1B,OAAOJ,GAAG,CAACK,SAAJ,KAAkB,CAAzB;AACD;;AAEM,SAASC,iBAAT,CAA2BN,GAA3B,EAAyF;EAC9F,OAAOA,GAAG,KAAKO,SAAR,IAAqBP,GAAG,KAAK,IAA7B,IAAqC,mBAAmBA,GAA/D;AACD;;AAEM,SAASG,WAAT,CAAqBH,GAArB,EAAsG;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EAC3G,IAAI,CAACK,iBAAiB,CAACN,GAAD,CAAtB,EAA6B,OAAO,KAAP;EAC7B,OACG,YAAYA,GAAZ,IAAmB,gBAAAA,GAAG,CAACQ,MAAJ,4DAAYC,MAAZ,MAAuBR,aAA3C,IACAD,GAAG,CAACU,aAAJ,KAAsB,SADtB,IAEAV,GAAG,CAACU,aAAJ,KAAsB,QAFtB,IAGAV,GAAG,CAACU,aAAJ,KAAsB,UAJxB;AAMD;;AAEM,SAASC,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;IACrF,OAAO5B,OAAO,CAAC2B,aAAR,CAAsBC,IAAtB,CAA2BC,GAAlC;EACD;;EACD,OAAO7B,OAAO,CAAC0B,GAAf;AACD;;AAGM,SAASI,sBAAT,CAAgCC,WAAhC,EAEmC;EACxC,IAAI,CAACA,WAAL,EAAkB,OAAO,KAAP;EAClB,OAAOC,OAAO,CAACD,WAAW,CAAC,UAAD,CAAZ,CAAd;AACD;;AAEM,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["arrayToMap","arr","selector","fallbackSelector","combine","reduce","accum","curr","_key","arrayToMapWithGetter","getSelector"],"sources":["arrayToMap.ts"],"sourcesContent":["import type { FilterByValueType } from '../types';\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: keyof FilterByValueType<T, string | number>,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n fallbackSelector: K,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n selector2: string,\n combineKey: true,\n): Record<string, T>;\n\n/**\n * Convert Array of the object to Object\n * @param {object[]} arr\n * @param {keyof object} selector\n * @param {keyof object} [fallbackSelector]\n * @param {boolean} [combine]\n * @returns {Record<keyof object, object>}\n * @example\n * ```\n * const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];\n * const obj = arrayToMap(arr, 'name');\n *\n * console.log(obj);\n * // {\n * // 'john': {name: 'john'},\n * // 'chris': {name: 'chris'},\n * // 'sravan': {name: 'sravan'},\n * // 'hoon': {name: 'hoon'}\n * // }\n * ```\n * */\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: K,\n fallbackSelector?: K,\n combine?: boolean,\n) {\n return arr.reduce((accum, curr) => {\n if (combine && fallbackSelector) {\n const _key = curr[selector] + (curr[fallbackSelector] as string);\n accum[_key] = curr;\n } else {\n const _key = (curr[selector] || curr[fallbackSelector as K]) as string;\n accum[_key] = curr;\n }\n\n return accum;\n }, {} as Record<string, T>);\n}\n\nexport function arrayToMapWithGetter<T
|
|
1
|
+
{"version":3,"names":["arrayToMap","arr","selector","fallbackSelector","combine","reduce","accum","curr","_key","arrayToMapWithGetter","getSelector"],"sources":["arrayToMap.ts"],"sourcesContent":["import type { FilterByValueType } from '../types';\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: keyof FilterByValueType<T, string | number>,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n fallbackSelector: K,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n selector2: string,\n combineKey: true,\n): Record<string, T>;\n\n/**\n * Convert Array of the object to Object\n * @param {object[]} arr\n * @param {keyof object} selector\n * @param {keyof object} [fallbackSelector]\n * @param {boolean} [combine]\n * @returns {Record<keyof object, object>}\n * @example\n * ```\n * const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];\n * const obj = arrayToMap(arr, 'name');\n *\n * console.log(obj);\n * // {\n * // 'john': {name: 'john'},\n * // 'chris': {name: 'chris'},\n * // 'sravan': {name: 'sravan'},\n * // 'hoon': {name: 'hoon'}\n * // }\n * ```\n * */\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: K,\n fallbackSelector?: K,\n combine?: boolean,\n) {\n return arr.reduce((accum, curr) => {\n if (combine && fallbackSelector) {\n const _key = curr[selector] + (curr[fallbackSelector] as string);\n accum[_key] = curr;\n } else {\n const _key = (curr[selector] || curr[fallbackSelector as K]) as string;\n accum[_key] = curr;\n }\n\n return accum;\n }, {} as Record<string, T>);\n}\n\nexport function arrayToMapWithGetter<T>(arr: T[], getSelector: (item: T) => string) {\n return arr.reduce((accum, curr) => {\n const _key = getSelector(curr);\n accum[_key] = curr;\n return accum;\n }, {} as Record<string, T>);\n}\n"],"mappings":";;;;;;;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,UAAT,CACbC,GADa,EAEbC,QAFa,EAGbC,gBAHa,EAIbC,OAJa,EAKb;EACA,OAAOH,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,IAAIH,OAAO,IAAID,gBAAf,EAAiC;MAC/B,MAAMK,IAAI,GAAGD,IAAI,CAACL,QAAD,CAAJ,GAAkBK,IAAI,CAACJ,gBAAD,CAAnC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD,CAHD,MAGO;MACL,MAAMC,IAAI,GAAID,IAAI,CAACL,QAAD,CAAJ,IAAkBK,IAAI,CAACJ,gBAAD,CAApC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD;;IAED,OAAOD,KAAP;EACD,CAVM,EAUJ,EAVI,CAAP;AAWD;;AAEM,SAASG,oBAAT,CAAiCR,GAAjC,EAA2CS,WAA3C,EAA6E;EAClF,OAAOT,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,MAAMC,IAAI,GAAGE,WAAW,CAACH,IAAD,CAAxB;;IACAD,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACA,OAAOD,KAAP;EACD,CAJM,EAIJ,EAJI,CAAP;AAKD"}
|
package/lib/commonjs/types.js
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';\nimport type
|
|
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 { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nimport './';\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 SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdMember = Member;\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":";;AA+BA"}
|
|
@@ -73,7 +73,15 @@ const getGroupChannelLastMessage = function (channel) {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
if (message.isUserMessage()) {
|
|
77
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (message.isAdminMessage()) {
|
|
81
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return EMPTY_MESSAGE;
|
|
77
85
|
};
|
|
78
86
|
|
|
79
87
|
exports.getGroupChannelLastMessage = getGroupChannelLastMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","isToday","format","isYesterday","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","truncate","maxLen"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\nimport isToday from 'date-fns/isToday';\nimport isYesterday from 'date-fns/isYesterday';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { truncate } 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 const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n return format(timestamp, 'MMM dd', { locale });\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\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 truncate(file, { maxLen: MAX_LEN }) + ext;\n }\n\n return truncate(message.name, { maxLen: MAX_LEN });\n }\n\n return message.message ?? EMPTY_MESSAGE;\n};\n"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAGA;;;;AAEO,MAAMA,oBAAoB,GAAG,UAClCC,aADkC,EAElCC,OAFkC,EAM/B;EAAA,IAHHC,cAGG,uEAHc,WAGd;EAAA,IAFHC,UAEG,uEAFU,cAEV;EAAA,IADHC,oBACG,uEADoB,eACpB;EACH,IAAIH,OAAO,CAACI,IAAR,KAAiBD,oBAAjB,IAAyCH,OAAO,CAACI,IAAR,KAAiB,EAA9D,EAAkE,OAAOJ,OAAO,CAACI,IAAf;EAClE,IAAIJ,OAAO,CAACK,WAAR,KAAwB,CAA5B,EAA+B,OAAOH,UAAP;EAC/B,OAAOF,OAAO,CAACM,OAAR,CACJC,MADI,CACG;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAgBA,MAAM,KAAKT,aAA3B;EAAA,CADH,EAEJU,GAFI,CAEA;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAkBA,QAAQ,IAAIT,cAA9B;EAAA,CAFA,EAGJU,IAHI,CAGC,IAHD,CAAP;AAID,C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AAE4B,MAAM,EAAET;IAAV,CAAvB,CAAP;EACD;;EAED,
|
|
1
|
+
{"version":3,"names":["getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","isToday","format","isYesterday","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","truncate","maxLen","isUserMessage","isAdminMessage"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\nimport isToday from 'date-fns/isToday';\nimport isYesterday from 'date-fns/isYesterday';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { truncate } 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 const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n return format(timestamp, 'MMM dd', { locale });\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\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 truncate(file, { maxLen: MAX_LEN }) + ext;\n }\n\n return truncate(message.name, { maxLen: MAX_LEN });\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"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAGA;;;;AAEO,MAAMA,oBAAoB,GAAG,UAClCC,aADkC,EAElCC,OAFkC,EAM/B;EAAA,IAHHC,cAGG,uEAHc,WAGd;EAAA,IAFHC,UAEG,uEAFU,cAEV;EAAA,IADHC,oBACG,uEADoB,eACpB;EACH,IAAIH,OAAO,CAACI,IAAR,KAAiBD,oBAAjB,IAAyCH,OAAO,CAACI,IAAR,KAAiB,EAA9D,EAAkE,OAAOJ,OAAO,CAACI,IAAf;EAClE,IAAIJ,OAAO,CAACK,WAAR,KAAwB,CAA5B,EAA+B,OAAOH,UAAP;EAC/B,OAAOF,OAAO,CAACM,OAAR,CACJC,MADI,CACG;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAgBA,MAAM,KAAKT,aAA3B;EAAA,CADH,EAEJU,GAFI,CAEA;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAkBA,QAAQ,IAAIT,cAA9B;EAAA,CAFA,EAGJU,IAHI,CAGC,IAHD,CAAP;AAID,CAbM;;;;AAeA,MAAMC,0BAA0B,GAAG,CAACZ,OAAD,EAAgCa,MAAhC,KAAoD;EAAA;;EAC5F,MAAMC,SAAS,GAAG,yBAAAd,OAAO,CAACe,WAAR,8EAAqBC,SAArB,KAAkChB,OAAO,CAACiB,QAAR,GAAmB,IAArD,IAA6DjB,OAAO,CAACgB,SAAvF;EACA,IAAI,IAAAE,gBAAA,EAAQJ,SAAR,CAAJ,EAAwB,OAAO,IAAAK,eAAA,EAAOL,SAAP,EAAkB,GAAlB,EAAuB;IAAED;EAAF,CAAvB,CAAP;EACxB,IAAI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|
|
52
52
|
const ref = useRef(callback);
|
|
53
|
-
|
|
54
|
-
ref.current = callback;
|
|
55
|
-
});
|
|
53
|
+
ref.current = callback;
|
|
56
54
|
return useCallback(function () {
|
|
57
55
|
return ref.current(...arguments);
|
|
58
56
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","idPool","useUniqId","key","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","idPool","useUniqId","key","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n"],"mappings":"AAAA;AAEA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,eAAjC,EAAkDC,MAAlD,EAA0DC,QAA1D,QAA0E,OAA1E;AAKA,MAAMC,MAAiC,GAAG,EAA1C;AACA,OAAO,MAAMC,SAAS,GAAIC,GAAD,IAAiB;EACxC,OAAOH,QAAQ,CAAC,MAAM;IACpB,IAAI,CAACC,MAAM,CAACE,GAAD,CAAX,EAAkBF,MAAM,CAACE,GAAD,CAAN,GAAc,CAAd;IAClB,OAAOF,MAAM,CAACE,GAAD,CAAN,EAAP;EACD,CAHc,CAAR,CAGJ,CAHI,CAAP;AAID,CALM;AAOP,OAAO,MAAMC,cAAc,GAAG,MAAM;EAClC,MAAM,GAAGC,OAAH,IAAcL,QAAQ,CAAC,CAAD,CAA5B;EACA,OAAOJ,WAAW,CAAC,MAAMS,OAAO,CAAEC,IAAD,IAAUA,IAAI,GAAG,CAAlB,CAAd,EAAoC,EAApC,CAAlB;AACD,CAHM;AAKP,OAAO,MAAMC,cAAc,GAAG,CAACC,WAAD,EAAmCC,IAAnC,KAA6D;EACzFZ,SAAS,CAACa,yBAAyB,CAACF,WAAD,CAA1B,EAAyCC,IAAzC,CAAT;AACD,CAFM;AAGP,OAAO,MAAME,oBAAoB,GAAG,CAACH,WAAD,EAAmCC,IAAnC,KAA6D;EAC/FX,eAAe,CAACY,yBAAyB,CAACF,WAAD,CAA1B,EAAyCC,IAAzC,CAAf;AACD,CAFM;AAGP,OAAO,MAAMG,OAAO,GAAOC,QAAJ,IAA0B;EAC/C,OAAOC,IAAI,CAACD,QAAD,CAAX;AACD,CAFM;;AAGP,MAAMC,IAAI,GAAuCD,QAApC,IAAmEA,QAAQ,EAAxF;;AACA,MAAMH,yBAAyB,GAAIF,WAAD,IAAsC,MAAM;EAC5E,MAAMO,UAAU,GAAGD,IAAI,CAACN,WAAD,CAAvB;EACA,OAAO,MAAM;IACX,IAAI,CAACO,UAAL,EAAiB;;IAEjB,IAAIA,UAAU,YAAYC,OAA1B,EAAmC;MACjCF,IAAI,CAAC,YAAY;QACf,MAAMG,iBAAiB,GAAG,MAAMF,UAAhC;QACA,IAAIE,iBAAJ,EAAuBA,iBAAiB;MACzC,CAHG,CAAJ;IAID,CALD,MAKO;MACLH,IAAI,CAACC,UAAD,CAAJ;IACD;EACF,CAXD;AAYD,CAdD;;AAgBA,OAAO,MAAMG,eAAe,GAAG,MAAM;EACnC,MAAMC,SAAS,GAAGpB,MAAM,CAAC,IAAD,CAAxB;EAEAF,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXsB,SAAS,CAACC,OAAV,GAAoB,KAApB;IACD,CAFD;EAGD,CAJQ,EAIN,EAJM,CAAT;EAMA,OAAOD,SAAP;AACD,CAVM;AAYP,OAAO,MAAME,gBAAgB,GAAuCR,QAApC,IAAuD;EACrF,MAAMS,GAAG,GAAGvB,MAAM,CAAIc,QAAJ,CAAlB;EACAS,GAAG,CAACF,OAAJ,GAAcP,QAAd;EACA,OAAOjB,WAAW,CAAE;IAAA,OAAa0B,GAAG,CAACF,OAAJ,CAAY,YAAZ,CAAb;EAAA,CAAF,EAA2C,EAA3C,CAAlB;AACD,CAJM"}
|
package/lib/module/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { Logger } from './shared/logger';
|
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
4
|
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
|
-
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents } from './shared/regex';
|
|
5
|
+
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex } from './shared/regex';
|
|
6
6
|
export * from './hooks';
|
|
7
7
|
export * from './ui-format/groupChannel';
|
|
8
8
|
export * from './ui-format/common';
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","conditionChaining","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { default as conditionChaining } from './shared/conditionChaining';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n} from './shared/regex';\n\nexport * from './hooks';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\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;\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n
|
|
1
|
+
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","conditionChaining","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { default as conditionChaining } from './shared/conditionChaining';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n} from './shared/regex';\n\nexport * from './hooks';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\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;\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SAASH,OAAO,IAAII,iBAApB,QAA6C,4BAA7C;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,QAaO,gBAbP;AAeA,cAAc,SAAd;AACA,cAAc,0BAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD"}
|
|
@@ -8,9 +8,18 @@ export function isDifferentChannel(a, b) {
|
|
|
8
8
|
if (!a || !b) return true;
|
|
9
9
|
return a.url !== b.url;
|
|
10
10
|
}
|
|
11
|
-
export const
|
|
11
|
+
export const isGroupChannelChatUnavailable = channel => {
|
|
12
12
|
return channel.myMutedState === 'muted' || channel.isFrozen && channel.myRole !== 'operator';
|
|
13
13
|
};
|
|
14
|
+
export const confirmAndMarkAsRead = async (sdk, channels) => {
|
|
15
|
+
const channelUrls = channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).map(it => it.url);
|
|
16
|
+
await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);
|
|
17
|
+
};
|
|
18
|
+
export const confirmAndMarkAsDelivered = async (sdk, channel) => {
|
|
19
|
+
if (channel.isGroupChannel() && channel.unreadMessageCount > 0) {
|
|
20
|
+
await sdk.groupChannel.markAsDelivered(channel.url);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
14
23
|
export function isDefaultCoverImage(coverUrl) {
|
|
15
24
|
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
16
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isDifferentChannel","a","b","url","
|
|
1
|
+
{"version":3,"names":["isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","confirmAndMarkAsRead","sdk","channels","channelUrls","filter","it","isGroupChannel","unreadMessageCount","map","groupChannel","markAsReadWithChannelUrls","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import type {\n SendbirdBaseChannel,\n SendbirdChannel,\n SendbirdChatSDK,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n} from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\n};\n\nexport const confirmAndMarkAsRead = async (sdk: SendbirdChatSDK, channels: SendbirdBaseChannel[]) => {\n const channelUrls = channels.filter((it) => it.isGroupChannel() && it.unreadMessageCount > 0).map((it) => it.url);\n await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);\n};\n\nexport const confirmAndMarkAsDelivered = async (sdk: SendbirdChatSDK, channel: SendbirdBaseChannel) => {\n if (channel.isGroupChannel() && channel.unreadMessageCount > 0) {\n await sdk.groupChannel.markAsDelivered(channel.url);\n }\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":"AAQA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,6BAA6B,GAAIC,OAAD,IAAmC;EAC9E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;AAIP,OAAO,MAAMC,oBAAoB,GAAG,OAAOC,GAAP,EAA6BC,QAA7B,KAAiE;EACnG,MAAMC,WAAW,GAAGD,QAAQ,CAACE,MAAT,CAAiBC,EAAD,IAAQA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAAvE,EAA0EC,GAA1E,CAA+EH,EAAD,IAAQA,EAAE,CAACX,GAAzF,CAApB;EACA,MAAMO,GAAG,CAACQ,YAAJ,CAAiBC,yBAAjB,CAA2CP,WAA3C,CAAN;AACD,CAHM;AAKP,OAAO,MAAMQ,yBAAyB,GAAG,OAAOV,GAAP,EAA6BL,OAA7B,KAA8D;EACrG,IAAIA,OAAO,CAACU,cAAR,MAA4BV,OAAO,CAACW,kBAAR,GAA6B,CAA7D,EAAgE;IAC9D,MAAMN,GAAG,CAACQ,YAAJ,CAAiBG,eAAjB,CAAiChB,OAAO,CAACF,GAAzC,CAAN;EACD;AACF,CAJM;AAMP,OAAO,SAASmB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BpB,OAA7B,EAA4DqB,aAA5D,EAAoF;EACzF,OAAOrB,OAAO,CAACsB,OAAR,CAAgBd,MAAhB,CAAwBe,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaH,aAA3C,CAAP;AACD;AAED,OAAO,SAASI,gBAAT,CAA0BnB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACE,MAAT,CAAiBkB,CAAD,IAAkCA,CAAC,CAAChB,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASiB,eAAT,CAAyBrB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACE,MAAT,CAAiBkB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD"}
|
|
@@ -5,11 +5,14 @@ export function isNewMessage(msg, currentUserId) {
|
|
|
5
5
|
if (msg.isAdminMessage()) return false;
|
|
6
6
|
return msg.updatedAt === 0;
|
|
7
7
|
}
|
|
8
|
+
export function isSendableMessage(msg) {
|
|
9
|
+
return msg !== undefined && msg !== null && 'sendingStatus' in msg;
|
|
10
|
+
}
|
|
8
11
|
export function isMyMessage(msg) {
|
|
9
12
|
var _msg$sender;
|
|
10
13
|
|
|
11
14
|
let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
|
|
12
|
-
if (!msg) return false;
|
|
15
|
+
if (!isSendableMessage(msg)) return false;
|
|
13
16
|
return 'sender' in msg && ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId || msg.sendingStatus === 'pending' || msg.sendingStatus === 'failed' || msg.sendingStatus === 'canceled';
|
|
14
17
|
}
|
|
15
18
|
export function messageKeyExtractor(message) {
|
|
@@ -26,8 +29,8 @@ export function messageKeyExtractor(message) {
|
|
|
26
29
|
export function messageComparator(a, b) {
|
|
27
30
|
let aStatusOffset = 0;
|
|
28
31
|
let bStatusOffset = 0;
|
|
29
|
-
if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
30
|
-
if (b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
32
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
33
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
31
34
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
32
35
|
}
|
|
33
36
|
export function hasSameSender(a, b) {
|
|
@@ -70,7 +73,7 @@ export function getMessageUniqId(msg) {
|
|
|
70
73
|
return String(msg.messageId);
|
|
71
74
|
}
|
|
72
75
|
export function getAvailableUriFromFileMessage(message) {
|
|
73
|
-
if (!message.url && message.messageParams && 'uri' in message.messageParams.file) {
|
|
76
|
+
if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {
|
|
74
77
|
return message.messageParams.file.uri;
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["messageTime","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"names":["messageTime","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type {\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdSendableMessage,\n} from '../types';\nimport { messageTime } 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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(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"],"mappings":"AAOA,SAASA,WAAT,QAA4B,qBAA5B;AAEA,OAAO,SAASC,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAD,EAAMC,aAAN,CAA7B;EACA,IAAIC,SAAJ,EAAe,OAAO,KAAP;EACf,IAAIF,GAAG,CAACI,cAAJ,EAAJ,EAA0B,OAAO,KAAP;EAC1B,OAAOJ,GAAG,CAACK,SAAJ,KAAkB,CAAzB;AACD;AAED,OAAO,SAASC,iBAAT,CAA2BN,GAA3B,EAAyF;EAC9F,OAAOA,GAAG,KAAKO,SAAR,IAAqBP,GAAG,KAAK,IAA7B,IAAqC,mBAAmBA,GAA/D;AACD;AAED,OAAO,SAASG,WAAT,CAAqBH,GAArB,EAAsG;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EAC3G,IAAI,CAACK,iBAAiB,CAACN,GAAD,CAAtB,EAA6B,OAAO,KAAP;EAC7B,OACG,YAAYA,GAAZ,IAAmB,gBAAAA,GAAG,CAACQ,MAAJ,4DAAYC,MAAZ,MAAuBR,aAA3C,IACAD,GAAG,CAACU,aAAJ,KAAsB,SADtB,IAEAV,GAAG,CAACU,aAAJ,KAAsB,QAFtB,IAGAV,GAAG,CAACU,aAAJ,KAAsB,UAJxB;AAMD;AAED,OAAO,SAASC,mBAAT,CAA6BC,OAA7B,EAA+D;EACpE,OAAOC,gBAAgB,CAACD,OAAD,CAAvB;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,iBA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,CAAgCC,WAAhC,EAEmC;EACxC,IAAI,CAACA,WAAL,EAAkB,OAAO,KAAP;EAClB,OAAOC,OAAO,CAACD,WAAW,CAAC,UAAD,CAAZ,CAAd;AACD;AAED,OAAO,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["arrayToMap","arr","selector","fallbackSelector","combine","reduce","accum","curr","_key","arrayToMapWithGetter","getSelector"],"sources":["arrayToMap.ts"],"sourcesContent":["import type { FilterByValueType } from '../types';\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: keyof FilterByValueType<T, string | number>,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n fallbackSelector: K,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n selector2: string,\n combineKey: true,\n): Record<string, T>;\n\n/**\n * Convert Array of the object to Object\n * @param {object[]} arr\n * @param {keyof object} selector\n * @param {keyof object} [fallbackSelector]\n * @param {boolean} [combine]\n * @returns {Record<keyof object, object>}\n * @example\n * ```\n * const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];\n * const obj = arrayToMap(arr, 'name');\n *\n * console.log(obj);\n * // {\n * // 'john': {name: 'john'},\n * // 'chris': {name: 'chris'},\n * // 'sravan': {name: 'sravan'},\n * // 'hoon': {name: 'hoon'}\n * // }\n * ```\n * */\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: K,\n fallbackSelector?: K,\n combine?: boolean,\n) {\n return arr.reduce((accum, curr) => {\n if (combine && fallbackSelector) {\n const _key = curr[selector] + (curr[fallbackSelector] as string);\n accum[_key] = curr;\n } else {\n const _key = (curr[selector] || curr[fallbackSelector as K]) as string;\n accum[_key] = curr;\n }\n\n return accum;\n }, {} as Record<string, T>);\n}\n\nexport function arrayToMapWithGetter<T
|
|
1
|
+
{"version":3,"names":["arrayToMap","arr","selector","fallbackSelector","combine","reduce","accum","curr","_key","arrayToMapWithGetter","getSelector"],"sources":["arrayToMap.ts"],"sourcesContent":["import type { FilterByValueType } from '../types';\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: keyof FilterByValueType<T, string | number>,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n fallbackSelector: K,\n): Record<string, T>;\n\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: string,\n selector2: string,\n combineKey: true,\n): Record<string, T>;\n\n/**\n * Convert Array of the object to Object\n * @param {object[]} arr\n * @param {keyof object} selector\n * @param {keyof object} [fallbackSelector]\n * @param {boolean} [combine]\n * @returns {Record<keyof object, object>}\n * @example\n * ```\n * const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];\n * const obj = arrayToMap(arr, 'name');\n *\n * console.log(obj);\n * // {\n * // 'john': {name: 'john'},\n * // 'chris': {name: 'chris'},\n * // 'sravan': {name: 'sravan'},\n * // 'hoon': {name: 'hoon'}\n * // }\n * ```\n * */\nexport default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n selector: K,\n fallbackSelector?: K,\n combine?: boolean,\n) {\n return arr.reduce((accum, curr) => {\n if (combine && fallbackSelector) {\n const _key = curr[selector] + (curr[fallbackSelector] as string);\n accum[_key] = curr;\n } else {\n const _key = (curr[selector] || curr[fallbackSelector as K]) as string;\n accum[_key] = curr;\n }\n\n return accum;\n }, {} as Record<string, T>);\n}\n\nexport function arrayToMapWithGetter<T>(arr: T[], getSelector: (item: T) => string) {\n return arr.reduce((accum, curr) => {\n const _key = getSelector(curr);\n accum[_key] = curr;\n return accum;\n }, {} as Record<string, T>);\n}\n"],"mappings":"AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,UAAT,CACbC,GADa,EAEbC,QAFa,EAGbC,gBAHa,EAIbC,OAJa,EAKb;EACA,OAAOH,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,IAAIH,OAAO,IAAID,gBAAf,EAAiC;MAC/B,MAAMK,IAAI,GAAGD,IAAI,CAACL,QAAD,CAAJ,GAAkBK,IAAI,CAACJ,gBAAD,CAAnC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD,CAHD,MAGO;MACL,MAAMC,IAAI,GAAID,IAAI,CAACL,QAAD,CAAJ,IAAkBK,IAAI,CAACJ,gBAAD,CAApC;;MACAG,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACD;;IAED,OAAOD,KAAP;EACD,CAVM,EAUJ,EAVI,CAAP;AAWD;AAED,OAAO,SAASG,oBAAT,CAAiCR,GAAjC,EAA2CS,WAA3C,EAA6E;EAClF,OAAOT,GAAG,CAACI,MAAJ,CAAW,CAACC,KAAD,EAAQC,IAAR,KAAiB;IACjC,MAAMC,IAAI,GAAGE,WAAW,CAACH,IAAD,CAAxB;;IACAD,KAAK,CAACE,IAAD,CAAL,GAAcD,IAAd;IACA,OAAOD,KAAP;EACD,CAJM,EAIJ,EAJI,CAAP;AAKD"}
|
package/lib/module/types.js
CHANGED
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';\nimport type
|
|
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 { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nimport './';\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 SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdMember = Member;\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":"AAAA;;AAEA;AA6BA,OAAO,IAAP"}
|
|
@@ -54,6 +54,14 @@ export const getGroupChannelLastMessage = function (channel) {
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
if (message.isUserMessage()) {
|
|
58
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (message.isAdminMessage()) {
|
|
62
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return EMPTY_MESSAGE;
|
|
58
66
|
};
|
|
59
67
|
//# sourceMappingURL=groupChannel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["format","isToday","isYesterday","truncate","getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","maxLen"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\nimport isToday from 'date-fns/isToday';\nimport isYesterday from 'date-fns/isYesterday';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { truncate } 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 const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n return format(timestamp, 'MMM dd', { locale });\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\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 truncate(file, { maxLen: MAX_LEN }) + ext;\n }\n\n return truncate(message.name, { maxLen: MAX_LEN });\n }\n\n return message.message ?? EMPTY_MESSAGE;\n};\n"],"mappings":"AACA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AAGA,SAASC,QAAT,QAAyB,UAAzB;AAEA,OAAO,MAAMC,oBAAoB,GAAG,UAClCC,aADkC,EAElCC,OAFkC,EAM/B;EAAA,IAHHC,cAGG,uEAHc,WAGd;EAAA,IAFHC,UAEG,uEAFU,cAEV;EAAA,IADHC,oBACG,uEADoB,eACpB;EACH,IAAIH,OAAO,CAACI,IAAR,KAAiBD,oBAAjB,IAAyCH,OAAO,CAACI,IAAR,KAAiB,EAA9D,EAAkE,OAAOJ,OAAO,CAACI,IAAf;EAClE,IAAIJ,OAAO,CAACK,WAAR,KAAwB,CAA5B,EAA+B,OAAOH,UAAP;EAC/B,OAAOF,OAAO,CAACM,OAAR,CACJC,MADI,CACG;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAgBA,MAAM,KAAKT,aAA3B;EAAA,CADH,EAEJU,GAFI,CAEA;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAkBA,QAAQ,IAAIT,cAA9B;EAAA,CAFA,EAGJU,IAHI,CAGC,IAHD,CAAP;AAID,CA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Af,CAAf;EACD;;EAED,
|
|
1
|
+
{"version":3,"names":["format","isToday","isYesterday","truncate","getGroupChannelTitle","currentUserId","channel","EMPTY_USERNAME","NO_MEMBERS","DEFAULT_CHANNEL_NAME","name","memberCount","members","filter","userId","map","nickname","join","getGroupChannelPreviewTime","locale","timestamp","lastMessage","createdAt","joinedAt","getGroupChannelLastMessage","EMPTY_MESSAGE","MAX_LEN","message","isFileMessage","extIdx","lastIndexOf","file","slice","ext","maxLen","isUserMessage","isAdminMessage"],"sources":["groupChannel.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport format from 'date-fns/format';\nimport isToday from 'date-fns/isToday';\nimport isYesterday from 'date-fns/isYesterday';\n\nimport type { SendbirdGroupChannel } from '../types';\nimport { truncate } 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 const timestamp = channel.lastMessage?.createdAt || channel.joinedAt * 1000 || channel.createdAt;\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n return format(timestamp, 'MMM dd', { locale });\n};\n\nexport const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_MESSAGE = '', MAX_LEN = 15) => {\n const message = channel.lastMessage;\n if (!message) return EMPTY_MESSAGE;\n\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 truncate(file, { maxLen: MAX_LEN }) + ext;\n }\n\n return truncate(message.name, { maxLen: MAX_LEN });\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"],"mappings":"AACA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,OAAOC,OAAP,MAAoB,kBAApB;AACA,OAAOC,WAAP,MAAwB,sBAAxB;AAGA,SAASC,QAAT,QAAyB,UAAzB;AAEA,OAAO,MAAMC,oBAAoB,GAAG,UAClCC,aADkC,EAElCC,OAFkC,EAM/B;EAAA,IAHHC,cAGG,uEAHc,WAGd;EAAA,IAFHC,UAEG,uEAFU,cAEV;EAAA,IADHC,oBACG,uEADoB,eACpB;EACH,IAAIH,OAAO,CAACI,IAAR,KAAiBD,oBAAjB,IAAyCH,OAAO,CAACI,IAAR,KAAiB,EAA9D,EAAkE,OAAOJ,OAAO,CAACI,IAAf;EAClE,IAAIJ,OAAO,CAACK,WAAR,KAAwB,CAA5B,EAA+B,OAAOH,UAAP;EAC/B,OAAOF,OAAO,CAACM,OAAR,CACJC,MADI,CACG;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAgBA,MAAM,KAAKT,aAA3B;EAAA,CADH,EAEJU,GAFI,CAEA;IAAA,IAAC;MAAEC;IAAF,CAAD;IAAA,OAAkBA,QAAQ,IAAIT,cAA9B;EAAA,CAFA,EAGJU,IAHI,CAGC,IAHD,CAAP;AAID,CAbM;AAeP,OAAO,MAAMC,0BAA0B,GAAG,CAACZ,OAAD,EAAgCa,MAAhC,KAAoD;EAAA;;EAC5F,MAAMC,SAAS,GAAG,yBAAAd,OAAO,CAACe,WAAR,8EAAqBC,SAArB,KAAkChB,OAAO,CAACiB,QAAR,GAAmB,IAArD,IAA6DjB,OAAO,CAACgB,SAAvF;EACA,IAAIrB,OAAO,CAACmB,SAAD,CAAX,EAAwB,OAAOpB,MAAM,CAACoB,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
|
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
4
|
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
|
-
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, } from './shared/regex';
|
|
5
|
+
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, } from './shared/regex';
|
|
6
6
|
export * from './hooks';
|
|
7
7
|
export * from './ui-format/groupChannel';
|
|
8
8
|
export * from './ui-format/common';
|
|
@@ -13,4 +13,4 @@ export declare const NOOP: () => void;
|
|
|
13
13
|
export declare const ASYNC_NOOP: () => Promise<undefined>;
|
|
14
14
|
export declare const PASS: <T>(val: T) => T;
|
|
15
15
|
export declare const toMegabyte: (byte: number) => number;
|
|
16
|
-
export type { FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage,
|
|
16
|
+
export type { FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, SendbirdMessage, SendbirdChatSDK, SendbirdChannel, SendbirdBaseChannel, SendbirdGroupChannel, SendbirdOpenChannel, SendbirdUser, SendbirdMember, SendbirdBaseMessage, SendbirdUserMessage, SendbirdFileMessage, SendbirdAdminMessage, SendbirdGroupChannelCreateParams, SendbirdFileMessageCreateParams, SendbirdUserMessageCreateParams, SendbirdError, SendbirdMessageCollection, SendbirdGroupChannelCollection, NotificationFiles, NotificationMentionedUsers, NotificationTranslations, PartialNullable, SendbirdDataPayload, SendbirdPreviousMessageListQuery, SendbirdSendableMessage, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, } from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
|
|
1
|
+
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdChatSDK, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Diff utils for channel
|
|
4
4
|
* @param {SendbirdBaseChannel} [a]
|
|
@@ -6,8 +6,10 @@ import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, Sendbi
|
|
|
6
6
|
* @returns {boolean}
|
|
7
7
|
* */
|
|
8
8
|
export declare function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const isGroupChannelChatUnavailable: (channel: SendbirdGroupChannel) => boolean;
|
|
10
|
+
export declare const confirmAndMarkAsRead: (sdk: SendbirdChatSDK, channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
11
|
+
export declare const confirmAndMarkAsDelivered: (sdk: SendbirdChatSDK, channel: SendbirdBaseChannel) => Promise<void>;
|
|
10
12
|
export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
11
|
-
export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("sendbird").Member[];
|
|
13
|
+
export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("@sendbird/chat/groupChannel").Member[];
|
|
12
14
|
export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
|
|
13
15
|
export declare function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[];
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';
|
|
1
|
+
import type { SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage, SendbirdSendableMessage } from '../types';
|
|
2
2
|
export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
3
|
+
export declare function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage;
|
|
3
4
|
export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string): boolean;
|
|
4
5
|
export declare function messageKeyExtractor(message: SendbirdMessage): string;
|
|
5
|
-
export declare function messageComparator
|
|
6
|
+
export declare function messageComparator(a: SendbirdMessage, b: SendbirdMessage): number;
|
|
6
7
|
export declare function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage): boolean;
|
|
7
8
|
export declare function calcMessageGrouping(groupEnabled: boolean, curr: SendbirdMessage, prev?: SendbirdMessage, next?: SendbirdMessage): {
|
|
8
9
|
groupWithPrev: boolean;
|
|
9
10
|
groupWithNext: boolean;
|
|
10
11
|
};
|
|
11
|
-
export declare function getMessageUniqId(msg:
|
|
12
|
+
export declare function getMessageUniqId(msg: SendbirdBaseMessage): string;
|
|
12
13
|
export declare function getAvailableUriFromFileMessage(message: SendbirdFileMessage): string;
|
|
13
14
|
declare type RawSendbirdDataPayload = {
|
|
14
15
|
sendbird: string | object;
|
|
@@ -2,4 +2,4 @@ import type { FilterByValueType } from '../types';
|
|
|
2
2
|
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: keyof FilterByValueType<T, string | number>): Record<string, T>;
|
|
3
3
|
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: string, fallbackSelector: K): Record<string, T>;
|
|
4
4
|
export default function arrayToMap<T extends Record<K, unknown>, K extends keyof T = keyof T>(arr: T[], selector: string, selector2: string, combineKey: true): Record<string, T>;
|
|
5
|
-
export declare function arrayToMapWithGetter<T
|
|
5
|
+
export declare function arrayToMapWithGetter<T>(arr: T[], getSelector: (item: T) => string): Record<string, T>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import type SendbirdChat from '@sendbird/chat';
|
|
3
|
+
import type { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
4
|
+
import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
|
|
5
|
+
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
|
+
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
7
|
+
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
8
|
+
import './';
|
|
3
9
|
export declare type FilterByValueType<T extends object, Type> = {
|
|
4
10
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
5
11
|
};
|
|
@@ -13,24 +19,31 @@ export declare type PartialNullable<T> = {
|
|
|
13
19
|
};
|
|
14
20
|
export declare type Optional<T> = T | undefined;
|
|
15
21
|
export declare type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
16
|
-
export declare type SendbirdChatSDK =
|
|
17
|
-
export declare type SendbirdMessage =
|
|
18
|
-
export declare type SendbirdChannel =
|
|
19
|
-
export declare type SendbirdUserMessage =
|
|
20
|
-
export declare type SendbirdFileMessage =
|
|
21
|
-
export declare type SendbirdAdminMessage =
|
|
22
|
-
export declare type SendbirdBaseMessage =
|
|
23
|
-
export declare type
|
|
24
|
-
export declare type
|
|
25
|
-
export declare type
|
|
26
|
-
export declare type
|
|
27
|
-
export declare type
|
|
28
|
-
export declare type
|
|
29
|
-
export declare type
|
|
30
|
-
export declare type
|
|
31
|
-
export declare type
|
|
32
|
-
export declare type
|
|
33
|
-
export declare type
|
|
22
|
+
export declare type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
|
|
23
|
+
export declare type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
|
|
24
|
+
export declare type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
|
|
25
|
+
export declare type SendbirdUserMessage = UserMessage;
|
|
26
|
+
export declare type SendbirdFileMessage = FileMessage;
|
|
27
|
+
export declare type SendbirdAdminMessage = AdminMessage;
|
|
28
|
+
export declare type SendbirdBaseMessage = BaseMessage;
|
|
29
|
+
export declare type SendbirdSendableMessage = SendableMessage;
|
|
30
|
+
export declare type SendbirdFileMessageCreateParams = FileMessageCreateParams;
|
|
31
|
+
export declare type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;
|
|
32
|
+
export declare type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
33
|
+
export declare type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
34
|
+
export declare type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
35
|
+
export declare type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
36
|
+
export declare type SendbirdUserUpdateParams = UserUpdateParams;
|
|
37
|
+
export declare type SendbirdUser = User;
|
|
38
|
+
export declare type SendbirdMember = Member;
|
|
39
|
+
export declare type SendbirdGroupChannel = GroupChannel;
|
|
40
|
+
export declare type SendbirdBaseChannel = BaseChannel;
|
|
41
|
+
export declare type SendbirdOpenChannel = OpenChannel;
|
|
42
|
+
export declare type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
43
|
+
export declare type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
44
|
+
export declare type SendbirdMessageCollection = MessageCollection;
|
|
45
|
+
export declare type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
46
|
+
export declare type SendbirdError = SBError;
|
|
34
47
|
export interface SendbirdDataPayload {
|
|
35
48
|
app_id: string;
|
|
36
49
|
audience_type: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/react": "*",
|
|
46
46
|
"react": "17.0.2",
|
|
47
|
-
"react-native": "0.
|
|
47
|
+
"react-native": "0.67.4",
|
|
48
48
|
"react-native-builder-bob": "^0.18.0",
|
|
49
49
|
"typescript": "^4.1.3"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"@sendbird/chat": "^4.0.13",
|
|
53
|
+
"react": ">=16.13.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
|
-
"sendbird": {
|
|
56
|
+
"@sendbird/chat": {
|
|
57
57
|
"optional": true
|
|
58
58
|
}
|
|
59
59
|
},
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"readmeFile": "./README.md",
|
|
77
77
|
"displayName": "@sendbird/uikit-utils"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "955f7adf0891976d8553d9c3b4c171225c775bc9"
|
|
80
80
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -58,8 +58,6 @@ export const useIsMountedRef = () => {
|
|
|
58
58
|
|
|
59
59
|
export const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {
|
|
60
60
|
const ref = useRef<T>(callback);
|
|
61
|
-
|
|
62
|
-
ref.current = callback;
|
|
63
|
-
});
|
|
61
|
+
ref.current = callback;
|
|
64
62
|
return useCallback(((...args) => ref.current(...args)) as T, []);
|
|
65
63
|
};
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,9 @@ export {
|
|
|
12
12
|
getFileType,
|
|
13
13
|
getFileExtension,
|
|
14
14
|
replaceUrlAsComponents,
|
|
15
|
+
normalizeFileName,
|
|
16
|
+
emailRegex,
|
|
17
|
+
phoneRegex,
|
|
15
18
|
} from './shared/regex';
|
|
16
19
|
|
|
17
20
|
export * from './hooks';
|
|
@@ -45,9 +48,9 @@ export type {
|
|
|
45
48
|
SendbirdUserMessage,
|
|
46
49
|
SendbirdFileMessage,
|
|
47
50
|
SendbirdAdminMessage,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
SendbirdGroupChannelCreateParams,
|
|
52
|
+
SendbirdFileMessageCreateParams,
|
|
53
|
+
SendbirdUserMessageCreateParams,
|
|
51
54
|
SendbirdError,
|
|
52
55
|
SendbirdMessageCollection,
|
|
53
56
|
SendbirdGroupChannelCollection,
|
|
@@ -56,4 +59,11 @@ export type {
|
|
|
56
59
|
NotificationTranslations,
|
|
57
60
|
PartialNullable,
|
|
58
61
|
SendbirdDataPayload,
|
|
62
|
+
SendbirdPreviousMessageListQuery,
|
|
63
|
+
SendbirdSendableMessage,
|
|
64
|
+
SendbirdGroupChannelListQuery,
|
|
65
|
+
SendbirdGroupChannelUpdateParams,
|
|
66
|
+
SendbirdUserMessageUpdateParams,
|
|
67
|
+
SendbirdFileMessageUpdateParams,
|
|
68
|
+
SendbirdUserUpdateParams,
|
|
59
69
|
} from './types';
|
package/src/sendbird/channel.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
SendbirdBaseChannel,
|
|
3
|
+
SendbirdChannel,
|
|
4
|
+
SendbirdChatSDK,
|
|
5
|
+
SendbirdGroupChannel,
|
|
6
|
+
SendbirdOpenChannel,
|
|
7
|
+
} from '../types';
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Diff utils for channel
|
|
@@ -11,10 +17,21 @@ export function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T):
|
|
|
11
17
|
return a.url !== b.url;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
export const
|
|
20
|
+
export const isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {
|
|
15
21
|
return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');
|
|
16
22
|
};
|
|
17
23
|
|
|
24
|
+
export const confirmAndMarkAsRead = async (sdk: SendbirdChatSDK, channels: SendbirdBaseChannel[]) => {
|
|
25
|
+
const channelUrls = channels.filter((it) => it.isGroupChannel() && it.unreadMessageCount > 0).map((it) => it.url);
|
|
26
|
+
await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const confirmAndMarkAsDelivered = async (sdk: SendbirdChatSDK, channel: SendbirdBaseChannel) => {
|
|
30
|
+
if (channel.isGroupChannel() && channel.unreadMessageCount > 0) {
|
|
31
|
+
await sdk.groupChannel.markAsDelivered(channel.url);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
18
35
|
export function isDefaultCoverImage(coverUrl: string) {
|
|
19
36
|
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
20
37
|
}
|
package/src/sendbird/message.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
SendbirdBaseMessage,
|
|
3
|
+
SendbirdDataPayload,
|
|
4
|
+
SendbirdFileMessage,
|
|
5
|
+
SendbirdMessage,
|
|
6
|
+
SendbirdSendableMessage,
|
|
7
|
+
} from '../types';
|
|
2
8
|
import { messageTime } from '../ui-format/common';
|
|
3
9
|
|
|
4
10
|
export function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {
|
|
@@ -8,8 +14,12 @@ export function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {
|
|
|
8
14
|
return msg.updatedAt === 0;
|
|
9
15
|
}
|
|
10
16
|
|
|
17
|
+
export function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {
|
|
18
|
+
return msg !== undefined && msg !== null && 'sendingStatus' in msg;
|
|
19
|
+
}
|
|
20
|
+
|
|
11
21
|
export function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {
|
|
12
|
-
if (!msg) return false;
|
|
22
|
+
if (!isSendableMessage(msg)) return false;
|
|
13
23
|
return (
|
|
14
24
|
('sender' in msg && msg.sender?.userId === currentUserId) ||
|
|
15
25
|
msg.sendingStatus === 'pending' ||
|
|
@@ -30,12 +40,12 @@ export function messageKeyExtractor(message: SendbirdMessage): string {
|
|
|
30
40
|
// | failed | timestamp(A) | 0 | ? |
|
|
31
41
|
// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |
|
|
32
42
|
// |-------------------|-------------------|-----------------|-------------------|
|
|
33
|
-
export function messageComparator
|
|
43
|
+
export function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {
|
|
34
44
|
let aStatusOffset = 0;
|
|
35
45
|
let bStatusOffset = 0;
|
|
36
46
|
|
|
37
|
-
if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
38
|
-
if (b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
47
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
48
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
39
49
|
|
|
40
50
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
41
51
|
}
|
|
@@ -73,7 +83,7 @@ export function calcMessageGrouping(
|
|
|
73
83
|
return { groupWithPrev: getPrev(), groupWithNext: getNext() };
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
export function getMessageUniqId(msg:
|
|
86
|
+
export function getMessageUniqId(msg: SendbirdBaseMessage) {
|
|
77
87
|
if (msg.isUserMessage() || msg.isFileMessage()) {
|
|
78
88
|
if (msg.sendingStatus === 'succeeded') return String(msg.messageId);
|
|
79
89
|
return msg.reqId;
|
|
@@ -83,7 +93,7 @@ export function getMessageUniqId(msg: SendbirdMessage) {
|
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
export function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {
|
|
86
|
-
if (!message.url && message.messageParams && 'uri' in message.messageParams.file) {
|
|
96
|
+
if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {
|
|
87
97
|
return message.messageParams.file.uri;
|
|
88
98
|
}
|
|
89
99
|
return message.url;
|
package/src/shared/arrayToMap.ts
CHANGED
|
@@ -58,10 +58,7 @@ export default function arrayToMap<T extends Record<K, unknown>, K extends keyof
|
|
|
58
58
|
}, {} as Record<string, T>);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export function arrayToMapWithGetter<T
|
|
62
|
-
arr: T[],
|
|
63
|
-
getSelector: (item: T) => string,
|
|
64
|
-
) {
|
|
61
|
+
export function arrayToMapWithGetter<T>(arr: T[], getSelector: (item: T) => string) {
|
|
65
62
|
return arr.reduce((accum, curr) => {
|
|
66
63
|
const _key = getSelector(curr);
|
|
67
64
|
accum[_key] = curr;
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
4
4
|
import type React from 'react';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import type SendbirdChat from '@sendbird/chat';
|
|
7
|
+
import type { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
8
|
+
import type {
|
|
9
|
+
GroupChannel,
|
|
10
|
+
GroupChannelCollection,
|
|
11
|
+
GroupChannelCreateParams,
|
|
12
|
+
GroupChannelListQuery,
|
|
13
|
+
GroupChannelModule,
|
|
14
|
+
GroupChannelUpdateParams,
|
|
15
|
+
Member,
|
|
16
|
+
MessageCollection,
|
|
17
|
+
} from '@sendbird/chat/groupChannel';
|
|
18
|
+
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
19
|
+
import type {
|
|
20
|
+
AdminMessage,
|
|
21
|
+
BaseMessage,
|
|
22
|
+
FileMessage,
|
|
23
|
+
FileMessageCreateParams,
|
|
24
|
+
FileMessageUpdateParams,
|
|
25
|
+
PreviousMessageListQuery,
|
|
26
|
+
UserMessage,
|
|
27
|
+
UserMessageCreateParams,
|
|
28
|
+
UserMessageUpdateParams,
|
|
29
|
+
} from '@sendbird/chat/message';
|
|
30
|
+
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
31
|
+
|
|
32
|
+
import './';
|
|
6
33
|
|
|
7
34
|
export type FilterByValueType<T extends object, Type> = {
|
|
8
35
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
@@ -30,29 +57,33 @@ export type Optional<T> = T | undefined;
|
|
|
30
57
|
|
|
31
58
|
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
32
59
|
|
|
33
|
-
|
|
34
|
-
export type
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export type
|
|
41
|
-
export type
|
|
42
|
-
export type
|
|
43
|
-
export type
|
|
44
|
-
export type
|
|
45
|
-
export type
|
|
46
|
-
export type
|
|
47
|
-
export type
|
|
48
|
-
export type
|
|
49
|
-
export type
|
|
50
|
-
export type
|
|
51
|
-
export type
|
|
52
|
-
export type
|
|
53
|
-
|
|
54
|
-
export type SendbirdGroupChannelCollection =
|
|
55
|
-
export type
|
|
60
|
+
export type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;
|
|
61
|
+
export type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;
|
|
62
|
+
export type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;
|
|
63
|
+
export type SendbirdUserMessage = UserMessage;
|
|
64
|
+
export type SendbirdFileMessage = FileMessage;
|
|
65
|
+
export type SendbirdAdminMessage = AdminMessage;
|
|
66
|
+
export type SendbirdBaseMessage = BaseMessage;
|
|
67
|
+
export type SendbirdSendableMessage = SendableMessage;
|
|
68
|
+
export type SendbirdFileMessageCreateParams = FileMessageCreateParams;
|
|
69
|
+
export type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;
|
|
70
|
+
export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
71
|
+
export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
72
|
+
export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
73
|
+
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
74
|
+
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
75
|
+
export type SendbirdUser = User;
|
|
76
|
+
export type SendbirdMember = Member;
|
|
77
|
+
export type SendbirdGroupChannel = GroupChannel;
|
|
78
|
+
export type SendbirdBaseChannel = BaseChannel;
|
|
79
|
+
export type SendbirdOpenChannel = OpenChannel;
|
|
80
|
+
|
|
81
|
+
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
82
|
+
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
83
|
+
export type SendbirdMessageCollection = MessageCollection;
|
|
84
|
+
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
85
|
+
|
|
86
|
+
export type SendbirdError = SBError;
|
|
56
87
|
|
|
57
88
|
export interface SendbirdDataPayload {
|
|
58
89
|
app_id: string;
|
|
@@ -43,5 +43,13 @@ export const getGroupChannelLastMessage = (channel: SendbirdGroupChannel, EMPTY_
|
|
|
43
43
|
return truncate(message.name, { maxLen: MAX_LEN });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
if (message.isUserMessage()) {
|
|
47
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (message.isAdminMessage()) {
|
|
51
|
+
return message.message ?? EMPTY_MESSAGE;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return EMPTY_MESSAGE;
|
|
47
55
|
};
|