@sendbird/uikit-utils 1.1.0 → 1.1.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.
@@ -3,35 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.channelComparator = channelComparator;
6
+ exports.getGroupChannels = getGroupChannels;
7
7
  exports.getMembersExcludeMe = getMembersExcludeMe;
8
+ exports.getOpenChannels = getOpenChannels;
8
9
  exports.groupChannelChatUnavailable = void 0;
9
10
  exports.isDefaultCoverImage = isDefaultCoverImage;
10
11
  exports.isDifferentChannel = isDifferentChannel;
11
12
 
12
- /**
13
- * Default sort comparator for channel
14
- * @param {SendbirdBaseChannel} a
15
- * @param {SendbirdBaseChannel} b
16
- * @returns {number}
17
- * */
18
- function channelComparator(a, b) {
19
- if (a.isGroupChannel() && b.isGroupChannel()) {
20
- var _b$lastMessage, _a$lastMessage;
21
-
22
- return (((_b$lastMessage = b.lastMessage) === null || _b$lastMessage === void 0 ? void 0 : _b$lastMessage.createdAt) ?? b.createdAt) - (((_a$lastMessage = a.lastMessage) === null || _a$lastMessage === void 0 ? void 0 : _a$lastMessage.createdAt) ?? a.createdAt);
23
- }
24
-
25
- return b.createdAt - a.createdAt;
26
- }
27
13
  /**
28
14
  * Diff utils for channel
29
15
  * @param {SendbirdBaseChannel} [a]
30
16
  * @param {SendbirdBaseChannel} [b]
31
17
  * @returns {boolean}
32
18
  * */
33
-
34
-
35
19
  function isDifferentChannel(a, b) {
36
20
  if (!a || !b) return true;
37
21
  return a.url !== b.url;
@@ -50,4 +34,12 @@ function isDefaultCoverImage(coverUrl) {
50
34
  function getMembersExcludeMe(channel, currentUserId) {
51
35
  return channel.members.filter(m => m.userId !== currentUserId);
52
36
  }
37
+
38
+ function getGroupChannels(channels) {
39
+ return channels.filter(c => c.isGroupChannel());
40
+ }
41
+
42
+ function getOpenChannels(channels) {
43
+ return channels.filter(c => c.isOpenChannel());
44
+ }
53
45
  //# sourceMappingURL=channel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["channelComparator","a","b","isGroupChannel","lastMessage","createdAt","isDifferentChannel","url","groupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","filter","m","userId"],"sources":["channel.ts"],"sourcesContent":["import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';\n\n/**\n * Default sort comparator for channel\n * @param {SendbirdBaseChannel} a\n * @param {SendbirdBaseChannel} b\n * @returns {number}\n * */\nexport function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number {\n if (a.isGroupChannel() && b.isGroupChannel()) {\n return (b.lastMessage?.createdAt ?? b.createdAt) - (a.lastMessage?.createdAt ?? a.createdAt);\n }\n return b.createdAt - a.createdAt;\n}\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 groupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\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"],"mappings":";;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAT,CAA0DC,CAA1D,EAAgEC,CAAhE,EAA8E;EACnF,IAAID,CAAC,CAACE,cAAF,MAAsBD,CAAC,CAACC,cAAF,EAA1B,EAA8C;IAAA;;IAC5C,OAAO,CAAC,mBAAAD,CAAC,CAACE,WAAF,kEAAeC,SAAf,KAA4BH,CAAC,CAACG,SAA/B,KAA6C,mBAAAJ,CAAC,CAACG,WAAF,kEAAeC,SAAf,KAA4BJ,CAAC,CAACI,SAA3E,CAAP;EACD;;EACD,OAAOH,CAAC,CAACG,SAAF,GAAcJ,CAAC,CAACI,SAAvB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,kBAAT,CAA2DL,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACM,GAAF,KAAUL,CAAC,CAACK,GAAnB;AACD;;AAEM,MAAMC,2BAA2B,GAAIC,OAAD,IAAmC;EAC5E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;;;;AAIA,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BP,OAA7B,EAA4DQ,aAA5D,EAAoF;EACzF,OAAOR,OAAO,CAACS,OAAR,CAAgBC,MAAhB,CAAwBC,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaJ,aAA3C,CAAP;AACD"}
1
+ {"version":3,"names":["isDifferentChannel","a","b","url","groupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","filter","m","userId","getGroupChannels","channels","c","isGroupChannel","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import 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 groupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":";;;;;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;;AAEM,MAAMC,2BAA2B,GAAIC,OAAD,IAAmC;EAC5E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;;;;AAIA,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;;AAEM,SAASC,mBAAT,CAA6BP,OAA7B,EAA4DQ,aAA5D,EAAoF;EACzF,OAAOR,OAAO,CAACS,OAAR,CAAgBC,MAAhB,CAAwBC,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaJ,aAA3C,CAAP;AACD;;AAEM,SAASK,gBAAT,CAA0BC,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACJ,MAAT,CAAiBK,CAAD,IAAkCA,CAAC,CAACC,cAAF,EAAlD,CAAP;AACD;;AAEM,SAASC,eAAT,CAAyBH,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACJ,MAAT,CAAiBK,CAAD,IAAiCA,CAAC,CAACG,aAAF,EAAjD,CAAP;AACD"}
@@ -27,6 +27,7 @@ function isMyMessage(msg) {
27
27
  var _msg$sender;
28
28
 
29
29
  let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
30
+ if (!msg) return false;
30
31
  return 'sender' in msg && ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId || msg.sendingStatus === 'pending' || msg.sendingStatus === 'failed' || msg.sendingStatus === 'canceled';
31
32
  }
32
33
 
@@ -1 +1 @@
1
- {"version":3,"names":["isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","messageTime","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';\nimport { messageTime } 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 isMyMessage(msg: SendbirdMessage, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\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<T extends SendbirdMessage>(a: T, b: T) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdMessage) {\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 && '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"],"mappings":";;;;;;;;;;;;;;;;AACA;;AAEO,SAASA,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;;AAEM,SAASF,WAAT,CAAqBH,GAArB,EAA8F;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EACnG,OACG,YAAYD,GAAZ,IAAmB,gBAAAA,GAAG,CAACM,MAAJ,4DAAYC,MAAZ,MAAuBN,aAA3C,IACAD,GAAG,CAACQ,aAAJ,KAAsB,SADtB,IAEAR,GAAG,CAACQ,aAAJ,KAAsB,QAFtB,IAGAR,GAAG,CAACQ,aAAJ,KAAsB,UAJxB;AAMD;;AAEM,SAASC,mBAAT,CAA6BC,OAA7B,EAA+D;EACpE,OAAOC,gBAAgB,CAACD,OAAD,CAAvB;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO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AO,CAACD,WAAW,CAAC,UAAD,CAAZ,CAAd;AACD;;AAEM,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD"}
1
+ {"version":3,"names":["isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","messageTime","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse"],"sources":["message.ts"],"sourcesContent":["import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';\nimport { messageTime } 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 isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!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<T extends SendbirdMessage>(a: T, b: T) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdMessage) {\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 && '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"],"mappings":";;;;;;;;;;;;;;;;AACA;;AAEO,SAASA,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;;AAEM,SAASF,WAAT,CAAqBH,GAArB,EAAsG;EAAA;;EAAA,IAAnDC,aAAmD,uEAAnC,iCAAmC;EAC3G,IAAI,CAACD,GAAL,EAAU,OAAO,KAAP;EACV,OACG,YAAYA,GAAZ,IAAmB,gBAAAA,GAAG,CAACM,MAAJ,4DAAYC,MAAZ,MAAuBN,aAA3C,IACAD,GAAG,CAACQ,aAAJ,KAAsB,SADtB,IAEAR,GAAG,CAACQ,aAAJ,KAAsB,QAFtB,IAGAR,GAAG,CAACQ,aAAJ,KAAsB,UAJxB;AAMD;;AAEM,SAASC,mBAAT,CAA6BC,OAA7B,EAA+D;EACpE,OAAOC,gBAAgB,CAACD,OAAD,CAAvB;AACD,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,iBAAT,CAAsDC,CAAtD,EAA4DC,CAA5D,EAAkE;EACvE,IAAIC,aAAa,GAAG,CAApB;EACA,IAAIC,aAAa,GAAG,CAApB;EAEA,IAAIH,CAAC,CAACL,aAAF,KAAoB,WAAxB,EAAqCO,aAAa,GAAG,MAAhB;EACrC,IAAID,CAAC,CAACN,aAAF,KAAoB,WAAxB,EAAqCQ,aAAa,GAAG,MAAhB;EAErC,OAAOF,CAAC,CAACG,SAAF,GAAcD,aAAd,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
4
- * @param {SendbirdBaseChannel} b
5
- * @returns {number}
6
- * */
7
- export function channelComparator(a, b) {
8
- if (a.isGroupChannel() && b.isGroupChannel()) {
9
- var _b$lastMessage, _a$lastMessage;
10
-
11
- return (((_b$lastMessage = b.lastMessage) === null || _b$lastMessage === void 0 ? void 0 : _b$lastMessage.createdAt) ?? b.createdAt) - (((_a$lastMessage = a.lastMessage) === null || _a$lastMessage === void 0 ? void 0 : _a$lastMessage.createdAt) ?? a.createdAt);
12
- }
13
-
14
- return b.createdAt - a.createdAt;
15
- }
16
1
  /**
17
2
  * Diff utils for channel
18
3
  * @param {SendbirdBaseChannel} [a]
19
4
  * @param {SendbirdBaseChannel} [b]
20
5
  * @returns {boolean}
21
6
  * */
22
-
23
7
  export function isDifferentChannel(a, b) {
24
8
  if (!a || !b) return true;
25
9
  return a.url !== b.url;
@@ -33,4 +17,10 @@ export function isDefaultCoverImage(coverUrl) {
33
17
  export function getMembersExcludeMe(channel, currentUserId) {
34
18
  return channel.members.filter(m => m.userId !== currentUserId);
35
19
  }
20
+ export function getGroupChannels(channels) {
21
+ return channels.filter(c => c.isGroupChannel());
22
+ }
23
+ export function getOpenChannels(channels) {
24
+ return channels.filter(c => c.isOpenChannel());
25
+ }
36
26
  //# sourceMappingURL=channel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["channelComparator","a","b","isGroupChannel","lastMessage","createdAt","isDifferentChannel","url","groupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","filter","m","userId"],"sources":["channel.ts"],"sourcesContent":["import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';\n\n/**\n * Default sort comparator for channel\n * @param {SendbirdBaseChannel} a\n * @param {SendbirdBaseChannel} b\n * @returns {number}\n * */\nexport function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number {\n if (a.isGroupChannel() && b.isGroupChannel()) {\n return (b.lastMessage?.createdAt ?? b.createdAt) - (a.lastMessage?.createdAt ?? a.createdAt);\n }\n return b.createdAt - a.createdAt;\n}\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 groupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\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"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAT,CAA0DC,CAA1D,EAAgEC,CAAhE,EAA8E;EACnF,IAAID,CAAC,CAACE,cAAF,MAAsBD,CAAC,CAACC,cAAF,EAA1B,EAA8C;IAAA;;IAC5C,OAAO,CAAC,mBAAAD,CAAC,CAACE,WAAF,kEAAeC,SAAf,KAA4BH,CAAC,CAACG,SAA/B,KAA6C,mBAAAJ,CAAC,CAACG,WAAF,kEAAeC,SAAf,KAA4BJ,CAAC,CAACI,SAA3E,CAAP;EACD;;EACD,OAAOH,CAAC,CAACG,SAAF,GAAcJ,CAAC,CAACI,SAAvB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA2DL,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACM,GAAF,KAAUL,CAAC,CAACK,GAAnB;AACD;AAED,OAAO,MAAMC,2BAA2B,GAAIC,OAAD,IAAmC;EAC5E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;AAIP,OAAO,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BP,OAA7B,EAA4DQ,aAA5D,EAAoF;EACzF,OAAOR,OAAO,CAACS,OAAR,CAAgBC,MAAhB,CAAwBC,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaJ,aAA3C,CAAP;AACD"}
1
+ {"version":3,"names":["isDifferentChannel","a","b","url","groupChannelChatUnavailable","channel","myMutedState","isFrozen","myRole","isDefaultCoverImage","coverUrl","startsWith","getMembersExcludeMe","currentUserId","members","filter","m","userId","getGroupChannels","channels","c","isGroupChannel","getOpenChannels","isOpenChannel"],"sources":["channel.ts"],"sourcesContent":["import 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 groupChannelChatUnavailable = (channel: SendbirdGroupChannel) => {\n return channel.myMutedState === 'muted' || (channel.isFrozen && channel.myRole !== 'operator');\n};\n\nexport function isDefaultCoverImage(coverUrl: string) {\n return coverUrl === '' || coverUrl.startsWith('https://static.sendbird.com/sample/cover');\n}\n\nexport function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {\n return channel.members.filter((m) => m.userId !== currentUserId);\n}\n\nexport function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {\n return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());\n}\n\nexport function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {\n return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());\n}\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,kBAAT,CAA2DC,CAA3D,EAAkEC,CAAlE,EAAkF;EACvF,IAAI,CAACD,CAAD,IAAM,CAACC,CAAX,EAAc,OAAO,IAAP;EACd,OAAOD,CAAC,CAACE,GAAF,KAAUD,CAAC,CAACC,GAAnB;AACD;AAED,OAAO,MAAMC,2BAA2B,GAAIC,OAAD,IAAmC;EAC5E,OAAOA,OAAO,CAACC,YAAR,KAAyB,OAAzB,IAAqCD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,MAAR,KAAmB,UAAnF;AACD,CAFM;AAIP,OAAO,SAASC,mBAAT,CAA6BC,QAA7B,EAA+C;EACpD,OAAOA,QAAQ,KAAK,EAAb,IAAmBA,QAAQ,CAACC,UAAT,CAAoB,0CAApB,CAA1B;AACD;AAED,OAAO,SAASC,mBAAT,CAA6BP,OAA7B,EAA4DQ,aAA5D,EAAoF;EACzF,OAAOR,OAAO,CAACS,OAAR,CAAgBC,MAAhB,CAAwBC,CAAD,IAAOA,CAAC,CAACC,MAAF,KAAaJ,aAA3C,CAAP;AACD;AAED,OAAO,SAASK,gBAAT,CAA0BC,QAA1B,EAA+E;EACpF,OAAOA,QAAQ,CAACJ,MAAT,CAAiBK,CAAD,IAAkCA,CAAC,CAACC,cAAF,EAAlD,CAAP;AACD;AAED,OAAO,SAASC,eAAT,CAAyBH,QAAzB,EAA6E;EAClF,OAAOA,QAAQ,CAACJ,MAAT,CAAiBK,CAAD,IAAiCA,CAAC,CAACG,aAAF,EAAjD,CAAP;AACD"}
@@ -9,6 +9,7 @@ export function isMyMessage(msg) {
9
9
  var _msg$sender;
10
10
 
11
11
  let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
12
+ if (!msg) return false;
12
13
  return 'sender' in msg && ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId || msg.sendingStatus === 'pending' || msg.sendingStatus === 'failed' || msg.sendingStatus === 'canceled';
13
14
  }
14
15
  export function messageKeyExtractor(message) {
@@ -1 +1 @@
1
- {"version":3,"names":["messageTime","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","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"],"sources":["message.ts"],"sourcesContent":["import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';\nimport { messageTime } 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 isMyMessage(msg: SendbirdMessage, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\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<T extends SendbirdMessage>(a: T, b: T) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdMessage) {\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 && '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.s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,IAAP;EACD,CAPD;;EASA,OAAO;IAAEU,aAAa,EAAEH,OAAO,EAAxB;IAA4BI,aAAa,EAAEF,OAAO;EAAlD,CAAP;AACD;AAED,OAAO,SAASf,gBAAT,CAA0BX,GAA1B,EAAgD;EACrD,IAAIA,GAAG,CAAC6B,aAAJ,MAAuB7B,GAAG,CAAC8B,aAAJ,EAA3B,EAAgD;IAC9C,IAAI9B,GAAG,CAACQ,aAAJ,KAAsB,WAA1B,EAAuC,OAAOuB,MAAM,CAAC/B,GAAG,CAACgC,SAAL,CAAb;IACvC,OAAOhC,GAAG,CAACiC,KAAX;EACD;;EAED,OAAOF,MAAM,CAAC/B,GAAG,CAACgC,SAAL,CAAb;AACD;AAED,OAAO,SAASE,8BAAT,CAAwCxB,OAAxC,EAAsE;EAC3E,IAAI,CAACA,OAAO,CAACyB,GAAT,IAAgBzB,OAAO,CAAC0B,aAAxB,IAAyC,SAAS1B,OAAO,CAAC0B,aAAR,CAAsBC,IAA5E,EAAkF;IAChF,OAAO3B,OAAO,CAAC0B,aAAR,CAAsBC,IAAtB,CAA2BC,GAAlC;EACD;;EACD,OAAO5B,OAAO,CAACyB,GAAf;AACD;AAGD,OAAO,SAASI,sBAAT,CAAgCC,WAAhC,EAEmC;EACxC,IAAI,CAACA,WAAL,EAAkB,OAAO,KAAP;EAClB,OAAOC,OAAO,CAACD,WAAW,CAAC,UAAD,CAAZ,CAAd;AACD;AAED,OAAO,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD"}
1
+ {"version":3,"names":["messageTime","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","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"],"sources":["message.ts"],"sourcesContent":["import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';\nimport { messageTime } 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 isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!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<T extends SendbirdMessage>(a: T, b: T) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (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 (messageTime(new Date(curr.createdAt)) !== messageTime(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 (messageTime(new Date(curr.createdAt)) !== messageTime(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdMessage) {\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 && '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"],"mappings":"AACA,SAASA,WAAT,QAA4B,qBAA5B;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,K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,KAAsB,WAA1B,EAAuC,OAAOuB,MAAM,CAAC/B,GAAG,CAACgC,SAAL,CAAb;IACvC,OAAOhC,GAAG,CAACiC,KAAX;EACD;;EAED,OAAOF,MAAM,CAAC/B,GAAG,CAACgC,SAAL,CAAb;AACD;AAED,OAAO,SAASE,8BAAT,CAAwCxB,OAAxC,EAAsE;EAC3E,IAAI,CAACA,OAAO,CAACyB,GAAT,IAAgBzB,OAAO,CAAC0B,aAAxB,IAAyC,SAAS1B,OAAO,CAAC0B,aAAR,CAAsBC,IAA5E,EAAkF;IAChF,OAAO3B,OAAO,CAAC0B,aAAR,CAAsBC,IAAtB,CAA2BC,GAAlC;EACD;;EACD,OAAO5B,OAAO,CAACyB,GAAf;AACD;AAGD,OAAO,SAASI,sBAAT,CAAgCC,WAAhC,EAEmC;EACxC,IAAI,CAACA,WAAL,EAAkB,OAAO,KAAP;EAClB,OAAOC,OAAO,CAACD,WAAW,CAAC,UAAD,CAAZ,CAAd;AACD;AAED,OAAO,SAASE,yBAAT,CAAmCF,WAAnC,EAA6F;EAClG,OAAO,OAAOA,WAAW,CAACG,QAAnB,KAAgC,QAAhC,GAA2CC,IAAI,CAACC,KAAL,CAAWL,WAAW,CAACG,QAAvB,CAA3C,GAA8EH,WAAW,CAACG,QAAjG;AACD"}
@@ -1,11 +1,4 @@
1
- import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';
2
- /**
3
- * Default sort comparator for channel
4
- * @param {SendbirdBaseChannel} a
5
- * @param {SendbirdBaseChannel} b
6
- * @returns {number}
7
- * */
8
- export declare function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number;
1
+ import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
9
2
  /**
10
3
  * Diff utils for channel
11
4
  * @param {SendbirdBaseChannel} [a]
@@ -16,3 +9,5 @@ export declare function isDifferentChannel<T extends SendbirdBaseChannel>(a?: T,
16
9
  export declare const groupChannelChatUnavailable: (channel: SendbirdGroupChannel) => boolean;
17
10
  export declare function isDefaultCoverImage(coverUrl: string): boolean;
18
11
  export declare function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string): import("sendbird").Member[];
12
+ export declare function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[];
13
+ export declare function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[];
@@ -1,6 +1,6 @@
1
1
  import type { SendbirdDataPayload, SendbirdFileMessage, SendbirdMessage } from '../types';
2
2
  export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
3
- export declare function isMyMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
3
+ export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string): boolean;
4
4
  export declare function messageKeyExtractor(message: SendbirdMessage): string;
5
5
  export declare function messageComparator<T extends SendbirdMessage>(a: T, b: T): number;
6
6
  export declare function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendbird/uikit-utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "UIKit utilities",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -71,5 +71,5 @@
71
71
  "readmeFile": "./README.md",
72
72
  "displayName": "@sendbird/uikit-utils"
73
73
  },
74
- "gitHead": "787ef6d52fec5d01e9b831d7a6f17e33614e2d09"
74
+ "gitHead": "7b0384ecf1025f70e8a19f0490231273893f3f56"
75
75
  }
@@ -1,17 +1,4 @@
1
- import type { SendbirdBaseChannel, SendbirdGroupChannel } from '../types';
2
-
3
- /**
4
- * Default sort comparator for channel
5
- * @param {SendbirdBaseChannel} a
6
- * @param {SendbirdBaseChannel} b
7
- * @returns {number}
8
- * */
9
- export function channelComparator<T extends SendbirdBaseChannel>(a: T, b: T): number {
10
- if (a.isGroupChannel() && b.isGroupChannel()) {
11
- return (b.lastMessage?.createdAt ?? b.createdAt) - (a.lastMessage?.createdAt ?? a.createdAt);
12
- }
13
- return b.createdAt - a.createdAt;
14
- }
1
+ import type { SendbirdBaseChannel, SendbirdChannel, SendbirdGroupChannel, SendbirdOpenChannel } from '../types';
15
2
 
16
3
  /**
17
4
  * Diff utils for channel
@@ -35,3 +22,11 @@ export function isDefaultCoverImage(coverUrl: string) {
35
22
  export function getMembersExcludeMe(channel: SendbirdGroupChannel, currentUserId?: string) {
36
23
  return channel.members.filter((m) => m.userId !== currentUserId);
37
24
  }
25
+
26
+ export function getGroupChannels(channels: SendbirdChannel[]): SendbirdGroupChannel[] {
27
+ return channels.filter((c): c is SendbirdGroupChannel => c.isGroupChannel());
28
+ }
29
+
30
+ export function getOpenChannels(channels: SendbirdChannel[]): SendbirdOpenChannel[] {
31
+ return channels.filter((c): c is SendbirdOpenChannel => c.isOpenChannel());
32
+ }
@@ -8,7 +8,8 @@ export function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {
8
8
  return msg.updatedAt === 0;
9
9
  }
10
10
 
11
- export function isMyMessage(msg: SendbirdMessage, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {
11
+ export function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {
12
+ if (!msg) return false;
12
13
  return (
13
14
  ('sender' in msg && msg.sender?.userId === currentUserId) ||
14
15
  msg.sendingStatus === 'pending' ||