@sendbird/uikit-utils 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/hooks/index.js +38 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/react-native.js +5 -7
- package/lib/commonjs/hooks/react-native.js.map +1 -1
- package/lib/commonjs/index.js +65 -118
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/sendbird/channel.js +29 -1
- package/lib/commonjs/sendbird/channel.js.map +1 -1
- package/lib/commonjs/sendbird/message.js +56 -1
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/sendbird/user.js +0 -6
- package/lib/commonjs/sendbird/user.js.map +1 -1
- package/lib/commonjs/shared/file.js +225 -0
- package/lib/commonjs/shared/file.js.map +1 -0
- package/lib/commonjs/shared/index.js +18 -39
- package/lib/commonjs/shared/index.js.map +1 -1
- package/lib/commonjs/shared/regex.js +1 -46
- package/lib/commonjs/shared/regex.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui-format/openChannel.js +22 -0
- package/lib/commonjs/ui-format/openChannel.js.map +1 -0
- package/lib/module/hooks/index.js +29 -1
- package/lib/module/hooks/index.js.map +1 -1
- package/lib/module/hooks/react-native.js +6 -8
- package/lib/module/hooks/react-native.js.map +1 -1
- package/lib/module/index.js +11 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/sendbird/channel.js +23 -1
- package/lib/module/sendbird/channel.js.map +1 -1
- package/lib/module/sendbird/message.js +51 -1
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/sendbird/user.js +0 -4
- package/lib/module/sendbird/user.js.map +1 -1
- package/lib/module/shared/file.js +192 -0
- package/lib/module/shared/file.js.map +1 -0
- package/lib/module/shared/index.js +15 -32
- package/lib/module/shared/index.js.map +1 -1
- package/lib/module/shared/regex.js +0 -33
- package/lib/module/shared/regex.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui-format/openChannel.js +10 -0
- package/lib/module/ui-format/openChannel.js.map +1 -0
- package/lib/typescript/src/hooks/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts +10 -5
- package/lib/typescript/src/sendbird/channel.d.ts +10 -1
- package/lib/typescript/src/sendbird/message.d.ts +3 -0
- package/lib/typescript/src/sendbird/user.d.ts +0 -2
- package/lib/typescript/src/shared/file.d.ts +68 -0
- package/lib/typescript/src/shared/index.d.ts +13 -13
- package/lib/typescript/src/shared/regex.d.ts +0 -6
- package/lib/typescript/src/types.d.ts +8 -3
- package/lib/typescript/src/ui-format/openChannel.d.ts +3 -0
- package/package.json +4 -4
- package/src/hooks/index.ts +31 -1
- package/src/hooks/react-native.ts +6 -8
- package/src/index.ts +20 -20
- package/src/sendbird/channel.ts +33 -2
- package/src/sendbird/message.ts +54 -1
- package/src/sendbird/user.ts +0 -7
- package/src/shared/file.ts +193 -0
- package/src/shared/index.ts +15 -32
- package/src/shared/regex.ts +0 -34
- package/src/types.ts +17 -2
- package/src/ui-format/openChannel.ts +11 -0
- package/lib/commonjs/shared/pubsub.js +0 -54
- package/lib/commonjs/shared/pubsub.js.map +0 -1
- package/lib/module/shared/pubsub.js +0 -45
- package/lib/module/shared/pubsub.js.map +0 -1
- package/lib/typescript/src/shared/pubsub.d.ts +0 -8
- package/src/shared/pubsub.ts +0 -42
package/src/sendbird/user.ts
CHANGED
|
@@ -9,13 +9,6 @@ export function ifOperator(role: Role, then: unknown, or?: unknown) {
|
|
|
9
9
|
return or;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function ifMuted<T>(muted: boolean, then: T): T | undefined;
|
|
13
|
-
export function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
|
|
14
|
-
export function ifMuted(muted: boolean, then: unknown, or?: unknown) {
|
|
15
|
-
if (muted) return then;
|
|
16
|
-
return or;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
export function getUserUniqId<T extends UserStruct>(user: T) {
|
|
20
13
|
return user.userId;
|
|
21
14
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const EXTENSION_MIME_MAP = {
|
|
2
|
+
// Image
|
|
3
|
+
'jpeg': 'image/jpeg',
|
|
4
|
+
'jpg': 'image/jpeg',
|
|
5
|
+
'png': 'image/png',
|
|
6
|
+
'gif': 'image/gif',
|
|
7
|
+
'webp': 'image/webp',
|
|
8
|
+
'svg': 'image/svg+xml',
|
|
9
|
+
|
|
10
|
+
// Video
|
|
11
|
+
'3gp': 'video/3gpp',
|
|
12
|
+
'mp4': 'video/mp4',
|
|
13
|
+
'mpeg': 'video/mpeg',
|
|
14
|
+
'ogv': 'video/ogg',
|
|
15
|
+
'video/quicktime': 'mov',
|
|
16
|
+
'webm': 'video/webm',
|
|
17
|
+
'avi': 'video/x-msvideo',
|
|
18
|
+
|
|
19
|
+
// Audio
|
|
20
|
+
'aac': 'audio/aac',
|
|
21
|
+
'mid': 'audio/midi',
|
|
22
|
+
'mp3': 'audio/mpeg',
|
|
23
|
+
'ogg': 'audio/ogg',
|
|
24
|
+
'wav': 'audio/wav',
|
|
25
|
+
'weba': 'audio/webm',
|
|
26
|
+
|
|
27
|
+
// Files
|
|
28
|
+
'txt': 'text/plain',
|
|
29
|
+
'pdf': 'application/pdf',
|
|
30
|
+
'doc': 'application/msword',
|
|
31
|
+
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
32
|
+
'xls': 'application/vnd.ms-excel',
|
|
33
|
+
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
34
|
+
'ppt': 'application/vnd.ms-powerpoint',
|
|
35
|
+
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
36
|
+
'zip': 'application/zip',
|
|
37
|
+
'json': 'application/json',
|
|
38
|
+
'gzip': 'application/x-gzip',
|
|
39
|
+
} as Record<string, string>;
|
|
40
|
+
|
|
41
|
+
export const imageExtRegex = /jpeg|jpg|png|webp|gif/i;
|
|
42
|
+
export const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;
|
|
43
|
+
export const videoExtRegex = /mov|vod|mp4|avi/i;
|
|
44
|
+
export const getFileType = (extOrType: string) => {
|
|
45
|
+
if (extOrType.indexOf('/') > -1) {
|
|
46
|
+
const type = extOrType.split('/')[0];
|
|
47
|
+
if (type === 'video') return 'video';
|
|
48
|
+
if (type === 'audio') return 'audio';
|
|
49
|
+
if (type === 'image') return 'image';
|
|
50
|
+
return 'file';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (extOrType.match(imageExtRegex)) return 'image';
|
|
54
|
+
if (extOrType.match(audioExtRegex)) return 'audio';
|
|
55
|
+
if (extOrType.match(videoExtRegex)) return 'video';
|
|
56
|
+
return 'file';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Calculates the downscaled size of an image while preserving its aspect ratio.
|
|
61
|
+
*
|
|
62
|
+
* @param {Object} origin - The original size object with `width` and `height` properties.
|
|
63
|
+
* @param {Object} resizing - The resizing object with optional `width` and `height` properties.
|
|
64
|
+
* @returns {Object} - A new size object with the downscaled `width` and `height` properties.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* getDownscaleSize({ width: 1200, height: 800 }, { width: 600 }); // returns { width: 600, height: 400 }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
type Size = { width: number; height: number };
|
|
71
|
+
export function getDownscaleSize(origin: Size, resizing: Partial<Size>) {
|
|
72
|
+
let ratio: number;
|
|
73
|
+
|
|
74
|
+
const maxWidth = resizing.width || origin.width,
|
|
75
|
+
maxHeight = resizing.height || origin.height;
|
|
76
|
+
|
|
77
|
+
if (origin.width <= maxWidth && origin.height <= maxHeight) {
|
|
78
|
+
ratio = 1;
|
|
79
|
+
} else if (origin.width > maxWidth && origin.height <= maxHeight) {
|
|
80
|
+
ratio = maxWidth / origin.width;
|
|
81
|
+
} else if (origin.width <= maxWidth && origin.height > maxHeight) {
|
|
82
|
+
ratio = maxHeight / origin.height;
|
|
83
|
+
} else {
|
|
84
|
+
ratio = Math.min(maxWidth / origin.width, maxHeight / origin.height);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return { width: origin.width * ratio, height: origin.height * ratio };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Normalize a file name by ensuring it has the given extension, if it doesn't already.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} fileName - The file name to normalize.
|
|
94
|
+
* @param {string} extension - The desired extension, without a leading period.
|
|
95
|
+
* @returns {string} - The normalized file name, with the extension.
|
|
96
|
+
*/
|
|
97
|
+
export function normalizeFileName(fileName: string, extension: string) {
|
|
98
|
+
if (!extension) return fileName;
|
|
99
|
+
|
|
100
|
+
// .extension
|
|
101
|
+
let _extension = extension.toLowerCase();
|
|
102
|
+
if (_extension.indexOf('.') !== 0) {
|
|
103
|
+
_extension = '.' + _extension;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// filename.extension | filename
|
|
107
|
+
const _filename = fileName.toLowerCase();
|
|
108
|
+
const hasExtension = _filename.lastIndexOf(_extension) === _filename.length - _extension.length;
|
|
109
|
+
if (!hasExtension) {
|
|
110
|
+
// filename.extension
|
|
111
|
+
return fileName + _extension;
|
|
112
|
+
} else {
|
|
113
|
+
// filename.extension
|
|
114
|
+
return fileName;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Parses a MIME type string into its components.
|
|
120
|
+
*
|
|
121
|
+
* @param mimeType - The MIME type string to parse.
|
|
122
|
+
* @returns An object containing the type, subtype, and parameters of the MIME type.
|
|
123
|
+
*/
|
|
124
|
+
type MimeType = { type: string; subtype: string; parameters: Record<string, string> };
|
|
125
|
+
export function parseMimeType(mimeType: string): MimeType {
|
|
126
|
+
const [fullType, ...parts] = mimeType.split(';');
|
|
127
|
+
const [type, subtype] = fullType.split('/');
|
|
128
|
+
const parameters: MimeType['parameters'] = {};
|
|
129
|
+
|
|
130
|
+
for (const part of parts) {
|
|
131
|
+
const [name, value] = part.trim().split('=');
|
|
132
|
+
parameters[name] = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return { type, subtype, parameters };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns the file extension based on the MIME type.
|
|
140
|
+
*
|
|
141
|
+
* @param {string | null | undefined} mimeType - The MIME type to look up.
|
|
142
|
+
* @returns {string} - The file extension for the given MIME type, or an empty string if no matching file extension was found.
|
|
143
|
+
*/
|
|
144
|
+
export function getFileExtensionFromMime(mimeType?: string | null): string {
|
|
145
|
+
if (!mimeType) return '';
|
|
146
|
+
const MIME_EXTENSION_MAP = Object.entries(EXTENSION_MIME_MAP).reduce((acc, [key, value]) => {
|
|
147
|
+
acc[value] = key;
|
|
148
|
+
return acc;
|
|
149
|
+
}, {} as Record<string, string>);
|
|
150
|
+
return MIME_EXTENSION_MAP[mimeType.toLowerCase()] || '';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns the MIME type based on the file extension.
|
|
155
|
+
*
|
|
156
|
+
* @param {string | null | undefined} ext - The file extension to look up.
|
|
157
|
+
* @returns {string} - The MIME type for the given file extension, or an empty string if no matching MIME type was found.
|
|
158
|
+
*/
|
|
159
|
+
export function getMimeFromFileExtension(ext?: string | null) {
|
|
160
|
+
if (!ext) return '';
|
|
161
|
+
return EXTENSION_MIME_MAP[ext.toLowerCase()] || '';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Returns the file extension of a file path.
|
|
166
|
+
*
|
|
167
|
+
* @param {string} filePath - The file path to extract the extension from.
|
|
168
|
+
* @returns {string} - The file extension, or an empty string if the file path does not have an extension.
|
|
169
|
+
*/
|
|
170
|
+
export function getFileExtension(filePath: string) {
|
|
171
|
+
const pathWithoutParams = filePath.split('?')[0];
|
|
172
|
+
|
|
173
|
+
const idx = pathWithoutParams.lastIndexOf('.');
|
|
174
|
+
if (idx === -1) return '';
|
|
175
|
+
|
|
176
|
+
const result = pathWithoutParams.slice(idx - pathWithoutParams.length).toLowerCase();
|
|
177
|
+
if (result === '.') return '';
|
|
178
|
+
else return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function getFileExtensionFromUri(uri: string) {
|
|
182
|
+
return fetch(uri).then((response) => response.headers.get('content-type'));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function isImage(filePath: string, mimeType?: string) {
|
|
186
|
+
const type = getFileType(mimeType || getFileExtension(filePath));
|
|
187
|
+
return type === 'image';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function shouldCompressImage(mime: string, compressionEnabled = true) {
|
|
191
|
+
const extension = getFileExtensionFromMime(mime);
|
|
192
|
+
return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
|
|
193
|
+
}
|
package/src/shared/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getFileExtension, getFileType } from './regex';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Converts a given string to a hashed string.
|
|
5
3
|
* */
|
|
@@ -23,34 +21,19 @@ export function conditionChaining<T, V>(conditions: T[], values: V[]) {
|
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} else {
|
|
42
|
-
ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { width: origin.width * ratio, height: origin.height * ratio };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function isImage(filePath: string, mimeType?: string) {
|
|
49
|
-
const type = getFileType(mimeType || getFileExtension(filePath));
|
|
50
|
-
return type === 'image';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function shouldCompressImage(filePath: string, compressionEnabled = true) {
|
|
54
|
-
const extension = getFileExtension(filePath);
|
|
55
|
-
return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
|
|
24
|
+
* Returns a new object with only the specified keys from the input object.
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} obj - The input object to pick keys from.
|
|
27
|
+
* @param {Array<string>} keys - An array of keys to pick from the input object.
|
|
28
|
+
* @returns {Object} - A new object containing only the specified keys from the input object.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* pick({ a: 1, b: '2', c: true }, ['a', 'c']); // returns { a: 1, c: true }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function pick<T extends { [key: string]: unknown }, Keys extends keyof T>(obj: T, keys: Keys[]) {
|
|
35
|
+
return keys.reduce((pickedObj, key) => {
|
|
36
|
+
pickedObj[key] = obj[key];
|
|
37
|
+
return pickedObj;
|
|
38
|
+
}, {} as { [key in Keys]: T[key] });
|
|
56
39
|
}
|
package/src/shared/regex.ts
CHANGED
|
@@ -84,37 +84,3 @@ export const replaceUrlAsComponents = <T>(originText: string, replacer: (url: st
|
|
|
84
84
|
});
|
|
85
85
|
return items;
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
export const imageExtRegex = /jpeg|jpg|png|webp|gif/i;
|
|
89
|
-
export const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;
|
|
90
|
-
export const videoExtRegex = /mov|vod|mp4|avi/i;
|
|
91
|
-
export const getFileType = (extOrType: string) => {
|
|
92
|
-
if (extOrType.indexOf('/') > -1) {
|
|
93
|
-
const type = extOrType.split('/')[0];
|
|
94
|
-
if (type === 'video') return 'video';
|
|
95
|
-
if (type === 'audio') return 'audio';
|
|
96
|
-
if (type === 'image') return 'image';
|
|
97
|
-
return 'file';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (extOrType.match(imageExtRegex)) return 'image';
|
|
101
|
-
if (extOrType.match(audioExtRegex)) return 'audio';
|
|
102
|
-
if (extOrType.match(videoExtRegex)) return 'video';
|
|
103
|
-
return 'file';
|
|
104
|
-
};
|
|
105
|
-
export function getFileExtension(filePath: string) {
|
|
106
|
-
const idx = filePath.lastIndexOf('.');
|
|
107
|
-
if (idx === -1) return '';
|
|
108
|
-
return filePath.slice(idx - filePath.length).toLowerCase();
|
|
109
|
-
}
|
|
110
|
-
export function normalizeFileName(fileName: string, extension: string) {
|
|
111
|
-
if (fileName.indexOf(extension) > -1) {
|
|
112
|
-
return fileName;
|
|
113
|
-
} else {
|
|
114
|
-
if (extension.indexOf('.') === 0) {
|
|
115
|
-
return `${fileName}${extension}`;
|
|
116
|
-
} else {
|
|
117
|
-
return `${fileName}.${extension}`;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
Emoji,
|
|
10
10
|
EmojiCategory,
|
|
11
11
|
EmojiContainer,
|
|
12
|
+
Participant,
|
|
12
13
|
RestrictedUser,
|
|
13
14
|
SendbirdError as SBError,
|
|
14
15
|
User,
|
|
@@ -24,7 +25,12 @@ import type {
|
|
|
24
25
|
Member,
|
|
25
26
|
MessageCollection,
|
|
26
27
|
} from '@sendbird/chat/groupChannel';
|
|
27
|
-
import type {
|
|
28
|
+
import type {
|
|
29
|
+
ModuleNamespaces,
|
|
30
|
+
OpenChannelCreateParams,
|
|
31
|
+
OpenChannelUpdateParams,
|
|
32
|
+
SendableMessage,
|
|
33
|
+
} from '@sendbird/chat/lib/__definition';
|
|
28
34
|
import type {
|
|
29
35
|
AdminMessage,
|
|
30
36
|
BaseMessage,
|
|
@@ -37,7 +43,7 @@ import type {
|
|
|
37
43
|
UserMessageCreateParams,
|
|
38
44
|
UserMessageUpdateParams,
|
|
39
45
|
} from '@sendbird/chat/message';
|
|
40
|
-
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
46
|
+
import type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
41
47
|
|
|
42
48
|
export type FilterByValueType<T extends object, Type> = {
|
|
43
49
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
@@ -65,6 +71,8 @@ export type Optional<T> = T | undefined;
|
|
|
65
71
|
|
|
66
72
|
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
67
73
|
|
|
74
|
+
export type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
|
|
75
|
+
|
|
68
76
|
export interface UserStruct {
|
|
69
77
|
userId: string;
|
|
70
78
|
}
|
|
@@ -81,12 +89,18 @@ export type SendbirdFileMessageCreateParams = FileMessageCreateParams;
|
|
|
81
89
|
export type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;
|
|
82
90
|
export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
83
91
|
export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
92
|
+
|
|
84
93
|
export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
85
94
|
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
95
|
+
export type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;
|
|
96
|
+
export type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;
|
|
97
|
+
|
|
86
98
|
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
87
99
|
export type SendbirdUser = User;
|
|
88
100
|
export type SendbirdRestrictedUser = RestrictedUser;
|
|
89
101
|
export type SendbirdMember = Member;
|
|
102
|
+
export type SendbirdParticipant = Participant;
|
|
103
|
+
|
|
90
104
|
export type SendbirdGroupChannel = GroupChannel;
|
|
91
105
|
export type SendbirdBaseChannel = BaseChannel;
|
|
92
106
|
export type SendbirdOpenChannel = OpenChannel;
|
|
@@ -98,6 +112,7 @@ export type SendbirdEmojiContainer = EmojiContainer;
|
|
|
98
112
|
|
|
99
113
|
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
100
114
|
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
115
|
+
export type SendbirdOpenChannelListQuery = OpenChannelListQuery;
|
|
101
116
|
export type SendbirdMessageCollection = MessageCollection;
|
|
102
117
|
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
103
118
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SendbirdOpenChannel } from '../types';
|
|
2
|
+
|
|
3
|
+
export const getOpenChannelTitle = (channel: SendbirdOpenChannel, DEFAULT_CHANNEL_NAME = 'Open Channel') => {
|
|
4
|
+
const trimmedChannelName = channel.name.trim();
|
|
5
|
+
if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;
|
|
6
|
+
return trimmedChannelName;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const getOpenChannelParticipants = (channel: SendbirdOpenChannel) => {
|
|
10
|
+
return `${channel.participantCount} participants`;
|
|
11
|
+
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createPubSub = void 0;
|
|
7
|
-
|
|
8
|
-
const createPubSub = function () {
|
|
9
|
-
let label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'pubsub';
|
|
10
|
-
const eventPool = {};
|
|
11
|
-
|
|
12
|
-
const getSubscribeListenerPool = event => {
|
|
13
|
-
if (!eventPool[event]) eventPool[event] = {};
|
|
14
|
-
return eventPool[event];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
subscribe: function (event, listener) {
|
|
19
|
-
let subscriber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
20
|
-
const name = `${label}_${event}_${subscriber}`;
|
|
21
|
-
const id = Symbol(name);
|
|
22
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
23
|
-
subscribeListenerPool[id] = listener;
|
|
24
|
-
return () => {
|
|
25
|
-
delete getSubscribeListenerPool(event)[id];
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
publish: function (event) {
|
|
29
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
30
|
-
args[_key - 1] = arguments[_key];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
34
|
-
const ids = Object.getOwnPropertySymbols(subscribeListenerPool);
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
ids.forEach(id => {
|
|
37
|
-
const listener = subscribeListenerPool[id];
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
listener(...args);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
if (listener.onError) {
|
|
43
|
-
err.stack += `\npubsub error: ${id.description}`;
|
|
44
|
-
listener.onError(err);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}, 0);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
exports.createPubSub = createPubSub;
|
|
54
|
-
//# sourceMappingURL=pubsub.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createPubSub","label","eventPool","getSubscribeListenerPool","event","subscribe","listener","subscriber","name","id","Symbol","subscribeListenerPool","publish","args","ids","Object","getOwnPropertySymbols","setTimeout","forEach","err","onError","stack","description"],"sources":["pubsub.ts"],"sourcesContent":["export type SubscribeListener = ((...args: unknown[]) => void) & { onError?: (error: unknown) => void };\nexport type SubscribeListenerPool = Record<symbol, SubscribeListener>;\n\nexport const createPubSub = (label = 'pubsub') => {\n const eventPool: Record<string, SubscribeListenerPool> = {};\n\n const getSubscribeListenerPool = (event: string) => {\n if (!eventPool[event]) eventPool[event] = {};\n return eventPool[event];\n };\n\n return {\n subscribe: (event: string, listener: SubscribeListener, subscriber = '') => {\n const name = `${label}_${event}_${subscriber}`;\n const id = Symbol(name);\n\n const subscribeListenerPool = getSubscribeListenerPool(event);\n subscribeListenerPool[id] = listener;\n\n return () => {\n delete getSubscribeListenerPool(event)[id];\n };\n },\n publish: (event: string, ...args: unknown[]) => {\n const subscribeListenerPool = getSubscribeListenerPool(event);\n const ids = Object.getOwnPropertySymbols(subscribeListenerPool);\n setTimeout(() => {\n ids.forEach((id) => {\n const listener = subscribeListenerPool[id];\n try {\n listener(...args);\n } catch (err: unknown) {\n if (listener.onError) {\n (err as Error).stack += `\\npubsub error: ${id.description}`;\n listener.onError(err);\n }\n }\n });\n }, 0);\n },\n };\n};\n"],"mappings":";;;;;;;AAGO,MAAMA,YAAY,GAAG,YAAsB;EAAA,IAArBC,KAAqB,uEAAb,QAAa;EAChD,MAAMC,SAAgD,GAAG,EAAzD;;EAEA,MAAMC,wBAAwB,GAAIC,KAAD,IAAmB;IAClD,IAAI,CAACF,SAAS,CAACE,KAAD,CAAd,EAAuBF,SAAS,CAACE,KAAD,CAAT,GAAmB,EAAnB;IACvB,OAAOF,SAAS,CAACE,KAAD,CAAhB;EACD,CAHD;;EAKA,OAAO;IACLC,SAAS,EAAE,UAACD,KAAD,EAAgBE,QAAhB,EAAiE;MAAA,IAApBC,UAAoB,uEAAP,EAAO;MAC1E,MAAMC,IAAI,GAAI,GAAEP,KAAM,IAAGG,KAAM,IAAGG,UAAW,EAA7C;MACA,MAAME,EAAE,GAAGC,MAAM,CAACF,IAAD,CAAjB;MAEA,MAAMG,qBAAqB,GAAGR,wBAAwB,CAACC,KAAD,CAAtD;MACAO,qBAAqB,CAACF,EAAD,CAArB,GAA4BH,QAA5B;MAEA,OAAO,MAAM;QACX,OAAOH,wBAAwB,CAACC,KAAD,CAAxB,CAAgCK,EAAhC,CAAP;MACD,CAFD;IAGD,CAXI;IAYLG,OAAO,EAAE,UAACR,KAAD,EAAuC;MAAA,kCAApBS,IAAoB;QAApBA,IAAoB;MAAA;;MAC9C,MAAMF,qBAAqB,GAAGR,wBAAwB,CAACC,KAAD,CAAtD;MACA,MAAMU,GAAG,GAAGC,MAAM,CAACC,qBAAP,CAA6BL,qBAA7B,CAAZ;MACAM,UAAU,CAAC,MAAM;QACfH,GAAG,CAACI,OAAJ,CAAaT,EAAD,IAAQ;UAClB,MAAMH,QAAQ,GAAGK,qBAAqB,CAACF,EAAD,CAAtC;;UACA,IAAI;YACFH,QAAQ,CAAC,GAAGO,IAAJ,CAAR;UACD,CAFD,CAEE,OAAOM,GAAP,EAAqB;YACrB,IAAIb,QAAQ,CAACc,OAAb,EAAsB;cACnBD,GAAD,CAAeE,KAAf,IAAyB,mBAAkBZ,EAAE,CAACa,WAAY,EAA1D;cACAhB,QAAQ,CAACc,OAAT,CAAiBD,GAAjB;YACD;UACF;QACF,CAVD;MAWD,CAZS,EAYP,CAZO,CAAV;IAaD;EA5BI,CAAP;AA8BD,CAtCM"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export const createPubSub = function () {
|
|
2
|
-
let label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'pubsub';
|
|
3
|
-
const eventPool = {};
|
|
4
|
-
|
|
5
|
-
const getSubscribeListenerPool = event => {
|
|
6
|
-
if (!eventPool[event]) eventPool[event] = {};
|
|
7
|
-
return eventPool[event];
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
subscribe: function (event, listener) {
|
|
12
|
-
let subscriber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
13
|
-
const name = `${label}_${event}_${subscriber}`;
|
|
14
|
-
const id = Symbol(name);
|
|
15
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
16
|
-
subscribeListenerPool[id] = listener;
|
|
17
|
-
return () => {
|
|
18
|
-
delete getSubscribeListenerPool(event)[id];
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
publish: function (event) {
|
|
22
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
23
|
-
args[_key - 1] = arguments[_key];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
27
|
-
const ids = Object.getOwnPropertySymbols(subscribeListenerPool);
|
|
28
|
-
setTimeout(() => {
|
|
29
|
-
ids.forEach(id => {
|
|
30
|
-
const listener = subscribeListenerPool[id];
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
listener(...args);
|
|
34
|
-
} catch (err) {
|
|
35
|
-
if (listener.onError) {
|
|
36
|
-
err.stack += `\npubsub error: ${id.description}`;
|
|
37
|
-
listener.onError(err);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}, 0);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=pubsub.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createPubSub","label","eventPool","getSubscribeListenerPool","event","subscribe","listener","subscriber","name","id","Symbol","subscribeListenerPool","publish","args","ids","Object","getOwnPropertySymbols","setTimeout","forEach","err","onError","stack","description"],"sources":["pubsub.ts"],"sourcesContent":["export type SubscribeListener = ((...args: unknown[]) => void) & { onError?: (error: unknown) => void };\nexport type SubscribeListenerPool = Record<symbol, SubscribeListener>;\n\nexport const createPubSub = (label = 'pubsub') => {\n const eventPool: Record<string, SubscribeListenerPool> = {};\n\n const getSubscribeListenerPool = (event: string) => {\n if (!eventPool[event]) eventPool[event] = {};\n return eventPool[event];\n };\n\n return {\n subscribe: (event: string, listener: SubscribeListener, subscriber = '') => {\n const name = `${label}_${event}_${subscriber}`;\n const id = Symbol(name);\n\n const subscribeListenerPool = getSubscribeListenerPool(event);\n subscribeListenerPool[id] = listener;\n\n return () => {\n delete getSubscribeListenerPool(event)[id];\n };\n },\n publish: (event: string, ...args: unknown[]) => {\n const subscribeListenerPool = getSubscribeListenerPool(event);\n const ids = Object.getOwnPropertySymbols(subscribeListenerPool);\n setTimeout(() => {\n ids.forEach((id) => {\n const listener = subscribeListenerPool[id];\n try {\n listener(...args);\n } catch (err: unknown) {\n if (listener.onError) {\n (err as Error).stack += `\\npubsub error: ${id.description}`;\n listener.onError(err);\n }\n }\n });\n }, 0);\n },\n };\n};\n"],"mappings":"AAGA,OAAO,MAAMA,YAAY,GAAG,YAAsB;EAAA,IAArBC,KAAqB,uEAAb,QAAa;EAChD,MAAMC,SAAgD,GAAG,EAAzD;;EAEA,MAAMC,wBAAwB,GAAIC,KAAD,IAAmB;IAClD,IAAI,CAACF,SAAS,CAACE,KAAD,CAAd,EAAuBF,SAAS,CAACE,KAAD,CAAT,GAAmB,EAAnB;IACvB,OAAOF,SAAS,CAACE,KAAD,CAAhB;EACD,CAHD;;EAKA,OAAO;IACLC,SAAS,EAAE,UAACD,KAAD,EAAgBE,QAAhB,EAAiE;MAAA,IAApBC,UAAoB,uEAAP,EAAO;MAC1E,MAAMC,IAAI,GAAI,GAAEP,KAAM,IAAGG,KAAM,IAAGG,UAAW,EAA7C;MACA,MAAME,EAAE,GAAGC,MAAM,CAACF,IAAD,CAAjB;MAEA,MAAMG,qBAAqB,GAAGR,wBAAwB,CAACC,KAAD,CAAtD;MACAO,qBAAqB,CAACF,EAAD,CAArB,GAA4BH,QAA5B;MAEA,OAAO,MAAM;QACX,OAAOH,wBAAwB,CAACC,KAAD,CAAxB,CAAgCK,EAAhC,CAAP;MACD,CAFD;IAGD,CAXI;IAYLG,OAAO,EAAE,UAACR,KAAD,EAAuC;MAAA,kCAApBS,IAAoB;QAApBA,IAAoB;MAAA;;MAC9C,MAAMF,qBAAqB,GAAGR,wBAAwB,CAACC,KAAD,CAAtD;MACA,MAAMU,GAAG,GAAGC,MAAM,CAACC,qBAAP,CAA6BL,qBAA7B,CAAZ;MACAM,UAAU,CAAC,MAAM;QACfH,GAAG,CAACI,OAAJ,CAAaT,EAAD,IAAQ;UAClB,MAAMH,QAAQ,GAAGK,qBAAqB,CAACF,EAAD,CAAtC;;UACA,IAAI;YACFH,QAAQ,CAAC,GAAGO,IAAJ,CAAR;UACD,CAFD,CAEE,OAAOM,GAAP,EAAqB;YACrB,IAAIb,QAAQ,CAACc,OAAb,EAAsB;cACnBD,GAAD,CAAeE,KAAf,IAAyB,mBAAkBZ,EAAE,CAACa,WAAY,EAA1D;cACAhB,QAAQ,CAACc,OAAT,CAAiBD,GAAjB;YACD;UACF;QACF,CAVD;MAWD,CAZS,EAYP,CAZO,CAAV;IAaD;EA5BI,CAAP;AA8BD,CAtCM"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type SubscribeListener = ((...args: unknown[]) => void) & {
|
|
2
|
-
onError?: (error: unknown) => void;
|
|
3
|
-
};
|
|
4
|
-
export type SubscribeListenerPool = Record<symbol, SubscribeListener>;
|
|
5
|
-
export declare const createPubSub: (label?: string) => {
|
|
6
|
-
subscribe: (event: string, listener: SubscribeListener, subscriber?: string) => () => void;
|
|
7
|
-
publish: (event: string, ...args: unknown[]) => void;
|
|
8
|
-
};
|
package/src/shared/pubsub.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export type SubscribeListener = ((...args: unknown[]) => void) & { onError?: (error: unknown) => void };
|
|
2
|
-
export type SubscribeListenerPool = Record<symbol, SubscribeListener>;
|
|
3
|
-
|
|
4
|
-
export const createPubSub = (label = 'pubsub') => {
|
|
5
|
-
const eventPool: Record<string, SubscribeListenerPool> = {};
|
|
6
|
-
|
|
7
|
-
const getSubscribeListenerPool = (event: string) => {
|
|
8
|
-
if (!eventPool[event]) eventPool[event] = {};
|
|
9
|
-
return eventPool[event];
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
subscribe: (event: string, listener: SubscribeListener, subscriber = '') => {
|
|
14
|
-
const name = `${label}_${event}_${subscriber}`;
|
|
15
|
-
const id = Symbol(name);
|
|
16
|
-
|
|
17
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
18
|
-
subscribeListenerPool[id] = listener;
|
|
19
|
-
|
|
20
|
-
return () => {
|
|
21
|
-
delete getSubscribeListenerPool(event)[id];
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
publish: (event: string, ...args: unknown[]) => {
|
|
25
|
-
const subscribeListenerPool = getSubscribeListenerPool(event);
|
|
26
|
-
const ids = Object.getOwnPropertySymbols(subscribeListenerPool);
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
ids.forEach((id) => {
|
|
29
|
-
const listener = subscribeListenerPool[id];
|
|
30
|
-
try {
|
|
31
|
-
listener(...args);
|
|
32
|
-
} catch (err: unknown) {
|
|
33
|
-
if (listener.onError) {
|
|
34
|
-
(err as Error).stack += `\npubsub error: ${id.description}`;
|
|
35
|
-
listener.onError(err);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}, 0);
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
};
|