Skip to content

Commit 9be61bf

Browse files
KMchaudharyKMchaudharysubodhr258
authored
Revert the GoDAM engagement features gated via "rtgodam_enable_engagement_feature" filter (#1832)
* Revert the GoDAM engagement features * feat: Add support for engagements parameter in video embed functionality * Add rtgodam_enable_engagement_feature hook to Enable engagement feature conditionally across video and gallery components * fix: Adjust handling of 'engagements' attribute for correct boolean parsing * Resolve copilot comments * fix: Update migration for engagements feature * fix: Update engagement defaults * Fix the engagment for non-transcoded videos, and non valid api key * Revert "fix: Update engagement defaults" This reverts commit 1f3289e. * Fix the status comparison by converting to lowercase --------- Co-authored-by: KMchaudhary <kuldipkumar.chaudhary@rtcamp.com> Co-authored-by: Subodh Rajpopat <subodh.rajpopat@rtcamp.com>
1 parent 45b10da commit 9be61bf

16 files changed

Lines changed: 228 additions & 18 deletions

File tree

assets/src/blocks/godam-gallery-v2/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
"performanceMode": {
7676
"type": "string",
7777
"default": "balanced"
78+
},
79+
"engagements": {
80+
"type": "boolean",
81+
"default": true
7882
}
7983
},
8084
"providesContext": {

assets/src/blocks/godam-gallery-v2/edit.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
207207
showTitle,
208208
layout,
209209
performanceMode,
210+
engagements,
210211
} = attributes;
212+
const engagementFeatureEnabled = window?.godamSettings?.engagementFeatureEnabled ?? false;
213+
const showEngagementSetting = engagementFeatureEnabled && ( window?.godamSettings?.enableGlobalVideoEngagement ?? false );
211214
const [ startDatePopoverOpen, setStartDatePopoverOpen ] = useState( false );
212215
const [ endDatePopoverOpen, setEndDatePopoverOpen ] = useState( false );
213216
const [ dateError, setDateError ] = useState( '' );
@@ -596,6 +599,16 @@ export default function Edit( { attributes, setAttributes, clientId } ) {
596599
checked={ !! showTitle }
597600
onChange={ ( value ) => setAttributes( { showTitle: value } ) }
598601
/>
602+
{
603+
showEngagementSetting && (
604+
<ToggleControl
605+
label={ __( 'Enable Likes & Comments', 'godam' ) }
606+
checked={ !! engagements }
607+
onChange={ ( value ) => setAttributes( { engagements: value } ) }
608+
help={ __( 'Engagement will only be visible for transcoded videos', 'godam' ) }
609+
/>
610+
)
611+
}
599612
<SelectControl
600613
label={ __( 'Performance', 'godam' ) }
601614
value={ performanceMode || 'balanced' }

assets/src/blocks/godam-gallery-v2/render.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ function godam_gallery_v2_get_video_data( $attachment_id ) {
254254
'data-layout' => $godam_layout,
255255
'data-ratio' => $godam_view_ratio,
256256
'data-embed-base-url' => home_url( '/' ),
257+
'data-engagements' => rtgodam_is_engagement_feature_enabled() && ! empty( $attributes['engagements'] ) ? 'show' : '',
257258
)
258259
);
259260

assets/src/blocks/godam-gallery-v2/view.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const { __ } = require( '@wordpress/i18n' );
163163
this.element = element;
164164
this.mode = element.dataset.mode || 'handpicked';
165165
this.embedBaseUrl = element.dataset.embedBaseUrl || '/';
166+
this.engagements = element.dataset.engagements || '';
166167
this.currentIndex = -1;
167168
this.previouslyFocusedElement = null;
168169
this.isLoading = false;
@@ -363,7 +364,8 @@ const { __ } = require( '@wordpress/i18n' );
363364

364365
this.currentIndex = index;
365366
activeGallery = this;
366-
this.modal.iframe.src = `${ this.embedBaseUrl }?godam_page=video-embed&id=${ encodeURIComponent( videoId ) }&godam_gallery=1`;
367+
const engagementsParam = this.engagements === 'show' ? '&engagements=show' : '';
368+
this.modal.iframe.src = `${ this.embedBaseUrl }?godam_page=video-embed&id=${ encodeURIComponent( videoId ) }&godam_gallery=1${ engagementsParam }`;
367369
this.modal.overlay.classList.add( 'is-active' );
368370
this.modal.modal.classList.add( 'is-active' );
369371
this.modal.closeButton.classList.add( 'is-active' );

assets/src/blocks/godam-player/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
"type": "boolean",
114114
"default": false
115115
},
116+
"engagements": {
117+
"type": "boolean",
118+
"default": false
119+
},
116120
"playerHeight": {
117121
"type": "string",
118122
"default": ""

assets/src/blocks/godam-player/edit-common-settings.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ const resolveLegacyPerformanceMode = ( preload, preloadPoster ) => {
4242
* @return {WPElement} The video settings component.
4343
*/
4444
const VideoSettings = ( { setAttributes, attributes, isInsideQueryLoop = false } ) => {
45-
const { autoplay, controls, loop, muted, preload, preloadPoster, performanceMode, showShareButton } =
45+
const { autoplay, controls, loop, muted, preload, preloadPoster, performanceMode, showShareButton, engagements } =
4646
attributes;
4747
const showShareButtonSetting = window?.godamSettings?.enableGlobalVideoShare ?? false;
48+
const engagementFeatureEnabled = window?.godamSettings?.engagementFeatureEnabled ?? false;
49+
const showEngagementSetting = engagementFeatureEnabled && ( window?.godamSettings?.enableGlobalVideoEngagement ?? false );
4850

4951
// Show a specific help for autoplay setting.
5052
const getAutoplayHelp = useMemo( () => {
@@ -77,6 +79,7 @@ const VideoSettings = ( { setAttributes, attributes, isInsideQueryLoop = false }
7779
muted: toggleAttribute( 'muted' ),
7880
controls: toggleAttribute( 'controls' ),
7981
showShareButton: toggleAttribute( 'showShareButton' ),
82+
engagements: toggleAttribute( 'engagements' ),
8083
};
8184
}, [ setAttributes ] );
8285

@@ -152,6 +155,17 @@ const VideoSettings = ( { setAttributes, attributes, isInsideQueryLoop = false }
152155
help={ performanceHelpText[ selectedPerformanceMode ] }
153156
/>
154157
) }
158+
{
159+
showEngagementSetting && (
160+
<ToggleControl
161+
__nextHasNoMarginBottom
162+
label={ __( 'Enable Likes & Comments', 'godam' ) }
163+
onChange={ toggleFactory.engagements }
164+
checked={ !! engagements }
165+
help={ __( 'Engagement will only be visible for transcoded videos', 'godam' ) }
166+
/>
167+
)
168+
}
155169
</>
156170
);
157171
};

assets/src/js/godam-video-embed.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,107 @@ document.addEventListener( 'godamAllPlayersReady', () => {
339339
}
340340
} );
341341
} );
342+
343+
/**
344+
* Render CommentBox component on video embed page by default.
345+
*
346+
* @since 1.5.0
347+
*/
348+
document.addEventListener( 'DOMContentLoaded', function() {
349+
const embedElement = document.querySelector( '.godam-video-embed' );
350+
351+
if ( embedElement?.getAttribute( 'data-show-engagements' ) !== 'true' ) {
352+
return;
353+
}
354+
355+
const urlParams = new URLSearchParams( window.location.search );
356+
357+
const videoId = urlParams.get( 'id' );
358+
359+
if ( ! videoId ) {
360+
return;
361+
}
362+
363+
const videoIdNum = parseInt( videoId, 10 );
364+
if ( ! videoIdNum || isNaN( videoIdNum ) ) {
365+
return;
366+
}
367+
368+
// Create and show loading overlay
369+
const loadingOverlay = document.createElement( 'div' );
370+
loadingOverlay.className = 'godam-video-embed-loading';
371+
372+
// Create spinner element
373+
const spinner = document.createElement( 'div' );
374+
spinner.className = 'godam-video-embed-spinner';
375+
loadingOverlay.appendChild( spinner );
376+
377+
document.body.appendChild( loadingOverlay );
378+
379+
// Function to hide loading overlay
380+
const hideLoadingOverlay = () => {
381+
if ( loadingOverlay && loadingOverlay.parentNode ) {
382+
loadingOverlay.style.opacity = '0';
383+
loadingOverlay.style.pointerEvents = 'none';
384+
loadingOverlay.style.transition = 'opacity 0.3s ease-out';
385+
setTimeout( () => {
386+
loadingOverlay.remove();
387+
}, 300 );
388+
}
389+
};
390+
391+
// Fallback: remove the overlay after 10 s in case the engagement store
392+
// event never fires or renderCommentBox() exits early.
393+
const overlayFallbackTimer = setTimeout( hideLoadingOverlay, 10000 );
394+
395+
// Listen for the engagement store to be initialized (once only).
396+
document.addEventListener( 'godamEngagementStoreInitialized', renderCommentBox, { once: true } );
397+
398+
// Render the comment box.
399+
function renderCommentBox() {
400+
// Always clear the fallback timer — we are now handling the overlay ourselves.
401+
clearTimeout( overlayFallbackTimer );
402+
403+
// Check WordPress dependencies
404+
if ( typeof wp === 'undefined' || ! wp.data || ! wp.element?.createRoot ) {
405+
hideLoadingOverlay();
406+
return;
407+
}
408+
409+
const storeName = 'godam-video-engagement';
410+
const select = wp.data.select( storeName );
411+
const dispatch = wp.data.dispatch( storeName );
412+
413+
if ( ! select || ! dispatch ) {
414+
hideLoadingOverlay();
415+
return;
416+
}
417+
418+
// Find video element and get instance ID
419+
const videoElement = document.querySelector( `.easydam-player.video-js[data-id="${ videoIdNum }"]` );
420+
const videoInstanceId = videoElement?.getAttribute( 'data-instance-id' );
421+
422+
if ( ! videoInstanceId ) {
423+
hideLoadingOverlay();
424+
return;
425+
}
426+
427+
// Get site URL
428+
const siteUrl = window.location.origin;
429+
430+
// Determine if engagements should be shown
431+
const skipEngagements = embedElement?.getAttribute( 'data-show-engagements' ) !== 'true';
432+
433+
// Dispatch action to initiate comment modal
434+
dispatch.initiateCommentModal(
435+
videoIdNum.toString(),
436+
siteUrl,
437+
`engagement-${ videoInstanceId }`,
438+
skipEngagements,
439+
true,
440+
);
441+
442+
// Hide loading overlay after modal is initiated
443+
hideLoadingOverlay();
444+
}
445+
} );

inc/classes/class-assets.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ private function enqueue_godam_settings() {
386386
$brand_image = $godam_settings['video_player']['brand_image'] ?? '';
387387
$brand_color = $godam_settings['video_player']['brand_color'] ?? '';
388388
$enable_gtm_tracking = $godam_settings['general']['enable_gtm_tracking'] ?? false;
389+
$engagement_feature_enabled = rtgodam_is_engagement_feature_enabled();
389390
$enable_global_video_engagement = $godam_settings['video']['enable_global_video_engagement'] ?? true;
390391
$enable_global_share = $godam_settings['video']['enable_global_video_share'] ?? true;
391392

@@ -396,7 +397,8 @@ private function enqueue_godam_settings() {
396397
'apiBase' => RTGODAM_API_BASE,
397398
'enableGTMTracking' => $enable_gtm_tracking,
398399
'videoPostSettings' => get_option( 'rtgodam_video_post_settings', array() ),
399-
'enableGlobalVideoEngagement' => $enable_global_video_engagement,
400+
'engagementFeatureEnabled' => $engagement_feature_enabled,
401+
'enableGlobalVideoEngagement' => $engagement_feature_enabled ? $enable_global_video_engagement : false,
400402
'enableGlobalVideoShare' => $enable_global_share,
401403

402404
);

inc/classes/class-video-engagement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public function add_engagement_to_video( $attributes, $instance_id, $easydam_met
149149
* @return bool True if engagements are enabled, otherwise false.
150150
*/
151151
public function check_if_engagements_enabled( $attachment_id, $attributes ) {
152+
if ( ! rtgodam_is_engagement_feature_enabled() ) {
153+
return false;
154+
}
152155

153156
if ( empty( $attachment_id ) || ! isset( $attributes['engagements'] ) ) {
154157
return false;

inc/classes/migrations/class-gallery-v1-to-v2.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* | category | (dropped) | V2 query does not support category filter |
3737
* | tag | (dropped) | V2 query does not support tag filter |
3838
* | search | (dropped) | V2 query does not support search filter |
39-
* | engagements | (dropped) | V2 does not have engagement support |
39+
* | engagements | engagements | direct pass-through |
4040
* | openToNewPage | (dropped) | V2 does not have single-page linking |
4141
*/
4242
class Gallery_V1_To_V2 {
@@ -374,6 +374,7 @@ private static function convert_block_match( array $block_match ) {
374374
'customDateStart' => '',
375375
'customDateEnd' => '',
376376
'showTitle' => true,
377+
'engagements' => true,
377378
);
378379

379380
$diff = array();
@@ -422,6 +423,7 @@ private static function map_attributes( array $v1 ) {
422423
'customDateStart',
423424
'customDateEnd',
424425
'showTitle',
426+
'engagements',
425427
);
426428

427429
foreach ( $passthrough as $key ) {
@@ -446,7 +448,7 @@ private static function map_attributes( array $v1 ) {
446448

447449
/*
448450
* Intentionally dropped (no equivalent in V2):
449-
* category, tag, search, engagements, openToNewPage, include.
451+
* category, tag, search, openToNewPage, include.
450452
*/
451453

452454
return $v2;

0 commit comments

Comments
 (0)