@sendbird/uikit-utils 1.0.1 → 1.0.2
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 +88 -0
- package/lib/commonjs/hooks/index.js.map +1 -0
- package/lib/commonjs/index.js +223 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/sendbird/attrs.js +57 -0
- package/lib/commonjs/sendbird/attrs.js.map +1 -0
- package/lib/commonjs/sendbird/channel.js +53 -0
- package/lib/commonjs/sendbird/channel.js.map +1 -0
- package/lib/commonjs/sendbird/message.js +111 -0
- package/lib/commonjs/sendbird/message.js.map +1 -0
- package/lib/commonjs/shared/arrayToMap.js +54 -0
- package/lib/commonjs/shared/arrayToMap.js.map +1 -0
- package/lib/commonjs/shared/conditionChaining.js +15 -0
- package/lib/commonjs/shared/conditionChaining.js.map +1 -0
- package/lib/commonjs/shared/logger.js +98 -0
- package/lib/commonjs/shared/logger.js.map +1 -0
- package/lib/commonjs/shared/pubsub.js +54 -0
- package/lib/commonjs/shared/pubsub.js.map +1 -0
- package/lib/commonjs/shared/regex.js +102 -0
- package/lib/commonjs/shared/regex.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/ui-format/common.js +106 -0
- package/lib/commonjs/ui-format/common.js.map +1 -0
- package/lib/commonjs/ui-format/groupChannel.js +80 -0
- package/lib/commonjs/ui-format/groupChannel.js.map +1 -0
- package/lib/module/hooks/index.js +60 -0
- package/lib/module/hooks/index.js.map +1 -0
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/sendbird/attrs.js +49 -0
- package/lib/module/sendbird/attrs.js.map +1 -0
- package/lib/module/sendbird/channel.js +36 -0
- package/lib/module/sendbird/channel.js.map +1 -0
- package/lib/module/sendbird/message.js +85 -0
- package/lib/module/sendbird/message.js.map +1 -0
- package/lib/module/shared/arrayToMap.js +45 -0
- package/lib/module/shared/arrayToMap.js.map +1 -0
- package/lib/module/shared/conditionChaining.js +7 -0
- package/lib/module/shared/conditionChaining.js.map +1 -0
- package/lib/module/shared/logger.js +90 -0
- package/lib/module/shared/logger.js.map +1 -0
- package/lib/module/shared/pubsub.js +45 -0
- package/lib/module/shared/pubsub.js.map +1 -0
- package/lib/module/shared/regex.js +78 -0
- package/lib/module/shared/regex.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/ui-format/common.js +85 -0
- package/lib/module/ui-format/common.js.map +1 -0
- package/lib/module/ui-format/groupChannel.js +59 -0
- package/lib/module/ui-format/groupChannel.js.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/sendbird/attrs.d.ts +43 -0
- package/lib/typescript/src/sendbird/channel.d.ts +18 -0
- package/lib/typescript/src/sendbird/message.d.ts +20 -0
- package/lib/typescript/src/shared/arrayToMap.d.ts +5 -0
- package/lib/typescript/src/shared/conditionChaining.d.ts +2 -0
- package/lib/typescript/src/shared/logger.d.ts +38 -0
- package/lib/typescript/src/shared/pubsub.d.ts +8 -0
- package/lib/typescript/src/shared/regex.d.ts +11 -0
- package/lib/typescript/src/types.d.ts +79 -0
- package/lib/typescript/src/ui-format/common.d.ts +43 -0
- package/lib/typescript/src/ui-format/groupChannel.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useUniqId = exports.useIsMountedRef = exports.useIIFE = exports.useFreshCallback = exports.useForceUpdate = exports.useAsyncLayoutEffect = exports.useAsyncEffect = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
+
const idPool = {};
|
|
12
|
+
|
|
13
|
+
const useUniqId = key => {
|
|
14
|
+
return (0, _react.useState)(() => {
|
|
15
|
+
if (!idPool[key]) idPool[key] = 1;
|
|
16
|
+
return idPool[key]++;
|
|
17
|
+
})[0];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.useUniqId = useUniqId;
|
|
21
|
+
|
|
22
|
+
const useForceUpdate = () => {
|
|
23
|
+
const [, updater] = (0, _react.useState)(0);
|
|
24
|
+
return (0, _react.useCallback)(() => updater(prev => prev + 1), []);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.useForceUpdate = useForceUpdate;
|
|
28
|
+
|
|
29
|
+
const useAsyncEffect = (asyncEffect, deps) => {
|
|
30
|
+
(0, _react.useEffect)(createAsyncEffectCallback(asyncEffect), deps);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.useAsyncEffect = useAsyncEffect;
|
|
34
|
+
|
|
35
|
+
const useAsyncLayoutEffect = (asyncEffect, deps) => {
|
|
36
|
+
(0, _react.useLayoutEffect)(createAsyncEffectCallback(asyncEffect), deps);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.useAsyncLayoutEffect = useAsyncLayoutEffect;
|
|
40
|
+
|
|
41
|
+
const useIIFE = callback => {
|
|
42
|
+
return iife(callback);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.useIIFE = useIIFE;
|
|
46
|
+
|
|
47
|
+
const iife = callback => callback();
|
|
48
|
+
|
|
49
|
+
const createAsyncEffectCallback = asyncEffect => () => {
|
|
50
|
+
const destructor = iife(asyncEffect);
|
|
51
|
+
return () => {
|
|
52
|
+
if (!destructor) return;
|
|
53
|
+
|
|
54
|
+
if (destructor instanceof Promise) {
|
|
55
|
+
iife(async () => {
|
|
56
|
+
const awaitedDestructor = await destructor;
|
|
57
|
+
if (awaitedDestructor) awaitedDestructor();
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
iife(destructor);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const useIsMountedRef = () => {
|
|
66
|
+
const isMounted = (0, _react.useRef)(true);
|
|
67
|
+
(0, _react.useEffect)(() => {
|
|
68
|
+
return () => {
|
|
69
|
+
isMounted.current = false;
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
return isMounted;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
exports.useIsMountedRef = useIsMountedRef;
|
|
76
|
+
|
|
77
|
+
const useFreshCallback = callback => {
|
|
78
|
+
const ref = (0, _react.useRef)(callback);
|
|
79
|
+
(0, _react.useLayoutEffect)(() => {
|
|
80
|
+
ref.current = callback;
|
|
81
|
+
});
|
|
82
|
+
return (0, _react.useCallback)(function () {
|
|
83
|
+
return ref.current(...arguments);
|
|
84
|
+
}, []);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
exports.useFreshCallback = useFreshCallback;
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 useLayoutEffect(() => {\n ref.current = callback;\n });\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/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AgB,MAAM;IACpBY,GAAG,CAACF,OAAJ,GAAcR,QAAd;EACD,CAFD;EAGA,OAAO,IAAAV,kBAAA,EAAa;IAAA,OAAaoB,GAAG,CAACF,OAAJ,CAAY,YAAZ,CAAb;EAAA,CAAb,EAAsD,EAAtD,CAAP;AACD,CANM"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
NOOP: true,
|
|
8
|
+
ASYNC_NOOP: true,
|
|
9
|
+
PASS: true,
|
|
10
|
+
Logger: true,
|
|
11
|
+
arrayToMap: true,
|
|
12
|
+
arrayToMapWithGetter: true,
|
|
13
|
+
createPubSub: true,
|
|
14
|
+
conditionChaining: true,
|
|
15
|
+
urlRegexStrict: true,
|
|
16
|
+
urlRegexRough: true,
|
|
17
|
+
newLineRegex: true,
|
|
18
|
+
audioExtRegex: true,
|
|
19
|
+
videoExtRegex: true,
|
|
20
|
+
imageExtRegex: true,
|
|
21
|
+
getFileType: true,
|
|
22
|
+
getFileExtension: true,
|
|
23
|
+
replaceUrlAsComponents: true
|
|
24
|
+
};
|
|
25
|
+
exports.ASYNC_NOOP = void 0;
|
|
26
|
+
Object.defineProperty(exports, "Logger", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _logger.Logger;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
exports.PASS = exports.NOOP = void 0;
|
|
33
|
+
Object.defineProperty(exports, "arrayToMap", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _arrayToMap.default;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "arrayToMapWithGetter", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return _arrayToMap.arrayToMapWithGetter;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "audioExtRegex", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () {
|
|
48
|
+
return _regex.audioExtRegex;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "conditionChaining", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _conditionChaining.default;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "createPubSub", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () {
|
|
60
|
+
return _pubsub.createPubSub;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "getFileExtension", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () {
|
|
66
|
+
return _regex.getFileExtension;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "getFileType", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () {
|
|
72
|
+
return _regex.getFileType;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "imageExtRegex", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () {
|
|
78
|
+
return _regex.imageExtRegex;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "newLineRegex", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () {
|
|
84
|
+
return _regex.newLineRegex;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "replaceUrlAsComponents", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _regex.replaceUrlAsComponents;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "urlRegexRough", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () {
|
|
96
|
+
return _regex.urlRegexRough;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "urlRegexStrict", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () {
|
|
102
|
+
return _regex.urlRegexStrict;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "videoExtRegex", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () {
|
|
108
|
+
return _regex.videoExtRegex;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
var _logger = require("./shared/logger");
|
|
113
|
+
|
|
114
|
+
var _arrayToMap = _interopRequireWildcard(require("./shared/arrayToMap"));
|
|
115
|
+
|
|
116
|
+
var _pubsub = require("./shared/pubsub");
|
|
117
|
+
|
|
118
|
+
var _conditionChaining = _interopRequireDefault(require("./shared/conditionChaining"));
|
|
119
|
+
|
|
120
|
+
var _regex = require("./shared/regex");
|
|
121
|
+
|
|
122
|
+
var _hooks = require("./hooks");
|
|
123
|
+
|
|
124
|
+
Object.keys(_hooks).forEach(function (key) {
|
|
125
|
+
if (key === "default" || key === "__esModule") return;
|
|
126
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
127
|
+
if (key in exports && exports[key] === _hooks[key]) return;
|
|
128
|
+
Object.defineProperty(exports, key, {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return _hooks[key];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
var _groupChannel = require("./ui-format/groupChannel");
|
|
137
|
+
|
|
138
|
+
Object.keys(_groupChannel).forEach(function (key) {
|
|
139
|
+
if (key === "default" || key === "__esModule") return;
|
|
140
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
141
|
+
if (key in exports && exports[key] === _groupChannel[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return _groupChannel[key];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
var _common = require("./ui-format/common");
|
|
151
|
+
|
|
152
|
+
Object.keys(_common).forEach(function (key) {
|
|
153
|
+
if (key === "default" || key === "__esModule") return;
|
|
154
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
155
|
+
if (key in exports && exports[key] === _common[key]) return;
|
|
156
|
+
Object.defineProperty(exports, key, {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return _common[key];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
var _channel = require("./sendbird/channel");
|
|
165
|
+
|
|
166
|
+
Object.keys(_channel).forEach(function (key) {
|
|
167
|
+
if (key === "default" || key === "__esModule") return;
|
|
168
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
169
|
+
if (key in exports && exports[key] === _channel[key]) return;
|
|
170
|
+
Object.defineProperty(exports, key, {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function () {
|
|
173
|
+
return _channel[key];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
var _message = require("./sendbird/message");
|
|
179
|
+
|
|
180
|
+
Object.keys(_message).forEach(function (key) {
|
|
181
|
+
if (key === "default" || key === "__esModule") return;
|
|
182
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
183
|
+
if (key in exports && exports[key] === _message[key]) return;
|
|
184
|
+
Object.defineProperty(exports, key, {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
get: function () {
|
|
187
|
+
return _message[key];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
var _attrs = require("./sendbird/attrs");
|
|
193
|
+
|
|
194
|
+
Object.keys(_attrs).forEach(function (key) {
|
|
195
|
+
if (key === "default" || key === "__esModule") return;
|
|
196
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
197
|
+
if (key in exports && exports[key] === _attrs[key]) return;
|
|
198
|
+
Object.defineProperty(exports, key, {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function () {
|
|
201
|
+
return _attrs[key];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
207
|
+
|
|
208
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
209
|
+
|
|
210
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
211
|
+
|
|
212
|
+
const NOOP = () => void 0;
|
|
213
|
+
|
|
214
|
+
exports.NOOP = NOOP;
|
|
215
|
+
|
|
216
|
+
const ASYNC_NOOP = async () => void 0;
|
|
217
|
+
|
|
218
|
+
exports.ASYNC_NOOP = ASYNC_NOOP;
|
|
219
|
+
|
|
220
|
+
const PASS = val => val;
|
|
221
|
+
|
|
222
|
+
exports.PASS = PASS;
|
|
223
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val"],"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 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 SendbirdGroupChannelParams,\n SendbirdFileMessageParams,\n SendbirdUserMessageParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAYA;;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"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PremiumFeatures = exports.ApplicationAttributes = void 0;
|
|
7
|
+
let ApplicationAttributes;
|
|
8
|
+
exports.ApplicationAttributes = ApplicationAttributes;
|
|
9
|
+
|
|
10
|
+
(function (ApplicationAttributes) {
|
|
11
|
+
ApplicationAttributes["reactions"] = "reactions";
|
|
12
|
+
ApplicationAttributes["message_search_v3"] = "message_search_v3";
|
|
13
|
+
ApplicationAttributes["enable_og_tag"] = "enable_og_tag";
|
|
14
|
+
ApplicationAttributes["use_last_seen_at"] = "use_last_seen_at";
|
|
15
|
+
ApplicationAttributes["enable_message_threading"] = "enable_message_threading";
|
|
16
|
+
ApplicationAttributes["allow_message_update_from_sdk"] = "allow_message_update_from_sdk";
|
|
17
|
+
ApplicationAttributes["allow_group_channel_create_from_sdk"] = "allow_group_channel_create_from_sdk";
|
|
18
|
+
ApplicationAttributes["allow_migration_api"] = "allow_migration_api";
|
|
19
|
+
ApplicationAttributes["allow_only_operator_sdk_to_update_group_channel_image"] = "allow_only_operator_sdk_to_update_group_channel_image";
|
|
20
|
+
ApplicationAttributes["allow_user_update_from_sdk"] = "allow_user_update_from_sdk";
|
|
21
|
+
ApplicationAttributes["allow_broadcast_channel"] = "allow_broadcast_channel";
|
|
22
|
+
ApplicationAttributes["allow_sdk_file_message_urls"] = "allow_sdk_file_message_urls";
|
|
23
|
+
ApplicationAttributes["allow_group_channel_leave_from_sdk"] = "allow_group_channel_leave_from_sdk";
|
|
24
|
+
ApplicationAttributes["allow_user_list_from_sdk"] = "allow_user_list_from_sdk";
|
|
25
|
+
ApplicationAttributes["allow_group_channel_invite_from_sdk"] = "allow_group_channel_invite_from_sdk";
|
|
26
|
+
ApplicationAttributes["allow_only_operator_sdk_to_update_group_channel_name"] = "allow_only_operator_sdk_to_update_group_channel_name";
|
|
27
|
+
ApplicationAttributes["allow_group_channel_update_from_sdk"] = "allow_group_channel_update_from_sdk";
|
|
28
|
+
ApplicationAttributes["allow_super_group_channel"] = "allow_super_group_channel";
|
|
29
|
+
ApplicationAttributes["allow_non_operators_to_mention_channel"] = "allow_non_operators_to_mention_channel";
|
|
30
|
+
ApplicationAttributes["allow_file_messages_from_sdk"] = "allow_file_messages_from_sdk";
|
|
31
|
+
ApplicationAttributes["allow_open_channel_create_from_sdk"] = "allow_open_channel_create_from_sdk";
|
|
32
|
+
ApplicationAttributes["allow_anonymous_message_update"] = "allow_anonymous_message_update";
|
|
33
|
+
ApplicationAttributes["allow_group_channel_delete_from_sdk"] = "allow_group_channel_delete_from_sdk";
|
|
34
|
+
ApplicationAttributes["allow_operators_to_ban_operators"] = "allow_operators_to_ban_operators";
|
|
35
|
+
ApplicationAttributes["allow_operators_to_edit_operators"] = "allow_operators_to_edit_operators";
|
|
36
|
+
})(ApplicationAttributes || (exports.ApplicationAttributes = ApplicationAttributes = {}));
|
|
37
|
+
|
|
38
|
+
let PremiumFeatures;
|
|
39
|
+
exports.PremiumFeatures = PremiumFeatures;
|
|
40
|
+
|
|
41
|
+
(function (PremiumFeatures) {
|
|
42
|
+
PremiumFeatures["reactions"] = "reactions";
|
|
43
|
+
PremiumFeatures["moderation_group"] = "moderation_group";
|
|
44
|
+
PremiumFeatures["message_search_v3"] = "message_search_v3";
|
|
45
|
+
PremiumFeatures["data_export"] = "data_export";
|
|
46
|
+
PremiumFeatures["migration"] = "migration";
|
|
47
|
+
PremiumFeatures["delivery_receipt"] = "delivery_receipt";
|
|
48
|
+
PremiumFeatures["auto_thumbnail"] = "auto_thumbnail";
|
|
49
|
+
PremiumFeatures["image_moderation"] = "image_moderation";
|
|
50
|
+
PremiumFeatures["super_group_channel"] = "super_group_channel";
|
|
51
|
+
PremiumFeatures["announcement"] = "announcement";
|
|
52
|
+
PremiumFeatures["moderation_open"] = "moderation_open";
|
|
53
|
+
PremiumFeatures["desk"] = "desk";
|
|
54
|
+
PremiumFeatures["bot_interface"] = "bot_interface";
|
|
55
|
+
PremiumFeatures["auto_trans"] = "auto_trans";
|
|
56
|
+
})(PremiumFeatures || (exports.PremiumFeatures = PremiumFeatures = {}));
|
|
57
|
+
//# sourceMappingURL=attrs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ApplicationAttributes","PremiumFeatures"],"sources":["attrs.ts"],"sourcesContent":["export enum ApplicationAttributes {\n reactions = 'reactions',\n message_search_v3 = 'message_search_v3',\n enable_og_tag = 'enable_og_tag',\n use_last_seen_at = 'use_last_seen_at',\n enable_message_threading = 'enable_message_threading',\n allow_message_update_from_sdk = 'allow_message_update_from_sdk',\n allow_group_channel_create_from_sdk = 'allow_group_channel_create_from_sdk',\n allow_migration_api = 'allow_migration_api',\n allow_only_operator_sdk_to_update_group_channel_image = 'allow_only_operator_sdk_to_update_group_channel_image',\n allow_user_update_from_sdk = 'allow_user_update_from_sdk',\n allow_broadcast_channel = 'allow_broadcast_channel',\n allow_sdk_file_message_urls = 'allow_sdk_file_message_urls',\n allow_group_channel_leave_from_sdk = 'allow_group_channel_leave_from_sdk',\n allow_user_list_from_sdk = 'allow_user_list_from_sdk',\n allow_group_channel_invite_from_sdk = 'allow_group_channel_invite_from_sdk',\n allow_only_operator_sdk_to_update_group_channel_name = 'allow_only_operator_sdk_to_update_group_channel_name',\n allow_group_channel_update_from_sdk = 'allow_group_channel_update_from_sdk',\n allow_super_group_channel = 'allow_super_group_channel',\n allow_non_operators_to_mention_channel = 'allow_non_operators_to_mention_channel',\n allow_file_messages_from_sdk = 'allow_file_messages_from_sdk',\n allow_open_channel_create_from_sdk = 'allow_open_channel_create_from_sdk',\n allow_anonymous_message_update = 'allow_anonymous_message_update',\n allow_group_channel_delete_from_sdk = 'allow_group_channel_delete_from_sdk',\n allow_operators_to_ban_operators = 'allow_operators_to_ban_operators',\n allow_operators_to_edit_operators = 'allow_operators_to_edit_operators',\n}\n\nexport enum PremiumFeatures {\n reactions = 'reactions',\n moderation_group = 'moderation_group',\n message_search_v3 = 'message_search_v3',\n data_export = 'data_export',\n migration = 'migration',\n delivery_receipt = 'delivery_receipt',\n auto_thumbnail = 'auto_thumbnail',\n image_moderation = 'image_moderation',\n super_group_channel = 'super_group_channel',\n announcement = 'announcement',\n moderation_open = 'moderation_open',\n desk = 'desk',\n bot_interface = 'bot_interface',\n auto_trans = 'auto_trans',\n}\n"],"mappings":";;;;;;IAAYA,qB;;;WAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;EAAAA,qB;GAAAA,qB,qCAAAA,qB;;IA4BAC,e;;;WAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;EAAAA,e;GAAAA,e,+BAAAA,e"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.channelComparator = channelComparator;
|
|
7
|
+
exports.getMembersExcludeMe = getMembersExcludeMe;
|
|
8
|
+
exports.groupChannelChatUnavailable = void 0;
|
|
9
|
+
exports.isDefaultCoverImage = isDefaultCoverImage;
|
|
10
|
+
exports.isDifferentChannel = isDifferentChannel;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default sort comparator for channel
|
|
14
|
+
* @param {SendbirdBaseChannel} a
|
|
15
|
+
* @param {SendbirdBaseChannel} b
|
|
16
|
+
* @returns {number}
|
|
17
|
+
* */
|
|
18
|
+
function channelComparator(a, b) {
|
|
19
|
+
if (a.isGroupChannel() && b.isGroupChannel()) {
|
|
20
|
+
var _b$lastMessage, _a$lastMessage;
|
|
21
|
+
|
|
22
|
+
return (((_b$lastMessage = b.lastMessage) === null || _b$lastMessage === void 0 ? void 0 : _b$lastMessage.createdAt) ?? b.createdAt) - (((_a$lastMessage = a.lastMessage) === null || _a$lastMessage === void 0 ? void 0 : _a$lastMessage.createdAt) ?? a.createdAt);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return b.createdAt - a.createdAt;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Diff utils for channel
|
|
29
|
+
* @param {SendbirdBaseChannel} [a]
|
|
30
|
+
* @param {SendbirdBaseChannel} [b]
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
* */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function isDifferentChannel(a, b) {
|
|
36
|
+
if (!a || !b) return true;
|
|
37
|
+
return a.url !== b.url;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const groupChannelChatUnavailable = channel => {
|
|
41
|
+
return channel.myMutedState === 'muted' || channel.isFrozen && channel.myRole !== 'operator';
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.groupChannelChatUnavailable = groupChannelChatUnavailable;
|
|
45
|
+
|
|
46
|
+
function isDefaultCoverImage(coverUrl) {
|
|
47
|
+
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getMembersExcludeMe(channel, currentUserId) {
|
|
51
|
+
return channel.members.filter(m => m.userId !== currentUserId);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["channelComparator","a","b","isGroupChannel","lastMessage","createdAt","isDifferentChannel","url","groupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","filter","m","userId"],"sources":["channel.ts"],"sourcesContent":["import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';\n\n/**\n * Default sort comparator for channel\n * @param {SendbirdBaseChannel} a\n * @param {SendbirdBaseChannel} b\n * @returns {number}\n * */\nexport function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number {\n if (a.isGroupChannel() && b.isGroupChannel()) {\n return (b.lastMessage?.createdAt ?? b.createdAt) - (a.lastMessage?.createdAt ?? a.createdAt);\n }\n return b.createdAt - a.createdAt;\n}\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 groupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\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"],"mappings":";;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAT,CAA0DC,CAA1D,EAAgEC,CAAhE,EAA8E;EACnF,IAAID,CAAC,CAACE,cAAF,MAAsBD,CAAC,CAACC,cAAF,EAA1B,EAA8C;IAAA;;IAC5C,OAAO,CAAC,mBAAAD,CAAC,CAACE,WAAF,kEAAeC,SAAf,KAA4BH,CAAC,CAACG,SAA/B,KAA6C,mBAAAJ,CAAC,CAACG,WAAF,kEAAeC,SAAf,KAA4BJ,CAAC,CAACI,SAA3E,CAAP;EACD;;EACD,OAAOH,CAAC,CAACG,SAAF,GAAcJ,CAAC,CAACI,SAAvB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CAA2DL,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACM,GAAF,KAAUL,CAAC,CAACK,GAAnB;AACD;;AAEM,MAAMC,2BAA2B,GAAIC,OAAD,IAAmC;EAC5E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;;;;AAIA,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BP,OAA7B,EAA4DQ,aAA5D,EAAoF;EACzF,OAAOR,OAAO,CAACS,OAAR,CAAgBC,MAAhB,CAAwBC,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaJ,aAA3C,CAAP;AACD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calcMessageGrouping = calcMessageGrouping;
|
|
7
|
+
exports.getAvailableUriFromFileMessage = getAvailableUriFromFileMessage;
|
|
8
|
+
exports.getMessageUniqId = getMessageUniqId;
|
|
9
|
+
exports.hasSameSender = hasSameSender;
|
|
10
|
+
exports.isMyMessage = isMyMessage;
|
|
11
|
+
exports.isNewMessage = isNewMessage;
|
|
12
|
+
exports.isSendbirdNotification = isSendbirdNotification;
|
|
13
|
+
exports.messageComparator = messageComparator;
|
|
14
|
+
exports.messageKeyExtractor = messageKeyExtractor;
|
|
15
|
+
exports.parseSendbirdNotification = parseSendbirdNotification;
|
|
16
|
+
|
|
17
|
+
var _common = require("../ui-format/common");
|
|
18
|
+
|
|
19
|
+
function isNewMessage(msg, currentUserId) {
|
|
20
|
+
const myMessage = isMyMessage(msg, currentUserId);
|
|
21
|
+
if (myMessage) return false;
|
|
22
|
+
if (msg.isAdminMessage()) return false;
|
|
23
|
+
return msg.updatedAt === 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isMyMessage(msg) {
|
|
27
|
+
var _msg$sender;
|
|
28
|
+
|
|
29
|
+
let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
|
|
30
|
+
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';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function messageKeyExtractor(message) {
|
|
34
|
+
return getMessageUniqId(message);
|
|
35
|
+
} // |-------------------|-------------------|-----------------|-------------------|
|
|
36
|
+
// | sending status | reqId | messageId | createdAt |
|
|
37
|
+
// |-------------------|-------------------|-----------------|-------------------|
|
|
38
|
+
// | pending | timestamp(A) | 0 | timestamp(B) |
|
|
39
|
+
// | canceled | timestamp(A) | 0 | ? |
|
|
40
|
+
// | failed | timestamp(A) | 0 | ? |
|
|
41
|
+
// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |
|
|
42
|
+
// |-------------------|-------------------|-----------------|-------------------|
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function messageComparator(a, b) {
|
|
46
|
+
let aStatusOffset = 0;
|
|
47
|
+
let bStatusOffset = 0;
|
|
48
|
+
if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;
|
|
49
|
+
if (b.sendingStatus !== 'succeeded') bStatusOffset = 999999;
|
|
50
|
+
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hasSameSender(a, b) {
|
|
54
|
+
var _a$sender, _b$sender;
|
|
55
|
+
|
|
56
|
+
if (!a || !b) return false;
|
|
57
|
+
if ('sender' in a && 'sender' in b) return ((_a$sender = a.sender) === null || _a$sender === void 0 ? void 0 : _a$sender.userId) === ((_b$sender = b.sender) === null || _b$sender === void 0 ? void 0 : _b$sender.userId);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function calcMessageGrouping(groupEnabled, curr, prev, next) {
|
|
62
|
+
const getPrev = () => {
|
|
63
|
+
if (!groupEnabled) return false;
|
|
64
|
+
if (!prev) return false;
|
|
65
|
+
if (curr.isAdminMessage()) return false;
|
|
66
|
+
if (!hasSameSender(curr, prev)) return false;
|
|
67
|
+
if ((0, _common.messageTime)(new Date(curr.createdAt)) !== (0, _common.messageTime)(new Date(prev.createdAt))) return false;
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getNext = () => {
|
|
72
|
+
if (!groupEnabled) return false;
|
|
73
|
+
if (!next) return false;
|
|
74
|
+
if (curr.isAdminMessage()) return false;
|
|
75
|
+
if (!hasSameSender(curr, next)) return false;
|
|
76
|
+
if ((0, _common.messageTime)(new Date(curr.createdAt)) !== (0, _common.messageTime)(new Date(next.createdAt))) return false;
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
groupWithPrev: getPrev(),
|
|
82
|
+
groupWithNext: getNext()
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getMessageUniqId(msg) {
|
|
87
|
+
if (msg.isUserMessage() || msg.isFileMessage()) {
|
|
88
|
+
if (msg.sendingStatus === 'succeeded') return String(msg.messageId);
|
|
89
|
+
return msg.reqId;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return String(msg.messageId);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getAvailableUriFromFileMessage(message) {
|
|
96
|
+
if (!message.url && message.messageParams && 'uri' in message.messageParams.file) {
|
|
97
|
+
return message.messageParams.file.uri;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return message.url;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isSendbirdNotification(dataPayload) {
|
|
104
|
+
if (!dataPayload) return false;
|
|
105
|
+
return Boolean(dataPayload['sendbird']);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parseSendbirdNotification(dataPayload) {
|
|
109
|
+
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +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 { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } 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 isMyMessage(msg: SendbirdMessage, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\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<T extends SendbirdMessage>(a: T, b: T) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (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: SendbirdMessage) {\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 && '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":";;;;;;;;;;;;;;;;AACA;;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,SAASF,WAAT,CAAqBH,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AAG,CAACiC,SAAL,CAAb;AACD;;AAEM,SAASE,8BAAT,CAAwCzB,OAAxC,EAAsE;EAC3E,IAAI,CAACA,OAAO,CAAC0B,GAAT,IAAgB1B,OAAO,CAAC2B,aAAxB,IAAyC,SAAS3B,OAAO,CAAC2B,aAAR,CAAsBC,IAA5E,EAAkF;IAChF,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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.arrayToMapWithGetter = arrayToMapWithGetter;
|
|
7
|
+
exports.default = arrayToMap;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert Array of the object to Object
|
|
11
|
+
* @param {object[]} arr
|
|
12
|
+
* @param {keyof object} selector
|
|
13
|
+
* @param {keyof object} [fallbackSelector]
|
|
14
|
+
* @param {boolean} [combine]
|
|
15
|
+
* @returns {Record<keyof object, object>}
|
|
16
|
+
* @example
|
|
17
|
+
* ```
|
|
18
|
+
* const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];
|
|
19
|
+
* const obj = arrayToMap(arr, 'name');
|
|
20
|
+
*
|
|
21
|
+
* console.log(obj);
|
|
22
|
+
* // {
|
|
23
|
+
* // 'john': {name: 'john'},
|
|
24
|
+
* // 'chris': {name: 'chris'},
|
|
25
|
+
* // 'sravan': {name: 'sravan'},
|
|
26
|
+
* // 'hoon': {name: 'hoon'}
|
|
27
|
+
* // }
|
|
28
|
+
* ```
|
|
29
|
+
* */
|
|
30
|
+
function arrayToMap(arr, selector, fallbackSelector, combine) {
|
|
31
|
+
return arr.reduce((accum, curr) => {
|
|
32
|
+
if (combine && fallbackSelector) {
|
|
33
|
+
const _key = curr[selector] + curr[fallbackSelector];
|
|
34
|
+
|
|
35
|
+
accum[_key] = curr;
|
|
36
|
+
} else {
|
|
37
|
+
const _key = curr[selector] || curr[fallbackSelector];
|
|
38
|
+
|
|
39
|
+
accum[_key] = curr;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return accum;
|
|
43
|
+
}, {});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function arrayToMapWithGetter(arr, getSelector) {
|
|
47
|
+
return arr.reduce((accum, curr) => {
|
|
48
|
+
const _key = getSelector(curr);
|
|
49
|
+
|
|
50
|
+
accum[_key] = curr;
|
|
51
|
+
return accum;
|
|
52
|
+
}, {});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=arrayToMap.js.map
|
|
@@ -0,0 +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 extends Record<K, unknown>, K extends keyof T = keyof T>(\n arr: T[],\n getSelector: (item: T) => string,\n) {\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,CACLR,GADK,EAELS,WAFK,EAGL;EACA,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const conditionChaining = (conditions, values) => {
|
|
9
|
+
const idx = conditions.findIndex(state => Boolean(state));
|
|
10
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
var _default = conditionChaining;
|
|
14
|
+
exports.default = _default;
|
|
15
|
+
//# sourceMappingURL=conditionChaining.js.map
|