@cometchat/chat-uikit-react-native
Version:
Ready-to-use Chat UI Components for React Native
91 lines • 4 kB
JavaScript
import { CometChat } from "@cometchat/chat-sdk-react-native";
import { localize } from "../resources/CometChatLocalize";
import { getMessagePreviewInternal } from "./MessageUtils";
import { MessageCategoryConstants } from "../constants/UIKitConstants";
import { CometChatUIKit } from "../CometChatUiKit";
class CometChatConversationUtils {
static getLastMessage(conversation) {
let msg = conversation?.getLastMessage && conversation?.getLastMessage();
if (!msg) {
return undefined;
}
switch (msg["category"]) {
case "message":
break;
case "custom":
break;
case "action":
break;
case "call":
break;
default:
break;
}
return msg;
}
static getMessagePreview = (lastMessage, theme) => {
const uid = CometChatUIKit.loggedInUser.getUid();
if (lastMessage != undefined) {
if (lastMessage.getDeletedAt() !== undefined) {
return getMessagePreviewInternal("block-fill", localize("DELETE_MSG_TEXT"), { theme });
}
if (lastMessage.getCategory() === MessageCategoryConstants.interactive) {
return getMessagePreviewInternal("block-fill", localize("NOT_SUPPORTED") ?? "This message type is not supported", { theme });
}
if (lastMessage.getCategory() == "call") {
let color = theme?.color?.textSecondary;
let text = "Video call";
let iconName = "phone-incoming-fill";
if (lastMessage.getType() == "audio") {
text = "Voice call";
}
if (uid === lastMessage.getSender().getUid()) {
iconName = "phone-outgoing-fill";
}
else if (lastMessage.getAction() === "unanswered") {
color = theme?.color?.error;
text = "Missed " + text.toLowerCase();
}
return getMessagePreviewInternal(iconName, text, { iconColor: color, theme });
}
let msgText = "";
if (lastMessage.getCategory() == "message") {
switch (lastMessage.getType()) {
case "text":
msgText = lastMessage.getText();
break;
case "image":
return getMessagePreviewInternal("photo-fill", localize('PHOTOS'), { theme });
case "audio":
return getMessagePreviewInternal("mic-fill", localize('MESSAGE_AUDIO'), { theme });
case "video":
return getMessagePreviewInternal("videocam-fill", localize("MESSAGE_VIDEO"), { theme });
case "file":
return getMessagePreviewInternal("description-fill", localize("MESSAGE_FILE"), { theme });
}
}
else if (lastMessage.getCategory() == CometChat.CATEGORY_CUSTOM) {
msgText = lastMessage.getType();
}
else if (lastMessage.getCategory() == CometChat.CATEGORY_ACTION) {
if (lastMessage?.getAction() === CometChat.ACTION_TYPE.MESSSAGE_DELETED) {
return getMessagePreviewInternal("block-fill", localize("DELETE_MSG_TEXT"), { theme });
}
msgText = lastMessage.getMessage();
}
else if (lastMessage.getCategory() === CometChat.CATEGORY_INTERACTIVE) {
msgText = "";
//todo unsupported bubble
}
else {
msgText = lastMessage["metadata"]?.pushNotification;
}
return msgText;
}
else {
return "";
}
};
}
export { CometChatConversationUtils };
//# sourceMappingURL=conversationUtils.js.map