@@ -2613,48 +2613,90 @@ const firstVisibleMsg = {
26132613
26142614 function ensureConversationForFileDrop() {
26152615 if (!fileDropConversationPromise) {
2616- var activeConversationId = getActiveConversationId();
2617- if (activeConversationId) {
2618- Kommunicate.openConversation(activeConversationId);
2619- } else {
2620- kommunicateIframe.classList.remove(
2621- 'km-iframe-dimension-with-popup',
2622- 'chat-popup-widget-horizontal'
2623- );
2624-
2625- kommunicateCommons.hide('#chat-popup-widget-container');
2626- kommunicateIframe.classList.add('km-iframe-dimension-no-popup');
2627- const conversationDetail = mckGroupLayout.createGroupDefaultSettings();
2628- mckMessageService.createNewConversation(
2629- conversationDetail,
2630- function (groupId) {
2631- /* Kommunicate.triggerEvent(KommunicateConstants.EVENT_IDS.WELCOME_MESSAGE, { "groupId": groupId, "applicationId": MCK_APP_ID });*/
2632- console.log('Conversation created for dropped file:', groupId);
2633- }
2634- );
2635- }
2616+ var expectedConversationId = null;
2617+ kommunicateIframe.classList.remove(
2618+ 'km-iframe-dimension-with-popup',
2619+ 'chat-popup-widget-horizontal'
2620+ );
2621+ kommunicateCommons.hide('#chat-popup-widget-container');
2622+ kommunicateCommons.setWidgetStateOpen(true);
2623+ kommunicateIframe.classList.remove('km-iframe-closed');
2624+ kommunicateIframe.classList.add('kommunicate-iframe-enable-media-query');
2625+ kommunicateCommons.hide('#applozic-badge-count');
2626+ kommunicateIframe.style.width = '';
2627+ POPUP_WIDGET
2628+ ? (kommunicateIframe.classList.add('km-iframe-dimension-with-popup'),
2629+ (popUpcloseButton.style.display = 'flex'))
2630+ : kommunicateIframe.classList.add('km-iframe-dimension-no-popup');
2631+
2632+ const conversationDetail = mckGroupLayout.createGroupDefaultSettings();
26362633
26372634 fileDropConversationPromise = new Promise(function (resolve, reject) {
26382635 var isResolved = false;
2639- var pollInterval = setInterval(function () {
2636+ var pollInterval = null;
2637+ var timeoutHandle = null;
2638+
2639+ function clearFileDropTimers() {
2640+ pollInterval && clearInterval(pollInterval);
2641+ timeoutHandle && clearTimeout(timeoutHandle);
2642+ }
2643+
2644+ function tryResolveWithActiveConversation() {
2645+ if (!expectedConversationId) {
2646+ return;
2647+ }
26402648 var activeConversationId = getActiveConversationId();
2641- if (activeConversationId) {
2649+ if (
2650+ activeConversationId &&
2651+ String(activeConversationId) === String(expectedConversationId)
2652+ ) {
26422653 isResolved = true;
2643- clearInterval(pollInterval);
2644- timeoutHandle && clearTimeout(timeoutHandle);
2654+ clearFileDropTimers();
26452655 resolve(activeConversationId);
26462656 }
2647- }, FILE_DROP_CONVERSATION_POLL_INTERVAL);
2648- var timeoutHandle = setTimeout(function () {
2657+ }
2658+
2659+ pollInterval = setInterval(
2660+ tryResolveWithActiveConversation,
2661+ FILE_DROP_CONVERSATION_POLL_INTERVAL
2662+ );
2663+
2664+ timeoutHandle = setTimeout(function () {
26492665 if (!isResolved) {
2650- clearInterval(pollInterval );
2666+ clearFileDropTimers( );
26512667 reject(
26522668 new Error(
26532669 'Timed out creating conversation for dropped file.'
26542670 )
26552671 );
26562672 }
26572673 }, FILE_DROP_CONVERSATION_TIMEOUT);
2674+ mckMessageService.createNewConversation(
2675+ conversationDetail,
2676+ function (groupId) {
2677+ // kommunicate.displayKommunicateWidget(true);
2678+ expectedConversationId = normalizeConversationId(groupId);
2679+ if (!expectedConversationId) {
2680+ isResolved = true;
2681+ clearFileDropTimers();
2682+ reject(
2683+ new Error(
2684+ 'Unable to determine conversation for dropped file.'
2685+ )
2686+ );
2687+ return;
2688+ }
2689+ try {
2690+ Kommunicate.openConversation(expectedConversationId);
2691+ } catch (error) {
2692+ console.error(
2693+ 'Unable to open conversation created for file drop:',
2694+ error
2695+ );
2696+ }
2697+ tryResolveWithActiveConversation();
2698+ }
2699+ );
26582700 });
26592701 }
26602702 return fileDropConversationPromise;
0 commit comments