cometchat-react-ui-kit2
Version:
CometChat UI Kit for React App
43 lines (42 loc) • 4.56 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Hooks = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ = require("../../../");
var _CometChatConversationEvents = require("../CometChatConversationEvents");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var Hooks = function Hooks(onConversationClickHandler, updateMessageList, backButtonClickHandler, conversationRef, activeConversation) {
/**ids */
var onItemClickId = "onItemClick_" + new Date().getTime();
var onDeleteConversationId = "onDeleteConversation_" + new Date().getTime();
var onMessageReadId = "onMessageRead_" + new Date().getTime();
var onMessageSentId = "onMessageSent_" + new Date().getTime();
var onBackButtonClickId = "onBackButtonClick_" + new Date().getTime();
(0, _react.useEffect)(function () {
_CometChatConversationEvents.CometChatConversationEvents.addListener(_CometChatConversationEvents.CometChatConversationEvents.onItemClick, onItemClickId, onConversationClickHandler);
_CometChatConversationEvents.CometChatConversationEvents.addListener(_CometChatConversationEvents.CometChatConversationEvents.onDeleteConversation, onDeleteConversationId, function (data) {
return updateMessageList(data, activeConversation);
});
_.CometChatMessageEvents.addListener(_.CometChatMessageEvents.onMessageRead, onMessageReadId, function (data) {
var _conversationRef$curr, _conversationRef$curr2;
return conversationRef === null || conversationRef === void 0 ? void 0 : (_conversationRef$curr = conversationRef.current) === null || _conversationRef$curr === void 0 ? void 0 : (_conversationRef$curr2 = _conversationRef$curr.conversationListRef) === null || _conversationRef$curr2 === void 0 ? void 0 : _conversationRef$curr2.resetUnreadCount(data);
});
_.CometChatMessageEvents.addListener(_.CometChatMessageEvents.onMessageSent, onMessageSentId, function (data) {
var _conversationRef$curr3, _conversationRef$curr4;
return conversationRef === null || conversationRef === void 0 ? void 0 : (_conversationRef$curr3 = conversationRef.current) === null || _conversationRef$curr3 === void 0 ? void 0 : (_conversationRef$curr4 = _conversationRef$curr3.conversationListRef) === null || _conversationRef$curr4 === void 0 ? void 0 : _conversationRef$curr4.updateLastMessage(data === null || data === void 0 ? void 0 : data.message);
});
_.CometChatMessageEvents.addListener(_.CometChatMessageEvents.onBackButtonClick, onBackButtonClickId, backButtonClickHandler);
return function () {
_CometChatConversationEvents.CometChatConversationEvents.removeListener(_CometChatConversationEvents.CometChatConversationEvents.onItemClick, onItemClickId);
_CometChatConversationEvents.CometChatConversationEvents.removeListener(_CometChatConversationEvents.CometChatConversationEvents.onDeleteConversation, onDeleteConversationId);
_CometChatConversationEvents.CometChatConversationEvents.removeListener(_.CometChatMessageEvents.onMessageRead, onMessageReadId);
_CometChatConversationEvents.CometChatConversationEvents.removeListener(_.CometChatMessageEvents.onMessageSent, onMessageSentId);
_CometChatConversationEvents.CometChatConversationEvents.removeListener(_.CometChatMessageEvents.onBackButtonClick, onBackButtonClickId);
};
}, [activeConversation]);
};
exports.Hooks = Hooks;