@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.
Files changed (70) hide show
  1. package/lib/commonjs/hooks/index.js +38 -1
  2. package/lib/commonjs/hooks/index.js.map +1 -1
  3. package/lib/commonjs/hooks/react-native.js +5 -7
  4. package/lib/commonjs/hooks/react-native.js.map +1 -1
  5. package/lib/commonjs/index.js +65 -118
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/sendbird/channel.js +29 -1
  8. package/lib/commonjs/sendbird/channel.js.map +1 -1
  9. package/lib/commonjs/sendbird/message.js +56 -1
  10. package/lib/commonjs/sendbird/message.js.map +1 -1
  11. package/lib/commonjs/sendbird/user.js +0 -6
  12. package/lib/commonjs/sendbird/user.js.map +1 -1
  13. package/lib/commonjs/shared/file.js +225 -0
  14. package/lib/commonjs/shared/file.js.map +1 -0
  15. package/lib/commonjs/shared/index.js +18 -39
  16. package/lib/commonjs/shared/index.js.map +1 -1
  17. package/lib/commonjs/shared/regex.js +1 -46
  18. package/lib/commonjs/shared/regex.js.map +1 -1
  19. package/lib/commonjs/types.js.map +1 -1
  20. package/lib/commonjs/ui-format/openChannel.js +22 -0
  21. package/lib/commonjs/ui-format/openChannel.js.map +1 -0
  22. package/lib/module/hooks/index.js +29 -1
  23. package/lib/module/hooks/index.js.map +1 -1
  24. package/lib/module/hooks/react-native.js +6 -8
  25. package/lib/module/hooks/react-native.js.map +1 -1
  26. package/lib/module/index.js +11 -4
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/sendbird/channel.js +23 -1
  29. package/lib/module/sendbird/channel.js.map +1 -1
  30. package/lib/module/sendbird/message.js +51 -1
  31. package/lib/module/sendbird/message.js.map +1 -1
  32. package/lib/module/sendbird/user.js +0 -4
  33. package/lib/module/sendbird/user.js.map +1 -1
  34. package/lib/module/shared/file.js +192 -0
  35. package/lib/module/shared/file.js.map +1 -0
  36. package/lib/module/shared/index.js +15 -32
  37. package/lib/module/shared/index.js.map +1 -1
  38. package/lib/module/shared/regex.js +0 -33
  39. package/lib/module/shared/regex.js.map +1 -1
  40. package/lib/module/types.js.map +1 -1
  41. package/lib/module/ui-format/openChannel.js +10 -0
  42. package/lib/module/ui-format/openChannel.js.map +1 -0
  43. package/lib/typescript/src/hooks/index.d.ts +3 -0
  44. package/lib/typescript/src/index.d.ts +10 -5
  45. package/lib/typescript/src/sendbird/channel.d.ts +10 -1
  46. package/lib/typescript/src/sendbird/message.d.ts +3 -0
  47. package/lib/typescript/src/sendbird/user.d.ts +0 -2
  48. package/lib/typescript/src/shared/file.d.ts +68 -0
  49. package/lib/typescript/src/shared/index.d.ts +13 -13
  50. package/lib/typescript/src/shared/regex.d.ts +0 -6
  51. package/lib/typescript/src/types.d.ts +8 -3
  52. package/lib/typescript/src/ui-format/openChannel.d.ts +3 -0
  53. package/package.json +4 -4
  54. package/src/hooks/index.ts +31 -1
  55. package/src/hooks/react-native.ts +6 -8
  56. package/src/index.ts +20 -20
  57. package/src/sendbird/channel.ts +33 -2
  58. package/src/sendbird/message.ts +54 -1
  59. package/src/sendbird/user.ts +0 -7
  60. package/src/shared/file.ts +193 -0
  61. package/src/shared/index.ts +15 -32
  62. package/src/shared/regex.ts +0 -34
  63. package/src/types.ts +17 -2
  64. package/src/ui-format/openChannel.ts +11 -0
  65. package/lib/commonjs/shared/pubsub.js +0 -54
  66. package/lib/commonjs/shared/pubsub.js.map +0 -1
  67. package/lib/module/shared/pubsub.js +0 -45
  68. package/lib/module/shared/pubsub.js.map +0 -1
  69. package/lib/typescript/src/shared/pubsub.d.ts +0 -8
  70. package/src/shared/pubsub.ts +0 -42
@@ -1 +1 @@
1
- {"version":3,"names":["require","shim","urlRegexStrict","urlRegexRough","phoneRegex","emailRegex","newLineRegex","createMentionTemplateRegex","trigger","RegExp","replaceWithRegex","text","regex","replacer","keyPrefix","matches","matchAll","founds","map","value","start","index","end","length","groups","matchIndex","items","cursor","forEach","restText","pop","head","slice","mid","match","tail","push","replaceUrlAsComponents","originText","strict","imageExtRegex","audioExtRegex","videoExtRegex","getFileType","extOrType","indexOf","type","split","getFileExtension","filePath","idx","lastIndexOf","toLowerCase","normalizeFileName","fileName","extension"],"sources":["regex.ts"],"sourcesContent":["// For iOS 12 backwards compatibility\nrequire('string.prototype.matchall').shim();\n\nexport const urlRegexStrict =\n /(https?:\\/\\/|www\\.)[-a-zA-Z0-9@:%._+~#=]{1,256}\\.(xn--)?[a-z0-9-]{2,20}\\b([-a-zA-Z0-9@:%_+[\\],.~#?&/=]*[-a-zA-Z0-9@:%_+\\]~#?&/=])*/g;\nexport const urlRegexRough =\n /(https?:\\/\\/|www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g;\nexport const phoneRegex = /[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,7}/;\nexport const emailRegex = /\\S+@\\S+\\.\\S+/;\nexport const newLineRegex = /\\r\\n|\\r|\\n/g;\n\nexport const createMentionTemplateRegex = (trigger: string) => new RegExp(`(${trigger}[{])(.*?)([}])`, 'g');\n\n// const cases = [\n// {\n// type: 'urlStrict',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'urlRough',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'email',\n// regex: emailRegex,\n// },\n// {\n// type: 'phone',\n// regex: urlRegexStrict,\n// },\n// ];\n\nexport const replaceWithRegex = <T>(\n text: string,\n regex: RegExp,\n replacer: (params: {\n match: string;\n groups: string[];\n matchIndex: number | undefined;\n index: number;\n keyPrefix: string;\n }) => T,\n keyPrefix: string,\n) => {\n const matches = [...text.matchAll(regex)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end, groups: value, matchIndex: value.index };\n });\n\n const items: Array<T | string> = [text];\n let cursor = 0;\n founds.forEach(({ text, start, end, groups, matchIndex }, index) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer({ match: text, groups, matchIndex, index, keyPrefix });\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n\nexport const replaceUrlAsComponents = <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => {\n const matches = [...originText.matchAll(strict ? urlRegexStrict : urlRegexRough)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end };\n });\n\n const items: Array<string | T> = [originText];\n let cursor = 0;\n founds.forEach(({ text, start, end }) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer(text);\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n\nexport const imageExtRegex = /jpeg|jpg|png|webp|gif/i;\nexport const audioExtRegex = /3gp|aac|aax|act|aiff|flac|gsm|m4a|m4b|m4p|tta|wma|mp3|webm|wav/i;\nexport const videoExtRegex = /mov|vod|mp4|avi/i;\nexport const getFileType = (extOrType: string) => {\n if (extOrType.indexOf('/') > -1) {\n const type = extOrType.split('/')[0];\n if (type === 'video') return 'video';\n if (type === 'audio') return 'audio';\n if (type === 'image') return 'image';\n return 'file';\n }\n\n if (extOrType.match(imageExtRegex)) return 'image';\n if (extOrType.match(audioExtRegex)) return 'audio';\n if (extOrType.match(videoExtRegex)) return 'video';\n return 'file';\n};\nexport function getFileExtension(filePath: string) {\n const idx = filePath.lastIndexOf('.');\n if (idx === -1) return '';\n return filePath.slice(idx - filePath.length).toLowerCase();\n}\nexport function normalizeFileName(fileName: string, extension: string) {\n if (fileName.indexOf(extension) > -1) {\n return fileName;\n } else {\n if (extension.indexOf('.') === 0) {\n return `${fileName}${extension}`;\n } else {\n return `${fileName}.${extension}`;\n }\n }\n}\n"],"mappings":"AAAA;AACAA,OAAO,CAAC,2BAAD,CAAP,CAAqCC,I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AAQ,CAACjB,KAAT,CAAekB,GAAG,GAAGD,QAAQ,CAAC1B,MAA9B,EAAsC6B,WAAtC,EAAP;AACD;AACD,OAAO,SAASC,iBAAT,CAA2BC,QAA3B,EAA6CC,SAA7C,EAAgE;EACrE,IAAID,QAAQ,CAACT,OAAT,CAAiBU,SAAjB,IAA8B,CAAC,CAAnC,EAAsC;IACpC,OAAOD,QAAP;EACD,CAFD,MAEO;IACL,IAAIC,SAAS,CAACV,OAAV,CAAkB,GAAlB,MAA2B,CAA/B,EAAkC;MAChC,OAAQ,GAAES,QAAS,GAAEC,SAAU,EAA/B;IACD,CAFD,MAEO;MACL,OAAQ,GAAED,QAAS,IAAGC,SAAU,EAAhC;IACD;EACF;AACF"}
1
+ {"version":3,"names":["require","shim","urlRegexStrict","urlRegexRough","phoneRegex","emailRegex","newLineRegex","createMentionTemplateRegex","trigger","RegExp","replaceWithRegex","text","regex","replacer","keyPrefix","matches","matchAll","founds","map","value","start","index","end","length","groups","matchIndex","items","cursor","forEach","restText","pop","head","slice","mid","match","tail","push","replaceUrlAsComponents","originText","strict"],"sources":["regex.ts"],"sourcesContent":["// For iOS 12 backwards compatibility\nrequire('string.prototype.matchall').shim();\n\nexport const urlRegexStrict =\n /(https?:\\/\\/|www\\.)[-a-zA-Z0-9@:%._+~#=]{1,256}\\.(xn--)?[a-z0-9-]{2,20}\\b([-a-zA-Z0-9@:%_+[\\],.~#?&/=]*[-a-zA-Z0-9@:%_+\\]~#?&/=])*/g;\nexport const urlRegexRough =\n /(https?:\\/\\/|www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g;\nexport const phoneRegex = /[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,7}/;\nexport const emailRegex = /\\S+@\\S+\\.\\S+/;\nexport const newLineRegex = /\\r\\n|\\r|\\n/g;\n\nexport const createMentionTemplateRegex = (trigger: string) => new RegExp(`(${trigger}[{])(.*?)([}])`, 'g');\n\n// const cases = [\n// {\n// type: 'urlStrict',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'urlRough',\n// regex: urlRegexStrict,\n// },\n// {\n// type: 'email',\n// regex: emailRegex,\n// },\n// {\n// type: 'phone',\n// regex: urlRegexStrict,\n// },\n// ];\n\nexport const replaceWithRegex = <T>(\n text: string,\n regex: RegExp,\n replacer: (params: {\n match: string;\n groups: string[];\n matchIndex: number | undefined;\n index: number;\n keyPrefix: string;\n }) => T,\n keyPrefix: string,\n) => {\n const matches = [...text.matchAll(regex)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end, groups: value, matchIndex: value.index };\n });\n\n const items: Array<T | string> = [text];\n let cursor = 0;\n founds.forEach(({ text, start, end, groups, matchIndex }, index) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer({ match: text, groups, matchIndex, index, keyPrefix });\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n\nexport const replaceUrlAsComponents = <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => {\n const matches = [...originText.matchAll(strict ? urlRegexStrict : urlRegexRough)];\n const founds = matches.map((value) => {\n const text = value[0];\n const start = value.index ?? 0;\n const end = start + text.length;\n return { text, start, end };\n });\n\n const items: Array<string | T> = [originText];\n let cursor = 0;\n founds.forEach(({ text, start, end }) => {\n const restText = items.pop() as string;\n const head = restText.slice(0, start - cursor);\n const mid = replacer(text);\n const tail = restText.slice(end - cursor);\n items.push(head, mid, tail);\n cursor = end;\n });\n return items;\n};\n"],"mappings":"AAAA;AACAA,OAAO,CAAC,2BAAD,CAAP,CAAqCC,IAArC;;AAEA,OAAO,MAAMC,cAAc,GACzB,qIADK;AAEP,OAAO,MAAMC,aAAa,GACxB,uGADK;AAEP,OAAO,MAAMC,UAAU,GAAG,sDAAnB;AACP,OA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AAQ,CAACG,KAAT,CAAeV,GAAG,GAAGK,MAArB,CAAb;IACAD,KAAK,CAACU,IAAN,CAAWL,IAAX,EAAiBE,GAAjB,EAAsBE,IAAtB;IACAR,MAAM,GAAGL,GAAT;EACD,CAPD;EAQA,OAAOI,KAAP;AACD,CApBM"}
@@ -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 { ModuleNamespaces, SendableMessage } 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, 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 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;\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type 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 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":""}
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 {};
@@ -1,12 +1,13 @@
1
1
  export { Logger } from './shared/logger';
2
2
  export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
3
- export { createPubSub } from './shared/pubsub';
4
- export { urlRegexStrict, urlRegexRough, newLineRegex, audioExtRegex, videoExtRegex, imageExtRegex, getFileType, getFileExtension, replaceUrlAsComponents, normalizeFileName, emailRegex, phoneRegex, replaceWithRegex, createMentionTemplateRegex, } from './shared/regex';
5
- export { BufferedRequest } from './shared/bufferedRequest';
3
+ export * from './shared/regex';
4
+ export * from './shared/bufferedRequest';
5
+ export * from './shared/file';
6
6
  export * from './shared';
7
7
  export * from './hooks';
8
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: <T>(param?: T | undefined) => param is NonNullable<T>;
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,68 @@
1
+ export declare const imageExtRegex: RegExp;
2
+ export declare const audioExtRegex: RegExp;
3
+ export declare const videoExtRegex: RegExp;
4
+ export declare const getFileType: (extOrType: string) => "video" | "audio" | "image" | "file";
5
+ /**
6
+ * Calculates the downscaled size of an image while preserving its aspect ratio.
7
+ *
8
+ * @param {Object} origin - The original size object with `width` and `height` properties.
9
+ * @param {Object} resizing - The resizing object with optional `width` and `height` properties.
10
+ * @returns {Object} - A new size object with the downscaled `width` and `height` properties.
11
+ * @example
12
+ * ```ts
13
+ * getDownscaleSize({ width: 1200, height: 800 }, { width: 600 }); // returns { width: 600, height: 400 }
14
+ * ```
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
+ /**
25
+ * Normalize a file name by ensuring it has the given extension, if it doesn't already.
26
+ *
27
+ * @param {string} fileName - The file name to normalize.
28
+ * @param {string} extension - The desired extension, without a leading period.
29
+ * @returns {string} - The normalized file name, with the extension.
30
+ */
31
+ export declare function normalizeFileName(fileName: string, extension: string): string;
32
+ /**
33
+ * Parses a MIME type string into its components.
34
+ *
35
+ * @param mimeType - The MIME type string to parse.
36
+ * @returns An object containing the type, subtype, and parameters of the MIME type.
37
+ */
38
+ type MimeType = {
39
+ type: string;
40
+ subtype: string;
41
+ parameters: Record<string, string>;
42
+ };
43
+ export declare function parseMimeType(mimeType: string): MimeType;
44
+ /**
45
+ * Returns the file extension based on the MIME type.
46
+ *
47
+ * @param {string | null | undefined} mimeType - The MIME type to look up.
48
+ * @returns {string} - The file extension for the given MIME type, or an empty string if no matching file extension was found.
49
+ */
50
+ export declare function getFileExtensionFromMime(mimeType?: string | null): string;
51
+ /**
52
+ * Returns the MIME type based on the file extension.
53
+ *
54
+ * @param {string | null | undefined} ext - The file extension to look up.
55
+ * @returns {string} - The MIME type for the given file extension, or an empty string if no matching MIME type was found.
56
+ */
57
+ export declare function getMimeFromFileExtension(ext?: string | null): string;
58
+ /**
59
+ * Returns the file extension of a file path.
60
+ *
61
+ * @param {string} filePath - The file path to extract the extension from.
62
+ * @returns {string} - The file extension, or an empty string if the file path does not have an extension.
63
+ */
64
+ export declare function getFileExtension(filePath: string): string;
65
+ export declare function getFileExtensionFromUri(uri: string): Promise<string | null>;
66
+ export declare function isImage(filePath: string, mimeType?: string): boolean;
67
+ export declare function shouldCompressImage(mime: string, compressionEnabled?: boolean): boolean;
68
+ export {};
@@ -11,16 +11,16 @@ export declare function replace(str: string, start: number, end: number, text: s
11
11
  * */
12
12
  export declare function conditionChaining<T, V>(conditions: T[], values: V[]): V;
13
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
- export {};
14
+ * Returns a new object with only the specified keys from the input object.
15
+ *
16
+ * @param {Object} obj - The input object to pick keys from.
17
+ * @param {Array<string>} keys - An array of keys to pick from the input object.
18
+ * @returns {Object} - A new object containing only the specified keys from the input object.
19
+ * @example
20
+ * ```ts
21
+ * pick({ a: 1, b: '2', c: true }, ['a', 'c']); // returns { a: 1, c: true }
22
+ * ```
23
+ */
24
+ export declare function pick<T extends {
25
+ [key: string]: unknown;
26
+ }, Keys extends keyof T>(obj: T, keys: Keys[]): { [key in Keys]: T[key]; };
@@ -12,9 +12,3 @@ export declare const replaceWithRegex: <T>(text: string, regex: RegExp, replacer
12
12
  keyPrefix: string;
13
13
  }) => T, keyPrefix: string) => (string | T)[];
14
14
  export declare const replaceUrlAsComponents: <T>(originText: string, replacer: (url: string) => T, strict?: boolean) => (string | T)[];
15
- export declare const imageExtRegex: RegExp;
16
- export declare const audioExtRegex: RegExp;
17
- export declare const videoExtRegex: RegExp;
18
- export declare const getFileType: (extOrType: string) => "video" | "audio" | "image" | "file";
19
- export declare function getFileExtension(filePath: string): string;
20
- export declare function normalizeFileName(fileName: string, extension: string): string;
@@ -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;
@@ -0,0 +1,3 @@
1
+ import type { SendbirdOpenChannel } from '../types';
2
+ export declare const getOpenChannelTitle: (channel: SendbirdOpenChannel, DEFAULT_CHANNEL_NAME?: string) => string;
3
+ export declare const getOpenChannelParticipants: (channel: SendbirdOpenChannel) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendbird/uikit-utils",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "UIKit utilities",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -45,12 +45,12 @@
45
45
  "@types/react": "*",
46
46
  "@types/react-native": "*",
47
47
  "react": "17.0.2",
48
- "react-native": "0.67.4",
48
+ "react-native": "0.67.5",
49
49
  "react-native-builder-bob": "^0.18.0",
50
50
  "typescript": "4.9.4"
51
51
  },
52
52
  "peerDependencies": {
53
- "@sendbird/chat": "^4.0.13",
53
+ "@sendbird/chat": "^4.3.0",
54
54
  "react": ">=16.13.1"
55
55
  },
56
56
  "peerDependenciesMeta": {
@@ -77,5 +77,5 @@
77
77
  "readmeFile": "./README.md",
78
78
  "displayName": "@sendbird/uikit-utils"
79
79
  },
80
- "gitHead": "a9bf41fd7919436db99f6cc3bacd0f8d791b7729"
80
+ "gitHead": "9ba7a005c941a3edd5b0f78d88d8cd1df6c280fc"
81
81
  }
@@ -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
+ };
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useRef } from 'react';
1
+ import { useEffect, useRef } from 'react';
2
2
  import { AppState, AppStateEvent, AppStateStatus } from 'react-native';
3
3
  import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
4
4
 
@@ -22,13 +22,11 @@ export const useSafeAreaPadding = <
22
22
  edges: T[],
23
23
  ): Result => {
24
24
  const safeAreaInsets = useSafeAreaInsets();
25
- return useMemo(() => {
26
- return edges.reduce((map, edge) => {
27
- const paddingKey = edgePaddingMap[edge];
28
- map[paddingKey] = safeAreaInsets[edge];
29
- return map;
30
- }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] });
31
- }, edges) as Result;
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;
32
30
  };
33
31
 
34
32
  type AppStateListener = (status: AppStateStatus) => void;
package/src/index.ts CHANGED
@@ -1,29 +1,14 @@
1
1
  export { Logger } from './shared/logger';
2
2
  export { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';
3
- export { createPubSub } from './shared/pubsub';
4
- export {
5
- urlRegexStrict,
6
- urlRegexRough,
7
- newLineRegex,
8
- audioExtRegex,
9
- videoExtRegex,
10
- imageExtRegex,
11
- getFileType,
12
- getFileExtension,
13
- replaceUrlAsComponents,
14
- normalizeFileName,
15
- emailRegex,
16
- phoneRegex,
17
- replaceWithRegex,
18
- createMentionTemplateRegex,
19
- } from './shared/regex';
20
- export { BufferedRequest } from './shared/bufferedRequest';
21
-
3
+ export * from './shared/regex';
4
+ export * from './shared/bufferedRequest';
5
+ export * from './shared/file';
22
6
  export * from './shared';
23
7
 
24
8
  export * from './hooks';
25
9
  export * from './hooks/react-native';
26
10
  export * from './ui-format/groupChannel';
11
+ export * from './ui-format/openChannel';
27
12
  export * from './ui-format/common';
28
13
  export * from './sendbird/channel';
29
14
  export * from './sendbird/message';
@@ -34,9 +19,19 @@ export const NOOP: () => void = () => void 0;
34
19
  export const ASYNC_NOOP = async () => void 0;
35
20
  export const PASS = <T>(val: T) => val;
36
21
  export const toMegabyte = (byte: number) => byte / 1024 / 1024;
37
- export const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';
22
+ export const isFunction = (param?: unknown): param is Function => typeof param === 'function';
23
+
24
+ export function ifThenOr<T>(cond: boolean, then: T): T | undefined;
25
+ export function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;
26
+ export function ifThenOr(cond: boolean, then: unknown, or?: unknown) {
27
+ if (cond) return then;
28
+ return or;
29
+ }
30
+
38
31
  export const SBErrorCode = {
39
32
  NON_AUTHORIZED: 400108,
33
+ CHANNEL_NOT_FOUND_SERVER: 400201,
34
+ CHANNEL_NOT_FOUND_SDK: 900500,
40
35
  };
41
36
  export const SBErrorMessage = {
42
37
  ACL:
@@ -54,6 +49,7 @@ export type {
54
49
  PartialDeep,
55
50
  Optional,
56
51
  ContextValue,
52
+ OnBeforeHandler,
57
53
  SendbirdMessage,
58
54
  SendbirdChatSDK,
59
55
  SendbirdChannel,
@@ -79,6 +75,7 @@ export type {
79
75
  SendbirdDataPayload,
80
76
  SendbirdPreviousMessageListQuery,
81
77
  SendbirdSendableMessage,
78
+ SendbirdOpenChannelListQuery,
82
79
  SendbirdGroupChannelListQuery,
83
80
  SendbirdGroupChannelUpdateParams,
84
81
  SendbirdUserMessageUpdateParams,
@@ -89,4 +86,7 @@ export type {
89
86
  SendbirdEmojiContainer,
90
87
  SendbirdEmoji,
91
88
  SendbirdEmojiCategory,
89
+ SendbirdOpenChannelUpdateParams,
90
+ SendbirdOpenChannelCreateParams,
91
+ SendbirdParticipant,
92
92
  } from './types';
@@ -1,5 +1,11 @@
1
1
  import { BufferedRequest } from '../shared/bufferedRequest';
2
- import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
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 frozen = channel.isFrozen && channel.myRole !== 'operator';
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
+ }
@@ -1,3 +1,4 @@
1
+ import { getFileExtension, getFileType } from '../shared/file';
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
- return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;
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
+ }