@sendbird/uikit-utils 3.0.4-rc.1 → 3.1.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 +51 -4
- package/lib/commonjs/sendbird/message.js.map +1 -1
- package/lib/commonjs/sendbird/user.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/sendbird/message.js +45 -4
- package/lib/module/sendbird/message.js.map +1 -1
- package/lib/module/sendbird/user.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/sendbird/message.d.ts +19 -4
- package/lib/typescript/src/sendbird/user.d.ts +2 -2
- package/lib/typescript/src/types.d.ts +2 -0
- package/package.json +4 -3
- package/src/sendbird/message.ts +64 -12
- package/src/sendbird/user.ts +3 -3
- package/src/types.ts +2 -0
|
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.calcMessageGrouping = calcMessageGrouping;
|
|
7
|
+
exports.convertFileTypeToMessageType = void 0;
|
|
7
8
|
exports.getAvailableUriFromFileMessage = getAvailableUriFromFileMessage;
|
|
8
9
|
exports.getDefaultMessageSearchQueryParams = getDefaultMessageSearchQueryParams;
|
|
10
|
+
exports.getFileIconFromMessageType = exports.getFileIconFromMessage = void 0;
|
|
9
11
|
exports.getFileTypeFromMessage = getFileTypeFromMessage;
|
|
10
12
|
exports.getMessageType = getMessageType;
|
|
11
13
|
exports.getMessageUniqId = getMessageUniqId;
|
|
@@ -18,6 +20,7 @@ exports.isSendbirdNotification = isSendbirdNotification;
|
|
|
18
20
|
exports.messageComparator = messageComparator;
|
|
19
21
|
exports.messageKeyExtractor = messageKeyExtractor;
|
|
20
22
|
exports.parseSendbirdNotification = parseSendbirdNotification;
|
|
23
|
+
exports.shouldRenderParentMessage = shouldRenderParentMessage;
|
|
21
24
|
exports.shouldRenderReaction = shouldRenderReaction;
|
|
22
25
|
var _message = require("@sendbird/chat/message");
|
|
23
26
|
var _file = require("../shared/file");
|
|
@@ -35,7 +38,7 @@ function isMyMessage(msg) {
|
|
|
35
38
|
var _msg$sender;
|
|
36
39
|
let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
|
|
37
40
|
if (!isSendableMessage(msg)) return false;
|
|
38
|
-
return
|
|
41
|
+
return ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId;
|
|
39
42
|
}
|
|
40
43
|
function messageKeyExtractor(message) {
|
|
41
44
|
return getMessageUniqId(message);
|
|
@@ -52,8 +55,8 @@ function messageKeyExtractor(message) {
|
|
|
52
55
|
function messageComparator(a, b) {
|
|
53
56
|
let aStatusOffset = 0;
|
|
54
57
|
let bStatusOffset = 0;
|
|
55
|
-
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset =
|
|
56
|
-
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset =
|
|
58
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
59
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
57
60
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
58
61
|
}
|
|
59
62
|
function hasSameSender(a, b) {
|
|
@@ -92,7 +95,8 @@ function getMessageUniqId(msg) {
|
|
|
92
95
|
return String(msg.messageId);
|
|
93
96
|
}
|
|
94
97
|
function getAvailableUriFromFileMessage(message) {
|
|
95
|
-
|
|
98
|
+
var _message$messageParam;
|
|
99
|
+
if (!message.url && (_message$messageParam = message.messageParams) !== null && _message$messageParam !== void 0 && _message$messageParam.file && 'uri' in message.messageParams.file) {
|
|
96
100
|
return message.messageParams.file.uri;
|
|
97
101
|
}
|
|
98
102
|
return message.url;
|
|
@@ -104,6 +108,10 @@ function isSendbirdNotification(dataPayload) {
|
|
|
104
108
|
function parseSendbirdNotification(dataPayload) {
|
|
105
109
|
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
106
110
|
}
|
|
111
|
+
function shouldRenderParentMessage(message) {
|
|
112
|
+
var _message$parentMessag, _message$parentMessag2;
|
|
113
|
+
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()));
|
|
114
|
+
}
|
|
107
115
|
function shouldRenderReaction(channel, reactionEnabled) {
|
|
108
116
|
if (channel.isOpenChannel()) {
|
|
109
117
|
return false;
|
|
@@ -118,9 +126,48 @@ function shouldRenderReaction(channel, reactionEnabled) {
|
|
|
118
126
|
function getReactionCount(reaction) {
|
|
119
127
|
return reaction.userIds.length;
|
|
120
128
|
}
|
|
129
|
+
const fileIconMapper = {
|
|
130
|
+
'audio': 'file-audio',
|
|
131
|
+
'image': 'photo',
|
|
132
|
+
'video': 'play',
|
|
133
|
+
'file': 'file-document'
|
|
134
|
+
};
|
|
121
135
|
function getFileTypeFromMessage(message) {
|
|
122
136
|
return (0, _file.getFileType)(message.type || (0, _file.getFileExtension)(message.name));
|
|
123
137
|
}
|
|
138
|
+
const convertFileTypeToMessageType = function () {
|
|
139
|
+
let fileType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'file';
|
|
140
|
+
switch (fileType) {
|
|
141
|
+
case 'audio':
|
|
142
|
+
case 'image':
|
|
143
|
+
case 'video':
|
|
144
|
+
return `file.${fileType}`;
|
|
145
|
+
case 'file':
|
|
146
|
+
return fileType;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
exports.convertFileTypeToMessageType = convertFileTypeToMessageType;
|
|
150
|
+
const getFileIconFromMessageType = messageType => {
|
|
151
|
+
switch (messageType) {
|
|
152
|
+
case 'file':
|
|
153
|
+
return fileIconMapper['file'];
|
|
154
|
+
case 'file.image':
|
|
155
|
+
return fileIconMapper['image'];
|
|
156
|
+
case 'file.video':
|
|
157
|
+
return fileIconMapper['video'];
|
|
158
|
+
case 'file.audio':
|
|
159
|
+
return fileIconMapper['audio'];
|
|
160
|
+
default:
|
|
161
|
+
return fileIconMapper['file'];
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
exports.getFileIconFromMessageType = getFileIconFromMessageType;
|
|
165
|
+
const getFileIconFromMessage = message => {
|
|
166
|
+
const fileType = getFileTypeFromMessage(message);
|
|
167
|
+
const messageType = convertFileTypeToMessageType(fileType);
|
|
168
|
+
return getFileIconFromMessageType(messageType);
|
|
169
|
+
};
|
|
170
|
+
exports.getFileIconFromMessage = getFileIconFromMessage;
|
|
124
171
|
function getMessageType(message) {
|
|
125
172
|
if (message.isAdminMessage()) {
|
|
126
173
|
return 'admin';
|
|
@@ -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","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","getMessageTimeFormat","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","isEphemeral","getReactionCount","reaction","userIds","getFileTypeFromMessage","getFileType","type","getFileExtension","name","getMessageType","ogMetaData","fileType","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","MessageSearchOrder","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n if (channel.isOpenChannel()) {\n return false;\n }\n\n if (channel.isGroupChannel()) {\n if (channel.isBroadcast) return false;\n if (channel.isSuper) return false;\n if (channel.isEphemeral) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\ntype MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio'}`;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage) {\n return getFileType(message.type || getFileExtension(message.name));\n}\n\nexport function getMessageType(message: SendbirdMessage): MessageType {\n if (message.isAdminMessage()) {\n return 'admin';\n }\n\n if (message.isUserMessage()) {\n if (message.ogMetaData) {\n return 'user.opengraph';\n }\n return 'user';\n }\n\n if (message.isFileMessage()) {\n const fileType = getFileTypeFromMessage(message);\n switch (fileType) {\n case 'image':\n case 'video': {\n return `file.${fileType}`;\n }\n case 'audio': {\n return `file.${fileType}`;\n }\n default: {\n return 'file';\n }\n }\n }\n\n return 'unknown';\n}\n\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAWA,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,GAA4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AQ,EAAExB,OAAO,CAACyB,SAAS,CAAC;IACnEC,KAAK,EAAEC,2BAAkB,CAACC;EAC5B,CAAC;AACH"}
|
|
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","getAvailableUriFromFileMessage","_message$messageParam","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","isEphemeral","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","getFileType","type","getFileExtension","name","convertFileTypeToMessageType","fileType","exports","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","MessageSearchOrder","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } 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 getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams?.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function 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.isSuper) return false;\n if (channel.isEphemeral) 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'}`;\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 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"],"mappings":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AEA,IAAIU,OAAO,CAACyB,aAAa,EAAE,EAAE;IAC3B,IAAIzB,OAAO,CAACuE,UAAU,EAAE;MACtB,OAAO,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAIvE,OAAO,CAAC0B,aAAa,EAAE,EAAE;IAC3B,MAAMuC,QAAQ,GAAGN,sBAAsB,CAAC3D,OAAO,CAAC;IAChD,QAAQiE,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB;AAEO,SAASO,kCAAkCA,CAACxB,OAA6B,EAAEyB,OAAe,EAAE;EACjG,OAAO;IACLA,OAAO;IACPC,UAAU,EAAE1B,OAAO,CAAChB,GAAG;IACvB2C,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAAC7B,OAAO,CAAC8B,QAAQ,EAAE9B,OAAO,CAAC+B,SAAS,CAAC;IACnEC,KAAK,EAAEC,2BAAkB,CAACC;EAC5B,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":";;;;;;;AAMO,SAASA,UAAUA,CAACC,
|
|
1
|
+
{"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role | null, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role | null, then: T, or: V): T | V;\nexport function ifOperator(role: Role | null, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":";;;;;;;AAMO,SAASA,UAAUA,CAACC,IAAiB,EAAEC,IAAa,EAAEC,EAAY,EAAE;EACzE,IAAIF,IAAI,KAAK,UAAU,EAAE,OAAOC,IAAI;EACpC,OAAOC,EAAE;AACX;AAEO,SAASC,aAAaA,CAAuBC,IAAO,EAAE;EAC3D,OAAOA,IAAI,CAACC,MAAM;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n MessageSearchQuery,\n MultipleFilesMessage,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport type OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdMultipleFilesMessage = MultipleFilesMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type { FeedChannel } from '@sendbird/chat/feedChannel';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n MessageSearchQuery,\n MultipleFilesMessage,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport type OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdMultipleFilesMessage = MultipleFilesMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\nexport type SendbirdFeedChannel = FeedChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
|
|
@@ -14,7 +14,7 @@ export function isMyMessage(msg) {
|
|
|
14
14
|
var _msg$sender;
|
|
15
15
|
let currentUserId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '##__USER_ID_IS_NOT_PROVIDED__##';
|
|
16
16
|
if (!isSendableMessage(msg)) return false;
|
|
17
|
-
return
|
|
17
|
+
return ((_msg$sender = msg.sender) === null || _msg$sender === void 0 ? void 0 : _msg$sender.userId) === currentUserId;
|
|
18
18
|
}
|
|
19
19
|
export function messageKeyExtractor(message) {
|
|
20
20
|
return getMessageUniqId(message);
|
|
@@ -31,8 +31,8 @@ export function messageKeyExtractor(message) {
|
|
|
31
31
|
export function messageComparator(a, b) {
|
|
32
32
|
let aStatusOffset = 0;
|
|
33
33
|
let bStatusOffset = 0;
|
|
34
|
-
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset =
|
|
35
|
-
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset =
|
|
34
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
35
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
36
36
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
37
37
|
}
|
|
38
38
|
export function hasSameSender(a, b) {
|
|
@@ -71,7 +71,8 @@ export function getMessageUniqId(msg) {
|
|
|
71
71
|
return String(msg.messageId);
|
|
72
72
|
}
|
|
73
73
|
export function getAvailableUriFromFileMessage(message) {
|
|
74
|
-
|
|
74
|
+
var _message$messageParam;
|
|
75
|
+
if (!message.url && (_message$messageParam = message.messageParams) !== null && _message$messageParam !== void 0 && _message$messageParam.file && 'uri' in message.messageParams.file) {
|
|
75
76
|
return message.messageParams.file.uri;
|
|
76
77
|
}
|
|
77
78
|
return message.url;
|
|
@@ -83,6 +84,10 @@ export function isSendbirdNotification(dataPayload) {
|
|
|
83
84
|
export function parseSendbirdNotification(dataPayload) {
|
|
84
85
|
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
85
86
|
}
|
|
87
|
+
export function shouldRenderParentMessage(message) {
|
|
88
|
+
var _message$parentMessag, _message$parentMessag2;
|
|
89
|
+
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()));
|
|
90
|
+
}
|
|
86
91
|
export function shouldRenderReaction(channel, reactionEnabled) {
|
|
87
92
|
if (channel.isOpenChannel()) {
|
|
88
93
|
return false;
|
|
@@ -97,9 +102,45 @@ export function shouldRenderReaction(channel, reactionEnabled) {
|
|
|
97
102
|
export function getReactionCount(reaction) {
|
|
98
103
|
return reaction.userIds.length;
|
|
99
104
|
}
|
|
105
|
+
const fileIconMapper = {
|
|
106
|
+
'audio': 'file-audio',
|
|
107
|
+
'image': 'photo',
|
|
108
|
+
'video': 'play',
|
|
109
|
+
'file': 'file-document'
|
|
110
|
+
};
|
|
100
111
|
export function getFileTypeFromMessage(message) {
|
|
101
112
|
return getFileType(message.type || getFileExtension(message.name));
|
|
102
113
|
}
|
|
114
|
+
export const convertFileTypeToMessageType = function () {
|
|
115
|
+
let fileType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'file';
|
|
116
|
+
switch (fileType) {
|
|
117
|
+
case 'audio':
|
|
118
|
+
case 'image':
|
|
119
|
+
case 'video':
|
|
120
|
+
return `file.${fileType}`;
|
|
121
|
+
case 'file':
|
|
122
|
+
return fileType;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export const getFileIconFromMessageType = messageType => {
|
|
126
|
+
switch (messageType) {
|
|
127
|
+
case 'file':
|
|
128
|
+
return fileIconMapper['file'];
|
|
129
|
+
case 'file.image':
|
|
130
|
+
return fileIconMapper['image'];
|
|
131
|
+
case 'file.video':
|
|
132
|
+
return fileIconMapper['video'];
|
|
133
|
+
case 'file.audio':
|
|
134
|
+
return fileIconMapper['audio'];
|
|
135
|
+
default:
|
|
136
|
+
return fileIconMapper['file'];
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
export const getFileIconFromMessage = message => {
|
|
140
|
+
const fileType = getFileTypeFromMessage(message);
|
|
141
|
+
const messageType = convertFileTypeToMessageType(fileType);
|
|
142
|
+
return getFileIconFromMessageType(messageType);
|
|
143
|
+
};
|
|
103
144
|
export function getMessageType(message) {
|
|
104
145
|
if (message.isAdminMessage()) {
|
|
105
146
|
return 'admin';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MessageSearchOrder","getFileExtension","getFileType","getMessageTimeFormat","isNewMessage","msg","currentUserId","myMessage","isMyMessage","isAdminMessage","updatedAt","isSendableMessage","undefined","_msg$sender","arguments","length","sender","userId","sendingStatus","messageKeyExtractor","message","getMessageUniqId","messageComparator","a","b","aStatusOffset","bStatusOffset","createdAt","hasSameSender","_a$sender","_b$sender","calcMessageGrouping","groupEnabled","curr","prev","next","getPrev","Date","getNext","groupWithPrev","groupWithNext","isUserMessage","isFileMessage","String","messageId","reqId","getAvailableUriFromFileMessage","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","isEphemeral","getReactionCount","reaction","userIds","getFileTypeFromMessage","type","name","getMessageType","ogMetaData","fileType","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } from '../shared/file';\nimport type {\n SendbirdBaseChannel,\n SendbirdBaseMessage,\n SendbirdDataPayload,\n SendbirdFileMessage,\n SendbirdGroupChannel,\n SendbirdMessage,\n SendbirdReaction,\n SendbirdSendableMessage,\n} from '../types';\nimport { getMessageTimeFormat } from '../ui-format/common';\n\nexport function isNewMessage(msg: SendbirdMessage, currentUserId?: string) {\n const myMessage = isMyMessage(msg, currentUserId);\n if (myMessage) return false;\n if (msg.isAdminMessage()) return false;\n return msg.updatedAt === 0;\n}\n\nexport function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage {\n return msg !== undefined && msg !== null && 'sendingStatus' in msg;\n}\n\nexport function isMyMessage(msg?: SendbirdMessage | null, currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##') {\n if (!isSendableMessage(msg)) return false;\n return (\n ('sender' in msg && msg.sender?.userId === currentUserId) ||\n msg.sendingStatus === 'pending' ||\n msg.sendingStatus === 'failed' ||\n msg.sendingStatus === 'canceled'\n );\n}\n\nexport function messageKeyExtractor(message: SendbirdMessage): string {\n return getMessageUniqId(message);\n}\n\n// |-------------------|-------------------|-----------------|-------------------|\n// | sending status | reqId | messageId | createdAt |\n// |-------------------|-------------------|-----------------|-------------------|\n// | pending | timestamp(A) | 0 | timestamp(B) |\n// | canceled | timestamp(A) | 0 | ? |\n// | failed | timestamp(A) | 0 | ? |\n// | succeeded | timestamp(A) / '' | id from DB | timestamp(C) |\n// |-------------------|-------------------|-----------------|-------------------|\nexport function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {\n let aStatusOffset = 0;\n let bStatusOffset = 0;\n\n if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = 999999;\n if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = 999999;\n\n return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);\n}\n\nexport function hasSameSender(a?: SendbirdMessage, b?: SendbirdMessage) {\n if (!a || !b) return false;\n if ('sender' in a && 'sender' in b) return a.sender?.userId === b.sender?.userId;\n return false;\n}\n\nexport function calcMessageGrouping(\n groupEnabled: boolean,\n curr: SendbirdMessage,\n prev?: SendbirdMessage,\n next?: SendbirdMessage,\n) {\n const getPrev = () => {\n if (!groupEnabled) return false;\n if (!prev) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, prev)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(prev.createdAt))) return false;\n return true;\n };\n\n const getNext = () => {\n if (!groupEnabled) return false;\n if (!next) return false;\n if (curr.isAdminMessage()) return false;\n if (!hasSameSender(curr, next)) return false;\n if (getMessageTimeFormat(new Date(curr.createdAt)) !== getMessageTimeFormat(new Date(next.createdAt))) return false;\n return true;\n };\n\n return { groupWithPrev: getPrev(), groupWithNext: getNext() };\n}\n\nexport function getMessageUniqId(msg: SendbirdBaseMessage) {\n if (msg.isUserMessage() || msg.isFileMessage()) {\n if (msg.sendingStatus === 'succeeded') return String(msg.messageId);\n return msg.reqId;\n }\n\n return String(msg.messageId);\n}\n\nexport function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {\n if (channel.isOpenChannel()) {\n return false;\n }\n\n if (channel.isGroupChannel()) {\n if (channel.isBroadcast) return false;\n if (channel.isSuper) return false;\n if (channel.isEphemeral) return false;\n }\n\n return reactionEnabled;\n}\n\nexport function getReactionCount(reaction: SendbirdReaction) {\n return reaction.userIds.length;\n}\n\ntype MessageType =\n | 'user'\n | 'admin'\n | 'file'\n | 'unknown'\n | `user.${'opengraph'}`\n | `file.${'image' | 'video' | 'audio'}`;\n\nexport function getFileTypeFromMessage(message: SendbirdFileMessage) {\n return getFileType(message.type || getFileExtension(message.name));\n}\n\nexport function getMessageType(message: SendbirdMessage): MessageType {\n if (message.isAdminMessage()) {\n return 'admin';\n }\n\n if (message.isUserMessage()) {\n if (message.ogMetaData) {\n return 'user.opengraph';\n }\n return 'user';\n }\n\n if (message.isFileMessage()) {\n const fileType = getFileTypeFromMessage(message);\n switch (fileType) {\n case 'image':\n case 'video': {\n return `file.${fileType}`;\n }\n case 'audio': {\n return `file.${fileType}`;\n }\n default: {\n return 'file';\n }\n }\n }\n\n return 'unknown';\n}\n\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"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,SAASC,gBAAgB,EAAEC,WAAW,QAAQ,gBAAgB;AAW9D,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,OAAO,SAASC,YAAYA,CAACC,GAAoB,EAAEC,aAAsB,EAAE;EACzE,MAAMC,SAAS,GAAGC,WAAW,CAACH,GAAG,EAAEC,aAAa,CA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ACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB;AAEA,OAAO,SAASC,kCAAkCA,CAAChB,OAA6B,EAAEiB,OAAe,EAAE;EACjG,OAAO;IACLA,OAAO;IACPC,UAAU,EAAElB,OAAO,CAACZ,GAAG;IACvB+B,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAACrB,OAAO,CAACsB,QAAQ,EAAEtB,OAAO,CAACuB,SAAS,CAAC;IACnEC,KAAK,EAAEnF,kBAAkB,CAACoF;EAC5B,CAAC;AACH"}
|
|
1
|
+
{"version":3,"names":["MessageSearchOrder","getFileExtension","getFileType","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","getAvailableUriFromFileMessage","_message$messageParam","url","messageParams","file","uri","isSendbirdNotification","dataPayload","Boolean","parseSendbirdNotification","sendbird","JSON","parse","shouldRenderParentMessage","_message$parentMessag","_message$parentMessag2","parentMessage","shouldRenderReaction","channel","reactionEnabled","isOpenChannel","isGroupChannel","isBroadcast","isSuper","isEphemeral","getReactionCount","reaction","userIds","fileIconMapper","getFileTypeFromMessage","type","name","convertFileTypeToMessageType","fileType","getFileIconFromMessageType","messageType","getFileIconFromMessage","getMessageType","ogMetaData","getDefaultMessageSearchQueryParams","keyword","channelUrl","messageTimestampFrom","Math","max","joinedAt","invitedAt","order","TIMESTAMP"],"sources":["message.ts"],"sourcesContent":["import { MessageSearchOrder } from '@sendbird/chat/message';\n\nimport { getFileExtension, getFileType } 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 getAvailableUriFromFileMessage(message: SendbirdFileMessage) {\n if (!message.url && message.messageParams?.file && 'uri' in message.messageParams.file) {\n return message.messageParams.file.uri;\n }\n return message.url;\n}\n\ntype RawSendbirdDataPayload = { sendbird: string | object };\nexport function isSendbirdNotification(dataPayload?: {\n [key: string]: string | object;\n}): dataPayload is RawSendbirdDataPayload {\n if (!dataPayload) return false;\n return Boolean(dataPayload['sendbird']);\n}\n\nexport function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload {\n return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;\n}\n\nexport function 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.isSuper) return false;\n if (channel.isEphemeral) 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'}`;\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 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"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,wBAAwB;AAE3D,SAASC,gBAAgB,EAAEC,WAAW,QAAQ,gBAAgB;AAY9D,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,IAAI,eAAe,IAAIA,GAAG;AACpE;AAEA,OAAO,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;AAEA,OAAO,SAASY,mBAAmBA,CAACC,OAAwB,EAAU;EACpE,OAAOC,gBAAgB,CAACD,OAAO,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AAC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BAA4B,CAACC,QAAQ,CAAC;EAC1D,OAAOC,0BAA0B,CAACC,WAAW,CAAC;AAChD,CAAC;AAED,OAAO,SAASE,cAAcA,CAAClE,OAAwB,EAAe;EACpE,IAAIA,OAAO,CAACV,cAAc,EAAE,EAAE;IAC5B,OAAO,OAAO;EAChB;EAEA,IAAIU,OAAO,CAACwB,aAAa,EAAE,EAAE;IAC3B,IAAIxB,OAAO,CAACmE,UAAU,EAAE;MACtB,OAAO,gBAAgB;IACzB;IACA,OAAO,MAAM;EACf;EAEA,IAAInE,OAAO,CAACyB,aAAa,EAAE,EAAE;IAC3B,MAAMqC,QAAQ,GAAGJ,sBAAsB,CAAC1D,OAAO,CAAC;IAChD,QAAQ8D,QAAQ;MACd,KAAK,OAAO;MACZ,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA,KAAK,OAAO;QAAE;UACZ,OAAQ,QAAOA,QAAS,EAAC;QAC3B;MACA;QAAS;UACP,OAAO,MAAM;QACf;IAAC;EAEL;EAEA,OAAO,SAAS;AAClB;AAEA,OAAO,SAASM,kCAAkCA,CAACrB,OAA6B,EAAEsB,OAAe,EAAE;EACjG,OAAO;IACLA,OAAO;IACPC,UAAU,EAAEvB,OAAO,CAAChB,GAAG;IACvBwC,oBAAoB,EAAEC,IAAI,CAACC,GAAG,CAAC1B,OAAO,CAAC2B,QAAQ,EAAE3B,OAAO,CAAC4B,SAAS,CAAC;IACnEC,KAAK,EAAE/F,kBAAkB,CAACgG;EAC5B,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role, then: T, or: V): T | V;\nexport function ifOperator(role: Role, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAUA,CAACC,
|
|
1
|
+
{"version":3,"names":["ifOperator","role","then","or","getUserUniqId","user","userId"],"sources":["user.ts"],"sourcesContent":["import type { Role } from '@sendbird/chat';\n\nimport type { UserStruct } from '../types';\n\nexport function ifOperator<T>(role: Role | null, then: T): T | undefined;\nexport function ifOperator<T, V>(role: Role | null, then: T, or: V): T | V;\nexport function ifOperator(role: Role | null, then: unknown, or?: unknown) {\n if (role === 'operator') return then;\n return or;\n}\n\nexport function getUserUniqId<T extends UserStruct>(user: T) {\n return user.userId;\n}\n"],"mappings":"AAMA,OAAO,SAASA,UAAUA,CAACC,IAAiB,EAAEC,IAAa,EAAEC,EAAY,EAAE;EACzE,IAAIF,IAAI,KAAK,UAAU,EAAE,OAAOC,IAAI;EACpC,OAAOC,EAAE;AACX;AAEA,OAAO,SAASC,aAAaA,CAAuBC,IAAO,EAAE;EAC3D,OAAOA,IAAI,CAACC,MAAM;AACpB"}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n MessageSearchQuery,\n MultipleFilesMessage,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport type OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdMultipleFilesMessage = MultipleFilesMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-empty-interface */\nimport type React from 'react';\n\nimport type SendbirdChat from '@sendbird/chat';\nimport type {\n BaseChannel,\n Emoji,\n EmojiCategory,\n EmojiContainer,\n Participant,\n RestrictedUser,\n SendbirdError as SBError,\n User,\n UserUpdateParams,\n} from '@sendbird/chat';\nimport type { FeedChannel } from '@sendbird/chat/feedChannel';\nimport type {\n GroupChannel,\n GroupChannelCollection,\n GroupChannelCreateParams,\n GroupChannelListQuery,\n GroupChannelModule,\n GroupChannelUpdateParams,\n Member,\n MessageCollection,\n} from '@sendbird/chat/groupChannel';\nimport type {\n ModuleNamespaces,\n OpenChannelCreateParams,\n OpenChannelUpdateParams,\n SendableMessage,\n} from '@sendbird/chat/lib/__definition';\nimport type {\n AdminMessage,\n BaseMessage,\n FileMessage,\n FileMessageCreateParams,\n FileMessageUpdateParams,\n MessageSearchQuery,\n MultipleFilesMessage,\n PreviousMessageListQuery,\n Reaction,\n UserMessage,\n UserMessageCreateParams,\n UserMessageUpdateParams,\n} from '@sendbird/chat/message';\nimport type { OpenChannel, OpenChannelListQuery, OpenChannelModule } from '@sendbird/chat/openChannel';\n\nexport type FilterByValueType<T extends object, Type> = {\n [K in keyof T as T[K] extends Type ? K : never]: T[K];\n};\n\nexport type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void\n ? I\n : never;\n\nexport type OmittedValues<T, K extends keyof T> = Omit<T, K>[keyof Omit<T, K>];\n\nexport type PartialDeep<T> = T extends object\n ? T extends Function\n ? T\n : {\n [P in keyof T]?: PartialDeep<T[P]>;\n }\n : T;\n\nexport type PartialNullable<T> = {\n [P in keyof T]?: T[P] | null;\n};\n\nexport type Optional<T> = T | undefined;\n\nexport type ContextValue<T extends React.Context<any>> = T extends React.Context<infer V> ? V : never;\n\nexport type OnBeforeHandler<T> = (params: T) => T | Promise<T>;\n\nexport interface UserStruct {\n userId: string;\n}\n\nexport type SendbirdChatSDK = SendbirdChat & ModuleNamespaces<[GroupChannelModule, OpenChannelModule]>;\nexport type SendbirdMessage = BaseMessage | FileMessage | UserMessage | AdminMessage | SendableMessage;\nexport type SendbirdChannel = BaseChannel | GroupChannel | OpenChannel;\nexport type SendbirdUserMessage = UserMessage;\nexport type SendbirdFileMessage = FileMessage;\nexport type SendbirdMultipleFilesMessage = MultipleFilesMessage;\nexport type SendbirdAdminMessage = AdminMessage;\nexport type SendbirdBaseMessage = BaseMessage;\nexport type SendbirdSendableMessage = SendableMessage;\nexport type SendbirdFileMessageCreateParams = FileMessageCreateParams;\nexport type SendbirdFileMessageUpdateParams = FileMessageUpdateParams;\nexport type SendbirdUserMessageCreateParams = UserMessageCreateParams;\nexport type SendbirdUserMessageUpdateParams = UserMessageUpdateParams;\n\nexport type SendbirdGroupChannelCreateParams = GroupChannelCreateParams;\nexport type SendbirdGroupChannelUpdateParams = GroupChannelUpdateParams;\nexport type SendbirdOpenChannelCreateParams = OpenChannelCreateParams;\nexport type SendbirdOpenChannelUpdateParams = OpenChannelUpdateParams;\n\nexport type SendbirdUserUpdateParams = UserUpdateParams;\nexport type SendbirdUser = User;\nexport type SendbirdRestrictedUser = RestrictedUser;\nexport type SendbirdMember = Member;\nexport type SendbirdParticipant = Participant;\n\nexport type SendbirdGroupChannel = GroupChannel;\nexport type SendbirdBaseChannel = BaseChannel;\nexport type SendbirdOpenChannel = OpenChannel;\nexport type SendbirdFeedChannel = FeedChannel;\n\nexport type SendbirdReaction = Reaction;\nexport type SendbirdEmoji = Emoji;\nexport type SendbirdEmojiCategory = EmojiCategory;\nexport type SendbirdEmojiContainer = EmojiContainer;\n\nexport type SendbirdGroupChannelCollection = GroupChannelCollection;\nexport type SendbirdGroupChannelListQuery = GroupChannelListQuery;\nexport type SendbirdOpenChannelListQuery = OpenChannelListQuery;\nexport type SendbirdMessageCollection = MessageCollection;\nexport type SendbirdPreviousMessageListQuery = PreviousMessageListQuery;\nexport type SendbirdMessageSearchQuery = MessageSearchQuery;\n\nexport type SendbirdError = SBError;\n\nexport interface SendbirdDataPayload {\n app_id: string;\n audience_type: string;\n category: string;\n channel: {\n channel_unread_message_count: number;\n channel_url: string;\n custom_type: string;\n name: string;\n };\n channel_type: string;\n created_at: number;\n custom_type: string;\n files: NotificationFiles[];\n mentioned_users: NotificationMentionedUsers[];\n message: string;\n message_id: number;\n push_sound: string;\n push_title: null;\n recipient: {\n id: string;\n name: string;\n push_template: string;\n };\n sender?: {\n id: string;\n name: string;\n profile_url: string;\n require_auth_for_profile_image: boolean;\n };\n sqs_ts: number;\n translations: NotificationTranslations;\n type: 'ADMM' | 'MESG' | 'FILE' | string;\n unread_message_count: number;\n}\nexport interface NotificationFiles {\n type: string;\n url: string;\n name: string;\n size: number;\n require_auth: boolean;\n}\n\nexport interface NotificationTranslations {}\nexport interface NotificationMentionedUsers {}\n"],"mappings":""}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MessageSearchOrder } from '@sendbird/chat/message';
|
|
2
|
-
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdGroupChannel, SendbirdMessage, SendbirdReaction, SendbirdSendableMessage } from '../types';
|
|
2
|
+
import type { SendbirdBaseChannel, SendbirdBaseMessage, SendbirdDataPayload, SendbirdFileMessage, SendbirdGroupChannel, SendbirdMessage, SendbirdReaction, SendbirdSendableMessage, SendbirdUserMessage } from '../types';
|
|
3
3
|
export declare function isNewMessage(msg: SendbirdMessage, currentUserId?: string): boolean;
|
|
4
4
|
export declare function isSendableMessage(msg?: SendbirdMessage | null): msg is SendbirdSendableMessage;
|
|
5
|
-
export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string):
|
|
5
|
+
export declare function isMyMessage(msg?: SendbirdMessage | null, currentUserId?: string): msg is SendbirdSendableMessage;
|
|
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;
|
|
@@ -19,10 +19,25 @@ export declare function isSendbirdNotification(dataPayload?: {
|
|
|
19
19
|
[key: string]: string | object;
|
|
20
20
|
}): dataPayload is RawSendbirdDataPayload;
|
|
21
21
|
export declare function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload): SendbirdDataPayload;
|
|
22
|
+
export declare function shouldRenderParentMessage(message: SendbirdMessage): message is (SendbirdUserMessage | SendbirdFileMessage) & {
|
|
23
|
+
parentMessage: SendbirdUserMessage | SendbirdFileMessage;
|
|
24
|
+
};
|
|
22
25
|
export declare function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean): boolean;
|
|
23
26
|
export declare function getReactionCount(reaction: SendbirdReaction): number;
|
|
24
|
-
type MessageType = 'user' | 'admin' | 'file' | 'unknown' | `user.${'opengraph'}` | `file.${'image' | 'video' | 'audio'}`;
|
|
25
|
-
export
|
|
27
|
+
export type MessageType = 'user' | 'admin' | 'file' | 'unknown' | `user.${'opengraph'}` | `file.${'image' | 'video' | 'audio'}`;
|
|
28
|
+
export type FileType = 'file' | 'image' | 'audio' | 'video';
|
|
29
|
+
declare const fileIconMapper: {
|
|
30
|
+
readonly audio: "file-audio";
|
|
31
|
+
readonly image: "photo";
|
|
32
|
+
readonly video: "play";
|
|
33
|
+
readonly file: "file-document";
|
|
34
|
+
};
|
|
35
|
+
type ValueOf<T> = T[keyof T];
|
|
36
|
+
export type FileIcon = ValueOf<typeof fileIconMapper>;
|
|
37
|
+
export declare function getFileTypeFromMessage(message: SendbirdFileMessage): FileType;
|
|
38
|
+
export declare const convertFileTypeToMessageType: (fileType?: FileType) => MessageType;
|
|
39
|
+
export declare const getFileIconFromMessageType: (messageType: MessageType) => FileIcon;
|
|
40
|
+
export declare const getFileIconFromMessage: (message: SendbirdFileMessage) => FileIcon;
|
|
26
41
|
export declare function getMessageType(message: SendbirdMessage): MessageType;
|
|
27
42
|
export declare function getDefaultMessageSearchQueryParams(channel: SendbirdGroupChannel, keyword: string): {
|
|
28
43
|
keyword: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Role } from '@sendbird/chat';
|
|
2
2
|
import type { UserStruct } from '../types';
|
|
3
|
-
export declare function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
4
|
-
export declare function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
3
|
+
export declare function ifOperator<T>(role: Role | null, then: T): T | undefined;
|
|
4
|
+
export declare function ifOperator<T, V>(role: Role | null, then: T, or: V): T | V;
|
|
5
5
|
export declare function getUserUniqId<T extends UserStruct>(user: T): string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import type SendbirdChat from '@sendbird/chat';
|
|
3
3
|
import type { BaseChannel, Emoji, EmojiCategory, EmojiContainer, Participant, RestrictedUser, SendbirdError as SBError, User, UserUpdateParams } from '@sendbird/chat';
|
|
4
|
+
import type { FeedChannel } from '@sendbird/chat/feedChannel';
|
|
4
5
|
import type { GroupChannel, GroupChannelCollection, GroupChannelCreateParams, GroupChannelListQuery, GroupChannelModule, GroupChannelUpdateParams, Member, MessageCollection } from '@sendbird/chat/groupChannel';
|
|
5
6
|
import type { ModuleNamespaces, OpenChannelCreateParams, OpenChannelUpdateParams, SendableMessage } from '@sendbird/chat/lib/__definition';
|
|
6
7
|
import type { AdminMessage, BaseMessage, FileMessage, FileMessageCreateParams, FileMessageUpdateParams, MessageSearchQuery, MultipleFilesMessage, PreviousMessageListQuery, Reaction, UserMessage, UserMessageCreateParams, UserMessageUpdateParams } from '@sendbird/chat/message';
|
|
@@ -47,6 +48,7 @@ export type SendbirdParticipant = Participant;
|
|
|
47
48
|
export type SendbirdGroupChannel = GroupChannel;
|
|
48
49
|
export type SendbirdBaseChannel = BaseChannel;
|
|
49
50
|
export type SendbirdOpenChannel = OpenChannel;
|
|
51
|
+
export type SendbirdFeedChannel = FeedChannel;
|
|
50
52
|
export type SendbirdReaction = Reaction;
|
|
51
53
|
export type SendbirdEmoji = Emoji;
|
|
52
54
|
export type SendbirdEmojiCategory = EmojiCategory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendbird/uikit-utils",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"typescript": "4.9.4"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@sendbird/chat": "^4.9.
|
|
58
|
+
"@sendbird/chat": "^4.9.8",
|
|
59
59
|
"react": ">=17.0.2",
|
|
60
60
|
"react-native": ">=0.65.0"
|
|
61
61
|
},
|
|
@@ -85,5 +85,6 @@
|
|
|
85
85
|
"entryPoint": "./src/index.ts",
|
|
86
86
|
"readmeFile": "./README.md",
|
|
87
87
|
"displayName": "@sendbird/uikit-utils"
|
|
88
|
-
}
|
|
88
|
+
},
|
|
89
|
+
"gitHead": "1ff295c9b8df84b188fbc1f477d3e59708b8fb80"
|
|
89
90
|
}
|
package/src/sendbird/message.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
SendbirdMessage,
|
|
11
11
|
SendbirdReaction,
|
|
12
12
|
SendbirdSendableMessage,
|
|
13
|
+
SendbirdUserMessage,
|
|
13
14
|
} from '../types';
|
|
14
15
|
import { getMessageTimeFormat } from '../ui-format/common';
|
|
15
16
|
|
|
@@ -24,14 +25,12 @@ export function isSendableMessage(msg?: SendbirdMessage | null): msg is Sendbird
|
|
|
24
25
|
return msg !== undefined && msg !== null && 'sendingStatus' in msg;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export function isMyMessage(
|
|
28
|
+
export function isMyMessage(
|
|
29
|
+
msg?: SendbirdMessage | null,
|
|
30
|
+
currentUserId = '##__USER_ID_IS_NOT_PROVIDED__##',
|
|
31
|
+
): msg is SendbirdSendableMessage {
|
|
28
32
|
if (!isSendableMessage(msg)) return false;
|
|
29
|
-
return
|
|
30
|
-
('sender' in msg && msg.sender?.userId === currentUserId) ||
|
|
31
|
-
msg.sendingStatus === 'pending' ||
|
|
32
|
-
msg.sendingStatus === 'failed' ||
|
|
33
|
-
msg.sendingStatus === 'canceled'
|
|
34
|
-
);
|
|
33
|
+
return msg.sender?.userId === currentUserId;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export function messageKeyExtractor(message: SendbirdMessage): string {
|
|
@@ -50,8 +49,8 @@ export function messageComparator(a: SendbirdMessage, b: SendbirdMessage) {
|
|
|
50
49
|
let aStatusOffset = 0;
|
|
51
50
|
let bStatusOffset = 0;
|
|
52
51
|
|
|
53
|
-
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset =
|
|
54
|
-
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset =
|
|
52
|
+
if (isSendableMessage(a) && a.sendingStatus !== 'succeeded') aStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
53
|
+
if (isSendableMessage(b) && b.sendingStatus !== 'succeeded') bStatusOffset = Number.MAX_SAFE_INTEGER;
|
|
55
54
|
|
|
56
55
|
return b.createdAt + bStatusOffset - (a.createdAt + aStatusOffset);
|
|
57
56
|
}
|
|
@@ -99,7 +98,7 @@ export function getMessageUniqId(msg: SendbirdBaseMessage) {
|
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
export function getAvailableUriFromFileMessage(message: SendbirdFileMessage) {
|
|
102
|
-
if (!message.url && message.messageParams
|
|
101
|
+
if (!message.url && message.messageParams?.file && 'uri' in message.messageParams.file) {
|
|
103
102
|
return message.messageParams.file.uri;
|
|
104
103
|
}
|
|
105
104
|
return message.url;
|
|
@@ -117,6 +116,18 @@ export function parseSendbirdNotification(dataPayload: RawSendbirdDataPayload):
|
|
|
117
116
|
return typeof dataPayload.sendbird === 'string' ? JSON.parse(dataPayload.sendbird) : dataPayload.sendbird;
|
|
118
117
|
}
|
|
119
118
|
|
|
119
|
+
export function shouldRenderParentMessage(message: SendbirdMessage): message is (
|
|
120
|
+
| SendbirdUserMessage
|
|
121
|
+
| SendbirdFileMessage
|
|
122
|
+
) & {
|
|
123
|
+
parentMessage: SendbirdUserMessage | SendbirdFileMessage;
|
|
124
|
+
} {
|
|
125
|
+
return !!(
|
|
126
|
+
(message.isFileMessage() || message.isUserMessage()) &&
|
|
127
|
+
(message.parentMessage?.isFileMessage() || message.parentMessage?.isUserMessage())
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
export function shouldRenderReaction(channel: SendbirdBaseChannel, reactionEnabled: boolean) {
|
|
121
132
|
if (channel.isOpenChannel()) {
|
|
122
133
|
return false;
|
|
@@ -135,7 +146,7 @@ export function getReactionCount(reaction: SendbirdReaction) {
|
|
|
135
146
|
return reaction.userIds.length;
|
|
136
147
|
}
|
|
137
148
|
|
|
138
|
-
type MessageType =
|
|
149
|
+
export type MessageType =
|
|
139
150
|
| 'user'
|
|
140
151
|
| 'admin'
|
|
141
152
|
| 'file'
|
|
@@ -143,9 +154,50 @@ type MessageType =
|
|
|
143
154
|
| `user.${'opengraph'}`
|
|
144
155
|
| `file.${'image' | 'video' | 'audio'}`;
|
|
145
156
|
|
|
146
|
-
export
|
|
157
|
+
export type FileType = 'file' | 'image' | 'audio' | 'video';
|
|
158
|
+
|
|
159
|
+
const fileIconMapper = {
|
|
160
|
+
'audio': 'file-audio',
|
|
161
|
+
'image': 'photo',
|
|
162
|
+
'video': 'play',
|
|
163
|
+
'file': 'file-document',
|
|
164
|
+
} as const;
|
|
165
|
+
|
|
166
|
+
type ValueOf<T> = T[keyof T];
|
|
167
|
+
export type FileIcon = ValueOf<typeof fileIconMapper>;
|
|
168
|
+
|
|
169
|
+
export function getFileTypeFromMessage(message: SendbirdFileMessage): FileType {
|
|
147
170
|
return getFileType(message.type || getFileExtension(message.name));
|
|
148
171
|
}
|
|
172
|
+
export const convertFileTypeToMessageType = (fileType: FileType = 'file'): MessageType => {
|
|
173
|
+
switch (fileType) {
|
|
174
|
+
case 'audio':
|
|
175
|
+
case 'image':
|
|
176
|
+
case 'video':
|
|
177
|
+
return `file.${fileType}`;
|
|
178
|
+
case 'file':
|
|
179
|
+
return fileType;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
export const getFileIconFromMessageType = (messageType: MessageType): FileIcon => {
|
|
183
|
+
switch (messageType) {
|
|
184
|
+
case 'file':
|
|
185
|
+
return fileIconMapper['file'];
|
|
186
|
+
case 'file.image':
|
|
187
|
+
return fileIconMapper['image'];
|
|
188
|
+
case 'file.video':
|
|
189
|
+
return fileIconMapper['video'];
|
|
190
|
+
case 'file.audio':
|
|
191
|
+
return fileIconMapper['audio'];
|
|
192
|
+
default:
|
|
193
|
+
return fileIconMapper['file'];
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
export const getFileIconFromMessage = (message: SendbirdFileMessage): FileIcon => {
|
|
197
|
+
const fileType = getFileTypeFromMessage(message);
|
|
198
|
+
const messageType = convertFileTypeToMessageType(fileType);
|
|
199
|
+
return getFileIconFromMessageType(messageType);
|
|
200
|
+
};
|
|
149
201
|
|
|
150
202
|
export function getMessageType(message: SendbirdMessage): MessageType {
|
|
151
203
|
if (message.isAdminMessage()) {
|
package/src/sendbird/user.ts
CHANGED
|
@@ -2,9 +2,9 @@ import type { Role } from '@sendbird/chat';
|
|
|
2
2
|
|
|
3
3
|
import type { UserStruct } from '../types';
|
|
4
4
|
|
|
5
|
-
export function ifOperator<T>(role: Role, then: T): T | undefined;
|
|
6
|
-
export function ifOperator<T, V>(role: Role, then: T, or: V): T | V;
|
|
7
|
-
export function ifOperator(role: Role, then: unknown, or?: unknown) {
|
|
5
|
+
export function ifOperator<T>(role: Role | null, then: T): T | undefined;
|
|
6
|
+
export function ifOperator<T, V>(role: Role | null, then: T, or: V): T | V;
|
|
7
|
+
export function ifOperator(role: Role | null, then: unknown, or?: unknown) {
|
|
8
8
|
if (role === 'operator') return then;
|
|
9
9
|
return or;
|
|
10
10
|
}
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
User,
|
|
16
16
|
UserUpdateParams,
|
|
17
17
|
} from '@sendbird/chat';
|
|
18
|
+
import type { FeedChannel } from '@sendbird/chat/feedChannel';
|
|
18
19
|
import type {
|
|
19
20
|
GroupChannel,
|
|
20
21
|
GroupChannelCollection,
|
|
@@ -107,6 +108,7 @@ export type SendbirdParticipant = Participant;
|
|
|
107
108
|
export type SendbirdGroupChannel = GroupChannel;
|
|
108
109
|
export type SendbirdBaseChannel = BaseChannel;
|
|
109
110
|
export type SendbirdOpenChannel = OpenChannel;
|
|
111
|
+
export type SendbirdFeedChannel = FeedChannel;
|
|
110
112
|
|
|
111
113
|
export type SendbirdReaction = Reaction;
|
|
112
114
|
export type SendbirdEmoji = Emoji;
|