Skip to content

Commit 6f64d50

Browse files
committed
address chat and media review feedback
1 parent 4f0d766 commit 6f64d50

5 files changed

Lines changed: 12 additions & 15 deletions

File tree

supabase/functions/_shared/storage-utils.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,8 @@ export async function deleteStorageObject(
2424

2525
export async function deleteListingMedia(
2626
supabase: SupabaseClient,
27-
slug: string
27+
listing: ListingMedia | null
2828
) {
29-
// Service-role callers use this after authorising the requested listing operation.
30-
const { data: listing, error: fetchError } = await supabase
31-
.from("listings")
32-
.select("avatar, photos")
33-
.eq("slug", slug)
34-
.maybeSingle<ListingMedia>();
35-
36-
if (fetchError) throw fetchError;
3729
if (!listing) return;
3830

3931
const deletePromises = [];

supabase/functions/delete-account/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ serve(async (req) => {
7272
// Fetch all listings for the user to delete their avatars
7373
const { data: listings, error: listingsError } = await supabaseAdmin
7474
.from("listings")
75-
.select("slug")
75+
.select("slug, avatar, photos")
7676
.eq("owner_id", user.id);
7777
if (listingsError) {
7878
console.error("Listings fetch error:", listingsError);
@@ -86,7 +86,7 @@ serve(async (req) => {
8686
}
8787

8888
try {
89-
await deleteListingMedia(supabaseAdmin, listing.slug);
89+
await deleteListingMedia(supabaseAdmin, listing);
9090
} catch (error) {
9191
console.error(
9292
`Error deleting media for listing ${listing.slug}:`,

supabase/functions/delete-listing/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ serve(async (req) => {
6161

6262
const { data: listing, error: listingError } = await supabaseAdmin
6363
.from("listings")
64-
.select("id, owner_id")
64+
.select("id, owner_id, avatar, photos")
6565
.eq("slug", slug)
6666
.maybeSingle();
6767

@@ -72,7 +72,7 @@ serve(async (req) => {
7272
}
7373

7474
// Delete all media first
75-
await deleteListingMedia(supabaseAdmin, slug);
75+
await deleteListingMedia(supabaseAdmin, listing);
7676

7777
// Delete the listing
7878
const { data: deletedListing, error: deleteError } = await supabaseAdmin

supabase/functions/send-email-for-new-chat-message/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ const handler = async (_request: Request): Promise<Response> => {
152152
throw new Error(`No recipient found for message ${record.id}`);
153153
}
154154

155-
// Determine recipient's role in the chat (listing owner (host) or the thread initiator (donor)?)
156-
// This ternary seems opposite to what's logical, but it is correct somehow
155+
// recipientRole is the role of the email recipient, not the sender.
156+
// If the owner sent the message, the recipient is the initiator; otherwise the recipient is the owner.
157157
const recipientRole =
158158
threadData.owner_id === messageData.sender_id ? "initiator" : "owner";
159159

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Match the thread-start rate-limit predicate:
2+
-- initiator_id = <user> and created_at >= now() - interval '1 hour'.
3+
4+
create index if not exists chat_threads_initiator_id_created_at_idx
5+
on public.chat_threads (initiator_id, created_at desc);

0 commit comments

Comments
 (0)