@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.
Files changed (65) 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 +54 -0
  4. package/lib/commonjs/hooks/react-native.js.map +1 -0
  5. package/lib/commonjs/index.js +53 -21
  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/index.js +86 -0
  14. package/lib/commonjs/shared/index.js.map +1 -0
  15. package/lib/commonjs/types.js.map +1 -1
  16. package/lib/commonjs/ui-format/openChannel.js +22 -0
  17. package/lib/commonjs/ui-format/openChannel.js.map +1 -0
  18. package/lib/module/hooks/index.js +29 -1
  19. package/lib/module/hooks/index.js.map +1 -1
  20. package/lib/module/hooks/react-native.js +37 -0
  21. package/lib/module/hooks/react-native.js.map +1 -0
  22. package/lib/module/index.js +10 -3
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/sendbird/channel.js +23 -1
  25. package/lib/module/sendbird/channel.js.map +1 -1
  26. package/lib/module/sendbird/message.js +51 -1
  27. package/lib/module/sendbird/message.js.map +1 -1
  28. package/lib/module/sendbird/user.js +0 -4
  29. package/lib/module/sendbird/user.js.map +1 -1
  30. package/lib/module/shared/index.js +67 -0
  31. package/lib/module/shared/index.js.map +1 -0
  32. package/lib/module/types.js.map +1 -1
  33. package/lib/module/ui-format/openChannel.js +10 -0
  34. package/lib/module/ui-format/openChannel.js.map +1 -0
  35. package/lib/typescript/src/hooks/index.d.ts +3 -0
  36. package/lib/typescript/src/hooks/react-native.d.ts +12 -0
  37. package/lib/typescript/src/index.d.ts +9 -4
  38. package/lib/typescript/src/sendbird/channel.d.ts +10 -1
  39. package/lib/typescript/src/sendbird/message.d.ts +3 -0
  40. package/lib/typescript/src/sendbird/user.d.ts +0 -2
  41. package/lib/typescript/src/shared/index.d.ts +32 -0
  42. package/lib/typescript/src/types.d.ts +8 -3
  43. package/lib/typescript/src/ui-format/openChannel.d.ts +3 -0
  44. package/package.json +5 -4
  45. package/src/hooks/index.ts +31 -1
  46. package/src/hooks/react-native.ts +54 -0
  47. package/src/index.ts +20 -3
  48. package/src/sendbird/channel.ts +33 -2
  49. package/src/sendbird/message.ts +54 -1
  50. package/src/sendbird/user.ts +0 -7
  51. package/src/shared/index.ts +66 -0
  52. package/src/types.ts +17 -2
  53. package/src/ui-format/openChannel.ts +11 -0
  54. package/lib/commonjs/shared/conditionChaining.js +0 -15
  55. package/lib/commonjs/shared/conditionChaining.js.map +0 -1
  56. package/lib/commonjs/shared/replace.js +0 -14
  57. package/lib/commonjs/shared/replace.js.map +0 -1
  58. package/lib/module/shared/conditionChaining.js +0 -7
  59. package/lib/module/shared/conditionChaining.js.map +0 -1
  60. package/lib/module/shared/replace.js +0 -6
  61. package/lib/module/shared/replace.js.map +0 -1
  62. package/lib/typescript/src/shared/conditionChaining.d.ts +0 -2
  63. package/lib/typescript/src/shared/replace.d.ts +0 -2
  64. package/src/shared/conditionChaining.ts +0 -6
  65. package/src/shared/replace.ts +0 -5
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.conditionChaining = conditionChaining;
7
+ exports.getDownscaleSize = getDownscaleSize;
8
+ exports.hash = hash;
9
+ exports.isImage = isImage;
10
+ exports.pick = pick;
11
+ exports.replace = replace;
12
+ exports.shouldCompressImage = shouldCompressImage;
13
+
14
+ var _regex = require("./regex");
15
+
16
+ /**
17
+ * Converts a given string to a hashed string.
18
+ * */
19
+ function hash(str) {
20
+ return String(Math.abs(str.split('').reduce((a, c) => (a << 5) - a + c.charCodeAt(0) | 0, 0)));
21
+ }
22
+ /**
23
+ * Replace a specific range of text in the string with another text.
24
+ * */
25
+
26
+
27
+ function replace(str, start, end, text) {
28
+ return str.slice(0, start) + text + str.slice(end);
29
+ }
30
+ /**
31
+ * Returns the value corresponding to the first true index of a given condition array.
32
+ * */
33
+
34
+
35
+ function conditionChaining(conditions, values) {
36
+ const idx = conditions.findIndex(state => Boolean(state));
37
+ return idx > -1 ? values[idx] : values[values.length - 1];
38
+ }
39
+ /**
40
+ * Calculates the downscale size.
41
+ * */
42
+
43
+
44
+ function getDownscaleSize(origin, resizing) {
45
+ let ratio;
46
+ const maxWidth = resizing.width || origin.width,
47
+ maxHeight = resizing.height || origin.height;
48
+
49
+ if (origin.width <= maxWidth && origin.height <= maxHeight) {
50
+ ratio = 1;
51
+ } else if (origin.width > maxWidth && origin.height <= maxHeight) {
52
+ ratio = maxWidth / origin.width;
53
+ } else if (origin.width <= maxWidth && origin.height > maxHeight) {
54
+ ratio = maxHeight / origin.height;
55
+ } else {
56
+ ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
57
+ }
58
+
59
+ return {
60
+ width: origin.width * ratio,
61
+ height: origin.height * ratio
62
+ };
63
+ }
64
+
65
+ function isImage(filePath, mimeType) {
66
+ const type = (0, _regex.getFileType)(mimeType || (0, _regex.getFileExtension)(filePath));
67
+ return type === 'image';
68
+ }
69
+
70
+ function shouldCompressImage(filePath) {
71
+ let compressionEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
72
+ const extension = (0, _regex.getFileExtension)(filePath);
73
+ return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
74
+ }
75
+ /**
76
+ * Returns the picked data from object.
77
+ * */
78
+
79
+
80
+ function pick(obj, keys) {
81
+ return keys.reduce((pickedObj, key) => {
82
+ pickedObj[key] = obj[key];
83
+ return pickedObj;
84
+ }, {});
85
+ }
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["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","getFileType","getFileExtension","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":";;;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACO,SAASA,IAAT,CAAcC,GAAd,EAA2B;EAChC,OAAOC,MAAM,CAACC,IAAI,CAACC,GAAL,CAASH,GAAG,CAACI,KAAJ,CAAU,EAAV,EAAcC,MAAd,CAAqB,CAACC,CAAD,EAAIC,CAAJ,KAAW,CAACD,CAAC,IAAI,CAAN,IAAWA,CAAX,GAAeC,CAAC,CAACC,UAAF,CAAa,CAAb,CAAhB,GAAmC,CAAlE,EAAqE,CAArE,CAAT,CAAD,CAAb;AACD;AAED;AACA;AACA;;;AACO,SAASC,OAAT,CAAiBT,GAAjB,EAA8BU,KAA9B,EAA6CC,GAA7C,EAA0DC,IAA1D,EAAwE;EAC7E,OAAOZ,GAAG,CAACa,KAAJ,CAAU,CAAV,EAAaH,KAAb,IAAsBE,IAAtB,GAA6BZ,GAAG,CAACa,KAAJ,CAAUF,GAAV,CAApC;AACD;AAED;AACA;AACA;;;AACO,SAASG,iBAAT,CAAiCC,UAAjC,EAAkDC,MAAlD,EAA+D;EACpE,MAAMC,GAAG,GAAGF,UAAU,CAACG,SAAX,CAAsBC,KAAD,IAAWC,OAAO,CAACD,KAAD,CAAvC,CAAZ;EACA,OAAOF,GAAG,GAAG,CAAC,CAAP,GAAWD,MAAM,CAACC,GAAD,CAAjB,GAAyBD,MAAM,CAACA,MAAM,CAACK,MAAP,GAAgB,CAAjB,CAAtC;AACD;AAED;AACA;AACA;;;AAEO,SAASC,gBAAT,CAA0BC,MAA1B,EAAwCC,QAAxC,EAAiE;EACtE,IAAIC,KAAJ;EAEA,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,KAAT,IAAkBJ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kBAArC,CAAd;AACD;AAED;AACA;AACA;;;AACO,SAASG,IAAT,CAA0EC,GAA1E,EAAkFC,IAAlF,EAAgG;EACrG,OAAOA,IAAI,CAACtC,MAAL,CAAY,CAACuC,SAAD,EAAYC,GAAZ,KAAoB;IACrCD,SAAS,CAACC,GAAD,CAAT,GAAiBH,GAAG,CAACG,GAAD,CAApB;IACA,OAAOD,SAAP;EACD,CAHM,EAGJ,EAHI,CAAP;AAID"}
@@ -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,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getOpenChannelTitle = exports.getOpenChannelParticipants = void 0;
7
+
8
+ const getOpenChannelTitle = function (channel) {
9
+ let DEFAULT_CHANNEL_NAME = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Open Channel';
10
+ const trimmedChannelName = channel.name.trim();
11
+ if (trimmedChannelName === '') return DEFAULT_CHANNEL_NAME;
12
+ return trimmedChannelName;
13
+ };
14
+
15
+ exports.getOpenChannelTitle = getOpenChannelTitle;
16
+
17
+ const getOpenChannelParticipants = channel => {
18
+ return `${channel.participantCount} participants`;
19
+ };
20
+
21
+ exports.getOpenChannelParticipants = getOpenChannelParticipants;
22
+ //# 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":";;;;;;;AAEO,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;;;;AAMA,MAAMG,0BAA0B,GAAIL,OAAD,IAAkC;EAC1E,OAAQ,GAAEA,OAAO,CAACM,gBAAiB,eAAnC;AACD,CAFM"}
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react';
3
3
  const idPool = {};
4
4
  export const useUniqId = key => {
5
5
  return useState(() => {
@@ -7,6 +7,10 @@ export const useUniqId = key => {
7
7
  return idPool[key]++;
8
8
  })[0];
9
9
  };
10
+ export const useUniqHandlerId = name => {
11
+ const id = useUniqId(name);
12
+ return `${name}_${id}`;
13
+ };
10
14
  export const useForceUpdate = () => {
11
15
  const [, updater] = useState(0);
12
16
  return useCallback(() => updater(prev => prev + 1), []);
@@ -65,4 +69,28 @@ export const useFreshCallback = callback => {
65
69
  return ref.current(...arguments);
66
70
  }, []);
67
71
  };
72
+ export const useDebounceEffect = function (action, delay) {
73
+ let deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
74
+ const timeoutRef = useRef();
75
+ useEffect(() => {
76
+ timeoutRef.current = setTimeout(async () => {
77
+ try {
78
+ await action();
79
+ } finally {
80
+ timeoutRef.current = undefined;
81
+ }
82
+ }, delay);
83
+ return () => {
84
+ if (timeoutRef.current) {
85
+ clearTimeout(timeoutRef.current);
86
+ timeoutRef.current = undefined;
87
+ }
88
+ };
89
+ }, [delay, ...deps]);
90
+ };
91
+ export const usePartialState = initialState => {
92
+ return useReducer((prev, state) => ({ ...prev,
93
+ ...state
94
+ }), initialState);
95
+ };
68
96
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useLayoutEffect","useRef","useState","idPool","useUniqId","key","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useIsFirstMount","isFirstMount","useFreshCallback","ref"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useIsFirstMount = () => {\n const isFirstMount = useRef(true);\n\n if (isFirstMount.current) {\n isFirstMount.current = false;\n return true;\n }\n\n return isFirstMount.current;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n"],"mappings":"AAAA;AAEA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,eAAjC,EAAkDC,MAAlD,EAA0DC,QAA1D,QAA0E,OAA1E;AAKA,MAAMC,MAAiC,GAAG,EAA1C;AACA,OAAO,MAAMC,SAAS,GAAIC,GAAD,IAAiB;EACxC,OAAOH,QAAQ,CAAC,MAAM;IACpB,IAAI,CAACC,MAAM,CAACE,GAAD,CAAX,EAAkBF,MAAM,CAACE,GAAD,CAAN,GAAc,CAAd;IAClB,OAAOF,MAAM,CAACE,GAAD,CAAN,EAAP;EACD,CAHc,CAAR,CAGJ,CAHI,CAAP;AAID,CALM;AAOP,OAAO,MAAMC,cAAc,GAAG,MAAM;E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OAAOD,SAAP;AACD,CAVM;AAYP,OAAO,MAAME,eAAe,GAAG,MAAM;EACnC,MAAMC,YAAY,GAAGvB,MAAM,CAAC,IAAD,CAA3B;;EAEA,IAAIuB,YAAY,CAACF,OAAjB,EAA0B;IACxBE,YAAY,CAACF,OAAb,GAAuB,KAAvB;IACA,OAAO,IAAP;EACD;;EAED,OAAOE,YAAY,CAACF,OAApB;AACD,CATM;AAWP,OAAO,MAAMG,gBAAgB,GAAuCV,QAApC,IAAuD;EACrF,MAAMW,GAAG,GAAGzB,MAAM,CAAIc,QAAJ,CAAlB;EACAW,GAAG,CAACJ,OAAJ,GAAcP,QAAd;EACA,OAAOjB,WAAW,CAAE;IAAA,OAAa4B,GAAG,CAACJ,OAAJ,CAAY,YAAZ,CAAb;EAAA,CAAF,EAA2C,EAA3C,CAAlB;AACD,CAJM"}
1
+ {"version":3,"names":["useCallback","useEffect","useLayoutEffect","useReducer","useRef","useState","idPool","useUniqId","key","useUniqHandlerId","name","id","useForceUpdate","updater","prev","useAsyncEffect","asyncEffect","deps","createAsyncEffectCallback","useAsyncLayoutEffect","useIIFE","callback","iife","destructor","Promise","awaitedDestructor","useIsMountedRef","isMounted","current","useIsFirstMount","isFirstMount","useFreshCallback","ref","useDebounceEffect","action","delay","timeoutRef","setTimeout","undefined","clearTimeout","usePartialState","initialState","state"],"sources":["index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from 'react';\nimport { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react';\n\ntype Destructor = () => void;\ntype AsyncEffectCallback = () => void | Destructor | Promise<void> | Promise<Destructor>;\n\nconst idPool: { [key: string]: number } = {};\nexport const useUniqId = (key: string) => {\n return useState(() => {\n if (!idPool[key]) idPool[key] = 1;\n return idPool[key]++;\n })[0];\n};\n\nexport const useUniqHandlerId = (name: string) => {\n const id = useUniqId(name);\n return `${name}_${id}`;\n};\n\nexport const useForceUpdate = () => {\n const [, updater] = useState(0);\n return useCallback(() => updater((prev) => prev + 1), []);\n};\n\nexport const useAsyncEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useAsyncLayoutEffect = (asyncEffect: AsyncEffectCallback, deps?: DependencyList) => {\n useLayoutEffect(createAsyncEffectCallback(asyncEffect), deps);\n};\nexport const useIIFE = <T>(callback: () => T) => {\n return iife(callback);\n};\nconst iife = <T extends (...args: any[]) => any>(callback: T): ReturnType<T> => callback();\nconst createAsyncEffectCallback = (asyncEffect: AsyncEffectCallback) => () => {\n const destructor = iife(asyncEffect);\n return () => {\n if (!destructor) return;\n\n if (destructor instanceof Promise) {\n iife(async () => {\n const awaitedDestructor = await destructor;\n if (awaitedDestructor) awaitedDestructor();\n });\n } else {\n iife(destructor);\n }\n };\n};\n\nexport const useIsMountedRef = () => {\n const isMounted = useRef(true);\n\n useEffect(() => {\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return isMounted;\n};\n\nexport const useIsFirstMount = () => {\n const isFirstMount = useRef(true);\n\n if (isFirstMount.current) {\n isFirstMount.current = false;\n return true;\n }\n\n return isFirstMount.current;\n};\n\nexport const useFreshCallback = <T extends (...args: any[]) => any>(callback: T): T => {\n const ref = useRef<T>(callback);\n ref.current = callback;\n return useCallback(((...args) => ref.current(...args)) as T, []);\n};\n\nexport const useDebounceEffect = (action: () => void, delay: number, deps: DependencyList = []) => {\n const timeoutRef = useRef<NodeJS.Timeout>();\n\n useEffect(() => {\n timeoutRef.current = setTimeout(async () => {\n try {\n await action();\n } finally {\n timeoutRef.current = undefined;\n }\n }, delay);\n\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = undefined;\n }\n };\n }, [delay, ...deps]);\n};\n\nexport const usePartialState = <S>(initialState: S) => {\n return useReducer((prev: S, state: Partial<S>) => ({ ...prev, ...state }), initialState);\n};\n"],"mappings":"AAAA;AAEA,SAASA,WAAT,EAAsB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,EAAzB;EAEAH,SAAS,CAAC,MAAM;IACdmC,UAAU,CAACR,OAAX,GAAqBS,UAAU,CAAC,YAAY;MAC1C,IAAI;QACF,MAAMH,MAAM,EAAZ;MACD,CAFD,SAEU;QACRE,UAAU,CAACR,OAAX,GAAqBU,SAArB;MACD;IACF,CAN8B,EAM5BH,KAN4B,CAA/B;IAQA,OAAO,MAAM;MACX,IAAIC,UAAU,CAACR,OAAf,EAAwB;QACtBW,YAAY,CAACH,UAAU,CAACR,OAAZ,CAAZ;QACAQ,UAAU,CAACR,OAAX,GAAqBU,SAArB;MACD;IACF,CALD;EAMD,CAfQ,EAeN,CAACH,KAAD,EAAQ,GAAGlB,IAAX,CAfM,CAAT;AAgBD,CAnBM;AAqBP,OAAO,MAAMuB,eAAe,GAAOC,YAAJ,IAAwB;EACrD,OAAOtC,UAAU,CAAC,CAACW,IAAD,EAAU4B,KAAV,MAAiC,EAAE,GAAG5B,IAAL;IAAW,GAAG4B;EAAd,CAAjC,CAAD,EAA0DD,YAA1D,CAAjB;AACD,CAFM"}
@@ -0,0 +1,37 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { AppState } from 'react-native';
3
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
+ const edgePaddingMap = {
5
+ left: 'paddingLeft',
6
+ right: 'paddingRight',
7
+ top: 'paddingTop',
8
+ bottom: 'paddingBottom'
9
+ };
10
+ export const useSafeAreaPadding = edges => {
11
+ const safeAreaInsets = useSafeAreaInsets();
12
+ return edges.reduce((map, edge) => {
13
+ const paddingKey = edgePaddingMap[edge];
14
+ map[paddingKey] = safeAreaInsets[edge];
15
+ return map;
16
+ }, {});
17
+ };
18
+ export const useAppState = (type, listener) => {
19
+ const callbackRef = useRef(listener);
20
+ callbackRef.current = listener;
21
+ useEffect(() => {
22
+ const eventListener = state => callbackRef.current(state);
23
+
24
+ const subscriber = AppState.addEventListener(type, eventListener);
25
+ return () => {
26
+ // @ts-ignore
27
+ if (subscriber !== null && subscriber !== void 0 && subscriber.remove) {
28
+ subscriber.remove();
29
+ } // @ts-ignore
30
+ else if (AppState.removeEventListener) {
31
+ // @ts-ignore
32
+ AppState.removeEventListener(type, eventListener);
33
+ }
34
+ };
35
+ }, []);
36
+ };
37
+ //# sourceMappingURL=react-native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","AppState","useSafeAreaInsets","edgePaddingMap","left","right","top","bottom","useSafeAreaPadding","edges","safeAreaInsets","reduce","map","edge","paddingKey","useAppState","type","listener","callbackRef","current","eventListener","state","subscriber","addEventListener","remove","removeEventListener"],"sources":["react-native.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport { AppState, AppStateEvent, AppStateStatus } from 'react-native';\nimport { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';\n\ntype EdgePaddingMap = {\n left: 'paddingLeft';\n right: 'paddingRight';\n top: 'paddingTop';\n bottom: 'paddingBottom';\n};\nconst edgePaddingMap: EdgePaddingMap = {\n left: 'paddingLeft',\n right: 'paddingRight',\n top: 'paddingTop',\n bottom: 'paddingBottom',\n};\n\nexport const useSafeAreaPadding = <\n T extends keyof EdgeInsets,\n Result extends { [key in EdgePaddingMap[T]]: EdgeInsets[T] },\n>(\n edges: T[],\n): Result => {\n const safeAreaInsets = useSafeAreaInsets();\n return edges.reduce((map, edge) => {\n const paddingKey = edgePaddingMap[edge];\n map[paddingKey] = safeAreaInsets[edge];\n return map;\n }, {} as { [key in EdgePaddingMap[T]]: EdgeInsets[T] }) as Result;\n};\n\ntype AppStateListener = (status: AppStateStatus) => void;\n\nexport const useAppState = (type: AppStateEvent, listener: AppStateListener) => {\n const callbackRef = useRef<AppStateListener>(listener);\n callbackRef.current = listener;\n\n useEffect(() => {\n const eventListener = (state: AppStateStatus) => callbackRef.current(state);\n const subscriber = AppState.addEventListener(type, eventListener);\n\n return () => {\n // @ts-ignore\n if (subscriber?.remove) {\n subscriber.remove();\n }\n // @ts-ignore\n else if (AppState.removeEventListener) {\n //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AAT,CAA6BT,IAA7B,EAAmCI,aAAnC;MACD;IACF,CAVD;EAWD,CAfQ,EAeN,EAfM,CAAT;AAgBD,CApBM"}
@@ -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 { default as replace } from './shared/replace';
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';
@@ -17,8 +18,14 @@ export const ASYNC_NOOP = async () => void 0;
17
18
  export const PASS = val => val;
18
19
  export const toMegabyte = byte => byte / 1024 / 1024;
19
20
  export const isFunction = param => typeof param === 'function';
21
+ export function ifThenOr(cond, then, or) {
22
+ if (cond) return then;
23
+ return or;
24
+ }
20
25
  export const SBErrorCode = {
21
- NON_AUTHORIZED: 400108
26
+ NON_AUTHORIZED: 400108,
27
+ CHANNEL_NOT_FOUND_SERVER: 400201,
28
+ CHANNEL_NOT_FOUND_SDK: 900500
22
29
  };
23
30
  export const SBErrorMessage = {
24
31
  ACL: 'Sendbird provides various access control options when using the Chat SDK.\n' + 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\n' + 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\n' + 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.'
@@ -1 +1 @@
1
- {"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","conditionChaining","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","replaceWithRegex","createMentionTemplateRegex","BufferedRequest","replace","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","SBErrorCode","NON_AUTHORIZED","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport { default as conditionChaining } from './shared/conditionChaining';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\nexport { default as replace } from './shared/replace';\n\nexport * from './hooks';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = <T>(param?: T): param is NonNullable<T> => typeof param === 'function';\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SAASH,OAAO,IAAII,iBAApB,QAA6C,4BAA7C;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,EAaEC,gBAbF,EAcEC,0BAdF,QAeO,gBAfP;AAgBA,SAASC,eAAT,QAAgC,0BAAhC;AACA,SAASnB,OAAO,IAAIoB,OAApB,QAAmC,kBAAnC;AAEA,cAAc,SAAd;AACA,cAAc,0BAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAOC,KAAJ,IAA2C,OAAOA,KAAP,KAAiB,UAA/E;AACP,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE;AADS,CAApB;AAGP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
1
+ {"version":3,"names":["Logger","default","arrayToMap","arrayToMapWithGetter","createPubSub","urlRegexStrict","urlRegexRough","newLineRegex","audioExtRegex","videoExtRegex","imageExtRegex","getFileType","getFileExtension","replaceUrlAsComponents","normalizeFileName","emailRegex","phoneRegex","replaceWithRegex","createMentionTemplateRegex","BufferedRequest","NOOP","ASYNC_NOOP","PASS","val","toMegabyte","byte","isFunction","param","ifThenOr","cond","then","or","SBErrorCode","NON_AUTHORIZED","CHANNEL_NOT_FOUND_SERVER","CHANNEL_NOT_FOUND_SDK","SBErrorMessage","ACL"],"sources":["index.ts"],"sourcesContent":["export { Logger } from './shared/logger';\nexport { default as arrayToMap, arrayToMapWithGetter } from './shared/arrayToMap';\nexport { createPubSub } from './shared/pubsub';\nexport {\n urlRegexStrict,\n urlRegexRough,\n newLineRegex,\n audioExtRegex,\n videoExtRegex,\n imageExtRegex,\n getFileType,\n getFileExtension,\n replaceUrlAsComponents,\n normalizeFileName,\n emailRegex,\n phoneRegex,\n replaceWithRegex,\n createMentionTemplateRegex,\n} from './shared/regex';\nexport { BufferedRequest } from './shared/bufferedRequest';\n\nexport * from './shared';\n\nexport * from './hooks';\nexport * from './hooks/react-native';\nexport * from './ui-format/groupChannel';\nexport * from './ui-format/openChannel';\nexport * from './ui-format/common';\nexport * from './sendbird/channel';\nexport * from './sendbird/message';\nexport * from './sendbird/attrs';\nexport * from './sendbird/user';\n\nexport const NOOP: () => void = () => void 0;\nexport const ASYNC_NOOP = async () => void 0;\nexport const PASS = <T>(val: T) => val;\nexport const toMegabyte = (byte: number) => byte / 1024 / 1024;\nexport const isFunction = (param?: unknown): param is Function => typeof param === 'function';\n\nexport function ifThenOr<T>(cond: boolean, then: T): T | undefined;\nexport function ifThenOr<T, V>(cond: boolean, then: T, or: V): T | V;\nexport function ifThenOr(cond: boolean, then: unknown, or?: unknown) {\n if (cond) return then;\n return or;\n}\n\nexport const SBErrorCode = {\n NON_AUTHORIZED: 400108,\n CHANNEL_NOT_FOUND_SERVER: 400201,\n CHANNEL_NOT_FOUND_SDK: 900500,\n};\nexport const SBErrorMessage = {\n ACL:\n 'Sendbird provides various access control options when using the Chat SDK.\\n' +\n 'By default, the Allow retrieving user list attribute is turned on to facilitate creating sample apps.\\n' +\n 'However, this may grant access to unwanted data or operations, leading to potential security concerns.\\n' +\n 'To manage your access control settings, you can turn on or off each setting on Sendbird Dashboard.',\n};\n\nexport type {\n UserStruct,\n FilterByValueType,\n UnionToIntersection,\n OmittedValues,\n PartialDeep,\n Optional,\n ContextValue,\n OnBeforeHandler,\n SendbirdMessage,\n SendbirdChatSDK,\n SendbirdChannel,\n SendbirdBaseChannel,\n SendbirdGroupChannel,\n SendbirdOpenChannel,\n SendbirdUser,\n SendbirdMember,\n SendbirdBaseMessage,\n SendbirdUserMessage,\n SendbirdFileMessage,\n SendbirdAdminMessage,\n SendbirdGroupChannelCreateParams,\n SendbirdFileMessageCreateParams,\n SendbirdUserMessageCreateParams,\n SendbirdError,\n SendbirdMessageCollection,\n SendbirdGroupChannelCollection,\n NotificationFiles,\n NotificationMentionedUsers,\n NotificationTranslations,\n PartialNullable,\n SendbirdDataPayload,\n SendbirdPreviousMessageListQuery,\n SendbirdSendableMessage,\n SendbirdOpenChannelListQuery,\n SendbirdGroupChannelListQuery,\n SendbirdGroupChannelUpdateParams,\n SendbirdUserMessageUpdateParams,\n SendbirdFileMessageUpdateParams,\n SendbirdUserUpdateParams,\n SendbirdRestrictedUser,\n SendbirdReaction,\n SendbirdEmojiContainer,\n SendbirdEmoji,\n SendbirdEmojiCategory,\n SendbirdOpenChannelUpdateParams,\n SendbirdOpenChannelCreateParams,\n SendbirdParticipant,\n} from './types';\n"],"mappings":"AAAA,SAASA,MAAT,QAAuB,iBAAvB;AACA,SAASC,OAAO,IAAIC,UAApB,EAAgCC,oBAAhC,QAA4D,qBAA5D;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SACEC,cADF,EAEEC,aAFF,EAGEC,YAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,aANF,EAOEC,WAPF,EAQEC,gBARF,EASEC,sBATF,EAUEC,iBAVF,EAWEC,UAXF,EAYEC,UAZF,EAaEC,gBAbF,EAcEC,0BAdF,QAeO,gBAfP;AAgBA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,cAAc,UAAd;AAEA,cAAc,SAAd;AACA,cAAc,sBAAd;AACA,cAAc,0BAAd;AACA,cAAc,yBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,oBAAd;AACA,cAAc,kBAAd;AACA,cAAc,iBAAd;AAEA,OAAO,MAAMC,IAAgB,GAAG,MAAM,KAAK,CAApC;AACP,OAAO,MAAMC,UAAU,GAAG,YAAY,KAAK,CAApC;AACP,OAAO,MAAMC,IAAI,GAAOC,GAAJ,IAAeA,GAA5B;AACP,OAAO,MAAMC,UAAU,GAAIC,IAAD,IAAkBA,IAAI,GAAG,IAAP,GAAc,IAAnD;AACP,OAAO,MAAMC,UAAU,GAAIC,KAAD,IAAwC,OAAOA,KAAP,KAAiB,UAA5E;AAIP,OAAO,SAASC,QAAT,CAAkBC,IAAlB,EAAiCC,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIF,IAAJ,EAAU,OAAOC,IAAP;EACV,OAAOC,EAAP;AACD;AAED,OAAO,MAAMC,WAAW,GAAG;EACzBC,cAAc,EAAE,MADS;EAEzBC,wBAAwB,EAAE,MAFD;EAGzBC,qBAAqB,EAAE;AAHE,CAApB;AAKP,OAAO,MAAMC,cAAc,GAAG;EAC5BC,GAAG,EACD,gFACA,yGADA,GAEA,0GAFA,GAGA;AAL0B,CAAvB"}
@@ -11,7 +11,8 @@ export function isDifferentChannel(a, b) {
11
11
  return a.url !== b.url;
12
12
  }
13
13
  export const getGroupChannelChatAvailableState = channel => {
14
- const frozen = channel.isFrozen && channel.myRole !== 'operator';
14
+ const isOperator = channel.myRole === 'operator';
15
+ const frozen = channel.isFrozen && !isOperator;
15
16
  const muted = channel.myMutedState === 'muted';
16
17
  const disabled = frozen || muted;
17
18
  return {
@@ -20,6 +21,17 @@ export const getGroupChannelChatAvailableState = channel => {
20
21
  muted
21
22
  };
22
23
  };
24
+ export const getOpenChannelChatAvailableState = async (channel, userId) => {
25
+ const isOperator = channel.isOperator(userId);
26
+ const frozen = channel.isFrozen && !isOperator;
27
+ const muted = (await channel.getMyMutedInfo()).isMuted;
28
+ const disabled = frozen || muted;
29
+ return {
30
+ disabled,
31
+ frozen,
32
+ muted
33
+ };
34
+ };
23
35
  export const confirmAndMarkAsRead = async channels => {
24
36
  channels.filter(it => it.isGroupChannel() && it.unreadMessageCount > 0).forEach(it => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));
25
37
  };
@@ -41,4 +53,14 @@ export function getOpenChannels(channels) {
41
53
  export function getChannelUniqId(channel) {
42
54
  return channel.url;
43
55
  }
56
+ export function getDefaultGroupChannelCreateParams(params) {
57
+ const createParams = {
58
+ name: '',
59
+ coverUrl: '',
60
+ isDistinct: false,
61
+ invitedUserIds: params.invitedUserIds
62
+ };
63
+ if (params.currentUserId) createParams.operatorUserIds = [params.currentUserId];
64
+ return createParams;
65
+ }
44
66
  //# sourceMappingURL=channel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","frozen","isFrozen","myRole","muted","myMutedState","disabled","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","userId","getGroupChannels","c","getOpenChannels","isOpenChannel","getChannelUniqId"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const frozen = channel.isFrozen && channel.myRole !== 'operator';\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n\nexport function getChannelUniqId(channel: SendbirdChannel) {\n return channel.url;\n}\n"],"mappings":"AAAA,SAASA,eAAT,QAAgC,2BAAhC;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,MAAM,GAAGD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAtD;EACA,MAAMC,KAAK,GAAGJ,OAAO,CAACK,YAAR,KAAyB,OAAvC;EACA,MAAMC,QAAQ,GAAGL,MAAM,IAAIG,KAA3B;EACA,OAAO;IAAEE,QAAF;IAAYL,MAAZ;IAAoBG;EAApB,CAAP;AACD,CALM;AAOP,OAAO,MAAMG,oBAAoB,GAAG,MAAOC,QAAP,IAA2C;EAC7EA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQhB,eAAe,CAACoB,UAAhB,CAA2BC,IAA3B,CAAgC,MAAML,EAAE,CAACI,UAAH,EAAtC,EAAuDJ,EAAE,CAACZ,GAA1D,CAFnB;AAGD,CAJM;AAMP,OAAO,MAAMkB,yBAAyB,GAAG,MAAOR,QAAP,IAA2C;EAClFA,QAAQ,CACLC,MADH,CACWC,EAAD,IAAoCA,EAAE,CAACC,cAAH,MAAuBD,EAAE,CAACE,kBAAH,GAAwB,CAD7F,EAEGC,OAFH,CAEYH,EAAD,IAAQhB,eAAe,CAACuB,eAAhB,CAAgCF,IAAhC,CAAqC,MAAML,EAAE,CAACO,eAAH,EAA3C,EAAiEP,EAAE,CAACZ,GAApE,CAFnB;AAGD,CAJM;AAMP,OAAO,SAASoB,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BrB,OAA7B,EAA4DsB,aAA5D,EAAoF;EACzF,OAAOtB,OAAO,CAACuB,OAAR,CAAgBd,MAAhB,CAAwBe,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaH,aAA3C,CAAP;AACD;AAED,OAAO,SAASI,gBAAT,CAA0BlB,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACC,MAAT,CAAiBkB,CAAD,IAAkCA,CAAC,CAAChB,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASiB,eAAT,CAAyBpB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACC,MAAT,CAAiBkB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD;AAED,OAAO,SAASC,gBAAT,CAA0B9B,OAA1B,EAAoD;EACzD,OAAOA,OAAO,CAACF,GAAf;AACD"}
1
+ {"version":3,"names":["BufferedRequest","isDifferentChannel","a","b","url","getGroupChannelChatAvailableState","channel","isOperator","myRole","frozen","isFrozen","muted","myMutedState","disabled","getOpenChannelChatAvailableState","userId","getMyMutedInfo","isMuted","confirmAndMarkAsRead","channels","filter","it","isGroupChannel","unreadMessageCount","forEach","markAsRead","push","confirmAndMarkAsDelivered","markAsDelivered","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","m","getGroupChannels","c","getOpenChannels","isOpenChannel","getChannelUniqId","getDefaultGroupChannelCreateParams","params","createParams","name","isDistinct","invitedUserIds","operatorUserIds"],"sources":["channel.ts"],"sourcesContent":["import { BufferedRequest } from '../shared/bufferedRequest';\nimport type {\n SendbirdBaseChannel,\n SendbirdChannel,\n SendbirdGroupChannel,\n SendbirdGroupChannelCreateParams,\n SendbirdOpenChannel,\n} from '../types';\n\n/**\n * Diff utils for channel\n * @param {SendbirdBaseChannel} [a]\n * @param {SendbirdBaseChannel} [b]\n * @returns {boolean}\n * */\nexport function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T, b?: T): boolean {\n if (!a || !b) return true;\n return a.url !== b.url;\n}\n\nexport const getGroupChannelChatAvailableState = (channel: SendbirdGroupChannel) => {\n const isOperator = channel.myRole === 'operator';\n const frozen = channel.isFrozen && !isOperator;\n const muted = channel.myMutedState === 'muted';\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const getOpenChannelChatAvailableState = async (channel: SendbirdOpenChannel, userId: string) => {\n const isOperator = channel.isOperator(userId);\n const frozen = channel.isFrozen && !isOperator;\n const muted = (await channel.getMyMutedInfo()).isMuted;\n const disabled = frozen || muted;\n return { disabled, frozen, muted };\n};\n\nexport const confirmAndMarkAsRead = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsRead.push(() => it.markAsRead(), it.url));\n};\n\nexport const confirmAndMarkAsDelivered = async (channels: SendbirdBaseChannel[]) => {\n channels\n .filter((it): it is SendbirdGroupChannel => it.isGroupChannel() && it.unreadMessageCount > 0)\n .forEach((it) => BufferedRequest.markAsDelivered.push(() => it.markAsDelivered(), it.url));\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n\nexport function getChannelUniqId(channel: SendbirdChannel) {\n return channel.url;\n}\n\nexport function getDefaultGroupChannelCreateParams(params: {\n invitedUserIds: string[];\n currentUserId?: string;\n}): SendbirdGroupChannelCreateParams {\n const createParams: SendbirdGroupChannelCreateParams = {\n name: '',\n coverUrl: '',\n isDistinct: false,\n invitedUserIds: params.invitedUserIds,\n };\n\n if (params.currentUserId) createParams.operatorUserIds = [params.currentUserId];\n\n return createParams;\n}\n"],"mappings":"AAAA,SAASA,eAAT,QAAgC,2BAAhC;;AASA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,iCAAiC,GAAIC,OAAD,IAAmC;EAClF,MAAMC,UAAU,GAAGD,OAAO,CAACE,MAAR,KAAmB,UAAtC;EACA,MAAMC,MAAM,GAAGH,OAAO,CAACI,QAAR,IAAoB,CAACH,UAApC;EACA,MAAMI,KAAK,GAAGL,OAAO,CAACM,YAAR,KAAyB,OAAvC;EACA,MAAMC,QAAQ,GAAGJ,MAAM,IAAIE,KAA3B;EACA,OAAO;IAAEE,QAAF;IAAYJ,MAAZ;IAAoBE;EAApB,CAAP;AACD,CANM;AAQP,OAAO,MAAMG,gCAAgC,GAAG,OAAOR,OAAP,EAAqCS,MAArC,KAAwD;EACtG,MAAMR,UAAU,GAAGD,OAAO,CAACC,UAAR,CAAmBQ,MAAnB,CAAnB;EACA,MAAMN,MAAM,GAAGH,OAAO,CAACI,QAAR,IAAoB,CAACH,UAAp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T,CAAiBiB,CAAD,IAAkCA,CAAC,CAACf,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASgB,eAAT,CAAyBnB,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACC,MAAT,CAAiBiB,CAAD,IAAiCA,CAAC,CAACE,aAAF,EAAjD,CAAP;AACD;AAED,OAAO,SAASC,gBAAT,CAA0BlC,OAA1B,EAAoD;EACzD,OAAOA,OAAO,CAACF,GAAf;AACD;AAED,OAAO,SAASqC,kCAAT,CAA4CC,MAA5C,EAG8B;EACnC,MAAMC,YAA8C,GAAG;IACrDC,IAAI,EAAE,EAD+C;IAErDd,QAAQ,EAAE,EAF2C;IAGrDe,UAAU,EAAE,KAHyC;IAIrDC,cAAc,EAAEJ,MAAM,CAACI;EAJ8B,CAAvD;EAOA,IAAIJ,MAAM,CAACT,aAAX,EAA0BU,YAAY,CAACI,eAAb,GAA+B,CAACL,MAAM,CAACT,aAAR,CAA/B;EAE1B,OAAOU,YAAP;AACD"}
@@ -1,3 +1,4 @@
1
+ import { getFileExtension, getFileType } from '../shared/regex';
1
2
  import { getMessageTimeFormat } from '../ui-format/common';
2
3
  export function isNewMessage(msg, currentUserId) {
3
4
  const myMessage = isMyMessage(msg, currentUserId);
@@ -87,9 +88,58 @@ export function parseSendbirdNotification(dataPayload) {
87
88
  return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
88
89
  }
89
90
  export function shouldRenderReaction(channel, reactionEnabled) {
90
- return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;
91
+ if (channel.isOpenChannel()) {
92
+ return false;
93
+ }
94
+
95
+ if (channel.isGroupChannel()) {
96
+ if (channel.isBroadcast) return false;
97
+ if (channel.isSuper) return false;
98
+ }
99
+
100
+ return reactionEnabled;
91
101
  }
92
102
  export function getReactionCount(reaction) {
93
103
  return reaction.userIds.length;
94
104
  }
105
+ export function getFileTypeFromMessage(message) {
106
+ return getFileType(message.type || getFileExtension(message.name));
107
+ }
108
+ export function getMessageType(message) {
109
+ if (message.isAdminMessage()) {
110
+ return 'admin';
111
+ }
112
+
113
+ if (message.isUserMessage()) {
114
+ if (message.ogMetaData) {
115
+ return 'user.opengraph';
116
+ }
117
+
118
+ return 'user';
119
+ }
120
+
121
+ if (message.isFileMessage()) {
122
+ const fileType = getFileTypeFromMessage(message);
123
+
124
+ switch (fileType) {
125
+ case 'image':
126
+ case 'video':
127
+ {
128
+ return `file.${fileType}`;
129
+ }
130
+
131
+ case 'audio':
132
+ {
133
+ return `file.${fileType}`;
134
+ }
135
+
136
+ default:
137
+ {
138
+ return 'file';
139
+ }
140
+ }
141
+ }
142
+
143
+ return 'unknown';
144
+ }
95
145
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isGroupChannel","isBroadcast","isSuper","getReactionCount","reaction","userIds","length"],"sources":["message.ts"],"sourcesContent":["import type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n return channel.isGroupChannel() && !channel.isBroadcast && !channel.isSuper && reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n"],"mappings":"AASA,SAASA,oBAAT,QAAqC,qBAArC;AAEA,OAAO,SAASC,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAD,EAAMC,aAAN,CAA7B;EACA,IAAIC,SAAJ,EAAe,OAAO,KAAP;EACf,IAAIF,GAAG,CAACI,cAAJ,EAAJ,EAA0B,OAAO,KAAP;EAC1B,OAAOJ,GAAG,CAACK,SAAJ,KAAkB,CAAzB;AACD;AAED,OAAO,SAASC,iBAAT,C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T,CAAiBC,MAAxB;AACD"}
1
+ {"version":3,"names":["getFileExtension","getFileType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","getReactionCount","reaction","userIds","length","getFileTypeFromMessage","type","name","getMessageType","ogMetaData","fileType"],"sources":["message.ts"],"sourcesContent":["import { getFileExtension, getFileType } from '../shared/regex';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n if (channel.isOpenChannel()) {\n return false;\n }\n\n if (channel.isGroupChannel()) {\n if (channel.isBroadcast) return false;\n if (channel.isSuper) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\ntype MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio'}`;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage) {\n return getFileType(message.type || getFileExtension(message.name));\n}\n\nexport function getMessageType(message: SendbirdMessage): MessageType {\n if (message.isAdminMessage()) {\n return 'admin';\n }\n\n if (message.isUserMessage()) {\n if (message.ogMetaData) {\n return 'user.opengraph';\n }\n return 'user';\n }\n\n if (message.isFileMessage()) {\n const fileType = getFileTypeFromMessage(message);\n switch (fileType) {\n case 'image':\n case 'video': {\n return `file.${fileType}`;\n }\n case 'audio': {\n return `file.${fileType}`;\n }\n default: {\n return 'file';\n }\n }\n }\n\n return 'unknown';\n}\n"],"mappings":"AAAA,SAASA,gBAAT,EAA2BC,WAA3B,QAA8C,iBAA9C;AAUA,SAASC,oBAAT,QAAqC,qBAArC;AAEA,OAAO,SAASC,YAAT,CAAsBC,GAAtB,EAA4CC,aAA5C,EAAoE;EACzE,MAAMC,SAAS,GAAG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A4DC,eAA5D,EAAsF;EAC3F,IAAID,OAAO,CAACE,aAAR,EAAJ,EAA6B;IAC3B,OAAO,KAAP;EACD;;EAED,IAAIF,OAAO,CAACG,cAAR,EAAJ,EAA8B;IAC5B,IAAIH,OAAO,CAACI,WAAZ,EAAyB,OAAO,KAAP;IACzB,IAAIJ,OAAO,CAACK,OAAZ,EAAqB,OAAO,KAAP;EACtB;;EAED,OAAOJ,eAAP;AACD;AAED,OAAO,SAASK,gBAAT,CAA0BC,QAA1B,EAAsD;EAC3D,OAAOA,QAAQ,CAACC,OAAT,CAAiBC,MAAxB;AACD;AAUD,OAAO,SAASC,sBAAT,CAAgC/C,OAAhC,EAA8D;EACnE,OAAOf,WAAW,CAACe,OAAO,CAACgD,IAAR,IAAgBhE,gBAAgB,CAACgB,OAAO,CAACiD,IAAT,CAAjC,CAAlB;AACD;AAED,OAAO,SAASC,cAAT,CAAwBlD,OAAxB,EAA+D;EACpE,IAAIA,OAAO,CAACR,cAAR,EAAJ,EAA8B;IAC5B,OAAO,OAAP;EACD;;EAED,IAAIQ,OAAO,CAACmB,aAAR,EAAJ,EAA6B;IAC3B,IAAInB,OAAO,CAACmD,UAAZ,EAAwB;MACtB,OAAO,gBAAP;IACD;;IACD,OAAO,MAAP;EACD;;EAED,IAAInD,OAAO,CAACoB,aAAR,EAAJ,EAA6B;IAC3B,MAAMgC,QAAQ,GAAGL,sBAAsB,CAAC/C,OAAD,CAAvC;;IACA,QAAQoD,QAAR;MACE,KAAK,OAAL;MACA,KAAK,OAAL;QAAc;UACZ,OAAQ,QAAOA,QAAS,EAAxB;QACD;;MACD,KAAK,OAAL;QAAc;UACZ,OAAQ,QAAOA,QAAS,EAAxB;QACD;;MACD;QAAS;UACP,OAAO,MAAP;QACD;IAVH;EAYD;;EAED,OAAO,SAAP;AACD"}
@@ -2,10 +2,6 @@ export function ifOperator(role, then, or) {
2
2
  if (role === 'operator') return then;
3
3
  return or;
4
4
  }
5
- export function ifMuted(muted, then, or) {
6
- if (muted) return then;
7
- return or;
8
- }
9
5
  export function getUserUniqId(user) {
10
6
  return user.userId;
11
7
  }
@@ -1 +1 @@
1
- {"version":3,"names":["ifOperator","role","then","or","ifMuted","muted","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function ifMuted<T>(muted: boolean, then: T): T | undefined;\nexport function ifMuted<T, V>(muted: boolean, then: T, or: V): T | V;\nexport function ifMuted(muted: boolean, then: unknown, or?: unknown) {\n if (muted) return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;AAID,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAiCH,IAAjC,EAAgDC,EAAhD,EAA8D;EACnE,IAAIE,KAAJ,EAAW,OAAOH,IAAP;EACX,OAAOC,EAAP;AACD;AAED,OAAO,SAASG,aAAT,CAA6CC,IAA7C,EAAsD;EAC3D,OAAOA,IAAI,CAACC,MAAZ;AACD"}
1
+ {"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAT,CAAoBC,IAApB,EAAgCC,IAAhC,EAA+CC,EAA/C,EAA6D;EAClE,IAAIF,IAAI,KAAK,UAAb,EAAyB,OAAOC,IAAP;EACzB,OAAOC,EAAP;AACD;AAED,OAAO,SAASC,aAAT,CAA6CC,IAA7C,EAAsD;EAC3D,OAAOA,IAAI,CAACC,MAAZ;AACD"}
@@ -0,0 +1,67 @@
1
+ import { getFileExtension, getFileType } from './regex';
2
+ /**
3
+ * Converts a given string to a hashed string.
4
+ * */
5
+
6
+ export function hash(str) {
7
+ return String(Math.abs(str.split('').reduce((a, c) => (a << 5) - a + c.charCodeAt(0) | 0, 0)));
8
+ }
9
+ /**
10
+ * Replace a specific range of text in the string with another text.
11
+ * */
12
+
13
+ export function replace(str, start, end, text) {
14
+ return str.slice(0, start) + text + str.slice(end);
15
+ }
16
+ /**
17
+ * Returns the value corresponding to the first true index of a given condition array.
18
+ * */
19
+
20
+ export function conditionChaining(conditions, values) {
21
+ const idx = conditions.findIndex(state => Boolean(state));
22
+ return idx > -1 ? values[idx] : values[values.length - 1];
23
+ }
24
+ /**
25
+ * Calculates the downscale size.
26
+ * */
27
+
28
+ export function getDownscaleSize(origin, resizing) {
29
+ let ratio;
30
+ const maxWidth = resizing.width || origin.width,
31
+ maxHeight = resizing.height || origin.height;
32
+
33
+ if (origin.width <= maxWidth && origin.height <= maxHeight) {
34
+ ratio = 1;
35
+ } else if (origin.width > maxWidth && origin.height <= maxHeight) {
36
+ ratio = maxWidth / origin.width;
37
+ } else if (origin.width <= maxWidth && origin.height > maxHeight) {
38
+ ratio = maxHeight / origin.height;
39
+ } else {
40
+ ratio = Math.max(maxWidth / origin.width, maxHeight / origin.height);
41
+ }
42
+
43
+ return {
44
+ width: origin.width * ratio,
45
+ height: origin.height * ratio
46
+ };
47
+ }
48
+ export function isImage(filePath, mimeType) {
49
+ const type = getFileType(mimeType || getFileExtension(filePath));
50
+ return type === 'image';
51
+ }
52
+ export function shouldCompressImage(filePath) {
53
+ let compressionEnabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
54
+ const extension = getFileExtension(filePath);
55
+ return Boolean(extension.match(/jpg|jpeg|png/i) && compressionEnabled);
56
+ }
57
+ /**
58
+ * Returns the picked data from object.
59
+ * */
60
+
61
+ export function pick(obj, keys) {
62
+ return keys.reduce((pickedObj, key) => {
63
+ pickedObj[key] = obj[key];
64
+ return pickedObj;
65
+ }, {});
66
+ }
67
+ //# sourceMappingURL=index.js.map