@sendbird/uikit-utils 3.5.4 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/sendbird/message.js +7 -1
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/ui-format/common.js +49 -1
- package/lib/commonjs/ui-format/common.js.map +1 -1
- package/lib/module/sendbird/message.js +7 -1
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/ui-format/common.js +45 -0
- package/lib/module/ui-format/common.js.map +1 -1
- package/lib/typescript/src/sendbird/message.d.ts +2 -2
- package/lib/typescript/src/ui-format/common.d.ts +22 -0
- package/package.json +5 -5
- package/src/sendbird/message.ts +11 -4
- package/src/ui-format/common.ts +43 -0
|
@@ -69,12 +69,14 @@ function hasSameSender(a, b) {
|
|
|
69
69
|
if ('sender' in a && 'sender' in b) return ((_a$sender = a.sender) === null || _a$sender === void 0 ? void 0 : _a$sender.userId) === ((_b$sender = b.sender) === null || _b$sender === void 0 ? void 0 : _b$sender.userId);
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
function calcMessageGrouping(groupEnabled, curr, prev, next) {
|
|
72
|
+
function calcMessageGrouping(groupEnabled, curr, prev, next, isReplyThreadType, hasParentMessageUI) {
|
|
73
73
|
const getPrev = () => {
|
|
74
74
|
if (!groupEnabled) return false;
|
|
75
75
|
if (!prev) return false;
|
|
76
76
|
if (curr.isAdminMessage()) return false;
|
|
77
77
|
if (!hasSameSender(curr, prev)) return false;
|
|
78
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
79
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
78
80
|
if ((0, _common.getMessageTimeFormat)(new Date(curr.createdAt)) !== (0, _common.getMessageTimeFormat)(new Date(prev.createdAt))) return false;
|
|
79
81
|
return true;
|
|
80
82
|
};
|
|
@@ -83,6 +85,8 @@ function calcMessageGrouping(groupEnabled, curr, prev, next) {
|
|
|
83
85
|
if (!next) return false;
|
|
84
86
|
if (curr.isAdminMessage()) return false;
|
|
85
87
|
if (!hasSameSender(curr, next)) return false;
|
|
88
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
89
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
86
90
|
if ((0, _common.getMessageTimeFormat)(new Date(curr.createdAt)) !== (0, _common.getMessageTimeFormat)(new Date(next.createdAt))) return false;
|
|
87
91
|
return true;
|
|
88
92
|
};
|
|
@@ -120,6 +124,8 @@ function parseSendbirdNotification(dataPayload) {
|
|
|
120
124
|
}
|
|
121
125
|
function shouldRenderParentMessage(message) {
|
|
122
126
|
var _message$parentMessag, _message$parentMessag2;
|
|
127
|
+
let hide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
128
|
+
if (hide) return false;
|
|
123
129
|
return !!((message.isFileMessage() || message.isUserMessage()) && ((_message$parentMessag = message.parentMessage) !== null && _message$parentMessag !== void 0 && _message$parentMessag.isFileMessage() || (_message$parentMessag2 = message.parentMessage) !== null && _message$parentMessag2 !== void 0 && _message$parentMessag2.isUserMessage()));
|
|
124
130
|
}
|
|
125
131
|
function shouldRenderReaction(channel, reactionEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_message","require","_file","_common","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","sendingStatus","Number","MAX_SAFE_INTEGER","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","getMessageTimeFormat","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getThumbnailUriFromFileMessage","thumbnails","url","getAvailableUriFromFileMessage","_message$messageParam","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isEphemeral","isChatNotification","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","getFileType","type","getFileExtension","name","convertFileTypeToMessageType","fileType","exports","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","isVoiceMessage","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","MessageSearchOrder","TIMESTAMP","SBU_MIME_PARAM_KEY","SBU_MIME_PARAM_VOICE_MESSAGE_VALUE","parameters","parseMimeType","getVoiceMessageFileObject","extension","getVoiceMessageMimeType","size"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType, parseMimeType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n SendbirdUserMessage,\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(\n msg?: SendbirdMessage | null,\n currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##',\n): msg is SendbirdSendableMessage {\n if (!isSendableMessage(msg)) return false;\n return msg.sender?.userId === currentUserId;\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 = Number.MAX_SAFE_INTEGER;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;\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 getThumbnailUriFromFileMessage(message: SendbirdFileMessage) {\n if (message.thumbnails && message.thumbnails.length > 0) {\n return message.thumbnails[0].url;\n }\n\n return getAvailableUriFromFileMessage(message);\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\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 shouldRenderParentMessage(message: SendbirdMessage): message is (\n | SendbirdUserMessage\n | SendbirdFileMessage\n) & {\n parentMessage: SendbirdUserMessage | SendbirdFileMessage;\n} {\n return !!(\n (message.isFileMessage() || message.isUserMessage()) &&\n (message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())\n );\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.isEphemeral) return false;\n if (channel.isChatNotification) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\nexport type MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio' | 'voice'}`;\n\nexport type FileType = 'file' | 'image' | 'audio' | 'video';\n\nconst fileIconMapper = {\n 'audio': 'file-audio',\n 'image': 'photo',\n 'video': 'play',\n 'file': 'file-document',\n} as const;\n\ntype ValueOf<T> = T[keyof T];\nexport type FileIcon = ValueOf<typeof fileIconMapper>;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage): FileType {\n return getFileType(message.type || getFileExtension(message.name));\n}\nexport const convertFileTypeToMessageType = (fileType: FileType = 'file'): MessageType => {\n switch (fileType) {\n case 'audio':\n case 'image':\n case 'video':\n return `file.${fileType}`;\n case 'file':\n return fileType;\n }\n};\nexport const getFileIconFromMessageType = (messageType: MessageType): FileIcon => {\n switch (messageType) {\n case 'file':\n return fileIconMapper['file'];\n case 'file.image':\n return fileIconMapper['image'];\n case 'file.video':\n return fileIconMapper['video'];\n case 'file.audio':\n return fileIconMapper['audio'];\n default:\n return fileIconMapper['file'];\n }\n};\nexport const getFileIconFromMessage = (message: SendbirdFileMessage): FileIcon => {\n const fileType = getFileTypeFromMessage(message);\n const messageType = convertFileTypeToMessageType(fileType);\n return getFileIconFromMessageType(messageType);\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 if (isVoiceMessage(message)) {\n return 'file.voice';\n }\n\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n\nconst SBU_MIME_PARAM_KEY = 'sbu_type';\nconst SBU_MIME_PARAM_VOICE_MESSAGE_VALUE = 'voice';\n\nexport function isVoiceMessage(message: SendbirdMessage): message is SendbirdFileMessage {\n if (!message.isFileMessage()) return false;\n\n const { parameters } = parseMimeType(message.type);\n return !!parameters[SBU_MIME_PARAM_KEY] && parameters[SBU_MIME_PARAM_KEY] === SBU_MIME_PARAM_VOICE_MESSAGE_VALUE;\n}\n\nexport function getVoiceMessageFileObject(uri: string, extension = 'm4a') {\n return {\n uri,\n type: getVoiceMessageMimeType(extension),\n name: `Voice_message.${extension}`,\n size: 0,\n };\n}\n\nexport function getVoiceMessageMimeType(extension = 'm4a') {\n return `audio/${extension};${SBU_MIME_PARAM_KEY}=${SBU_MIME_PARAM_VOICE_MESSAGE_VALUE}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAYA,IAAAE,OAAA,GAAAF,OAAA;AAEO,SAASG,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEO,SAASG,WAAWA,CACzBH,GAA4B,EAEI;EAAA,IAAAQ,WAAA;EAAA,IADhCP,aAAa,GAAAQ,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,iCAAiC;EAEjD,IAAI,CAACH,iBAAiB,CAACN,GAAG,CAAC,EAAE,OAAO,KAAK;EACzC,OAAO,EAAAQ,WAAA,GAAAR,GAAG,CAACW,MAAM,cAAAH,WAAA,uBAAVA,WAAA,CAAYI,MAAM,MAAKX,aAAa;AAC7C;AAEO,SAASY,mBAAmBA,CAACC,OAAwB,EAAU;EACpE,OAAOC,gBAAgB,CAACD,OAAO,CAAC;A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C,IAAI,CAACC,GAAG,CAAC9B,OAAO,CAAC+B,QAAQ,EAAE/B,OAAO,CAACgC,SAAS,CAAC;IACnEC,KAAK,EAAEC,2BAAkB,CAACC;EAC5B,CAAC;AACH;AAEA,MAAMC,kBAAkB,GAAG,UAAU;AACrC,MAAMC,kCAAkC,GAAG,OAAO;AAE3C,SAASb,cAAcA,CAAC1E,OAAwB,EAAkC;EACvF,IAAI,CAACA,OAAO,CAAC0B,aAAa,EAAE,EAAE,OAAO,KAAK;EAE1C,MAAM;IAAE8D;EAAW,CAAC,GAAG,IAAAC,mBAAa,EAACzF,OAAO,CAAC+D,IAAI,CAAC;EAClD,OAAO,CAAC,CAACyB,UAAU,CAACF,kBAAkB,CAAC,IAAIE,UAAU,CAACF,kBAAkB,CAAC,KAAKC,kCAAkC;AAClH;AAEO,SAASG,yBAAyBA,CAACrD,GAAW,EAAqB;EAAA,IAAnBsD,SAAS,GAAAhG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACtE,OAAO;IACL0C,GAAG;IACH0B,IAAI,EAAE6B,uBAAuB,CAACD,SAAS,CAAC;IACxC1B,IAAI,EAAG,iBAAgB0B,SAAU,EAAC;IAClCE,IAAI,EAAE;EACR,CAAC;AACH;AAEO,SAASD,uBAAuBA,CAAA,EAAoB;EAAA,IAAnBD,SAAS,GAAAhG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACvD,OAAQ,SAAQgG,SAAU,IAAGL,kBAAmB,IAAGC,kCAAmC,EAAC;AACzF"}
|
|
1
|
+
{"version":3,"names":["_message","require","_file","_common","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","sendingStatus","Number","MAX_SAFE_INTEGER","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","isReplyThreadType","hasParentMessageUI","getPrev","parentMessageId","threadInfo","getMessageTimeFormat","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getThumbnailUriFromFileMessage","thumbnails","url","getAvailableUriFromFileMessage","_message$messageParam","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","hide","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isEphemeral","isChatNotification","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","getFileType","type","getFileExtension","name","convertFileTypeToMessageType","fileType","exports","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","isVoiceMessage","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","MessageSearchOrder","TIMESTAMP","SBU_MIME_PARAM_KEY","SBU_MIME_PARAM_VOICE_MESSAGE_VALUE","parameters","parseMimeType","getVoiceMessageFileObject","extension","getVoiceMessageMimeType","size"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType, parseMimeType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n SendbirdUserMessage,\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(\n msg?: SendbirdMessage | null,\n currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##',\n): msg is SendbirdSendableMessage {\n if (!isSendableMessage(msg)) return false;\n return msg.sender?.userId === currentUserId;\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 = Number.MAX_SAFE_INTEGER;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;\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 isReplyThreadType?: boolean,\n hasParentMessageUI?: boolean,\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 (hasParentMessageUI && curr.parentMessageId) return false;\n if (isReplyThreadType && curr.threadInfo) 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 (hasParentMessageUI && curr.parentMessageId) return false;\n if (isReplyThreadType && curr.threadInfo) 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 getThumbnailUriFromFileMessage(message: SendbirdFileMessage) {\n if (message.thumbnails && message.thumbnails.length > 0) {\n return message.thumbnails[0].url;\n }\n\n return getAvailableUriFromFileMessage(message);\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\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 shouldRenderParentMessage(\n message: SendbirdMessage,\n hide = false,\n): message is (SendbirdUserMessage | SendbirdFileMessage) & {\n parentMessage: SendbirdUserMessage | SendbirdFileMessage;\n} {\n if (hide) return false;\n return !!(\n (message.isFileMessage() || message.isUserMessage()) &&\n (message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())\n );\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.isEphemeral) return false;\n if (channel.isChatNotification) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\nexport type MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio' | 'voice'}`;\n\nexport type FileType = 'file' | 'image' | 'audio' | 'video';\n\nconst fileIconMapper = {\n 'audio': 'file-audio',\n 'image': 'photo',\n 'video': 'play',\n 'file': 'file-document',\n} as const;\n\ntype ValueOf<T> = T[keyof T];\nexport type FileIcon = ValueOf<typeof fileIconMapper>;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage): FileType {\n return getFileType(message.type || getFileExtension(message.name));\n}\nexport const convertFileTypeToMessageType = (fileType: FileType = 'file'): MessageType => {\n switch (fileType) {\n case 'audio':\n case 'image':\n case 'video':\n return `file.${fileType}`;\n case 'file':\n return fileType;\n }\n};\nexport const getFileIconFromMessageType = (messageType: MessageType): FileIcon => {\n switch (messageType) {\n case 'file':\n return fileIconMapper['file'];\n case 'file.image':\n return fileIconMapper['image'];\n case 'file.video':\n return fileIconMapper['video'];\n case 'file.audio':\n return fileIconMapper['audio'];\n default:\n return fileIconMapper['file'];\n }\n};\nexport const getFileIconFromMessage = (message: SendbirdFileMessage): FileIcon => {\n const fileType = getFileTypeFromMessage(message);\n const messageType = convertFileTypeToMessageType(fileType);\n return getFileIconFromMessageType(messageType);\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 if (isVoiceMessage(message)) {\n return 'file.voice';\n }\n\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n\nconst SBU_MIME_PARAM_KEY = 'sbu_type';\nconst SBU_MIME_PARAM_VOICE_MESSAGE_VALUE = 'voice';\n\nexport function isVoiceMessage(message: SendbirdMessage): message is SendbirdFileMessage {\n if (!message.isFileMessage()) return false;\n\n const { parameters } = parseMimeType(message.type);\n return !!parameters[SBU_MIME_PARAM_KEY] && parameters[SBU_MIME_PARAM_KEY] === SBU_MIME_PARAM_VOICE_MESSAGE_VALUE;\n}\n\nexport function getVoiceMessageFileObject(uri: string, extension = 'm4a') {\n return {\n uri,\n type: getVoiceMessageMimeType(extension),\n name: `Voice_message.${extension}`,\n size: 0,\n };\n}\n\nexport function getVoiceMessageMimeType(extension = 'm4a') {\n return `audio/${extension};${SBU_MIME_PARAM_KEY}=${SBU_MIME_PARAM_VOICE_MESSAGE_VALUE}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAYA,IAAAE,OAAA,GAAAF,OAAA;AAEO,SAASG,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,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CAAC,GAAG,IAAAC,mBAAa,EAAC9F,OAAO,CAACoE,IAAI,CAAC;EAClD,OAAO,CAAC,CAACyB,UAAU,CAACF,kBAAkB,CAAC,IAAIE,UAAU,CAACF,kBAAkB,CAAC,KAAKC,kCAAkC;AAClH;AAEO,SAASG,yBAAyBA,CAACtD,GAAW,EAAqB;EAAA,IAAnBuD,SAAS,GAAArG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACtE,OAAO;IACL8C,GAAG;IACH2B,IAAI,EAAE6B,uBAAuB,CAACD,SAAS,CAAC;IACxC1B,IAAI,EAAG,iBAAgB0B,SAAU,EAAC;IAClCE,IAAI,EAAE;EACR,CAAC;AACH;AAEO,SAASD,uBAAuBA,CAAA,EAAoB;EAAA,IAAnBD,SAAS,GAAArG,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACvD,OAAQ,SAAQqG,SAAU,IAAGL,kBAAmB,IAAGC,kCAAmC,EAAC;AACzF"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.truncatedCount = exports.truncate = exports.millsToMSS = exports.millsToMMSS = exports.getMessageTimeFormat = exports.getMessagePreviewTitle = exports.getMessagePreviewTime = exports.getMessagePreviewBody = exports.getDateSeparatorFormat = void 0;
|
|
6
|
+
exports.truncatedCount = exports.truncate = exports.millsToMSS = exports.millsToMMSS = exports.getThreadParentMessageTimeFormat = exports.getReplyCountFormat = exports.getReadableFileSize = exports.getMessageTimeFormat = exports.getMessagePreviewTitle = exports.getMessagePreviewTime = exports.getMessagePreviewBody = exports.getDateSeparatorFormat = void 0;
|
|
7
7
|
var _dateFns = require("date-fns");
|
|
8
8
|
const defaultOpts = {
|
|
9
9
|
mode: 'mid',
|
|
@@ -174,5 +174,53 @@ const millsToMSS = mills => {
|
|
|
174
174
|
const ss = String(seconds).padStart(2, '0');
|
|
175
175
|
return `${minutes}:${ss}`;
|
|
176
176
|
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Message reply count format
|
|
180
|
+
* If reply count is 1: 1 'reply'
|
|
181
|
+
* If the reply count is greater than 1 : '{count} replies'
|
|
182
|
+
* If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'
|
|
183
|
+
* */
|
|
177
184
|
exports.millsToMSS = millsToMSS;
|
|
185
|
+
const getReplyCountFormat = (replyCount, maxReplyCount) => {
|
|
186
|
+
if (maxReplyCount && replyCount > maxReplyCount) {
|
|
187
|
+
return `${maxReplyCount}+ replies`;
|
|
188
|
+
} else if (replyCount === 1) {
|
|
189
|
+
return `${replyCount} reply`;
|
|
190
|
+
} else if (replyCount > 1) {
|
|
191
|
+
return `${replyCount} replies`;
|
|
192
|
+
}
|
|
193
|
+
return '';
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Thread parent message time format
|
|
198
|
+
*
|
|
199
|
+
* @param {Date} date
|
|
200
|
+
* @param {Locale} [locale]
|
|
201
|
+
* @returns {string}
|
|
202
|
+
* */
|
|
203
|
+
exports.getReplyCountFormat = getReplyCountFormat;
|
|
204
|
+
const getThreadParentMessageTimeFormat = (date, locale) => {
|
|
205
|
+
return (0, _dateFns.format)(date, "MMM dd 'at' h:mm a", {
|
|
206
|
+
locale
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* File size format
|
|
212
|
+
*
|
|
213
|
+
* @param {number} fileSize
|
|
214
|
+
* @returns {string}
|
|
215
|
+
* */
|
|
216
|
+
exports.getThreadParentMessageTimeFormat = getThreadParentMessageTimeFormat;
|
|
217
|
+
const getReadableFileSize = fileSize => {
|
|
218
|
+
if (fileSize <= 0) {
|
|
219
|
+
return '0 B';
|
|
220
|
+
}
|
|
221
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
222
|
+
const digitGroups = Math.floor(Math.log10(fileSize) / Math.log10(1024));
|
|
223
|
+
return `${(fileSize / Math.pow(1024, digitGroups)).toFixed(1)} ${units[digitGroups]}`;
|
|
224
|
+
};
|
|
225
|
+
exports.getReadableFileSize = getReadableFileSize;
|
|
178
226
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_dateFns","require","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","exports","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","isThisYear","format","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp","isToday","isYesterday","millsToMMSS","mills","seconds","max","minutes","mm","String","padStart","ss","millsToMSS"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/dd', { locale });\n};\n\n/**\n * milliseconds to 00:00 format\n * */\nexport const millsToMMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const mm = String(minutes).padStart(2, '0');\n const ss = String(seconds).padStart(2, '0');\n\n return `${mm}:${ss}`;\n};\n\n/**\n * milliseconds to 0:00 format\n * */\nexport const millsToMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const ss = String(seconds).padStart(2, '0');\n\n return `${minutes}:${ss}`;\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAMA,MAAMC,WAA2B,GAAG;EAAEC,IAAI,EAAE,KAAK;EAAEC,MAAM,EAAE,EAAE;EAAEC,SAAS,EAAE;AAAM,CAAC;;AAEjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,GAAG,SAAAA,CAACC,GAAW,EAA0D;EAAA,IAAxDC,IAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGP,WAAW;EAC/E,MAAMU,OAAO,GAAG;IAAE,GAAGV,WAAW;IAAE,GAAGM;EAAK,CAAC;EAC3C,MAAM;IAAEJ,MAAM;IAAED,IAAI;IAAEE;EAAU,CAAC,GAAGO,OAAO;EAE3C,IAAIL,GAAG,CAACG,MAAM,IAAIN,MAAM,EAAE,OAAOG,GAAG;EAEpC,IAAIJ,IAAI,KAAK,MAAM,EAAE;IACnB,OAAOE,SAAS,GAAGE,GAAG,CAACM,KAAK,CAAC,CAACT,MAAM,CAAC;EACvC;E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,OAAO,GAAGA,OAAO,GAAG,EAAE;EAEtB,MAAMG,EAAE,GAAGC,MAAM,CAACF,OAAO,CAAC,CAACG,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAC3C,MAAMC,EAAE,GAAGF,MAAM,CAACJ,OAAO,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAE3C,OAAQ,GAAEF,EAAG,IAAGG,EAAG,EAAC;AACtB,CAAC;;AAED;AACA;AACA;AAFAtC,OAAA,CAAA8B,WAAA,GAAAA,WAAA;AAGO,MAAMS,UAAU,GAAIR,KAAa,IAAK;EAC3C,IAAIC,OAAO,GAAGrC,IAAI,CAACG,KAAK,CAACH,IAAI,CAACsC,GAAG,CAAC,CAAC,EAAEF,KAAK,CAAC,GAAG,IAAI,CAAC;EACnD,MAAMG,OAAO,GAAGvC,IAAI,CAACG,KAAK,CAACkC,OAAO,GAAG,EAAE,CAAC;EACxCA,OAAO,GAAGA,OAAO,GAAG,EAAE;EAEtB,MAAMM,EAAE,GAAGF,MAAM,CAACJ,OAAO,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAE3C,OAAQ,GAAEH,OAAQ,IAAGI,EAAG,EAAC;AAC3B,CAAC;AAACtC,OAAA,CAAAuC,UAAA,GAAAA,UAAA"}
|
|
1
|
+
{"version":3,"names":["_dateFns","require","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","exports","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","isThisYear","format","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp","isToday","isYesterday","millsToMMSS","mills","seconds","max","minutes","mm","String","padStart","ss","millsToMSS","getReplyCountFormat","replyCount","maxReplyCount","getThreadParentMessageTimeFormat","getReadableFileSize","fileSize","units","digitGroups","log10","pow","toFixed"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/dd', { locale });\n};\n\n/**\n * milliseconds to 00:00 format\n * */\nexport const millsToMMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const mm = String(minutes).padStart(2, '0');\n const ss = String(seconds).padStart(2, '0');\n\n return `${mm}:${ss}`;\n};\n\n/**\n * milliseconds to 0:00 format\n * */\nexport const millsToMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const ss = String(seconds).padStart(2, '0');\n\n return `${minutes}:${ss}`;\n};\n\n/**\n * Message reply count format\n * If reply count is 1: 1 'reply'\n * If the reply count is greater than 1 : '{count} replies'\n * If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'\n * */\nexport const getReplyCountFormat = (replyCount: number, maxReplyCount?: number) => {\n if (maxReplyCount && replyCount > maxReplyCount) {\n return `${maxReplyCount}+ replies`;\n } else if (replyCount === 1) {\n return `${replyCount} reply`;\n } else if (replyCount > 1) {\n return `${replyCount} replies`;\n }\n return '';\n};\n\n/**\n * Thread parent message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getThreadParentMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, \"MMM dd 'at' h:mm a\", { locale });\n};\n\n/**\n * File size format\n *\n * @param {number} fileSize\n * @returns {string}\n * */\nexport const getReadableFileSize = (fileSize: number): string => {\n if (fileSize <= 0) {\n return '0 B';\n }\n const units = ['B', 'KB', 'MB', 'GB', 'TB'];\n const digitGroups = Math.floor(Math.log10(fileSize) / Math.log10(1024));\n return `${(fileSize / Math.pow(1024, digitGroups)).toFixed(1)} ${units[digitGroups]}`;\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAMA,MAAMC,WAA2B,GAAG;EAAEC,IAAI,EAAE,KAAK;EAAEC,MAAM,EAAE,EAAE;EAAEC,SAAS,EAAE;AAAM,CAAC;;AAEjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,GAAG,SAAAA,CAACC,GAAW,EAA0D;EAAA,IAAxDC,IAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGP,WAAW;EAC/E,MAAMU,OAAO,GAAG;IAAE,GAAGV,WAAW;IAAE,GAAGM;EAAK,CAAC;EAC3C,MAAM;IAAEJ,MAAM;IAAED,IAAI;IAAEE;EAAU,CAAC,GAAGO,OAAO;EAE3C,IAAIL,GAAG,CAACG,MAAM,IAAIN,MAAM,EAAE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AU,GAAG,CAAC,EAAE;IACzB,OAAQ,GAAEA,UAAW,UAAS;EAChC;EACA,OAAO,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANAzC,OAAA,CAAAwC,mBAAA,GAAAA,mBAAA;AAOO,MAAMG,gCAAgC,GAAGA,CAACrC,IAAU,EAAEC,MAAe,KAAa;EACvF,OAAO,IAAAE,eAAM,EAACH,IAAI,EAAE,oBAAoB,EAAE;IAAEC;EAAO,CAAC,CAAC;AACvD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AALAP,OAAA,CAAA2C,gCAAA,GAAAA,gCAAA;AAMO,MAAMC,mBAAmB,GAAIC,QAAgB,IAAa;EAC/D,IAAIA,QAAQ,IAAI,CAAC,EAAE;IACjB,OAAO,KAAK;EACd;EACA,MAAMC,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;EAC3C,MAAMC,WAAW,GAAGpD,IAAI,CAACG,KAAK,CAACH,IAAI,CAACqD,KAAK,CAACH,QAAQ,CAAC,GAAGlD,IAAI,CAACqD,KAAK,CAAC,IAAI,CAAC,CAAC;EACvE,OAAQ,GAAE,CAACH,QAAQ,GAAGlD,IAAI,CAACsD,GAAG,CAAC,IAAI,EAAEF,WAAW,CAAC,EAAEG,OAAO,CAAC,CAAC,CAAE,IAAGJ,KAAK,CAACC,WAAW,CAAE,EAAC;AACvF,CAAC;AAAC/C,OAAA,CAAA4C,mBAAA,GAAAA,mBAAA"}
|
|
@@ -41,12 +41,14 @@ export function hasSameSender(a, b) {
|
|
|
41
41
|
if ('sender' in a && 'sender' in b) return ((_a$sender = a.sender) === null || _a$sender === void 0 ? void 0 : _a$sender.userId) === ((_b$sender = b.sender) === null || _b$sender === void 0 ? void 0 : _b$sender.userId);
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
|
-
export function calcMessageGrouping(groupEnabled, curr, prev, next) {
|
|
44
|
+
export function calcMessageGrouping(groupEnabled, curr, prev, next, isReplyThreadType, hasParentMessageUI) {
|
|
45
45
|
const getPrev = () => {
|
|
46
46
|
if (!groupEnabled) return false;
|
|
47
47
|
if (!prev) return false;
|
|
48
48
|
if (curr.isAdminMessage()) return false;
|
|
49
49
|
if (!hasSameSender(curr, prev)) return false;
|
|
50
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
51
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
50
52
|
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;
|
|
51
53
|
return true;
|
|
52
54
|
};
|
|
@@ -55,6 +57,8 @@ export function calcMessageGrouping(groupEnabled, curr, prev, next) {
|
|
|
55
57
|
if (!next) return false;
|
|
56
58
|
if (curr.isAdminMessage()) return false;
|
|
57
59
|
if (!hasSameSender(curr, next)) return false;
|
|
60
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
61
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
58
62
|
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;
|
|
59
63
|
return true;
|
|
60
64
|
};
|
|
@@ -92,6 +96,8 @@ export function parseSendbirdNotification(dataPayload) {
|
|
|
92
96
|
}
|
|
93
97
|
export function shouldRenderParentMessage(message) {
|
|
94
98
|
var _message$parentMessag, _message$parentMessag2;
|
|
99
|
+
let hide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
100
|
+
if (hide) return false;
|
|
95
101
|
return !!((message.isFileMessage() || message.isUserMessage()) && ((_message$parentMessag = message.parentMessage) !== null && _message$parentMessag !== void 0 && _message$parentMessag.isFileMessage() || (_message$parentMessag2 = message.parentMessage) !== null && _message$parentMessag2 !== void 0 && _message$parentMessag2.isUserMessage()));
|
|
96
102
|
}
|
|
97
103
|
export function shouldRenderReaction(channel, reactionEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MessageSearchOrder","getFileExtension","getFileType","parseMimeType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","sendingStatus","Number","MAX_SAFE_INTEGER","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getThumbnailUriFromFileMessage","thumbnails","url","getAvailableUriFromFileMessage","_message$messageParam","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isEphemeral","isChatNotification","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","type","name","convertFileTypeToMessageType","fileType","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","isVoiceMessage","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","TIMESTAMP","SBU_MIME_PARAM_KEY","SBU_MIME_PARAM_VOICE_MESSAGE_VALUE","parameters","getVoiceMessageFileObject","extension","getVoiceMessageMimeType","size"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType, parseMimeType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n SendbirdUserMessage,\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(\n msg?: SendbirdMessage | null,\n currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##',\n): msg is SendbirdSendableMessage {\n if (!isSendableMessage(msg)) return false;\n return msg.sender?.userId === currentUserId;\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 = Number.MAX_SAFE_INTEGER;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;\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 getThumbnailUriFromFileMessage(message: SendbirdFileMessage) {\n if (message.thumbnails && message.thumbnails.length > 0) {\n return message.thumbnails[0].url;\n }\n\n return getAvailableUriFromFileMessage(message);\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\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 shouldRenderParentMessage(message: SendbirdMessage): message is (\n | SendbirdUserMessage\n | SendbirdFileMessage\n) & {\n parentMessage: SendbirdUserMessage | SendbirdFileMessage;\n} {\n return !!(\n (message.isFileMessage() || message.isUserMessage()) &&\n (message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())\n );\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.isEphemeral) return false;\n if (channel.isChatNotification) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\nexport type MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio' | 'voice'}`;\n\nexport type FileType = 'file' | 'image' | 'audio' | 'video';\n\nconst fileIconMapper = {\n 'audio': 'file-audio',\n 'image': 'photo',\n 'video': 'play',\n 'file': 'file-document',\n} as const;\n\ntype ValueOf<T> = T[keyof T];\nexport type FileIcon = ValueOf<typeof fileIconMapper>;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage): FileType {\n return getFileType(message.type || getFileExtension(message.name));\n}\nexport const convertFileTypeToMessageType = (fileType: FileType = 'file'): MessageType => {\n switch (fileType) {\n case 'audio':\n case 'image':\n case 'video':\n return `file.${fileType}`;\n case 'file':\n return fileType;\n }\n};\nexport const getFileIconFromMessageType = (messageType: MessageType): FileIcon => {\n switch (messageType) {\n case 'file':\n return fileIconMapper['file'];\n case 'file.image':\n return fileIconMapper['image'];\n case 'file.video':\n return fileIconMapper['video'];\n case 'file.audio':\n return fileIconMapper['audio'];\n default:\n return fileIconMapper['file'];\n }\n};\nexport const getFileIconFromMessage = (message: SendbirdFileMessage): FileIcon => {\n const fileType = getFileTypeFromMessage(message);\n const messageType = convertFileTypeToMessageType(fileType);\n return getFileIconFromMessageType(messageType);\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 if (isVoiceMessage(message)) {\n return 'file.voice';\n }\n\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n\nconst SBU_MIME_PARAM_KEY = 'sbu_type';\nconst SBU_MIME_PARAM_VOICE_MESSAGE_VALUE = 'voice';\n\nexport function isVoiceMessage(message: SendbirdMessage): message is SendbirdFileMessage {\n if (!message.isFileMessage()) return false;\n\n const { parameters } = parseMimeType(message.type);\n return !!parameters[SBU_MIME_PARAM_KEY] && parameters[SBU_MIME_PARAM_KEY] === SBU_MIME_PARAM_VOICE_MESSAGE_VALUE;\n}\n\nexport function getVoiceMessageFileObject(uri: string, extension = 'm4a') {\n return {\n uri,\n type: getVoiceMessageMimeType(extension),\n name: `Voice_message.${extension}`,\n size: 0,\n };\n}\n\nexport function getVoiceMessageMimeType(extension = 'm4a') {\n return `audio/${extension};${SBU_MIME_PARAM_KEY}=${SBU_MIME_PARAM_VOICE_MESSAGE_VALUE}`;\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,SAASC,gBAAgB,EAAEC,WAAW,EAAEC,aAAa,QAAQ,gBAAgB;AAY7E,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,OAAO,SAASC,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CAAC;EACjD,IAAIC,SAAS,EAAE,OAAO,KAAK;EAC3B,IAAIF,GAAG,CAACI,cAAc,EAAE,EAAE,OAAO,KAAK;EACtC,OAAOJ,GAAG,CAACK,SAAS,KAAK,CAAC;AAC5B;AAEA,OAAO,SAASC,iBAAiBA,CAACN,GAA4B,EAAkC;EAC9F,OAAOA,GAAG,KAAKO,SAAS,IAAIP,GAAG,KAAK,IAAI,I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,uBAAuBA,CAAA,EAAoB;EAAA,IAAnBD,SAAS,GAAA1F,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACvD,OAAQ,SAAQ0F,SAAU,IAAGJ,kBAAmB,IAAGC,kCAAmC,EAAC;AACzF"}
|
|
1
|
+
{"version":3,"names":["MessageSearchOrder","getFileExtension","getFileType","parseMimeType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","sendingStatus","Number","MAX_SAFE_INTEGER","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","isReplyThreadType","hasParentMessageUI","getPrev","parentMessageId","threadInfo","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getThumbnailUriFromFileMessage","thumbnails","url","getAvailableUriFromFileMessage","_message$messageParam","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","hide","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isEphemeral","isChatNotification","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","type","name","convertFileTypeToMessageType","fileType","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","isVoiceMessage","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","TIMESTAMP","SBU_MIME_PARAM_KEY","SBU_MIME_PARAM_VOICE_MESSAGE_VALUE","parameters","getVoiceMessageFileObject","extension","getVoiceMessageMimeType","size"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType, parseMimeType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n SendbirdUserMessage,\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(\n msg?: SendbirdMessage | null,\n currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##',\n): msg is SendbirdSendableMessage {\n if (!isSendableMessage(msg)) return false;\n return msg.sender?.userId === currentUserId;\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 = Number.MAX_SAFE_INTEGER;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;\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 isReplyThreadType?: boolean,\n hasParentMessageUI?: boolean,\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 (hasParentMessageUI && curr.parentMessageId) return false;\n if (isReplyThreadType && curr.threadInfo) 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 (hasParentMessageUI && curr.parentMessageId) return false;\n if (isReplyThreadType && curr.threadInfo) 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 getThumbnailUriFromFileMessage(message: SendbirdFileMessage) {\n if (message.thumbnails && message.thumbnails.length > 0) {\n return message.thumbnails[0].url;\n }\n\n return getAvailableUriFromFileMessage(message);\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\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 shouldRenderParentMessage(\n message: SendbirdMessage,\n hide = false,\n): message is (SendbirdUserMessage | SendbirdFileMessage) & {\n parentMessage: SendbirdUserMessage | SendbirdFileMessage;\n} {\n if (hide) return false;\n return !!(\n (message.isFileMessage() || message.isUserMessage()) &&\n (message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())\n );\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.isEphemeral) return false;\n if (channel.isChatNotification) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\nexport type MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio' | 'voice'}`;\n\nexport type FileType = 'file' | 'image' | 'audio' | 'video';\n\nconst fileIconMapper = {\n 'audio': 'file-audio',\n 'image': 'photo',\n 'video': 'play',\n 'file': 'file-document',\n} as const;\n\ntype ValueOf<T> = T[keyof T];\nexport type FileIcon = ValueOf<typeof fileIconMapper>;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage): FileType {\n return getFileType(message.type || getFileExtension(message.name));\n}\nexport const convertFileTypeToMessageType = (fileType: FileType = 'file'): MessageType => {\n switch (fileType) {\n case 'audio':\n case 'image':\n case 'video':\n return `file.${fileType}`;\n case 'file':\n return fileType;\n }\n};\nexport const getFileIconFromMessageType = (messageType: MessageType): FileIcon => {\n switch (messageType) {\n case 'file':\n return fileIconMapper['file'];\n case 'file.image':\n return fileIconMapper['image'];\n case 'file.video':\n return fileIconMapper['video'];\n case 'file.audio':\n return fileIconMapper['audio'];\n default:\n return fileIconMapper['file'];\n }\n};\nexport const getFileIconFromMessage = (message: SendbirdFileMessage): FileIcon => {\n const fileType = getFileTypeFromMessage(message);\n const messageType = convertFileTypeToMessageType(fileType);\n return getFileIconFromMessageType(messageType);\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 if (isVoiceMessage(message)) {\n return 'file.voice';\n }\n\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\nexport function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string) {\n return {\n keyword,\n channelUrl: channel.url,\n messageTimestampFrom: Math.max(channel.joinedAt, channel.invitedAt),\n order: MessageSearchOrder.TIMESTAMP,\n };\n}\n\nconst SBU_MIME_PARAM_KEY = 'sbu_type';\nconst SBU_MIME_PARAM_VOICE_MESSAGE_VALUE = 'voice';\n\nexport function isVoiceMessage(message: SendbirdMessage): message is SendbirdFileMessage {\n if (!message.isFileMessage()) return false;\n\n const { parameters } = parseMimeType(message.type);\n return !!parameters[SBU_MIME_PARAM_KEY] && parameters[SBU_MIME_PARAM_KEY] === SBU_MIME_PARAM_VOICE_MESSAGE_VALUE;\n}\n\nexport function getVoiceMessageFileObject(uri: string, extension = 'm4a') {\n return {\n uri,\n type: getVoiceMessageMimeType(extension),\n name: `Voice_message.${extension}`,\n size: 0,\n };\n}\n\nexport function getVoiceMessageMimeType(extension = 'm4a') {\n return `audio/${extension};${SBU_MIME_PARAM_KEY}=${SBU_MIME_PARAM_VOICE_MESSAGE_VALUE}`;\n}\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,SAASC,gBAAgB,EAAEC,WAAW,EAA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AAU,EAAExB,OAAO,CAACnB,GAAG;IACvB4C,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAAC3B,OAAO,CAAC4B,QAAQ,EAAE5B,OAAO,CAAC6B,SAAS,CAAC;IACnEC,KAAK,EAAExG,kBAAkB,CAACyG;EAC5B,CAAC;AACH;AAEA,MAAMC,kBAAkB,GAAG,UAAU;AACrC,MAAMC,kCAAkC,GAAG,OAAO;AAElD,OAAO,SAASZ,cAAcA,CAAC3E,OAAwB,EAAkC;EACvF,IAAI,CAACA,OAAO,CAAC6B,aAAa,EAAE,EAAE,OAAO,KAAK;EAE1C,MAAM;IAAE2D;EAAW,CAAC,GAAGzG,aAAa,CAACiB,OAAO,CAACkE,IAAI,CAAC;EAClD,OAAO,CAAC,CAACsB,UAAU,CAACF,kBAAkB,CAAC,IAAIE,UAAU,CAACF,kBAAkB,CAAC,KAAKC,kCAAkC;AAClH;AAEA,OAAO,SAASE,yBAAyBA,CAACjD,GAAW,EAAqB;EAAA,IAAnBkD,SAAS,GAAA/F,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACtE,OAAO;IACL6C,GAAG;IACH0B,IAAI,EAAEyB,uBAAuB,CAACD,SAAS,CAAC;IACxCvB,IAAI,EAAG,iBAAgBuB,SAAU,EAAC;IAClCE,IAAI,EAAE;EACR,CAAC;AACH;AAEA,OAAO,SAASD,uBAAuBA,CAAA,EAAoB;EAAA,IAAnBD,SAAS,GAAA/F,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAF,SAAA,GAAAE,SAAA,MAAG,KAAK;EACvD,OAAQ,SAAQ+F,SAAU,IAAGJ,kBAAmB,IAAGC,kCAAmC,EAAC;AACzF"}
|
|
@@ -160,4 +160,49 @@ export const millsToMSS = mills => {
|
|
|
160
160
|
const ss = String(seconds).padStart(2, '0');
|
|
161
161
|
return `${minutes}:${ss}`;
|
|
162
162
|
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Message reply count format
|
|
166
|
+
* If reply count is 1: 1 'reply'
|
|
167
|
+
* If the reply count is greater than 1 : '{count} replies'
|
|
168
|
+
* If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'
|
|
169
|
+
* */
|
|
170
|
+
export const getReplyCountFormat = (replyCount, maxReplyCount) => {
|
|
171
|
+
if (maxReplyCount && replyCount > maxReplyCount) {
|
|
172
|
+
return `${maxReplyCount}+ replies`;
|
|
173
|
+
} else if (replyCount === 1) {
|
|
174
|
+
return `${replyCount} reply`;
|
|
175
|
+
} else if (replyCount > 1) {
|
|
176
|
+
return `${replyCount} replies`;
|
|
177
|
+
}
|
|
178
|
+
return '';
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Thread parent message time format
|
|
183
|
+
*
|
|
184
|
+
* @param {Date} date
|
|
185
|
+
* @param {Locale} [locale]
|
|
186
|
+
* @returns {string}
|
|
187
|
+
* */
|
|
188
|
+
export const getThreadParentMessageTimeFormat = (date, locale) => {
|
|
189
|
+
return format(date, "MMM dd 'at' h:mm a", {
|
|
190
|
+
locale
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* File size format
|
|
196
|
+
*
|
|
197
|
+
* @param {number} fileSize
|
|
198
|
+
* @returns {string}
|
|
199
|
+
* */
|
|
200
|
+
export const getReadableFileSize = fileSize => {
|
|
201
|
+
if (fileSize <= 0) {
|
|
202
|
+
return '0 B';
|
|
203
|
+
}
|
|
204
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
205
|
+
const digitGroups = Math.floor(Math.log10(fileSize) / Math.log10(1024));
|
|
206
|
+
return `${(fileSize / Math.pow(1024, digitGroups)).toFixed(1)} ${units[digitGroups]}`;
|
|
207
|
+
};
|
|
163
208
|
//# sourceMappingURL=common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["format","isThisYear","isToday","isYesterday","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp","millsToMMSS","mills","seconds","max","minutes","mm","String","padStart","ss","millsToMSS"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/dd', { locale });\n};\n\n/**\n * milliseconds to 00:00 format\n * */\nexport const millsToMMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const mm = String(minutes).padStart(2, '0');\n const ss = String(seconds).padStart(2, '0');\n\n return `${mm}:${ss}`;\n};\n\n/**\n * milliseconds to 0:00 format\n * */\nexport const millsToMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const ss = String(seconds).padStart(2, '0');\n\n return `${minutes}:${ss}`;\n};\n"],"mappings":"AACA,SAASA,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAEC,WAAW,QAAQ,UAAU;AAMnE,MAAMC,WAA2B,GAAG;EAAEC,IAAI,EAAE,KAAK;EAAEC,MAAM,EAAE,EAAE;EAAEC,SAAS,EAAE;AAAM,CAAC;;AAEjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,QAAQ,GAAG,SAAAA,CAACC,GAAW,EAA0D;EAAA,IAAxDC,IAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGP,WAAW;EAC/E,MAAMU,OAAO,GAAG;IAAE,GAAGV,WAAW;IAAE,GAAGM;EAAK,CAAC;EAC3C,MAAM;IAAEJ,MAAM;IAAED,IAAI;IAAEE;EAAU,CAAC,GAAGO,OAAO;EAE3C,IAAIL,GAAG,CAACG,MAAM,IAAIN,MAAM,EAAE,OAAOG,GAAG;EAEpC,IAAIJ,IAAI,KAAK,MAAM,EAAE;IACnB,OAAOE,SAAS,GAAGE,GAAG,CAACM,KAAK,CAAC,CAACT,MAAM,CAAC;EACvC;EAEA,IAAID,IAAI,KAAK,KAAK,EAAE;IAClB,MAAMW,IAAI,GAAGC,IAAI,CAACC,IAAI,CAACZ,MAAM,GAAG,CAAC,CAAC;IAClC,MAAMa,KAAK,GAAGF,IAAI,CAACG,KAAK,CAACd,MAAM,GAAG,CAAC,CAAC;IACpC,OAAOG,GAAG,CAACM,KAAK,CAAC,CAAC,EAAEC,IAAI,CAAC,GAAGT,SAAS,GAA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,GAAG,EAAE;EAEtB,MAAMM,EAAE,GAAGF,MAAM,CAACJ,OAAO,CAAC,CAACK,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAE3C,OAAQ,GAAEH,OAAQ,IAAGI,EAAG,EAAC;AAC3B,CAAC"}
|
|
1
|
+
{"version":3,"names":["format","isThisYear","isToday","isYesterday","defaultOpts","mode","maxLen","separator","truncate","str","opts","arguments","length","undefined","options","slice","lead","Math","ceil","trail","floor","Error","truncatedCount","count","MAX","MAX_SUFFIX","getDateSeparatorFormat","date","locale","getMessageTimeFormat","getMessagePreviewTitle","message","EMPTY_USERNAME","isFileMessage","isUserMessage","sender","nickname","isAdminMessage","getMessagePreviewBody","EMPTY_MESSAGE","extIdx","name","lastIndexOf","file","ext","getMessagePreviewTime","timestamp","millsToMMSS","mills","seconds","max","minutes","mm","String","padStart","ss","millsToMSS","getReplyCountFormat","replyCount","maxReplyCount","getThreadParentMessageTimeFormat","getReadableFileSize","fileSize","units","digitGroups","log10","pow","toFixed"],"sources":["common.ts"],"sourcesContent":["import type { Locale } from 'date-fns';\nimport { format, isThisYear, isToday, isYesterday } from 'date-fns';\n\nimport type { SendbirdBaseMessage } from '../types';\n\ntype TruncateMode = 'head' | 'mid' | 'tail';\ntype TruncateOption = { mode: TruncateMode; maxLen: number; separator: string };\nconst defaultOpts: TruncateOption = { mode: 'mid', maxLen: 40, separator: '...' };\n\n/**\n * String truncate util\n * @param {string} str\n * @param {Object} opts Options for truncate\n * @param {'head' | 'mid' | 'tail'} opts.mode default \"mid\"\n * @param {number} opts.maxLen default 40\n * @param {string} opts.separator default \"...\"\n * @returns {string}\n * */\nexport const truncate = (str: string, opts: Partial<TruncateOption> = defaultOpts): string => {\n const options = { ...defaultOpts, ...opts };\n const { maxLen, mode, separator } = options;\n\n if (str.length <= maxLen) return str;\n\n if (mode === 'head') {\n return separator + str.slice(-maxLen);\n }\n\n if (mode === 'mid') {\n const lead = Math.ceil(maxLen / 2);\n const trail = Math.floor(maxLen / 2);\n return str.slice(0, lead) + separator + str.slice(-trail);\n }\n\n if (mode === 'tail') {\n return str.slice(0, maxLen) + separator;\n }\n\n throw new Error('Invalid truncate mode: ' + mode);\n};\n\n/**\n * Count truncate util\n * If count exceed the limit, it comes in the form of \"MAX+\"\n *\n * @param {number} count\n * @param {number} MAX default 99\n * @param {string} MAX_SUFFIX default +\n * @returns {string}\n * */\nexport const truncatedCount = (count: number, MAX = 99, MAX_SUFFIX = '+') => {\n if (count >= MAX) return `${MAX}${MAX_SUFFIX}`;\n return `${count}`;\n};\n\n/**\n * Messages date separator format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getDateSeparatorFormat = (date: Date, locale?: Locale): string => {\n if (isThisYear(date)) return format(date, 'MMM dd, yyyy', { locale });\n return format(date, 'E, MMM dd', { locale });\n};\n\n/**\n * Message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, 'p', { locale });\n};\n\n/**\n * Message preview title text\n * */\nexport const getMessagePreviewTitle = (message: SendbirdBaseMessage, EMPTY_USERNAME = '(No name)') => {\n if (message.isFileMessage() || message.isUserMessage()) {\n return message.sender.nickname || EMPTY_USERNAME;\n }\n if (message.isAdminMessage()) {\n return 'Admin';\n }\n return EMPTY_USERNAME;\n};\n\n/**\n * Message preview body text\n * */\nexport const getMessagePreviewBody = (message: SendbirdBaseMessage, EMPTY_MESSAGE = '') => {\n if (message.isFileMessage()) {\n const extIdx = message.name.lastIndexOf('.');\n if (extIdx > -1) {\n const file = message.name.slice(0, extIdx);\n const ext = message.name.slice(extIdx);\n return file + ext;\n }\n\n return message.name;\n }\n\n if (message.isUserMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n if (message.isAdminMessage()) {\n return message.message ?? EMPTY_MESSAGE;\n }\n\n return EMPTY_MESSAGE;\n};\n\n/**\n * Message preview time format\n * */\nexport const getMessagePreviewTime = (timestamp: number, locale?: Locale) => {\n if (isToday(timestamp)) return format(timestamp, 'p', { locale });\n if (isYesterday(timestamp)) return 'Yesterday';\n if (isThisYear(timestamp)) return format(timestamp, 'MMM dd', { locale });\n\n return format(timestamp, 'yyyy/MM/dd', { locale });\n};\n\n/**\n * milliseconds to 00:00 format\n * */\nexport const millsToMMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const mm = String(minutes).padStart(2, '0');\n const ss = String(seconds).padStart(2, '0');\n\n return `${mm}:${ss}`;\n};\n\n/**\n * milliseconds to 0:00 format\n * */\nexport const millsToMSS = (mills: number) => {\n let seconds = Math.floor(Math.max(0, mills) / 1000);\n const minutes = Math.floor(seconds / 60);\n seconds = seconds % 60;\n\n const ss = String(seconds).padStart(2, '0');\n\n return `${minutes}:${ss}`;\n};\n\n/**\n * Message reply count format\n * If reply count is 1: 1 'reply'\n * If the reply count is greater than 1 : '{count} replies'\n * If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'\n * */\nexport const getReplyCountFormat = (replyCount: number, maxReplyCount?: number) => {\n if (maxReplyCount && replyCount > maxReplyCount) {\n return `${maxReplyCount}+ replies`;\n } else if (replyCount === 1) {\n return `${replyCount} reply`;\n } else if (replyCount > 1) {\n return `${replyCount} replies`;\n }\n return '';\n};\n\n/**\n * Thread parent message time format\n *\n * @param {Date} date\n * @param {Locale} [locale]\n * @returns {string}\n * */\nexport const getThreadParentMessageTimeFormat = (date: Date, locale?: Locale): string => {\n return format(date, \"MMM dd 'at' h:mm a\", { locale });\n};\n\n/**\n * File size format\n *\n * @param {number} fileSize\n * @returns {string}\n * */\nexport const getReadableFileSize = (fileSize: number): string => {\n if (fileSize <= 0) {\n return '0 B';\n }\n const units = ['B', 'KB', 'MB', 'GB', 'TB'];\n const digitGroups = Math.floor(Math.log10(fileSize) / Math.log10(1024));\n return `${(fileSize / Math.pow(1024, digitGroups)).toFixed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mB,GAAGA,CAACC,UAAkB,EAAEC,aAAsB,KAAK;EACjF,IAAIA,aAAa,IAAID,UAAU,GAAGC,aAAa,EAAE;IAC/C,OAAQ,GAAEA,aAAc,WAAU;EACpC,CAAC,MAAM,IAAID,UAAU,KAAK,CAAC,EAAE;IAC3B,OAAQ,GAAEA,UAAW,QAAO;EAC9B,CAAC,MAAM,IAAIA,UAAU,GAAG,CAAC,EAAE;IACzB,OAAQ,GAAEA,UAAW,UAAS;EAChC;EACA,OAAO,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,gCAAgC,GAAGA,CAACjC,IAAU,EAAEC,MAAe,KAAa;EACvF,OAAO5B,MAAM,CAAC2B,IAAI,EAAE,oBAAoB,EAAE;IAAEC;EAAO,CAAC,CAAC;AACvD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMiC,mBAAmB,GAAIC,QAAgB,IAAa;EAC/D,IAAIA,QAAQ,IAAI,CAAC,EAAE;IACjB,OAAO,KAAK;EACd;EACA,MAAMC,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;EAC3C,MAAMC,WAAW,GAAG/C,IAAI,CAACG,KAAK,CAACH,IAAI,CAACgD,KAAK,CAACH,QAAQ,CAAC,GAAG7C,IAAI,CAACgD,KAAK,CAAC,IAAI,CAAC,CAAC;EACvE,OAAQ,GAAE,CAACH,QAAQ,GAAG7C,IAAI,CAACiD,GAAG,CAAC,IAAI,EAAEF,WAAW,CAAC,EAAEG,OAAO,CAAC,CAAC,CAAE,IAAGJ,KAAK,CAACC,WAAW,CAAE,EAAC;AACvF,CAAC"}
|
|
@@ -6,7 +6,7 @@ export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?
|
|
|
6
6
|
export declare function messageKeyExtractor(message: SendbirdMessage): string;
|
|
7
7
|
export declare function messageComparator(a: SendbirdMessage, b: SendbirdMessage): number;
|
|
8
8
|
export declare function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage): boolean;
|
|
9
|
-
export declare function calcMessageGrouping(groupEnabled: boolean, curr: SendbirdMessage, prev?: SendbirdMessage, next?: SendbirdMessage): {
|
|
9
|
+
export declare function calcMessageGrouping(groupEnabled: boolean, curr: SendbirdMessage, prev?: SendbirdMessage, next?: SendbirdMessage, isReplyThreadType?: boolean, hasParentMessageUI?: boolean): {
|
|
10
10
|
groupWithPrev: boolean;
|
|
11
11
|
groupWithNext: boolean;
|
|
12
12
|
};
|
|
@@ -20,7 +20,7 @@ export declare function isSendbirdNotification(dataPayload?: {
|
|
|
20
20
|
[key: string]: string | object;
|
|
21
21
|
}): dataPayload is RawSendbirdDataPayload;
|
|
22
22
|
export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
|
|
23
|
-
export declare function shouldRenderParentMessage(message: SendbirdMessage): message is (SendbirdUserMessage | SendbirdFileMessage) & {
|
|
23
|
+
export declare function shouldRenderParentMessage(message: SendbirdMessage, hide?: boolean): message is (SendbirdUserMessage | SendbirdFileMessage) & {
|
|
24
24
|
parentMessage: SendbirdUserMessage | SendbirdFileMessage;
|
|
25
25
|
};
|
|
26
26
|
export declare function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean): boolean;
|
|
@@ -62,4 +62,26 @@ export declare const millsToMMSS: (mills: number) => string;
|
|
|
62
62
|
* milliseconds to 0:00 format
|
|
63
63
|
* */
|
|
64
64
|
export declare const millsToMSS: (mills: number) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Message reply count format
|
|
67
|
+
* If reply count is 1: 1 'reply'
|
|
68
|
+
* If the reply count is greater than 1 : '{count} replies'
|
|
69
|
+
* If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'
|
|
70
|
+
* */
|
|
71
|
+
export declare const getReplyCountFormat: (replyCount: number, maxReplyCount?: number) => string;
|
|
72
|
+
/**
|
|
73
|
+
* Thread parent message time format
|
|
74
|
+
*
|
|
75
|
+
* @param {Date} date
|
|
76
|
+
* @param {Locale} [locale]
|
|
77
|
+
* @returns {string}
|
|
78
|
+
* */
|
|
79
|
+
export declare const getThreadParentMessageTimeFormat: (date: Date, locale?: Locale) => string;
|
|
80
|
+
/**
|
|
81
|
+
* File size format
|
|
82
|
+
*
|
|
83
|
+
* @param {number} fileSize
|
|
84
|
+
* @returns {string}
|
|
85
|
+
* */
|
|
86
|
+
export declare const getReadableFileSize: (fileSize: number) => string;
|
|
65
87
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "A collection of utility functions and constants for building chat UI components with Sendbird UIKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sendbird",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/react": "*",
|
|
52
52
|
"@types/react-native": "*",
|
|
53
|
-
"react": "
|
|
54
|
-
"react-native": "0.
|
|
53
|
+
"react": "18.2.0",
|
|
54
|
+
"react-native": "0.74.3",
|
|
55
55
|
"react-native-builder-bob": "^0.18.0",
|
|
56
56
|
"typescript": "5.2.2"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@sendbird/chat": "^4.
|
|
59
|
+
"@sendbird/chat": "^4.12.9",
|
|
60
60
|
"react": ">=17.0.2",
|
|
61
61
|
"react-native": ">=0.65.0"
|
|
62
62
|
},
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
]
|
|
83
83
|
]
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "51d39985ece857b026d311c621ec3c555cf896a1"
|
|
86
86
|
}
|
package/src/sendbird/message.ts
CHANGED
|
@@ -66,12 +66,16 @@ export function calcMessageGrouping(
|
|
|
66
66
|
curr: SendbirdMessage,
|
|
67
67
|
prev?: SendbirdMessage,
|
|
68
68
|
next?: SendbirdMessage,
|
|
69
|
+
isReplyThreadType?: boolean,
|
|
70
|
+
hasParentMessageUI?: boolean,
|
|
69
71
|
) {
|
|
70
72
|
const getPrev = () => {
|
|
71
73
|
if (!groupEnabled) return false;
|
|
72
74
|
if (!prev) return false;
|
|
73
75
|
if (curr.isAdminMessage()) return false;
|
|
74
76
|
if (!hasSameSender(curr, prev)) return false;
|
|
77
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
78
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
75
79
|
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;
|
|
76
80
|
return true;
|
|
77
81
|
};
|
|
@@ -81,6 +85,8 @@ export function calcMessageGrouping(
|
|
|
81
85
|
if (!next) return false;
|
|
82
86
|
if (curr.isAdminMessage()) return false;
|
|
83
87
|
if (!hasSameSender(curr, next)) return false;
|
|
88
|
+
if (hasParentMessageUI && curr.parentMessageId) return false;
|
|
89
|
+
if (isReplyThreadType && curr.threadInfo) return false;
|
|
84
90
|
if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;
|
|
85
91
|
return true;
|
|
86
92
|
};
|
|
@@ -125,12 +131,13 @@ export function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload):
|
|
|
125
131
|
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
126
132
|
}
|
|
127
133
|
|
|
128
|
-
export function shouldRenderParentMessage(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
) & {
|
|
134
|
+
export function shouldRenderParentMessage(
|
|
135
|
+
message: SendbirdMessage,
|
|
136
|
+
hide = false,
|
|
137
|
+
): message is (SendbirdUserMessage | SendbirdFileMessage) & {
|
|
132
138
|
parentMessage: SendbirdUserMessage | SendbirdFileMessage;
|
|
133
139
|
} {
|
|
140
|
+
if (hide) return false;
|
|
134
141
|
return !!(
|
|
135
142
|
(message.isFileMessage() || message.isUserMessage()) &&
|
|
136
143
|
(message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())
|
package/src/ui-format/common.ts
CHANGED
|
@@ -152,3 +152,46 @@ export const millsToMSS = (mills: number) => {
|
|
|
152
152
|
|
|
153
153
|
return `${minutes}:${ss}`;
|
|
154
154
|
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Message reply count format
|
|
158
|
+
* If reply count is 1: 1 'reply'
|
|
159
|
+
* If the reply count is greater than 1 : '{count} replies'
|
|
160
|
+
* If the reply count is greater than {maxReplyCount} : '{maxReplyCount}+ replies'
|
|
161
|
+
* */
|
|
162
|
+
export const getReplyCountFormat = (replyCount: number, maxReplyCount?: number) => {
|
|
163
|
+
if (maxReplyCount && replyCount > maxReplyCount) {
|
|
164
|
+
return `${maxReplyCount}+ replies`;
|
|
165
|
+
} else if (replyCount === 1) {
|
|
166
|
+
return `${replyCount} reply`;
|
|
167
|
+
} else if (replyCount > 1) {
|
|
168
|
+
return `${replyCount} replies`;
|
|
169
|
+
}
|
|
170
|
+
return '';
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Thread parent message time format
|
|
175
|
+
*
|
|
176
|
+
* @param {Date} date
|
|
177
|
+
* @param {Locale} [locale]
|
|
178
|
+
* @returns {string}
|
|
179
|
+
* */
|
|
180
|
+
export const getThreadParentMessageTimeFormat = (date: Date, locale?: Locale): string => {
|
|
181
|
+
return format(date, "MMM dd 'at' h:mm a", { locale });
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* File size format
|
|
186
|
+
*
|
|
187
|
+
* @param {number} fileSize
|
|
188
|
+
* @returns {string}
|
|
189
|
+
* */
|
|
190
|
+
export const getReadableFileSize = (fileSize: number): string => {
|
|
191
|
+
if (fileSize <= 0) {
|
|
192
|
+
return '0 B';
|
|
193
|
+
}
|
|
194
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
195
|
+
const digitGroups = Math.floor(Math.log10(fileSize) / Math.log10(1024));
|
|
196
|
+
return `${(fileSize / Math.pow(1024, digitGroups)).toFixed(1)} ${units[digitGroups]}`;
|
|
197
|
+
};
|