@sendbird/uikit-utils 2.0.3 → 2.1.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/index.js +15 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +13 -7
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/sendbird/user.js +18 -0
- package/lib/commonjs/sendbird/user.js.map +1 -0
- package/lib/commonjs/shared/bufferedRequest.js +38 -12
- package/lib/commonjs/shared/bufferedRequest.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +11 -4
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/sendbird/user.js +9 -0
- package/lib/module/sendbird/user.js.map +1 -0
- package/lib/module/shared/bufferedRequest.js +39 -12
- package/lib/module/shared/bufferedRequest.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/sendbird/channel.d.ts +5 -1
- package/lib/typescript/src/sendbird/user.d.ts +5 -0
- package/lib/typescript/src/shared/bufferedRequest.d.ts +5 -3
- package/lib/typescript/src/types.d.ts +2 -1
- package/package.json +2 -2
- package/src/index.ts +6 -2
- package/src/sendbird/channel.ts +7 -4
- package/src/sendbird/user.ts +15 -0
- package/src/shared/bufferedRequest.ts +37 -12
- package/src/types.ts +2 -1
package/lib/commonjs/index.js
CHANGED
|
@@ -239,6 +239,20 @@ Object.keys(_attrs).forEach(function (key) {
|
|
|
239
239
|
});
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
+
var _user = require("./sendbird/user");
|
|
243
|
+
|
|
244
|
+
Object.keys(_user).forEach(function (key) {
|
|
245
|
+
if (key === "default" || key === "__esModule") return;
|
|
246
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
247
|
+
if (key in exports && exports[key] === _user[key]) return;
|
|
248
|
+
Object.defineProperty(exports, key, {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () {
|
|
251
|
+
return _user[key];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
242
256
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
243
257
|
|
|
244
258
|
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); }
|
|
@@ -269,7 +283,7 @@ const SBErrorCode = {
|
|
|
269
283
|
};
|
|
270
284
|
exports.SBErrorCode = SBErrorCode;
|
|
271
285
|
const SBErrorMessage = {
|
|
272
|
-
ACL:
|
|
286
|
+
ACL: 'Sendbird provides various access control options when using the Chat SDK.\n' + 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\n' + 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\n' + 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.'
|
|
273
287
|
};
|
|
274
288
|
exports.SBErrorMessage = SBErrorMessage;
|
|
275
289
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { 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';\nexport { BufferedRequest } from './shared/bufferedRequest';\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;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n
|
|
1
|
+
{"version":3,"names":["NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { 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';\nexport { BufferedRequest } from './shared/bufferedRequest';\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';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;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;;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;;;;AACA,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;;;AACA,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;;AAGA,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.confirmAndMarkAsRead = exports.confirmAndMarkAsDelivered = void 0;
|
|
6
|
+
exports.getGroupChannelChatAvailableState = exports.confirmAndMarkAsRead = exports.confirmAndMarkAsDelivered = void 0;
|
|
7
7
|
exports.getGroupChannels = getGroupChannels;
|
|
8
8
|
exports.getMembersExcludeMe = getMembersExcludeMe;
|
|
9
9
|
exports.getOpenChannels = getOpenChannels;
|
|
10
10
|
exports.isDefaultCoverImage = isDefaultCoverImage;
|
|
11
11
|
exports.isDifferentChannel = isDifferentChannel;
|
|
12
|
-
exports.isGroupChannelChatUnavailable = void 0;
|
|
13
12
|
|
|
14
13
|
var _bufferedRequest = require("../shared/bufferedRequest");
|
|
15
14
|
|
|
@@ -24,20 +23,27 @@ function isDifferentChannel(a, b) {
|
|
|
24
23
|
return a.url !== b.url;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
const getGroupChannelChatAvailableState = channel => {
|
|
27
|
+
const frozen = channel.isFrozen && channel.myRole !== 'operator';
|
|
28
|
+
const muted = channel.myMutedState === 'muted';
|
|
29
|
+
const disabled = frozen || muted;
|
|
30
|
+
return {
|
|
31
|
+
disabled,
|
|
32
|
+
frozen,
|
|
33
|
+
muted
|
|
34
|
+
};
|
|
29
35
|
};
|
|
30
36
|
|
|
31
|
-
exports.
|
|
37
|
+
exports.getGroupChannelChatAvailableState = getGroupChannelChatAvailableState;
|
|
32
38
|
|
|
33
39
|
const confirmAndMarkAsRead = async channels => {
|
|
34
|
-
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
40
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));
|
|
35
41
|
};
|
|
36
42
|
|
|
37
43
|
exports.confirmAndMarkAsRead = confirmAndMarkAsRead;
|
|
38
44
|
|
|
39
45
|
const confirmAndMarkAsDelivered = async channels => {
|
|
40
|
-
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
46
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));
|
|
41
47
|
};
|
|
42
48
|
|
|
43
49
|
exports.confirmAndMarkAsDelivered = confirmAndMarkAsDelivered;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isDifferentChannel","a","b","url","
|
|
1
|
+
{"version":3,"names":["isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","frozen","isFrozen","myRole","muted","myMutedState","disabled","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","BufferedRequest","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const frozen = channel.isFrozen && channel.myRole !== 'operator';\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":";;;;;;;;;;;;AAAA;;AAGA;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,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAtD;EACA,MAAMC,KAAK,GAAGJ,OAAO,CAACK,YAAR,KAAyB,OAAvC;EACA,MAAMC,QAAQ,GAAGL,MAAM,IAAIG,KAA3B;EACA,OAAO;IAAEE,QAAF;IAAYL,MAAZ;IAAoBG;EAApB,CAAP;AACD,CALM;;;;AAOA,MAAMG,oBAAoB,GAAG,MAAOC,QAAP,IAA2C;EAC7EA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQI,gCAAA,CAAgBC,UAAhB,CAA2BC,IAA3B,CAAgC,MAAMN,EAAE,CAACK,UAAH,EAAtC,EAAuDL,EAAE,CAACZ,GAA1D,CAFnB;AAGD,CAJM;;;;AAMA,MAAMmB,yBAAyB,GAAG,MAAOT,QAAP,IAA2C;EAClFA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQI,gCAAA,CAAgBI,eAAhB,CAAgCF,IAAhC,CAAqC,MAAMN,EAAE,CAACQ,eAAH,EAA3C,EAAiER,EAAE,CAACZ,GAApE,CAFnB;AAGD,CAJM;;;;AAMA,SAASqB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BtB,OAA7B,EAA4DuB,aAA5D,EAAoF;EACzF,OAAOvB,OAAO,CAACwB,OAAR,CAAgBf,MAAhB,CAAwBgB,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaH,aAA3C,CAAP;AACD;;AAEM,SAASI,gBAAT,CAA0BnB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACC,MAAT,CAAiBmB,CAAD,IAAkCA,CAAC,CAACjB,cAAF,EAAlD,CAAP;AACD;;AAEM,SAASkB,eAAT,CAAyBrB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACC,MAAT,CAAiBmB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ifMuted = ifMuted;
|
|
7
|
+
exports.ifOperator = ifOperator;
|
|
8
|
+
|
|
9
|
+
function ifOperator(role, then, or) {
|
|
10
|
+
if (role === 'operator') return then;
|
|
11
|
+
return or;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ifMuted(muted, then, or) {
|
|
15
|
+
if (muted) return then;
|
|
16
|
+
return or;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ifOperator","role","then","or","ifMuted","muted"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function ifMuted<T>(muted: boolean, then: T): T | undefined;\nexport function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;\nexport function ifMuted(muted: boolean, then: unknown, or?: unknown) {\n if (muted) return then;\n return or;\n}\n"],"mappings":";;;;;;;;AAIO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;;AAIM,SAASC,OAAT,CAAiBC,KAAjB,EAAiCH,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIE,KAAJ,EAAW,OAAOH,IAAP;EACX,OAAOC,EAAP;AACD"}
|
|
@@ -11,7 +11,19 @@ let REQ_PER_TIMEOUT = 5;
|
|
|
11
11
|
let TIMEOUT_MILLS = 1000;
|
|
12
12
|
const SAFE_TIMEOUT_BUFFER = 100;
|
|
13
13
|
|
|
14
|
+
function generateRandomId() {
|
|
15
|
+
return Math.random().toString(16).slice(2);
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
class BufferedRequest {
|
|
19
|
+
static updateMarkAsReadOptions(reqPerTimeout, timeoutMills) {
|
|
20
|
+
BufferedRequest.markAsRead = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static updateMarkAsDeliveredOptions(reqPerTimeout, timeoutMills) {
|
|
24
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
static get reqPerTimeout() {
|
|
16
28
|
return REQ_PER_TIMEOUT;
|
|
17
29
|
}
|
|
@@ -35,29 +47,35 @@ class BufferedRequest {
|
|
|
35
47
|
static create() {
|
|
36
48
|
let reqPerTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : REQ_PER_TIMEOUT;
|
|
37
49
|
let timeoutMills = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TIMEOUT_MILLS;
|
|
38
|
-
const waitQueue =
|
|
39
|
-
const nextQueue =
|
|
50
|
+
const waitQueue = new Map();
|
|
51
|
+
const nextQueue = new Map();
|
|
40
52
|
let state = 'idle';
|
|
41
53
|
let timeout;
|
|
42
54
|
return {
|
|
43
|
-
push(func) {
|
|
44
|
-
waitQueue.
|
|
55
|
+
push(func, lane) {
|
|
56
|
+
waitQueue.set(lane ?? generateRandomId(), func);
|
|
45
57
|
this.invoke();
|
|
46
58
|
},
|
|
47
59
|
|
|
48
60
|
shift() {
|
|
49
|
-
if (nextQueue.
|
|
50
|
-
const nextRemains = Math.min(reqPerTimeout - nextQueue.
|
|
61
|
+
if (nextQueue.size < reqPerTimeout) {
|
|
62
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.size, waitQueue.size);
|
|
63
|
+
const lanes = [...waitQueue.keys()];
|
|
51
64
|
|
|
52
65
|
for (let n = 0; n < nextRemains; n++) {
|
|
53
|
-
const
|
|
54
|
-
|
|
66
|
+
const lane = lanes[n];
|
|
67
|
+
const func = waitQueue.get(lane);
|
|
68
|
+
|
|
69
|
+
if (func) {
|
|
70
|
+
waitQueue.delete(lane);
|
|
71
|
+
nextQueue.set(lane, func);
|
|
72
|
+
}
|
|
55
73
|
}
|
|
56
74
|
}
|
|
57
75
|
},
|
|
58
76
|
|
|
59
77
|
handleIdle() {
|
|
60
|
-
if (0 < nextQueue.
|
|
78
|
+
if (0 < nextQueue.size) {
|
|
61
79
|
state = 'processing';
|
|
62
80
|
this.invoke();
|
|
63
81
|
}
|
|
@@ -68,14 +86,22 @@ class BufferedRequest {
|
|
|
68
86
|
timeout = setTimeout(() => {
|
|
69
87
|
timeout = undefined;
|
|
70
88
|
|
|
71
|
-
if (0 < nextQueue.
|
|
89
|
+
if (0 < nextQueue.size || 0 < waitQueue.size) {
|
|
72
90
|
this.invoke();
|
|
73
91
|
} else {
|
|
74
92
|
state = 'idle';
|
|
75
93
|
}
|
|
76
94
|
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
let index = 0;
|
|
96
|
+
const nextRequestBaseTimeout = timeoutMills / nextQueue.size;
|
|
97
|
+
nextQueue.forEach(func => {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
func(); // TODO: Add retry
|
|
100
|
+
//.catch(() => waitQueue.set(lane, func));
|
|
101
|
+
}, nextRequestBaseTimeout * index);
|
|
102
|
+
index++;
|
|
103
|
+
});
|
|
104
|
+
nextQueue.clear();
|
|
79
105
|
},
|
|
80
106
|
|
|
81
107
|
async invoke() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","BufferedRequest","reqPerTimeout","
|
|
1
|
+
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","generateRandomId","Math","random","toString","slice","BufferedRequest","updateMarkAsReadOptions","reqPerTimeout","timeoutMills","markAsRead","create","updateMarkAsDeliveredOptions","markAsDelivered","value","waitQueue","Map","nextQueue","state","timeout","push","func","lane","set","invoke","shift","size","nextRemains","min","lanes","keys","n","get","delete","handleIdle","handleProcessing","setTimeout","undefined","index","nextRequestBaseTimeout","forEach","clear"],"sources":["bufferedRequest.ts"],"sourcesContent":["type Func = (...args: unknown[]) => Promise<unknown>;\ntype State = 'idle' | 'processing';\n\nlet REQ_PER_TIMEOUT = 5;\nlet TIMEOUT_MILLS = 1000;\nconst SAFE_TIMEOUT_BUFFER = 100;\n\nfunction generateRandomId() {\n return Math.random().toString(16).slice(2);\n}\n\nexport class BufferedRequest {\n public static markAsRead = BufferedRequest.create();\n public static markAsDelivered = BufferedRequest.create();\n\n public static updateMarkAsReadOptions(reqPerTimeout: number, timeoutMills: number) {\n BufferedRequest.markAsRead = BufferedRequest.create(reqPerTimeout, timeoutMills);\n }\n public static updateMarkAsDeliveredOptions(reqPerTimeout: number, timeoutMills: number) {\n BufferedRequest.markAsDelivered = BufferedRequest.create(reqPerTimeout, timeoutMills);\n }\n\n public static get reqPerTimeout() {\n return REQ_PER_TIMEOUT;\n }\n public static set reqPerTimeout(value: number) {\n REQ_PER_TIMEOUT = value;\n BufferedRequest.markAsRead = BufferedRequest.create();\n BufferedRequest.markAsDelivered = BufferedRequest.create();\n }\n\n public static get timeoutMills() {\n return TIMEOUT_MILLS;\n }\n public static set timeoutMills(value: number) {\n TIMEOUT_MILLS = value;\n BufferedRequest.markAsRead = BufferedRequest.create();\n BufferedRequest.markAsDelivered = BufferedRequest.create();\n }\n\n public static create(reqPerTimeout = REQ_PER_TIMEOUT, timeoutMills = TIMEOUT_MILLS) {\n const waitQueue = new Map<string, Func>();\n const nextQueue = new Map<string, Func>();\n\n let state: State = 'idle';\n let timeout: NodeJS.Timeout | undefined;\n\n return {\n push(func: Func, lane?: string) {\n waitQueue.set(lane ?? generateRandomId(), func);\n this.invoke();\n },\n shift() {\n if (nextQueue.size < reqPerTimeout) {\n const nextRemains = Math.min(reqPerTimeout - nextQueue.size, waitQueue.size);\n const lanes = [...waitQueue.keys()];\n for (let n = 0; n < nextRemains; n++) {\n const lane = lanes[n];\n const func = waitQueue.get(lane);\n if (func) {\n waitQueue.delete(lane);\n nextQueue.set(lane, func);\n }\n }\n }\n },\n handleIdle() {\n if (0 < nextQueue.size) {\n state = 'processing';\n this.invoke();\n }\n },\n handleProcessing() {\n if (timeout) return;\n\n timeout = setTimeout(() => {\n timeout = undefined;\n if (0 < nextQueue.size || 0 < waitQueue.size) {\n this.invoke();\n } else {\n state = 'idle';\n }\n }, timeoutMills + SAFE_TIMEOUT_BUFFER);\n\n let index = 0;\n const nextRequestBaseTimeout = timeoutMills / nextQueue.size;\n nextQueue.forEach((func) => {\n setTimeout(() => {\n func();\n // TODO: Add retry\n //.catch(() => waitQueue.set(lane, func));\n }, nextRequestBaseTimeout * index);\n index++;\n });\n nextQueue.clear();\n },\n async invoke() {\n this.shift();\n\n if (state === 'idle') {\n this.handleIdle();\n }\n\n if (state === 'processing') {\n this.handleProcessing();\n }\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;AAGA,IAAIA,eAAe,GAAG,CAAtB;AACA,IAAIC,aAAa,GAAG,IAApB;AACA,MAAMC,mBAAmB,GAAG,GAA5B;;AAEA,SAASC,gBAAT,GAA4B;EAC1B,OAAOC,IAAI,CAACC,MAAL,GAAcC,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAP;AACD;;AAEM,MAAMC,eAAN,CAAsB;EAIU,OAAvBC,uBAAuB,CAACC,aAAD,EAAwBC,YAAxB,EAA8C;IACjFH,eAAe,CAACI,UAAhB,GAA6BJ,eAAe,CAACK,MAAhB,CAAuBH,aAAvB,EAAsCC,YAAtC,CAA7B;EACD;;EACyC,OAA5BG,4BAA4B,CAACJ,aAAD,EAAwBC,YAAxB,EAA8C;IACtFH,eAAe,CAACO,eAAhB,GAAkCP,eAAe,CAACK,MAAhB,CAAuBH,aAAvB,EAAsCC,YAAtC,CAAlC;EACD;;EAE8B,WAAbD,aAAa,GAAG;IAChC,OAAOV,eAAP;EACD;;EAC8B,WAAbU,aAAa,CAACM,KAAD,EAAgB;IAC7ChB,eAAe,GAAGgB,KAAlB;IACAR,eAAe,CAACI,UAAhB,GAA6BJ,eAAe,CAACK,MAAhB,EAA7B;IACAL,eAAe,CAACO,eAAhB,GAAkCP,eAAe,CAACK,MAAhB,EAAlC;EACD;;EAE6B,WAAZF,YAAY,GAAG;IAC/B,OAAOV,aAAP;EACD;;EAC6B,WAAZU,YAAY,CAACK,KAAD,EAAgB;IAC5Cf,aAAa,GAAGe,KAAhB;IACAR,eAAe,CAACI,UAAhB,GAA6BJ,eAAe,CAACK,MAAhB,EAA7B;IACAL,eAAe,CAACO,eAAhB,GAAkCP,eAAe,CAACK,MAAhB,EAAlC;EACD;;EAEmB,OAANA,MAAM,GAAgE;IAAA,IAA/DH,aAA+D,uEAA/CV,eAA+C;IAAA,IAA9BW,YAA8B,uEAAfV,aAAe;IAClF,MAAMgB,SAAS,GAAG,IAAIC,GAAJ,EAAlB;IACA,MAAMC,SAAS,GAAG,IAAID,GAAJ,EAAlB;IAEA,IAAIE,KAAY,GAAG,MAAnB;IACA,IAAIC,OAAJ;IAEA,OAAO;MACLC,IAAI,CAACC,IAAD,EAAaC,IAAb,EAA4B;QAC9BP,SAAS,CAACQ,GAAV,CAAcD,IAAI,IAAIrB,gBAAgB,EAAtC,EAA0CoB,IAA1C;QACA,KAAKG,MAAL;MACD,CAJI;;MAKLC,KAAK,GAAG;QACN,IAAIR,SAAS,CAACS,IAAV,GAAiBlB,aAArB,EAAoC;UAClC,MAAMmB,WAAW,GAAGzB,IAAI,CAAC0B,GAAL,CAASpB,aAAa,GAAGS,SAAS,CAACS,IAAnC,EAAyCX,SAAS,CAACW,IAAnD,CAApB;UACA,MAAMG,KAAK,GAAG,CAAC,GAAGd,SAAS,CAACe,IAAV,EAAJ,CAAd;;UACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGJ,WAApB,EAAiCI,CAAC,EAAlC,EAAsC;YACpC,MAAMT,IAAI,GAAGO,KAAK,CAACE,CAAD,CAAlB;YACA,MAAMV,IAAI,GAAGN,SAAS,CAACiB,GAAV,CAAcV,IAAd,CAAb;;YACA,IAAID,IAAJ,EAAU;cACRN,SAAS,CAACkB,MAAV,CAAiBX,IAAjB;cACAL,SAAS,CAACM,GAAV,CAAcD,IAAd,EAAoBD,IAApB;YACD;UACF;QACF;MACF,CAlBI;;MAmBLa,UAAU,GAAG;QACX,IAAI,IAAIjB,SAAS,CAACS,IAAlB,EAAwB;UACtBR,KAAK,GAAG,YAAR;UACA,KAAKM,MAAL;QACD;MACF,CAxBI;;MAyBLW,gBAAgB,GAAG;QACjB,IAAIhB,OAAJ,EAAa;QAEbA,OAAO,GAAGiB,UAAU,CAAC,MAAM;UACzBjB,OAAO,GAAGkB,SAAV;;UACA,IAAI,IAAIpB,SAAS,CAACS,IAAd,IAAsB,IAAIX,SAAS,CAACW,IAAxC,EAA8C;YAC5C,KAAKF,MAAL;UACD,CAFD,MAEO;YACLN,KAAK,GAAG,MAAR;UACD;QACF,CAPmB,EAOjBT,YAAY,GAAGT,mBAPE,CAApB;QASA,IAAIsC,KAAK,GAAG,CAAZ;QACA,MAAMC,sBAAsB,GAAG9B,YAAY,GAAGQ,SAAS,CAACS,IAAxD;QACAT,SAAS,CAACuB,OAAV,CAAmBnB,IAAD,IAAU;UAC1Be,UAAU,CAAC,MAAM;YACff,IAAI,GADW,CAEf;YACA;UACD,CAJS,EAIPkB,sBAAsB,GAAGD,KAJlB,CAAV;UAKAA,KAAK;QACN,CAPD;QAQArB,SAAS,CAACwB,KAAV;MACD,CAhDI;;MAiDL,MAAMjB,MAAN,GAAe;QACb,KAAKC,KAAL;;QAEA,IAAIP,KAAK,KAAK,MAAd,EAAsB;UACpB,KAAKgB,UAAL;QACD;;QAED,IAAIhB,KAAK,KAAK,YAAd,EAA4B;UAC1B,KAAKiB,gBAAL;QACD;MACF;;IA3DI,CAAP;EA6DD;;AAjG0B;;;;gBAAhB7B,e,gBACgBA,eAAe,CAACK,MAAhB,E;;gBADhBL,e,qBAEqBA,eAAe,CAACK,MAAhB,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type { 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"}
|
|
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, RestrictedUser, 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 SendbirdRestrictedUser = RestrictedUser;\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"}
|
package/lib/module/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './ui-format/common';
|
|
|
10
10
|
export * from './sendbird/channel';
|
|
11
11
|
export * from './sendbird/message';
|
|
12
12
|
export * from './sendbird/attrs';
|
|
13
|
+
export * from './sendbird/user';
|
|
13
14
|
export const NOOP = () => void 0;
|
|
14
15
|
export const ASYNC_NOOP = async () => void 0;
|
|
15
16
|
export const PASS = val => val;
|
|
@@ -19,6 +20,6 @@ export const SBErrorCode = {
|
|
|
19
20
|
NON_AUTHORIZED: 400108
|
|
20
21
|
};
|
|
21
22
|
export const SBErrorMessage = {
|
|
22
|
-
ACL:
|
|
23
|
+
ACL: 'Sendbird provides various access control options when using the Chat SDK.\n' + 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\n' + 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\n' + 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.'
|
|
23
24
|
};
|
|
24
25
|
//# sourceMappingURL=index.js.map
|
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","normalizeFileName","emailRegex","phoneRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { 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';\nexport { BufferedRequest } from './shared/bufferedRequest';\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;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n
|
|
1
|
+
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","conditionChaining","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { 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';\nexport { BufferedRequest } from './shared/bufferedRequest';\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';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n} 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;AAcA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,cAAc,SAAd;AACA,cAAc,0BAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;AACP,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;AAGP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
|
|
@@ -10,14 +10,21 @@ export function isDifferentChannel(a, b) {
|
|
|
10
10
|
if (!a || !b) return true;
|
|
11
11
|
return a.url !== b.url;
|
|
12
12
|
}
|
|
13
|
-
export const
|
|
14
|
-
|
|
13
|
+
export const getGroupChannelChatAvailableState = channel => {
|
|
14
|
+
const frozen = channel.isFrozen && channel.myRole !== 'operator';
|
|
15
|
+
const muted = channel.myMutedState === 'muted';
|
|
16
|
+
const disabled = frozen || muted;
|
|
17
|
+
return {
|
|
18
|
+
disabled,
|
|
19
|
+
frozen,
|
|
20
|
+
muted
|
|
21
|
+
};
|
|
15
22
|
};
|
|
16
23
|
export const confirmAndMarkAsRead = async channels => {
|
|
17
|
-
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
24
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));
|
|
18
25
|
};
|
|
19
26
|
export const confirmAndMarkAsDelivered = async channels => {
|
|
20
|
-
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
27
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));
|
|
21
28
|
};
|
|
22
29
|
export function isDefaultCoverImage(coverUrl) {
|
|
23
30
|
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","
|
|
1
|
+
{"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","frozen","isFrozen","myRole","muted","myMutedState","disabled","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const frozen = channel.isFrozen && channel.myRole !== 'operator';\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":"AAAA,SAASA,eAAT,QAAgC,2BAAhC;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAtD;EACA,MAAMC,KAAK,GAAGJ,OAAO,CAACK,YAAR,KAAyB,OAAvC;EACA,MAAMC,QAAQ,GAAGL,MAAM,IAAIG,KAA3B;EACA,OAAO;IAAEE,QAAF;IAAYL,MAAZ;IAAoBG;EAApB,CAAP;AACD,CALM;AAOP,OAAO,MAAMG,oBAAoB,GAAG,MAAOC,QAAP,IAA2C;EAC7EA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQhB,eAAe,CAACoB,UAAhB,CAA2BC,IAA3B,CAAgC,MAAML,EAAE,CAACI,UAAH,EAAtC,EAAuDJ,EAAE,CAACZ,GAA1D,CAFnB;AAGD,CAJM;AAMP,OAAO,MAAMkB,yBAAyB,GAAG,MAAOR,QAAP,IAA2C;EAClFA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQhB,eAAe,CAACuB,eAAhB,CAAgCF,IAAhC,CAAqC,MAAML,EAAE,CAACO,eAAH,EAA3C,EAAiEP,EAAE,CAACZ,GAApE,CAFnB;AAGD,CAJM;AAMP,OAAO,SAASoB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BrB,OAA7B,EAA4DsB,aAA5D,EAAoF;EACzF,OAAOtB,OAAO,CAACuB,OAAR,CAAgBd,MAAhB,CAAwBe,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaH,aAA3C,CAAP;AACD;AAED,OAAO,SAASI,gBAAT,CAA0BlB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACC,MAAT,CAAiBkB,CAAD,IAAkCA,CAAC,CAAChB,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASiB,eAAT,CAAyBpB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACC,MAAT,CAAiBkB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ifOperator","role","then","or","ifMuted","muted"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function ifMuted<T>(muted: boolean, then: T): T | undefined;\nexport function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;\nexport function ifMuted(muted: boolean, then: unknown, or?: unknown) {\n if (muted) return then;\n return or;\n}\n"],"mappings":"AAIA,OAAO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;AAID,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAiCH,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIE,KAAJ,EAAW,OAAOH,IAAP;EACX,OAAOC,EAAP;AACD"}
|
|
@@ -3,7 +3,20 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3
3
|
let REQ_PER_TIMEOUT = 5;
|
|
4
4
|
let TIMEOUT_MILLS = 1000;
|
|
5
5
|
const SAFE_TIMEOUT_BUFFER = 100;
|
|
6
|
+
|
|
7
|
+
function generateRandomId() {
|
|
8
|
+
return Math.random().toString(16).slice(2);
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export class BufferedRequest {
|
|
12
|
+
static updateMarkAsReadOptions(reqPerTimeout, timeoutMills) {
|
|
13
|
+
BufferedRequest.markAsRead = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static updateMarkAsDeliveredOptions(reqPerTimeout, timeoutMills) {
|
|
17
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
static get reqPerTimeout() {
|
|
8
21
|
return REQ_PER_TIMEOUT;
|
|
9
22
|
}
|
|
@@ -27,29 +40,35 @@ export class BufferedRequest {
|
|
|
27
40
|
static create() {
|
|
28
41
|
let reqPerTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : REQ_PER_TIMEOUT;
|
|
29
42
|
let timeoutMills = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TIMEOUT_MILLS;
|
|
30
|
-
const waitQueue =
|
|
31
|
-
const nextQueue =
|
|
43
|
+
const waitQueue = new Map();
|
|
44
|
+
const nextQueue = new Map();
|
|
32
45
|
let state = 'idle';
|
|
33
46
|
let timeout;
|
|
34
47
|
return {
|
|
35
|
-
push(func) {
|
|
36
|
-
waitQueue.
|
|
48
|
+
push(func, lane) {
|
|
49
|
+
waitQueue.set(lane ?? generateRandomId(), func);
|
|
37
50
|
this.invoke();
|
|
38
51
|
},
|
|
39
52
|
|
|
40
53
|
shift() {
|
|
41
|
-
if (nextQueue.
|
|
42
|
-
const nextRemains = Math.min(reqPerTimeout - nextQueue.
|
|
54
|
+
if (nextQueue.size < reqPerTimeout) {
|
|
55
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.size, waitQueue.size);
|
|
56
|
+
const lanes = [...waitQueue.keys()];
|
|
43
57
|
|
|
44
58
|
for (let n = 0; n < nextRemains; n++) {
|
|
45
|
-
const
|
|
46
|
-
|
|
59
|
+
const lane = lanes[n];
|
|
60
|
+
const func = waitQueue.get(lane);
|
|
61
|
+
|
|
62
|
+
if (func) {
|
|
63
|
+
waitQueue.delete(lane);
|
|
64
|
+
nextQueue.set(lane, func);
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
67
|
}
|
|
49
68
|
},
|
|
50
69
|
|
|
51
70
|
handleIdle() {
|
|
52
|
-
if (0 < nextQueue.
|
|
71
|
+
if (0 < nextQueue.size) {
|
|
53
72
|
state = 'processing';
|
|
54
73
|
this.invoke();
|
|
55
74
|
}
|
|
@@ -60,14 +79,22 @@ export class BufferedRequest {
|
|
|
60
79
|
timeout = setTimeout(() => {
|
|
61
80
|
timeout = undefined;
|
|
62
81
|
|
|
63
|
-
if (0 < nextQueue.
|
|
82
|
+
if (0 < nextQueue.size || 0 < waitQueue.size) {
|
|
64
83
|
this.invoke();
|
|
65
84
|
} else {
|
|
66
85
|
state = 'idle';
|
|
67
86
|
}
|
|
68
87
|
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
let index = 0;
|
|
89
|
+
const nextRequestBaseTimeout = timeoutMills / nextQueue.size;
|
|
90
|
+
nextQueue.forEach(func => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
func(); // TODO: Add retry
|
|
93
|
+
//.catch(() => waitQueue.set(lane, func));
|
|
94
|
+
}, nextRequestBaseTimeout * index);
|
|
95
|
+
index++;
|
|
96
|
+
});
|
|
97
|
+
nextQueue.clear();
|
|
71
98
|
},
|
|
72
99
|
|
|
73
100
|
async invoke() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","BufferedRequest","reqPerTimeout","
|
|
1
|
+
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","generateRandomId","Math","random","toString","slice","BufferedRequest","updateMarkAsReadOptions","reqPerTimeout","timeoutMills","markAsRead","create","updateMarkAsDeliveredOptions","markAsDelivered","value","waitQueue","Map","nextQueue","state","timeout","push","func","lane","set","invoke","shift","size","nextRemains","min","lanes","keys","n","get","delete","handleIdle","handleProcessing","setTimeout","undefined","index","nextRequestBaseTimeout","forEach","clear"],"sources":["bufferedRequest.ts"],"sourcesContent":["type Func = (...args: unknown[]) => Promise<unknown>;\ntype State = 'idle' | 'processing';\n\nlet REQ_PER_TIMEOUT = 5;\nlet TIMEOUT_MILLS = 1000;\nconst SAFE_TIMEOUT_BUFFER = 100;\n\nfunction generateRandomId() {\n return Math.random().toString(16).slice(2);\n}\n\nexport class BufferedRequest {\n public static markAsRead = BufferedRequest.create();\n public static markAsDelivered = BufferedRequest.create();\n\n public static updateMarkAsReadOptions(reqPerTimeout: number, timeoutMills: number) {\n BufferedRequest.markAsRead = BufferedRequest.create(reqPerTimeout, timeoutMills);\n }\n public static updateMarkAsDeliveredOptions(reqPerTimeout: number, timeoutMills: number) {\n BufferedRequest.markAsDelivered = BufferedRequest.create(reqPerTimeout, timeoutMills);\n }\n\n public static get reqPerTimeout() {\n return REQ_PER_TIMEOUT;\n }\n public static set reqPerTimeout(value: number) {\n REQ_PER_TIMEOUT = value;\n BufferedRequest.markAsRead = BufferedRequest.create();\n BufferedRequest.markAsDelivered = BufferedRequest.create();\n }\n\n public static get timeoutMills() {\n return TIMEOUT_MILLS;\n }\n public static set timeoutMills(value: number) {\n TIMEOUT_MILLS = value;\n BufferedRequest.markAsRead = BufferedRequest.create();\n BufferedRequest.markAsDelivered = BufferedRequest.create();\n }\n\n public static create(reqPerTimeout = REQ_PER_TIMEOUT, timeoutMills = TIMEOUT_MILLS) {\n const waitQueue = new Map<string, Func>();\n const nextQueue = new Map<string, Func>();\n\n let state: State = 'idle';\n let timeout: NodeJS.Timeout | undefined;\n\n return {\n push(func: Func, lane?: string) {\n waitQueue.set(lane ?? generateRandomId(), func);\n this.invoke();\n },\n shift() {\n if (nextQueue.size < reqPerTimeout) {\n const nextRemains = Math.min(reqPerTimeout - nextQueue.size, waitQueue.size);\n const lanes = [...waitQueue.keys()];\n for (let n = 0; n < nextRemains; n++) {\n const lane = lanes[n];\n const func = waitQueue.get(lane);\n if (func) {\n waitQueue.delete(lane);\n nextQueue.set(lane, func);\n }\n }\n }\n },\n handleIdle() {\n if (0 < nextQueue.size) {\n state = 'processing';\n this.invoke();\n }\n },\n handleProcessing() {\n if (timeout) return;\n\n timeout = setTimeout(() => {\n timeout = undefined;\n if (0 < nextQueue.size || 0 < waitQueue.size) {\n this.invoke();\n } else {\n state = 'idle';\n }\n }, timeoutMills + SAFE_TIMEOUT_BUFFER);\n\n let index = 0;\n const nextRequestBaseTimeout = timeoutMills / nextQueue.size;\n nextQueue.forEach((func) => {\n setTimeout(() => {\n func();\n // TODO: Add retry\n //.catch(() => waitQueue.set(lane, func));\n }, nextRequestBaseTimeout * index);\n index++;\n });\n nextQueue.clear();\n },\n async invoke() {\n this.shift();\n\n if (state === 'idle') {\n this.handleIdle();\n }\n\n if (state === 'processing') {\n this.handleProcessing();\n }\n },\n };\n }\n}\n"],"mappings":"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"}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type { 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"}
|
|
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, RestrictedUser, 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 SendbirdRestrictedUser = RestrictedUser;\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"}
|
|
@@ -10,6 +10,7 @@ export * from './ui-format/common';
|
|
|
10
10
|
export * from './sendbird/channel';
|
|
11
11
|
export * from './sendbird/message';
|
|
12
12
|
export * from './sendbird/attrs';
|
|
13
|
+
export * from './sendbird/user';
|
|
13
14
|
export declare const NOOP: () => void;
|
|
14
15
|
export declare const ASYNC_NOOP: () => Promise<undefined>;
|
|
15
16
|
export declare const PASS: <T>(val: T) => T;
|
|
@@ -21,4 +22,4 @@ export declare const SBErrorCode: {
|
|
|
21
22
|
export declare const SBErrorMessage: {
|
|
22
23
|
ACL: string;
|
|
23
24
|
};
|
|
24
|
-
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';
|
|
25
|
+
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, SendbirdRestrictedUser, } from './types';
|
|
@@ -6,7 +6,11 @@ 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 getGroupChannelChatAvailableState: (channel: SendbirdGroupChannel) => {
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
frozen: boolean;
|
|
12
|
+
muted: boolean;
|
|
13
|
+
};
|
|
10
14
|
export declare const confirmAndMarkAsRead: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
11
15
|
export declare const confirmAndMarkAsDelivered: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
12
16
|
export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Role } from '@sendbird/chat';
|
|
2
|
+
export declare function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
3
|
+
export declare function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
4
|
+
export declare function ifMuted<T>(muted: boolean, then: T): T | undefined;
|
|
5
|
+
export declare function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
declare type Func = (...args: unknown[]) => Promise<unknown>;
|
|
2
2
|
export declare class BufferedRequest {
|
|
3
3
|
static markAsRead: {
|
|
4
|
-
push(func: Func): void;
|
|
4
|
+
push(func: Func, lane?: string): void;
|
|
5
5
|
shift(): void;
|
|
6
6
|
handleIdle(): void;
|
|
7
7
|
handleProcessing(): void;
|
|
8
8
|
invoke(): Promise<void>;
|
|
9
9
|
};
|
|
10
10
|
static markAsDelivered: {
|
|
11
|
-
push(func: Func): void;
|
|
11
|
+
push(func: Func, lane?: string): void;
|
|
12
12
|
shift(): void;
|
|
13
13
|
handleIdle(): void;
|
|
14
14
|
handleProcessing(): void;
|
|
15
15
|
invoke(): Promise<void>;
|
|
16
16
|
};
|
|
17
|
+
static updateMarkAsReadOptions(reqPerTimeout: number, timeoutMills: number): void;
|
|
18
|
+
static updateMarkAsDeliveredOptions(reqPerTimeout: number, timeoutMills: number): void;
|
|
17
19
|
static get reqPerTimeout(): number;
|
|
18
20
|
static set reqPerTimeout(value: number);
|
|
19
21
|
static get timeoutMills(): number;
|
|
20
22
|
static set timeoutMills(value: number);
|
|
21
23
|
static create(reqPerTimeout?: number, timeoutMills?: number): {
|
|
22
|
-
push(func: Func): void;
|
|
24
|
+
push(func: Func, lane?: string): void;
|
|
23
25
|
shift(): void;
|
|
24
26
|
handleIdle(): void;
|
|
25
27
|
handleProcessing(): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type SendbirdChat from '@sendbird/chat';
|
|
3
|
-
import type { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
3
|
+
import type { BaseChannel, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
4
4
|
import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
|
|
5
5
|
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
6
|
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
@@ -35,6 +35,7 @@ export declare type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
|
35
35
|
export declare type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
36
36
|
export declare type SendbirdUserUpdateParams = UserUpdateParams;
|
|
37
37
|
export declare type SendbirdUser = User;
|
|
38
|
+
export declare type SendbirdRestrictedUser = RestrictedUser;
|
|
38
39
|
export declare type SendbirdMember = Member;
|
|
39
40
|
export declare type SendbirdGroupChannel = GroupChannel;
|
|
40
41
|
export declare type SendbirdBaseChannel = BaseChannel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"readmeFile": "./README.md",
|
|
77
77
|
"displayName": "@sendbird/uikit-utils"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "c778a84a632487047fe532db188b32dfa6e93a7f"
|
|
80
80
|
}
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export * from './ui-format/common';
|
|
|
24
24
|
export * from './sendbird/channel';
|
|
25
25
|
export * from './sendbird/message';
|
|
26
26
|
export * from './sendbird/attrs';
|
|
27
|
+
export * from './sendbird/user';
|
|
27
28
|
|
|
28
29
|
export const NOOP: () => void = () => void 0;
|
|
29
30
|
export const ASYNC_NOOP = async () => void 0;
|
|
@@ -35,8 +36,10 @@ export const SBErrorCode = {
|
|
|
35
36
|
};
|
|
36
37
|
export const SBErrorMessage = {
|
|
37
38
|
ACL:
|
|
38
|
-
|
|
39
|
-
'
|
|
39
|
+
'Sendbird provides various access control options when using the Chat SDK.\n' +
|
|
40
|
+
'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\n' +
|
|
41
|
+
'However, this may grant access to unwanted data or operations, leading to potential security concerns.\n' +
|
|
42
|
+
'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
export type {
|
|
@@ -76,4 +79,5 @@ export type {
|
|
|
76
79
|
SendbirdUserMessageUpdateParams,
|
|
77
80
|
SendbirdFileMessageUpdateParams,
|
|
78
81
|
SendbirdUserUpdateParams,
|
|
82
|
+
SendbirdRestrictedUser,
|
|
79
83
|
} from './types';
|
package/src/sendbird/channel.ts
CHANGED
|
@@ -12,20 +12,23 @@ export function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T):
|
|
|
12
12
|
return a.url !== b.url;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const
|
|
16
|
-
|
|
15
|
+
export const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {
|
|
16
|
+
const frozen = channel.isFrozen && channel.myRole !== 'operator';
|
|
17
|
+
const muted = channel.myMutedState === 'muted';
|
|
18
|
+
const disabled = frozen || muted;
|
|
19
|
+
return { disabled, frozen, muted };
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
export const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {
|
|
20
23
|
channels
|
|
21
24
|
.filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)
|
|
22
|
-
.forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
25
|
+
.forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
export const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {
|
|
26
29
|
channels
|
|
27
30
|
.filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)
|
|
28
|
-
.forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
31
|
+
.forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));
|
|
29
32
|
};
|
|
30
33
|
|
|
31
34
|
export function isDefaultCoverImage(coverUrl: string) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Role } from '@sendbird/chat';
|
|
2
|
+
|
|
3
|
+
export function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
4
|
+
export function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
5
|
+
export function ifOperator(role: Role, then: unknown, or?: unknown) {
|
|
6
|
+
if (role === 'operator') return then;
|
|
7
|
+
return or;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function ifMuted<T>(muted: boolean, then: T): T | undefined;
|
|
11
|
+
export function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
|
|
12
|
+
export function ifMuted(muted: boolean, then: unknown, or?: unknown) {
|
|
13
|
+
if (muted) return then;
|
|
14
|
+
return or;
|
|
15
|
+
}
|
|
@@ -5,10 +5,21 @@ let REQ_PER_TIMEOUT = 5;
|
|
|
5
5
|
let TIMEOUT_MILLS = 1000;
|
|
6
6
|
const SAFE_TIMEOUT_BUFFER = 100;
|
|
7
7
|
|
|
8
|
+
function generateRandomId() {
|
|
9
|
+
return Math.random().toString(16).slice(2);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export class BufferedRequest {
|
|
9
13
|
public static markAsRead = BufferedRequest.create();
|
|
10
14
|
public static markAsDelivered = BufferedRequest.create();
|
|
11
15
|
|
|
16
|
+
public static updateMarkAsReadOptions(reqPerTimeout: number, timeoutMills: number) {
|
|
17
|
+
BufferedRequest.markAsRead = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
18
|
+
}
|
|
19
|
+
public static updateMarkAsDeliveredOptions(reqPerTimeout: number, timeoutMills: number) {
|
|
20
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create(reqPerTimeout, timeoutMills);
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
public static get reqPerTimeout() {
|
|
13
24
|
return REQ_PER_TIMEOUT;
|
|
14
25
|
}
|
|
@@ -28,28 +39,33 @@ export class BufferedRequest {
|
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
public static create(reqPerTimeout = REQ_PER_TIMEOUT, timeoutMills = TIMEOUT_MILLS) {
|
|
31
|
-
const waitQueue
|
|
32
|
-
const nextQueue
|
|
42
|
+
const waitQueue = new Map<string, Func>();
|
|
43
|
+
const nextQueue = new Map<string, Func>();
|
|
33
44
|
|
|
34
45
|
let state: State = 'idle';
|
|
35
46
|
let timeout: NodeJS.Timeout | undefined;
|
|
36
47
|
|
|
37
48
|
return {
|
|
38
|
-
push(func: Func) {
|
|
39
|
-
waitQueue.
|
|
49
|
+
push(func: Func, lane?: string) {
|
|
50
|
+
waitQueue.set(lane ?? generateRandomId(), func);
|
|
40
51
|
this.invoke();
|
|
41
52
|
},
|
|
42
53
|
shift() {
|
|
43
|
-
if (nextQueue.
|
|
44
|
-
const nextRemains = Math.min(reqPerTimeout - nextQueue.
|
|
54
|
+
if (nextQueue.size < reqPerTimeout) {
|
|
55
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.size, waitQueue.size);
|
|
56
|
+
const lanes = [...waitQueue.keys()];
|
|
45
57
|
for (let n = 0; n < nextRemains; n++) {
|
|
46
|
-
const
|
|
47
|
-
|
|
58
|
+
const lane = lanes[n];
|
|
59
|
+
const func = waitQueue.get(lane);
|
|
60
|
+
if (func) {
|
|
61
|
+
waitQueue.delete(lane);
|
|
62
|
+
nextQueue.set(lane, func);
|
|
63
|
+
}
|
|
48
64
|
}
|
|
49
65
|
}
|
|
50
66
|
},
|
|
51
67
|
handleIdle() {
|
|
52
|
-
if (0 < nextQueue.
|
|
68
|
+
if (0 < nextQueue.size) {
|
|
53
69
|
state = 'processing';
|
|
54
70
|
this.invoke();
|
|
55
71
|
}
|
|
@@ -59,15 +75,24 @@ export class BufferedRequest {
|
|
|
59
75
|
|
|
60
76
|
timeout = setTimeout(() => {
|
|
61
77
|
timeout = undefined;
|
|
62
|
-
if (0 < nextQueue.
|
|
78
|
+
if (0 < nextQueue.size || 0 < waitQueue.size) {
|
|
63
79
|
this.invoke();
|
|
64
80
|
} else {
|
|
65
81
|
state = 'idle';
|
|
66
82
|
}
|
|
67
83
|
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
68
84
|
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
let index = 0;
|
|
86
|
+
const nextRequestBaseTimeout = timeoutMills / nextQueue.size;
|
|
87
|
+
nextQueue.forEach((func) => {
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
func();
|
|
90
|
+
// TODO: Add retry
|
|
91
|
+
//.catch(() => waitQueue.set(lane, func));
|
|
92
|
+
}, nextRequestBaseTimeout * index);
|
|
93
|
+
index++;
|
|
94
|
+
});
|
|
95
|
+
nextQueue.clear();
|
|
71
96
|
},
|
|
72
97
|
async invoke() {
|
|
73
98
|
this.shift();
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type React from 'react';
|
|
5
5
|
|
|
6
6
|
import type SendbirdChat from '@sendbird/chat';
|
|
7
|
-
import type { BaseChannel, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
7
|
+
import type { BaseChannel, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
8
8
|
import type {
|
|
9
9
|
GroupChannel,
|
|
10
10
|
GroupChannelCollection,
|
|
@@ -73,6 +73,7 @@ export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
|
73
73
|
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
74
74
|
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
75
75
|
export type SendbirdUser = User;
|
|
76
|
+
export type SendbirdRestrictedUser = RestrictedUser;
|
|
76
77
|
export type SendbirdMember = Member;
|
|
77
78
|
export type SendbirdGroupChannel = GroupChannel;
|
|
78
79
|
export type SendbirdBaseChannel = BaseChannel;
|