@@ -855,8 +855,13 @@ const getPreviousEvent = (events, currentEventId, wrap = true) => {
855855// Get read for a specific user
856856const getReadForUser = function ( event , userId = null ) {
857857 const currentUserId = userId || this ?. ctx ?. data ?. currentUser ?. id
858- return event . imageReading ?. reads ?. [ currentUserId ] || null ;
859- } ;
858+
859+ if ( ! currentUserId ) {
860+ return null
861+ }
862+
863+ return event . imageReading ?. reads ?. [ currentUserId ] || null
864+ }
860865
861866/**
862867 * Get first event from an array that a user can read
@@ -865,7 +870,7 @@ const getReadForUser = function(event, userId = null) {
865870 * @param {Object } options - Additional options for eligibility
866871 * @returns {Object|null } First event user can read or null if none
867872 */
868- const getFirstUserReadableEvent = ( events , userId = null ) => {
873+ const getFirstUserReadableEvent = function ( events , userId = null ) {
869874 // Get user ID from context if not provided and we're in a template context
870875 const currentUserId = userId || ( this ?. ctx ?. data ?. currentUser ?. id )
871876
@@ -886,8 +891,13 @@ const getFirstUserReadableEvent = (events, userId = null) => {
886891const userHasReadEvent = function ( event , userId ) {
887892 const currentUserId = userId || ( this ?. ctx ?. data ?. currentUser ?. id )
888893
889- return ! ! getReadForUser ( event , currentUserId ) ;
890- } ;
894+ if ( ! currentUserId ) {
895+ console . warn ( 'userHasReadEvent: No userId provided and no context available' )
896+ return false
897+ }
898+
899+ return ! ! getReadForUser ( event , currentUserId )
900+ }
891901
892902/**
893903 * Check if current user can read an event
@@ -898,26 +908,30 @@ const userHasReadEvent = function(event, userId) {
898908 */
899909const canUserReadEvent = function ( event , userId = null , options = { } ) {
900910 const {
901- maxReadsPerEvent = 2 // Default max reads per event
902- } = options ;
911+ maxReadsPerEvent = 2
912+ } = options
903913
904914 const currentUserId = userId || ( this ?. ctx ?. data ?. currentUser ?. id )
905915
906- const metadata = getReadingMetadata ( event ) ;
916+ if ( ! currentUserId ) {
917+ console . warn ( 'canUserReadEvent: No userId provided and no context available' )
918+ return false
919+ }
920+
921+ const metadata = getReadingMetadata ( event )
907922
908923 // If we already have enough unique readers, no more reads needed
909924 if ( metadata . uniqueReaderCount >= maxReadsPerEvent ) {
910- return false ;
925+ return false
911926 }
912927
913928 // User can't read if they've already read it
914929 if ( userHasReadEvent ( event , currentUserId ) ) {
915- return false ;
930+ return false
916931 }
917932
918- // User can read if we haven't reached max readers and they haven't already read it
919- return true ;
920- } ;
933+ return true
934+ }
921935
922936/**
923937 * Check if an event has any reads
0 commit comments