@@ -16,10 +16,8 @@ const handler = async (_request: Request): Promise<Response> => {
1616 // Prepare data
1717 const { record } = await _request . json ( ) ;
1818 if ( ! record ) throw new Error ( "No record provided" ) ;
19- console . log ( "Record:" , record ) ;
2019
2120 const supabaseUrl = Deno . env . get ( "SUPABASE_URL" ) ;
22- console . log ( "Supabase URL:" , supabaseUrl ) ;
2321
2422 const supabaseServiceKey = Deno . env . get ( "SUPABASE_SERVICE_ROLE_KEY" ) ;
2523 if (
@@ -33,6 +31,7 @@ const handler = async (_request: Request): Promise<Response> => {
3331
3432 const supabase = createClient ( supabaseUrl , supabaseServiceKey ) ;
3533 const resend = new Resend ( RESEND_API_KEY ) ;
34+ console . log ( "Processing chat message email" , { messageId : record . id } ) ;
3635
3736 const { data : messageData , error : messageError } = await supabase
3837 . from ( "chat_messages" )
@@ -44,8 +43,6 @@ const handler = async (_request: Request): Promise<Response> => {
4443 throw new Error ( `Failed to fetch message data: ${ messageError ?. message } ` ) ;
4544 }
4645
47- console . log ( "Message Data:" , messageData ) ;
48-
4946 const { data : threadData , error : threadError } = await supabase
5047 . from ( "chat_threads" )
5148 . select ( "id, listing_id, initiator_id, owner_id" )
@@ -95,32 +92,21 @@ const handler = async (_request: Request): Promise<Response> => {
9592 const ownerProfile = profileById . get ( threadData . owner_id ) ;
9693
9794 const senderName = senderProfile ?. first_name ?? "Someone" ;
98- console . log ( "Sender name:" , senderName ) ;
9995
10096 const senderAvatar = senderProfile ?. avatar ;
101- console . log ( "Sender avatar:" , senderAvatar ) ;
10297
10398 const listingAvatar = listingData . avatar ;
104- console . log ( "Listing avatar:" , listingAvatar ) ;
10599
106100 const listingSlug = listingData . slug ?? "" ;
107- console . log ( "Listing slug:" , listingSlug ) ;
108101
109102 const listingName = listingData . name ;
110- console . log ( "Listing name:" , listingName ) ;
111103
112104 const listingType = listingData . type ;
113- console . log ( "Listing type:" , listingType ) ;
114105
115106 const listingAreaName = listingData . area_name ?? "" ;
116- console . log ( "Listing area name:" , listingAreaName ) ;
117107
118108 const ownerHasMultipleNonResidentialListings =
119109 listingData . owner_has_multiple_non_residential_listings ;
120- console . log (
121- "Owner has multiple non-residential listings:" ,
122- ownerHasMultipleNonResidentialListings
123- ) ;
124110
125111 // Determine recipient_id (the user who isn't the sender)
126112 const recipientId =
@@ -152,7 +138,6 @@ const handler = async (_request: Request): Promise<Response> => {
152138 avatarMajorUrl = senderAvatar ;
153139 avatarMajorBucket = "avatars" ;
154140 avatarMinorUrl = null ; // No secondary avatar needed
155- console . log ( "Recipient is owner. Showing sender avatar:" , senderAvatar ) ;
156141 } else {
157142 // If the recipient is the initiator (donor/guest)
158143 if ( listingType === "residential" ) {
@@ -161,39 +146,23 @@ const handler = async (_request: Request): Promise<Response> => {
161146 avatarMajorUrl = senderAvatar ;
162147 avatarMajorBucket = "avatars" ;
163148 avatarMinorUrl = null ; // No secondary avatar needed
164- console . log (
165- "Recipient is initiator (residential). Showing sender avatar:" ,
166- senderAvatar
167- ) ;
168149 } else {
169150 // For non-residential listings, show the listing's avatar as primary
170151 // and the sender's (host's) avatar as secondary.
171152 avatarMajorUrl = listingAvatar ;
172153 avatarMajorBucket = "listing_avatars" ;
173154 avatarMinorUrl = senderAvatar ;
174- console . log (
175- "Recipient is initiator (non-residential). Showing listing avatar:" ,
176- listingAvatar ,
177- "and sender avatar:" ,
178- senderAvatar
179- ) ;
180155 }
181156 }
182157
183- console . log ( "Sender ID from chat_messages:" , record . sender_id ) ;
184- console . log ( "Recipient ID from chat_threads:" , recipientId ) ;
185- console . log ( "Message:" , record . content ) ;
186- console . log ( "Recipient Role:" , recipientRole ) ;
187-
188158 // Do auth admin query to get recipient email (keeping this pattern for security)
189159 // TODO: Minify this query to just ask for the email address
190160 const { data : recipientData , error : recipientError } =
191161 await supabase . auth . admin . getUserById ( recipientId ) ;
192- console . log ( "Recipient data:" , recipientData ) ;
193- if ( recipientError ) console . log ( "Recipient error:" , recipientError ) ;
162+ if ( recipientError )
163+ console . error ( "Recipient lookup error:" , recipientError ) ;
194164
195165 const recipientEmail = recipientData ?. user ?. email ;
196- console . log ( "Recipient Email:" , recipientEmail ) ;
197166
198167 if ( ! recipientEmail ) {
199168 throw new Error ( `No email found for recipient ${ recipientId } ` ) ;
0 commit comments