@sendbird/uikit-utils 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/hooks/index.js +38 -1
- package/lib/commonjs/hooks/index.js.map +1 -1
- package/lib/commonjs/hooks/react-native.js +54 -0
- package/lib/commonjs/hooks/react-native.js.map +1 -0
- package/lib/commonjs/index.js +53 -21
- 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/index.js +86 -0
- package/lib/commonjs/shared/index.js.map +1 -0
- 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 +37 -0
- package/lib/module/hooks/react-native.js.map +1 -0
- package/lib/module/index.js +10 -3
- 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/index.js +67 -0
- package/lib/module/shared/index.js.map +1 -0
- 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/hooks/react-native.d.ts +12 -0
- package/lib/typescript/src/index.d.ts +9 -4
- 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/index.d.ts +32 -0
- package/lib/typescript/src/types.d.ts +8 -3
- package/lib/typescript/src/ui-format/openChannel.d.ts +3 -0
- package/package.json +5 -4
- package/src/hooks/index.ts +31 -1
- package/src/hooks/react-native.ts +54 -0
- package/src/index.ts +20 -3
- package/src/sendbird/channel.ts +33 -2
- package/src/sendbird/message.ts +54 -1
- package/src/sendbird/user.ts +0 -7
- package/src/shared/index.ts +66 -0
- package/src/types.ts +17 -2
- package/src/ui-format/openChannel.ts +11 -0
- package/lib/commonjs/shared/conditionChaining.js +0 -15
- package/lib/commonjs/shared/conditionChaining.js.map +0 -1
- package/lib/commonjs/shared/replace.js +0 -14
- package/lib/commonjs/shared/replace.js.map +0 -1
- package/lib/module/shared/conditionChaining.js +0 -7
- package/lib/module/shared/conditionChaining.js.map +0 -1
- package/lib/module/shared/replace.js +0 -6
- package/lib/module/shared/replace.js.map +0 -1
- package/lib/typescript/src/shared/conditionChaining.d.ts +0 -2
- package/lib/typescript/src/shared/replace.d.ts +0 -2
- package/src/shared/conditionChaining.ts +0 -6
- package/src/shared/replace.ts +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getFileExtension","getFileType","hash","str","String","Math","abs","split","reduce","a","c","charCodeAt","replace","start","end","text","slice","conditionChaining","conditions","values","idx","findIndex","state","Boolean","length","getDownscaleSize","origin","resizing","ratio","maxWidth","width","maxHeight","height","max","isImage","filePath","mimeType","type","shouldCompressImage","compressionEnabled","extension","match","pick","obj","keys","pickedObj","key"],"sources":["index.ts"],"sourcesContent":["import { getFileExtension, getFileType } from './regex';\n\n/**\n * Converts a given string to a hashed string.\n * */\nexport function hash(str: string) {\n return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));\n}\n\n/**\n * Replace a specific range of text in the string with another text.\n * */\nexport function replace(str: string, start: number, end: number, text: string) {\n return str.slice(0, start) + text + str.slice(end);\n}\n\n/**\n * Returns the value corresponding to the first true index of a given condition array.\n * */\nexport function conditionChaining<T, V>(conditions: T[], values: V[]) {\n const idx = conditions.findIndex((state) => Boolean(state));\n return idx > -1 ? values[idx] : values[values.length - 1];\n}\n\n/**\n * Calculates the downscale size.\n * */\ntype Size = { width: number; height: number };\nexport function getDownscaleSize(origin: Size, resizing: Partial<Size>) {\n let ratio;\n\n const maxWidth = resizing.width || origin.width,\n maxHeight = resizing.height || origin.height;\n\n if (origin.width <= maxWidth && origin.height <= maxHeight) {\n ratio = 1;\n } else if (origin.width > maxWidth && origin.height <= maxHeight) {\n ratio = maxWidth / origin.width;\n } else if (origin.width <= maxWidth && origin.height > maxHeight) {\n ratio = maxHeight / origin.height;\n } else {\n ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);\n }\n\n return { width: origin.width * ratio, height: origin.height * ratio };\n}\n\nexport function isImage(filePath: string, mimeType?: string) {\n const type = getFileType(mimeType || getFileExtension(filePath));\n return type === 'image';\n}\n\nexport function shouldCompressImage(filePath: string, compressionEnabled = true) {\n const extension = getFileExtension(filePath);\n return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);\n}\n\n/**\n * Returns the picked data from object.\n * */\nexport function pick<T extends { [key: string]: unknown }, Keys extends keyof T>(obj: T, keys: Keys[]) {\n return keys.reduce((pickedObj, key) => {\n pickedObj[key] = obj[key];\n return pickedObj;\n }, {} as { [key in Keys]: T[key] });\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 {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} 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 {
|
|
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 {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} 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 {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\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 OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\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;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\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":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const getOpenChannelTitle = function (channel) {
|
|
2
|
+
let DEFAULT_CHANNEL_NAME = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Open Channel';
|
|
3
|
+
const trimmedChannelName = channel.name.trim();
|
|
4
|
+
if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;
|
|
5
|
+
return trimmedChannelName;
|
|
6
|
+
};
|
|
7
|
+
export const getOpenChannelParticipants = channel => {
|
|
8
|
+
return `${channel.participantCount} participants`;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=openChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getOpenChannelTitle","channel","DEFAULT_CHANNEL_NAME","trimmedChannelName","name","trim","getOpenChannelParticipants","participantCount"],"sources":["openChannel.ts"],"sourcesContent":["import type { SendbirdOpenChannel } from '../types';\n\nexport const getOpenChannelTitle = (channel: SendbirdOpenChannel, DEFAULT_CHANNEL_NAME = 'Open Channel') => {\n const trimmedChannelName = channel.name.trim();\n if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;\n return trimmedChannelName;\n};\n\nexport const getOpenChannelParticipants = (channel: SendbirdOpenChannel) => {\n return `${channel.participantCount} participants`;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,GAAG,UAACC,OAAD,EAAyE;EAAA,IAA1CC,oBAA0C,uEAAnB,cAAmB;EAC1G,MAAMC,kBAAkB,GAAGF,OAAO,CAACG,IAAR,CAAaC,IAAb,EAA3B;EACA,IAAIF,kBAAkB,KAAK,EAA3B,EAA+B,OAAOD,oBAAP;EAC/B,OAAOC,kBAAP;AACD,CAJM;AAMP,OAAO,MAAMG,0BAA0B,GAAIL,OAAD,IAAkC;EAC1E,OAAQ,GAAEA,OAAO,CAACM,gBAAiB,eAAnC;AACD,CAFM"}
|
|
@@ -2,6 +2,7 @@ import type { DependencyList } from 'react';
|
|
|
2
2
|
type Destructor = () => void;
|
|
3
3
|
type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
|
|
4
4
|
export declare const useUniqId: (key: string) => number;
|
|
5
|
+
export declare const useUniqHandlerId: (name: string) => string;
|
|
5
6
|
export declare const useForceUpdate: () => () => void;
|
|
6
7
|
export declare const useAsyncEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
7
8
|
export declare const useAsyncLayoutEffect: (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => void;
|
|
@@ -9,4 +10,6 @@ export declare const useIIFE: <T>(callback: () => T) => T;
|
|
|
9
10
|
export declare const useIsMountedRef: () => import("react").MutableRefObject<boolean>;
|
|
10
11
|
export declare const useIsFirstMount: () => boolean;
|
|
11
12
|
export declare const useFreshCallback: <T extends (...args: any[]) => any>(callback: T) => T;
|
|
13
|
+
export declare const useDebounceEffect: (action: () => void, delay: number, deps?: DependencyList) => void;
|
|
14
|
+
export declare const usePartialState: <S>(initialState: S) => [S & Partial<S>, import("react").Dispatch<Partial<S>>];
|
|
12
15
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppStateEvent, AppStateStatus } from 'react-native';
|
|
2
|
+
import { EdgeInsets } from 'react-native-safe-area-context';
|
|
3
|
+
type EdgePaddingMap = {
|
|
4
|
+
left: 'paddingLeft';
|
|
5
|
+
right: 'paddingRight';
|
|
6
|
+
top: 'paddingTop';
|
|
7
|
+
bottom: 'paddingBottom';
|
|
8
|
+
};
|
|
9
|
+
export declare const useSafeAreaPadding: <T extends keyof EdgeInsets, Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T]; }>(edges: T[]) => Result;
|
|
10
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
11
|
+
export declare const useAppState: (type: AppStateEvent, listener: AppStateListener) => void;
|
|
12
|
+
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
4
|
export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, replaceWithRegex, createMentionTemplateRegex, } from './shared/regex';
|
|
6
5
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
7
|
-
export
|
|
6
|
+
export * from './shared';
|
|
8
7
|
export * from './hooks';
|
|
8
|
+
export * from './hooks/react-native';
|
|
9
9
|
export * from './ui-format/groupChannel';
|
|
10
|
+
export * from './ui-format/openChannel';
|
|
10
11
|
export * from './ui-format/common';
|
|
11
12
|
export * from './sendbird/channel';
|
|
12
13
|
export * from './sendbird/message';
|
|
@@ -16,11 +17,15 @@ export declare const NOOP: () => void;
|
|
|
16
17
|
export declare const ASYNC_NOOP: () => Promise<undefined>;
|
|
17
18
|
export declare const PASS: <T>(val: T) => T;
|
|
18
19
|
export declare const toMegabyte: (byte: number) => number;
|
|
19
|
-
export declare const isFunction:
|
|
20
|
+
export declare const isFunction: (param?: unknown) => param is Function;
|
|
21
|
+
export declare function ifThenOr<T>(cond: boolean, then: T): T | undefined;
|
|
22
|
+
export declare function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;
|
|
20
23
|
export declare const SBErrorCode: {
|
|
21
24
|
NON_AUTHORIZED: number;
|
|
25
|
+
CHANNEL_NOT_FOUND_SERVER: number;
|
|
26
|
+
CHANNEL_NOT_FOUND_SDK: number;
|
|
22
27
|
};
|
|
23
28
|
export declare const SBErrorMessage: {
|
|
24
29
|
ACL: string;
|
|
25
30
|
};
|
|
26
|
-
export type { UserStruct, 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, SendbirdReaction, SendbirdEmojiContainer, SendbirdEmoji, SendbirdEmojiCategory, } from './types';
|
|
31
|
+
export type { UserStruct, FilterByValueType, UnionToIntersection, OmittedValues, PartialDeep, Optional, ContextValue, OnBeforeHandler, 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, SendbirdOpenChannelListQuery, SendbirdGroupChannelListQuery, SendbirdGroupChannelUpdateParams, SendbirdUserMessageUpdateParams, SendbirdFileMessageUpdateParams, SendbirdUserUpdateParams, SendbirdRestrictedUser, SendbirdReaction, SendbirdEmojiContainer, SendbirdEmoji, SendbirdEmojiCategory, SendbirdOpenChannelUpdateParams, SendbirdOpenChannelCreateParams, SendbirdParticipant, } from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
|
|
1
|
+
import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdGroupChannelCreateParams, SendbirdOpenChannel } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Diff utils for channel
|
|
4
4
|
* @param {SendbirdBaseChannel} [a]
|
|
@@ -11,6 +11,11 @@ export declare const getGroupChannelChatAvailableState: (channel: SendbirdGroupC
|
|
|
11
11
|
frozen: boolean;
|
|
12
12
|
muted: boolean;
|
|
13
13
|
};
|
|
14
|
+
export declare const getOpenChannelChatAvailableState: (channel: SendbirdOpenChannel, userId: string) => Promise<{
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
frozen: boolean;
|
|
17
|
+
muted: boolean;
|
|
18
|
+
}>;
|
|
14
19
|
export declare const confirmAndMarkAsRead: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
15
20
|
export declare const confirmAndMarkAsDelivered: (channels: SendbirdBaseChannel[]) => Promise<void>;
|
|
16
21
|
export declare function isDefaultCoverImage(coverUrl: string): boolean;
|
|
@@ -18,3 +23,7 @@ export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, curre
|
|
|
18
23
|
export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
|
|
19
24
|
export declare function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[];
|
|
20
25
|
export declare function getChannelUniqId(channel: SendbirdChannel): string;
|
|
26
|
+
export declare function getDefaultGroupChannelCreateParams(params: {
|
|
27
|
+
invitedUserIds: string[];
|
|
28
|
+
currentUserId?: string;
|
|
29
|
+
}): SendbirdGroupChannelCreateParams;
|
|
@@ -20,4 +20,7 @@ export declare function isSendbirdNotification(dataPayload?: {
|
|
|
20
20
|
export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
|
|
21
21
|
export declare function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean): boolean;
|
|
22
22
|
export declare function getReactionCount(reaction: SendbirdReaction): number;
|
|
23
|
+
type MessageType = 'user' | 'admin' | 'file' | 'unknown' | `user.${'opengraph'}` | `file.${'image' | 'video' | 'audio'}`;
|
|
24
|
+
export declare function getFileTypeFromMessage(message: SendbirdFileMessage): "video" | "audio" | "image" | "file";
|
|
25
|
+
export declare function getMessageType(message: SendbirdMessage): MessageType;
|
|
23
26
|
export {};
|
|
@@ -2,6 +2,4 @@ import type { Role } from '@sendbird/chat';
|
|
|
2
2
|
import type { UserStruct } from '../types';
|
|
3
3
|
export declare function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
4
4
|
export declare function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
5
|
-
export declare function ifMuted<T>(muted: boolean, then: T): T | undefined;
|
|
6
|
-
export declare function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;
|
|
7
5
|
export declare function getUserUniqId<T extends UserStruct>(user: T): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string to a hashed string.
|
|
3
|
+
* */
|
|
4
|
+
export declare function hash(str: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Replace a specific range of text in the string with another text.
|
|
7
|
+
* */
|
|
8
|
+
export declare function replace(str: string, start: number, end: number, text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
11
|
+
* */
|
|
12
|
+
export declare function conditionChaining<T, V>(conditions: T[], values: V[]): V;
|
|
13
|
+
/**
|
|
14
|
+
* Calculates the downscale size.
|
|
15
|
+
* */
|
|
16
|
+
type Size = {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function getDownscaleSize(origin: Size, resizing: Partial<Size>): {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function isImage(filePath: string, mimeType?: string): boolean;
|
|
25
|
+
export declare function shouldCompressImage(filePath: string, compressionEnabled?: boolean): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the picked data from object.
|
|
28
|
+
* */
|
|
29
|
+
export declare function pick<T extends {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}, Keys extends keyof T>(obj: T, keys: Keys[]): { [key in Keys]: T[key]; };
|
|
32
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type SendbirdChat from '@sendbird/chat';
|
|
3
|
-
import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
3
|
+
import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, Participant, 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
|
-
import type { ModuleNamespaces, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
5
|
+
import type { ModuleNamespaces, OpenChannelCreateParams, OpenChannelUpdateParams, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
6
|
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
7
|
-
import type { OpenChannel, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
7
|
+
import type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';
|
|
8
8
|
export type FilterByValueType<T extends object, Type> = {
|
|
9
9
|
[K in keyof T as T[K] extends Type ? K : never]: T[K];
|
|
10
10
|
};
|
|
@@ -18,6 +18,7 @@ export type PartialNullable<T> = {
|
|
|
18
18
|
};
|
|
19
19
|
export type Optional<T> = T | undefined;
|
|
20
20
|
export type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;
|
|
21
|
+
export type OnBeforeHandler<T> = (params: T) => T | Promise<T>;
|
|
21
22
|
export interface UserStruct {
|
|
22
23
|
userId: string;
|
|
23
24
|
}
|
|
@@ -35,10 +36,13 @@ export type SendbirdUserMessageCreateParams = UserMessageCreateParams;
|
|
|
35
36
|
export type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;
|
|
36
37
|
export type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;
|
|
37
38
|
export type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;
|
|
39
|
+
export type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;
|
|
40
|
+
export type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;
|
|
38
41
|
export type SendbirdUserUpdateParams = UserUpdateParams;
|
|
39
42
|
export type SendbirdUser = User;
|
|
40
43
|
export type SendbirdRestrictedUser = RestrictedUser;
|
|
41
44
|
export type SendbirdMember = Member;
|
|
45
|
+
export type SendbirdParticipant = Participant;
|
|
42
46
|
export type SendbirdGroupChannel = GroupChannel;
|
|
43
47
|
export type SendbirdBaseChannel = BaseChannel;
|
|
44
48
|
export type SendbirdOpenChannel = OpenChannel;
|
|
@@ -48,6 +52,7 @@ export type SendbirdEmojiCategory = EmojiCategory;
|
|
|
48
52
|
export type SendbirdEmojiContainer = EmojiContainer;
|
|
49
53
|
export type SendbirdGroupChannelCollection = GroupChannelCollection;
|
|
50
54
|
export type SendbirdGroupChannelListQuery = GroupChannelListQuery;
|
|
55
|
+
export type SendbirdOpenChannelListQuery = OpenChannelListQuery;
|
|
51
56
|
export type SendbirdMessageCollection = MessageCollection;
|
|
52
57
|
export type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;
|
|
53
58
|
export type SendbirdError = SBError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "UIKit utilities",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -43,13 +43,14 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/react": "*",
|
|
46
|
+
"@types/react-native": "*",
|
|
46
47
|
"react": "17.0.2",
|
|
47
|
-
"react-native": "0.67.
|
|
48
|
+
"react-native": "0.67.5",
|
|
48
49
|
"react-native-builder-bob": "^0.18.0",
|
|
49
50
|
"typescript": "4.9.4"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"@sendbird/chat": "^4.0
|
|
53
|
+
"@sendbird/chat": "^4.3.0",
|
|
53
54
|
"react": ">=16.13.1"
|
|
54
55
|
},
|
|
55
56
|
"peerDependenciesMeta": {
|
|
@@ -76,5 +77,5 @@
|
|
|
76
77
|
"readmeFile": "./README.md",
|
|
77
78
|
"displayName": "@sendbird/uikit-utils"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "05ec076e3a2433089586870c9a7e7bf7639b06be"
|
|
80
81
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type { DependencyList } from 'react';
|
|
3
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
type Destructor = () => void;
|
|
6
6
|
type AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;
|
|
@@ -13,6 +13,11 @@ export const useUniqId = (key: string) => {
|
|
|
13
13
|
})[0];
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export const useUniqHandlerId = (name: string) => {
|
|
17
|
+
const id = useUniqId(name);
|
|
18
|
+
return `${name}_${id}`;
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
export const useForceUpdate = () => {
|
|
17
22
|
const [, updater] = useState(0);
|
|
18
23
|
return useCallback(() => updater((prev) => prev + 1), []);
|
|
@@ -72,3 +77,28 @@ export const useFreshCallback = <T extends (...args: any[]) => any>(callback: T)
|
|
|
72
77
|
ref.current = callback;
|
|
73
78
|
return useCallback(((...args) => ref.current(...args)) as T, []);
|
|
74
79
|
};
|
|
80
|
+
|
|
81
|
+
export const useDebounceEffect = (action: () => void, delay: number, deps: DependencyList = []) => {
|
|
82
|
+
const timeoutRef = useRef<NodeJS.Timeout>();
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
timeoutRef.current = setTimeout(async () => {
|
|
86
|
+
try {
|
|
87
|
+
await action();
|
|
88
|
+
} finally {
|
|
89
|
+
timeoutRef.current = undefined;
|
|
90
|
+
}
|
|
91
|
+
}, delay);
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
if (timeoutRef.current) {
|
|
95
|
+
clearTimeout(timeoutRef.current);
|
|
96
|
+
timeoutRef.current = undefined;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, [delay, ...deps]);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const usePartialState = <S>(initialState: S) => {
|
|
103
|
+
return useReducer((prev: S, state: Partial<S>) => ({ ...prev, ...state }), initialState);
|
|
104
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { AppState, AppStateEvent, AppStateStatus } from 'react-native';
|
|
3
|
+
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
4
|
+
|
|
5
|
+
type EdgePaddingMap = {
|
|
6
|
+
left: 'paddingLeft';
|
|
7
|
+
right: 'paddingRight';
|
|
8
|
+
top: 'paddingTop';
|
|
9
|
+
bottom: 'paddingBottom';
|
|
10
|
+
};
|
|
11
|
+
const edgePaddingMap: EdgePaddingMap = {
|
|
12
|
+
left: 'paddingLeft',
|
|
13
|
+
right: 'paddingRight',
|
|
14
|
+
top: 'paddingTop',
|
|
15
|
+
bottom: 'paddingBottom',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const useSafeAreaPadding = <
|
|
19
|
+
T extends keyof EdgeInsets,
|
|
20
|
+
Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },
|
|
21
|
+
>(
|
|
22
|
+
edges: T[],
|
|
23
|
+
): Result => {
|
|
24
|
+
const safeAreaInsets = useSafeAreaInsets();
|
|
25
|
+
return edges.reduce((map, edge) => {
|
|
26
|
+
const paddingKey = edgePaddingMap[edge];
|
|
27
|
+
map[paddingKey] = safeAreaInsets[edge];
|
|
28
|
+
return map;
|
|
29
|
+
}, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] }) as Result;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type AppStateListener = (status: AppStateStatus) => void;
|
|
33
|
+
|
|
34
|
+
export const useAppState = (type: AppStateEvent, listener: AppStateListener) => {
|
|
35
|
+
const callbackRef = useRef<AppStateListener>(listener);
|
|
36
|
+
callbackRef.current = listener;
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const eventListener = (state: AppStateStatus) => callbackRef.current(state);
|
|
40
|
+
const subscriber = AppState.addEventListener(type, eventListener);
|
|
41
|
+
|
|
42
|
+
return () => {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
if (subscriber?.remove) {
|
|
45
|
+
subscriber.remove();
|
|
46
|
+
}
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
else if (AppState.removeEventListener) {
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
AppState.removeEventListener(type, eventListener);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Logger } from './shared/logger';
|
|
2
2
|
export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
|
|
3
3
|
export { createPubSub } from './shared/pubsub';
|
|
4
|
-
export { default as conditionChaining } from './shared/conditionChaining';
|
|
5
4
|
export {
|
|
6
5
|
urlRegexStrict,
|
|
7
6
|
urlRegexRough,
|
|
@@ -19,10 +18,13 @@ export {
|
|
|
19
18
|
createMentionTemplateRegex,
|
|
20
19
|
} from './shared/regex';
|
|
21
20
|
export { BufferedRequest } from './shared/bufferedRequest';
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
export * from './shared';
|
|
23
23
|
|
|
24
24
|
export * from './hooks';
|
|
25
|
+
export * from './hooks/react-native';
|
|
25
26
|
export * from './ui-format/groupChannel';
|
|
27
|
+
export * from './ui-format/openChannel';
|
|
26
28
|
export * from './ui-format/common';
|
|
27
29
|
export * from './sendbird/channel';
|
|
28
30
|
export * from './sendbird/message';
|
|
@@ -33,9 +35,19 @@ export const NOOP: () => void = () => void 0;
|
|
|
33
35
|
export const ASYNC_NOOP = async () => void 0;
|
|
34
36
|
export const PASS = <T>(val: T) => val;
|
|
35
37
|
export const toMegabyte = (byte: number) => byte / 1024 / 1024;
|
|
36
|
-
export const isFunction =
|
|
38
|
+
export const isFunction = (param?: unknown): param is Function => typeof param === 'function';
|
|
39
|
+
|
|
40
|
+
export function ifThenOr<T>(cond: boolean, then: T): T | undefined;
|
|
41
|
+
export function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;
|
|
42
|
+
export function ifThenOr(cond: boolean, then: unknown, or?: unknown) {
|
|
43
|
+
if (cond) return then;
|
|
44
|
+
return or;
|
|
45
|
+
}
|
|
46
|
+
|
|
37
47
|
export const SBErrorCode = {
|
|
38
48
|
NON_AUTHORIZED: 400108,
|
|
49
|
+
CHANNEL_NOT_FOUND_SERVER: 400201,
|
|
50
|
+
CHANNEL_NOT_FOUND_SDK: 900500,
|
|
39
51
|
};
|
|
40
52
|
export const SBErrorMessage = {
|
|
41
53
|
ACL:
|
|
@@ -53,6 +65,7 @@ export type {
|
|
|
53
65
|
PartialDeep,
|
|
54
66
|
Optional,
|
|
55
67
|
ContextValue,
|
|
68
|
+
OnBeforeHandler,
|
|
56
69
|
SendbirdMessage,
|
|
57
70
|
SendbirdChatSDK,
|
|
58
71
|
SendbirdChannel,
|
|
@@ -78,6 +91,7 @@ export type {
|
|
|
78
91
|
SendbirdDataPayload,
|
|
79
92
|
SendbirdPreviousMessageListQuery,
|
|
80
93
|
SendbirdSendableMessage,
|
|
94
|
+
SendbirdOpenChannelListQuery,
|
|
81
95
|
SendbirdGroupChannelListQuery,
|
|
82
96
|
SendbirdGroupChannelUpdateParams,
|
|
83
97
|
SendbirdUserMessageUpdateParams,
|
|
@@ -88,4 +102,7 @@ export type {
|
|
|
88
102
|
SendbirdEmojiContainer,
|
|
89
103
|
SendbirdEmoji,
|
|
90
104
|
SendbirdEmojiCategory,
|
|
105
|
+
SendbirdOpenChannelUpdateParams,
|
|
106
|
+
SendbirdOpenChannelCreateParams,
|
|
107
|
+
SendbirdParticipant,
|
|
91
108
|
} from './types';
|
package/src/sendbird/channel.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { BufferedRequest } from '../shared/bufferedRequest';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
SendbirdBaseChannel,
|
|
4
|
+
SendbirdChannel,
|
|
5
|
+
SendbirdGroupChannel,
|
|
6
|
+
SendbirdGroupChannelCreateParams,
|
|
7
|
+
SendbirdOpenChannel,
|
|
8
|
+
} from '../types';
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
11
|
* Diff utils for channel
|
|
@@ -13,12 +19,21 @@ export function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T):
|
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {
|
|
16
|
-
const
|
|
22
|
+
const isOperator = channel.myRole === 'operator';
|
|
23
|
+
const frozen = channel.isFrozen && !isOperator;
|
|
17
24
|
const muted = channel.myMutedState === 'muted';
|
|
18
25
|
const disabled = frozen || muted;
|
|
19
26
|
return { disabled, frozen, muted };
|
|
20
27
|
};
|
|
21
28
|
|
|
29
|
+
export const getOpenChannelChatAvailableState = async (channel: SendbirdOpenChannel, userId: string) => {
|
|
30
|
+
const isOperator = channel.isOperator(userId);
|
|
31
|
+
const frozen = channel.isFrozen && !isOperator;
|
|
32
|
+
const muted = (await channel.getMyMutedInfo()).isMuted;
|
|
33
|
+
const disabled = frozen || muted;
|
|
34
|
+
return { disabled, frozen, muted };
|
|
35
|
+
};
|
|
36
|
+
|
|
22
37
|
export const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {
|
|
23
38
|
channels
|
|
24
39
|
.filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)
|
|
@@ -50,3 +65,19 @@ export function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChanne
|
|
|
50
65
|
export function getChannelUniqId(channel: SendbirdChannel) {
|
|
51
66
|
return channel.url;
|
|
52
67
|
}
|
|
68
|
+
|
|
69
|
+
export function getDefaultGroupChannelCreateParams(params: {
|
|
70
|
+
invitedUserIds: string[];
|
|
71
|
+
currentUserId?: string;
|
|
72
|
+
}): SendbirdGroupChannelCreateParams {
|
|
73
|
+
const createParams: SendbirdGroupChannelCreateParams = {
|
|
74
|
+
name: '',
|
|
75
|
+
coverUrl: '',
|
|
76
|
+
isDistinct: false,
|
|
77
|
+
invitedUserIds: params.invitedUserIds,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (params.currentUserId) createParams.operatorUserIds = [params.currentUserId];
|
|
81
|
+
|
|
82
|
+
return createParams;
|
|
83
|
+
}
|
package/src/sendbird/message.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getFileExtension, getFileType } from '../shared/regex';
|
|
1
2
|
import type {
|
|
2
3
|
SendbirdBaseChannel,
|
|
3
4
|
SendbirdBaseMessage,
|
|
@@ -114,9 +115,61 @@ export function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload):
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
export function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {
|
|
117
|
-
|
|
118
|
+
if (channel.isOpenChannel()) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (channel.isGroupChannel()) {
|
|
123
|
+
if (channel.isBroadcast) return false;
|
|
124
|
+
if (channel.isSuper) return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return reactionEnabled;
|
|
118
128
|
}
|
|
119
129
|
|
|
120
130
|
export function getReactionCount(reaction: SendbirdReaction) {
|
|
121
131
|
return reaction.userIds.length;
|
|
122
132
|
}
|
|
133
|
+
|
|
134
|
+
type MessageType =
|
|
135
|
+
| 'user'
|
|
136
|
+
| 'admin'
|
|
137
|
+
| 'file'
|
|
138
|
+
| 'unknown'
|
|
139
|
+
| `user.${'opengraph'}`
|
|
140
|
+
| `file.${'image' | 'video' | 'audio'}`;
|
|
141
|
+
|
|
142
|
+
export function getFileTypeFromMessage(message: SendbirdFileMessage) {
|
|
143
|
+
return getFileType(message.type || getFileExtension(message.name));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function getMessageType(message: SendbirdMessage): MessageType {
|
|
147
|
+
if (message.isAdminMessage()) {
|
|
148
|
+
return 'admin';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (message.isUserMessage()) {
|
|
152
|
+
if (message.ogMetaData) {
|
|
153
|
+
return 'user.opengraph';
|
|
154
|
+
}
|
|
155
|
+
return 'user';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (message.isFileMessage()) {
|
|
159
|
+
const fileType = getFileTypeFromMessage(message);
|
|
160
|
+
switch (fileType) {
|
|
161
|
+
case 'image':
|
|
162
|
+
case 'video': {
|
|
163
|
+
return `file.${fileType}`;
|
|
164
|
+
}
|
|
165
|
+
case 'audio': {
|
|
166
|
+
return `file.${fileType}`;
|
|
167
|
+
}
|
|
168
|
+
default: {
|
|
169
|
+
return 'file';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return 'unknown';
|
|
175
|
+
}
|
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,66 @@
|
|
|
1
|
+
import { getFileExtension, getFileType } from './regex';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a given string to a hashed string.
|
|
5
|
+
* */
|
|
6
|
+
export function hash(str: string) {
|
|
7
|
+
return String(Math.abs(str.split('').reduce((a, c) => ((a << 5) - a + c.charCodeAt(0)) | 0, 0)));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Replace a specific range of text in the string with another text.
|
|
12
|
+
* */
|
|
13
|
+
export function replace(str: string, start: number, end: number, text: string) {
|
|
14
|
+
return str.slice(0, start) + text + str.slice(end);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the value corresponding to the first true index of a given condition array.
|
|
19
|
+
* */
|
|
20
|
+
export function conditionChaining<T, V>(conditions: T[], values: V[]) {
|
|
21
|
+
const idx = conditions.findIndex((state) => Boolean(state));
|
|
22
|
+
return idx > -1 ? values[idx] : values[values.length - 1];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Calculates the downscale size.
|
|
27
|
+
* */
|
|
28
|
+
type Size = { width: number; height: number };
|
|
29
|
+
export function getDownscaleSize(origin: Size, resizing: Partial<Size>) {
|
|
30
|
+
let ratio;
|
|
31
|
+
|
|
32
|
+
const maxWidth = resizing.width || origin.width,
|
|
33
|
+
maxHeight = resizing.height || origin.height;
|
|
34
|
+
|
|
35
|
+
if (origin.width <= maxWidth && origin.height <= maxHeight) {
|
|
36
|
+
ratio = 1;
|
|
37
|
+
} else if (origin.width > maxWidth && origin.height <= maxHeight) {
|
|
38
|
+
ratio = maxWidth / origin.width;
|
|
39
|
+
} else if (origin.width <= maxWidth && origin.height > maxHeight) {
|
|
40
|
+
ratio = maxHeight / origin.height;
|
|
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);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the picked data from object.
|
|
60
|
+
* */
|
|
61
|
+
export function pick<T extends { [key: string]: unknown }, Keys extends keyof T>(obj: T, keys: Keys[]) {
|
|
62
|
+
return keys.reduce((pickedObj, key) => {
|
|
63
|
+
pickedObj[key] = obj[key];
|
|
64
|
+
return pickedObj;
|
|
65
|
+
}, {} as { [key in Keys]: T[key] });
|
|
66
|
+
}
|