@sendbird/uikit-utils 2.0.1 → 2.0.3
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 +10 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +6 -7
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/shared/bufferedRequest.js +103 -0
- package/lib/commonjs/shared/bufferedRequest.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +6 -7
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/shared/bufferedRequest.js +93 -0
- package/lib/module/shared/bufferedRequest.js.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/sendbird/channel.d.ts +3 -3
- package/lib/typescript/src/shared/bufferedRequest.d.ts +29 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/sendbird/channel.ts +10 -14
- package/src/shared/bufferedRequest.ts +85 -0
package/lib/commonjs/index.js
CHANGED
|
@@ -27,9 +27,16 @@ var _exportNames = {
|
|
|
27
27
|
replaceUrlAsComponents: true,
|
|
28
28
|
normalizeFileName: true,
|
|
29
29
|
emailRegex: true,
|
|
30
|
-
phoneRegex: true
|
|
30
|
+
phoneRegex: true,
|
|
31
|
+
BufferedRequest: true
|
|
31
32
|
};
|
|
32
33
|
exports.ASYNC_NOOP = void 0;
|
|
34
|
+
Object.defineProperty(exports, "BufferedRequest", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _bufferedRequest.BufferedRequest;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
33
40
|
Object.defineProperty(exports, "Logger", {
|
|
34
41
|
enumerable: true,
|
|
35
42
|
get: function () {
|
|
@@ -146,6 +153,8 @@ var _conditionChaining = _interopRequireDefault(require("./shared/conditionChain
|
|
|
146
153
|
|
|
147
154
|
var _regex = require("./shared/regex");
|
|
148
155
|
|
|
156
|
+
var _bufferedRequest = require("./shared/bufferedRequest");
|
|
157
|
+
|
|
149
158
|
var _hooks = require("./hooks");
|
|
150
159
|
|
|
151
160
|
Object.keys(_hooks).forEach(function (key) {
|
|
@@ -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';\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 \"An error occurred because you don't have access to the user list in your application.\\n\" +\n 'In order to gain access, you can turn on this attribute in the Access Control List settings 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} from './types';\n"],"mappings":"
|
|
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 \"An error occurred because you don't have access to the user list in your application.\\n\" +\n 'In order to gain access, you can turn on this attribute in the Access Control List settings 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} 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;;;;;;;;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,4FACA;AAH0B,CAAvB"}
|
|
@@ -11,6 +11,8 @@ exports.isDefaultCoverImage = isDefaultCoverImage;
|
|
|
11
11
|
exports.isDifferentChannel = isDifferentChannel;
|
|
12
12
|
exports.isGroupChannelChatUnavailable = void 0;
|
|
13
13
|
|
|
14
|
+
var _bufferedRequest = require("../shared/bufferedRequest");
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Diff utils for channel
|
|
16
18
|
* @param {SendbirdBaseChannel} [a]
|
|
@@ -28,17 +30,14 @@ const isGroupChannelChatUnavailable = channel => {
|
|
|
28
30
|
|
|
29
31
|
exports.isGroupChannelChatUnavailable = isGroupChannelChatUnavailable;
|
|
30
32
|
|
|
31
|
-
const confirmAndMarkAsRead = async
|
|
32
|
-
|
|
33
|
-
await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);
|
|
33
|
+
const confirmAndMarkAsRead = async channels => {
|
|
34
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
exports.confirmAndMarkAsRead = confirmAndMarkAsRead;
|
|
37
38
|
|
|
38
|
-
const confirmAndMarkAsDelivered = async
|
|
39
|
-
|
|
40
|
-
await sdk.groupChannel.markAsDelivered(channel.url);
|
|
41
|
-
}
|
|
39
|
+
const confirmAndMarkAsDelivered = async channels => {
|
|
40
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => _bufferedRequest.BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
exports.confirmAndMarkAsDelivered = confirmAndMarkAsDelivered;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","confirmAndMarkAsRead","
|
|
1
|
+
{"version":3,"names":["isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","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 isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\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()));\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()));\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,6BAA6B,GAAIC,OAAD,IAAmC;EAC9E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;;;;AAIA,MAAMC,oBAAoB,GAAG,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,CAFnB;AAGD,CAJM;;;;AAMA,MAAME,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,CAFnB;AAGD,CAJM;;;;AAMA,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BnB,OAA7B,EAA4DoB,aAA5D,EAAoF;EACzF,OAAOpB,OAAO,CAACqB,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,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BufferedRequest = void 0;
|
|
7
|
+
|
|
8
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
|
|
10
|
+
let REQ_PER_TIMEOUT = 5;
|
|
11
|
+
let TIMEOUT_MILLS = 1000;
|
|
12
|
+
const SAFE_TIMEOUT_BUFFER = 100;
|
|
13
|
+
|
|
14
|
+
class BufferedRequest {
|
|
15
|
+
static get reqPerTimeout() {
|
|
16
|
+
return REQ_PER_TIMEOUT;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static set reqPerTimeout(value) {
|
|
20
|
+
REQ_PER_TIMEOUT = value;
|
|
21
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
22
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static get timeoutMills() {
|
|
26
|
+
return TIMEOUT_MILLS;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static set timeoutMills(value) {
|
|
30
|
+
TIMEOUT_MILLS = value;
|
|
31
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
32
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static create() {
|
|
36
|
+
let reqPerTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : REQ_PER_TIMEOUT;
|
|
37
|
+
let timeoutMills = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TIMEOUT_MILLS;
|
|
38
|
+
const waitQueue = [];
|
|
39
|
+
const nextQueue = [];
|
|
40
|
+
let state = 'idle';
|
|
41
|
+
let timeout;
|
|
42
|
+
return {
|
|
43
|
+
push(func) {
|
|
44
|
+
waitQueue.push(func);
|
|
45
|
+
this.invoke();
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
shift() {
|
|
49
|
+
if (nextQueue.length < reqPerTimeout) {
|
|
50
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.length, waitQueue.length);
|
|
51
|
+
|
|
52
|
+
for (let n = 0; n < nextRemains; n++) {
|
|
53
|
+
const func = waitQueue.shift();
|
|
54
|
+
if (func) nextQueue.push(func);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
handleIdle() {
|
|
60
|
+
if (0 < nextQueue.length) {
|
|
61
|
+
state = 'processing';
|
|
62
|
+
this.invoke();
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
handleProcessing() {
|
|
67
|
+
if (timeout) return;
|
|
68
|
+
timeout = setTimeout(() => {
|
|
69
|
+
timeout = undefined;
|
|
70
|
+
|
|
71
|
+
if (0 < nextQueue.length || 0 < waitQueue.length) {
|
|
72
|
+
this.invoke();
|
|
73
|
+
} else {
|
|
74
|
+
state = 'idle';
|
|
75
|
+
}
|
|
76
|
+
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
77
|
+
nextQueue.forEach(func => func());
|
|
78
|
+
nextQueue.length = 0;
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
async invoke() {
|
|
82
|
+
this.shift();
|
|
83
|
+
|
|
84
|
+
if (state === 'idle') {
|
|
85
|
+
this.handleIdle();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (state === 'processing') {
|
|
89
|
+
this.handleProcessing();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.BufferedRequest = BufferedRequest;
|
|
99
|
+
|
|
100
|
+
_defineProperty(BufferedRequest, "markAsRead", BufferedRequest.create());
|
|
101
|
+
|
|
102
|
+
_defineProperty(BufferedRequest, "markAsDelivered", BufferedRequest.create());
|
|
103
|
+
//# sourceMappingURL=bufferedRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","BufferedRequest","reqPerTimeout","value","markAsRead","create","markAsDelivered","timeoutMills","waitQueue","nextQueue","state","timeout","push","func","invoke","shift","length","nextRemains","Math","min","n","handleIdle","handleProcessing","setTimeout","undefined","forEach"],"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\nexport class BufferedRequest {\n public static markAsRead = BufferedRequest.create();\n public static markAsDelivered = BufferedRequest.create();\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: Func[] = [];\n const nextQueue: Func[] = [];\n\n let state: State = 'idle';\n let timeout: NodeJS.Timeout | undefined;\n\n return {\n push(func: Func) {\n waitQueue.push(func);\n this.invoke();\n },\n shift() {\n if (nextQueue.length < reqPerTimeout) {\n const nextRemains = Math.min(reqPerTimeout - nextQueue.length, waitQueue.length);\n for (let n = 0; n < nextRemains; n++) {\n const func = waitQueue.shift();\n if (func) nextQueue.push(func);\n }\n }\n },\n handleIdle() {\n if (0 < nextQueue.length) {\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.length || 0 < waitQueue.length) {\n this.invoke();\n } else {\n state = 'idle';\n }\n }, timeoutMills + SAFE_TIMEOUT_BUFFER);\n\n nextQueue.forEach((func) => func());\n nextQueue.length = 0;\n },\n async invoke() {\n this.shift();\n\n if (state === 'idle') {\n this.handleIdle();\n }\n\n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GAAG,CAAb,EAAgBA,CAAC,GAAGH,WAApB,EAAiCG,CAAC,EAAlC,EAAsC;YACpC,MAAMP,IAAI,GAAGL,SAAS,CAACO,KAAV,EAAb;YACA,IAAIF,IAAJ,EAAUJ,SAAS,CAACG,IAAV,CAAeC,IAAf;UACX;QACF;MACF,CAbI;;MAcLQ,UAAU,GAAG;QACX,IAAI,IAAIZ,SAAS,CAACO,MAAlB,EAA0B;UACxBN,KAAK,GAAG,YAAR;UACA,KAAKI,MAAL;QACD;MACF,CAnBI;;MAoBLQ,gBAAgB,GAAG;QACjB,IAAIX,OAAJ,EAAa;QAEbA,OAAO,GAAGY,UAAU,CAAC,MAAM;UACzBZ,OAAO,GAAGa,SAAV;;UACA,IAAI,IAAIf,SAAS,CAACO,MAAd,IAAwB,IAAIR,SAAS,CAACQ,MAA1C,EAAkD;YAChD,KAAKF,MAAL;UACD,CAFD,MAEO;YACLJ,KAAK,GAAG,MAAR;UACD;QACF,CAPmB,EAOjBH,YAAY,GAAGP,mBAPE,CAApB;QASAS,SAAS,CAACgB,OAAV,CAAmBZ,IAAD,IAAUA,IAAI,EAAhC;QACAJ,SAAS,CAACO,MAAV,GAAmB,CAAnB;MACD,CAlCI;;MAmCL,MAAMF,MAAN,GAAe;QACb,KAAKC,KAAL;;QAEA,IAAIL,KAAK,KAAK,MAAd,EAAsB;UACpB,KAAKW,UAAL;QACD;;QAED,IAAIX,KAAK,KAAK,YAAd,EAA4B;UAC1B,KAAKY,gBAAL;QACD;MACF;;IA7CI,CAAP;EA+CD;;AA5E0B;;;;gBAAhBrB,e,gBACgBA,eAAe,CAACI,MAAhB,E;;gBADhBJ,e,qBAEqBA,eAAe,CAACI,MAAhB,E"}
|
package/lib/module/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap
|
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
4
|
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
5
|
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex } from './shared/regex';
|
|
6
|
+
export { BufferedRequest } from './shared/bufferedRequest';
|
|
6
7
|
export * from './hooks';
|
|
7
8
|
export * from './ui-format/groupChannel';
|
|
8
9
|
export * from './ui-format/common';
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","conditionChaining","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","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';\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 \"An error occurred because you don't have access to the user list in your application.\\n\" +\n 'In order to gain access, you can turn on this attribute in the Access Control List settings 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} 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;
|
|
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 \"An error occurred because you don't have access to the user list in your application.\\n\" +\n 'In order to gain access, you can turn on this attribute in the Access Control List settings 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} 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;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,4FACA;AAH0B,CAAvB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { BufferedRequest } from '../shared/bufferedRequest';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Diff utils for channel
|
|
3
5
|
* @param {SendbirdBaseChannel} [a]
|
|
@@ -11,14 +13,11 @@ export function isDifferentChannel(a, b) {
|
|
|
11
13
|
export const isGroupChannelChatUnavailable = channel => {
|
|
12
14
|
return channel.myMutedState === 'muted' || channel.isFrozen && channel.myRole !== 'operator';
|
|
13
15
|
};
|
|
14
|
-
export const confirmAndMarkAsRead = async
|
|
15
|
-
|
|
16
|
-
await sdk.groupChannel.markAsReadWithChannelUrls(channelUrls);
|
|
16
|
+
export const confirmAndMarkAsRead = async channels => {
|
|
17
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
17
18
|
};
|
|
18
|
-
export const confirmAndMarkAsDelivered = async
|
|
19
|
-
|
|
20
|
-
await sdk.groupChannel.markAsDelivered(channel.url);
|
|
21
|
-
}
|
|
19
|
+
export const confirmAndMarkAsDelivered = async channels => {
|
|
20
|
+
channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
22
21
|
};
|
|
23
22
|
export function isDefaultCoverImage(coverUrl) {
|
|
24
23
|
return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","confirmAndMarkAsRead","
|
|
1
|
+
{"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","isGroupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","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 isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\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()));\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()));\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,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AAkCA,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,93 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
let REQ_PER_TIMEOUT = 5;
|
|
4
|
+
let TIMEOUT_MILLS = 1000;
|
|
5
|
+
const SAFE_TIMEOUT_BUFFER = 100;
|
|
6
|
+
export class BufferedRequest {
|
|
7
|
+
static get reqPerTimeout() {
|
|
8
|
+
return REQ_PER_TIMEOUT;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static set reqPerTimeout(value) {
|
|
12
|
+
REQ_PER_TIMEOUT = value;
|
|
13
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
14
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static get timeoutMills() {
|
|
18
|
+
return TIMEOUT_MILLS;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static set timeoutMills(value) {
|
|
22
|
+
TIMEOUT_MILLS = value;
|
|
23
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
24
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static create() {
|
|
28
|
+
let reqPerTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : REQ_PER_TIMEOUT;
|
|
29
|
+
let timeoutMills = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TIMEOUT_MILLS;
|
|
30
|
+
const waitQueue = [];
|
|
31
|
+
const nextQueue = [];
|
|
32
|
+
let state = 'idle';
|
|
33
|
+
let timeout;
|
|
34
|
+
return {
|
|
35
|
+
push(func) {
|
|
36
|
+
waitQueue.push(func);
|
|
37
|
+
this.invoke();
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
shift() {
|
|
41
|
+
if (nextQueue.length < reqPerTimeout) {
|
|
42
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.length, waitQueue.length);
|
|
43
|
+
|
|
44
|
+
for (let n = 0; n < nextRemains; n++) {
|
|
45
|
+
const func = waitQueue.shift();
|
|
46
|
+
if (func) nextQueue.push(func);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
handleIdle() {
|
|
52
|
+
if (0 < nextQueue.length) {
|
|
53
|
+
state = 'processing';
|
|
54
|
+
this.invoke();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
handleProcessing() {
|
|
59
|
+
if (timeout) return;
|
|
60
|
+
timeout = setTimeout(() => {
|
|
61
|
+
timeout = undefined;
|
|
62
|
+
|
|
63
|
+
if (0 < nextQueue.length || 0 < waitQueue.length) {
|
|
64
|
+
this.invoke();
|
|
65
|
+
} else {
|
|
66
|
+
state = 'idle';
|
|
67
|
+
}
|
|
68
|
+
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
69
|
+
nextQueue.forEach(func => func());
|
|
70
|
+
nextQueue.length = 0;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async invoke() {
|
|
74
|
+
this.shift();
|
|
75
|
+
|
|
76
|
+
if (state === 'idle') {
|
|
77
|
+
this.handleIdle();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (state === 'processing') {
|
|
81
|
+
this.handleProcessing();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_defineProperty(BufferedRequest, "markAsRead", BufferedRequest.create());
|
|
91
|
+
|
|
92
|
+
_defineProperty(BufferedRequest, "markAsDelivered", BufferedRequest.create());
|
|
93
|
+
//# sourceMappingURL=bufferedRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["REQ_PER_TIMEOUT","TIMEOUT_MILLS","SAFE_TIMEOUT_BUFFER","BufferedRequest","reqPerTimeout","value","markAsRead","create","markAsDelivered","timeoutMills","waitQueue","nextQueue","state","timeout","push","func","invoke","shift","length","nextRemains","Math","min","n","handleIdle","handleProcessing","setTimeout","undefined","forEach"],"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\nexport class BufferedRequest {\n public static markAsRead = BufferedRequest.create();\n public static markAsDelivered = BufferedRequest.create();\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: Func[] = [];\n const nextQueue: Func[] = [];\n\n let state: State = 'idle';\n let timeout: NodeJS.Timeout | undefined;\n\n return {\n push(func: Func) {\n waitQueue.push(func);\n this.invoke();\n },\n shift() {\n if (nextQueue.length < reqPerTimeout) {\n const nextRemains = Math.min(reqPerTimeout - nextQueue.length, waitQueue.length);\n for (let n = 0; n < nextRemains; n++) {\n const func = waitQueue.shift();\n if (func) nextQueue.push(func);\n }\n }\n },\n handleIdle() {\n if (0 < nextQueue.length) {\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.length || 0 < waitQueue.length) {\n this.invoke();\n } else {\n state = 'idle';\n }\n }, timeoutMills + SAFE_TIMEOUT_BUFFER);\n\n nextQueue.forEach((func) => func());\n nextQueue.length = 0;\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,OAAO,MAAMC,eAAN,CAAsB;EAII,WAAbC,aAAa,GAAG;IAChC,OAAOJ,eAAP;EACD;;EAC8B,WAAbI,aAAa,CAACC,KAAD,EAAgB;IAC7CL,eAAe,GAAGK,KAAlB;IACAF,eAAe,CAACG,UAAhB,GAA6BH,eAAe,CAACI,MAAhB,EAA7B;IACAJ,eAAe,CAACK,eAAhB,GAAkCL,eAAe,CAACI,MAAhB,EAAlC;EACD;;EAE6B,WAAZE,YAAY,GAAG;IAC/B,OAAOR,aAAP;EACD;;EAC6B,WAAZQ,YAAY,CAACJ,KAAD,EAAgB;IAC5CJ,aAAa,GAAGI,KAAhB;IACAF,eAAe,CAACG,UAAhB,GAA6BH,eAAe,CAACI,MAAhB,EAA7B;IACAJ,eAAe,CAACK,eAAhB,GAAkCL,eAAe,CAACI,MAAhB,EAAlC;EACD;;EAEmB,OAANA,MAAM,GAAgE;IAAA,IAA/DH,aAA+D,uEAA/CJ,eAA+C;IAAA,IAA9BS,YAA8B,uEAAfR,aAAe;IAClF,MAAMS,SAAiB,GAAG,EAA1B;IACA,MAAMC,SAAiB,GAAG,EAA1B;IAEA,IAAIC,KAAY,GAAG,MAAnB;IACA,IAAIC,OAAJ;IAEA,OAAO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QACD;MACF;;IA7CI,CAAP;EA+CD;;AA5E0B;;gBAAhBrB,e,gBACgBA,eAAe,CAACI,MAAhB,E;;gBADhBJ,e,qBAEqBA,eAAe,CAACI,MAAhB,E"}
|
|
@@ -3,6 +3,7 @@ export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap
|
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
4
|
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
5
|
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, } from './shared/regex';
|
|
6
|
+
export { BufferedRequest } from './shared/bufferedRequest';
|
|
6
7
|
export * from './hooks';
|
|
7
8
|
export * from './ui-format/groupChannel';
|
|
8
9
|
export * from './ui-format/common';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SendbirdBaseChannel, SendbirdChannel,
|
|
1
|
+
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Diff utils for channel
|
|
4
4
|
* @param {SendbirdBaseChannel} [a]
|
|
@@ -7,8 +7,8 @@ import type { SendbirdBaseChannel, SendbirdChannel, SendbirdChatSDK, SendbirdGro
|
|
|
7
7
|
* */
|
|
8
8
|
export declare function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean;
|
|
9
9
|
export declare const isGroupChannelChatUnavailable: (channel: SendbirdGroupChannel) => boolean;
|
|
10
|
-
export declare const confirmAndMarkAsRead: (
|
|
11
|
-
export declare const confirmAndMarkAsDelivered: (
|
|
10
|
+
export declare const confirmAndMarkAsRead: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
11
|
+
export declare const confirmAndMarkAsDelivered: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
12
12
|
export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
13
13
|
export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("@sendbird/chat/groupChannel").Member[];
|
|
14
14
|
export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare type Func = (...args: unknown[]) => Promise<unknown>;
|
|
2
|
+
export declare class BufferedRequest {
|
|
3
|
+
static markAsRead: {
|
|
4
|
+
push(func: Func): void;
|
|
5
|
+
shift(): void;
|
|
6
|
+
handleIdle(): void;
|
|
7
|
+
handleProcessing(): void;
|
|
8
|
+
invoke(): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
static markAsDelivered: {
|
|
11
|
+
push(func: Func): void;
|
|
12
|
+
shift(): void;
|
|
13
|
+
handleIdle(): void;
|
|
14
|
+
handleProcessing(): void;
|
|
15
|
+
invoke(): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
static get reqPerTimeout(): number;
|
|
18
|
+
static set reqPerTimeout(value: number);
|
|
19
|
+
static get timeoutMills(): number;
|
|
20
|
+
static set timeoutMills(value: number);
|
|
21
|
+
static create(reqPerTimeout?: number, timeoutMills?: number): {
|
|
22
|
+
push(func: Func): void;
|
|
23
|
+
shift(): void;
|
|
24
|
+
handleIdle(): void;
|
|
25
|
+
handleProcessing(): void;
|
|
26
|
+
invoke(): Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
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": "e3a34ae962741ffd2b647a466cf97e38f5006379"
|
|
80
80
|
}
|
package/src/index.ts
CHANGED
package/src/sendbird/channel.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
SendbirdChannel,
|
|
4
|
-
SendbirdChatSDK,
|
|
5
|
-
SendbirdGroupChannel,
|
|
6
|
-
SendbirdOpenChannel,
|
|
7
|
-
} from '../types';
|
|
1
|
+
import { BufferedRequest } from '../shared/bufferedRequest';
|
|
2
|
+
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* Diff utils for channel
|
|
@@ -21,15 +16,16 @@ export const isGroupChannelChatUnavailable = (channel: SendbirdGroupChannel) =>
|
|
|
21
16
|
return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');
|
|
22
17
|
};
|
|
23
18
|
|
|
24
|
-
export const confirmAndMarkAsRead = async (
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
export const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {
|
|
20
|
+
channels
|
|
21
|
+
.filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)
|
|
22
|
+
.forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead()));
|
|
27
23
|
};
|
|
28
24
|
|
|
29
|
-
export const confirmAndMarkAsDelivered = async (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
export const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {
|
|
26
|
+
channels
|
|
27
|
+
.filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)
|
|
28
|
+
.forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered()));
|
|
33
29
|
};
|
|
34
30
|
|
|
35
31
|
export function isDefaultCoverImage(coverUrl: string) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
type Func = (...args: unknown[]) => Promise<unknown>;
|
|
2
|
+
type State = 'idle' | 'processing';
|
|
3
|
+
|
|
4
|
+
let REQ_PER_TIMEOUT = 5;
|
|
5
|
+
let TIMEOUT_MILLS = 1000;
|
|
6
|
+
const SAFE_TIMEOUT_BUFFER = 100;
|
|
7
|
+
|
|
8
|
+
export class BufferedRequest {
|
|
9
|
+
public static markAsRead = BufferedRequest.create();
|
|
10
|
+
public static markAsDelivered = BufferedRequest.create();
|
|
11
|
+
|
|
12
|
+
public static get reqPerTimeout() {
|
|
13
|
+
return REQ_PER_TIMEOUT;
|
|
14
|
+
}
|
|
15
|
+
public static set reqPerTimeout(value: number) {
|
|
16
|
+
REQ_PER_TIMEOUT = value;
|
|
17
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
18
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static get timeoutMills() {
|
|
22
|
+
return TIMEOUT_MILLS;
|
|
23
|
+
}
|
|
24
|
+
public static set timeoutMills(value: number) {
|
|
25
|
+
TIMEOUT_MILLS = value;
|
|
26
|
+
BufferedRequest.markAsRead = BufferedRequest.create();
|
|
27
|
+
BufferedRequest.markAsDelivered = BufferedRequest.create();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static create(reqPerTimeout = REQ_PER_TIMEOUT, timeoutMills = TIMEOUT_MILLS) {
|
|
31
|
+
const waitQueue: Func[] = [];
|
|
32
|
+
const nextQueue: Func[] = [];
|
|
33
|
+
|
|
34
|
+
let state: State = 'idle';
|
|
35
|
+
let timeout: NodeJS.Timeout | undefined;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
push(func: Func) {
|
|
39
|
+
waitQueue.push(func);
|
|
40
|
+
this.invoke();
|
|
41
|
+
},
|
|
42
|
+
shift() {
|
|
43
|
+
if (nextQueue.length < reqPerTimeout) {
|
|
44
|
+
const nextRemains = Math.min(reqPerTimeout - nextQueue.length, waitQueue.length);
|
|
45
|
+
for (let n = 0; n < nextRemains; n++) {
|
|
46
|
+
const func = waitQueue.shift();
|
|
47
|
+
if (func) nextQueue.push(func);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
handleIdle() {
|
|
52
|
+
if (0 < nextQueue.length) {
|
|
53
|
+
state = 'processing';
|
|
54
|
+
this.invoke();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
handleProcessing() {
|
|
58
|
+
if (timeout) return;
|
|
59
|
+
|
|
60
|
+
timeout = setTimeout(() => {
|
|
61
|
+
timeout = undefined;
|
|
62
|
+
if (0 < nextQueue.length || 0 < waitQueue.length) {
|
|
63
|
+
this.invoke();
|
|
64
|
+
} else {
|
|
65
|
+
state = 'idle';
|
|
66
|
+
}
|
|
67
|
+
}, timeoutMills + SAFE_TIMEOUT_BUFFER);
|
|
68
|
+
|
|
69
|
+
nextQueue.forEach((func) => func());
|
|
70
|
+
nextQueue.length = 0;
|
|
71
|
+
},
|
|
72
|
+
async invoke() {
|
|
73
|
+
this.shift();
|
|
74
|
+
|
|
75
|
+
if (state === 'idle') {
|
|
76
|
+
this.handleIdle();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (state === 'processing') {
|
|
80
|
+
this.handleProcessing();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|