Skip to content

Commit f0d76fe

Browse files
committed
address copilot followups
1 parent 3e45e07 commit f0d76fe

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

src/components/ListingRead/ListingRead.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ const ListingRead = memo(function Listing({
9595
const demoListing = isDemoListing(listing) ? listing : null;
9696
const rawRealListing =
9797
!isDemo && listing && !isDemoListing(listing) ? (listing as Listing) : null;
98-
const realListing = rawRealListing
99-
? getAnonymousSensitiveListingTeaser(rawRealListing, user)
100-
: null;
98+
const realListing = useMemo(
99+
() =>
100+
rawRealListing
101+
? getAnonymousSensitiveListingTeaser(rawRealListing, user)
102+
: null,
103+
[rawRealListing, user]
104+
);
101105
const listingForDisplay = demoListing ?? realListing;
102106

103107
// Load existing thread if any (only if not in demo mode). Depend on the

src/features/chat/chatData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ async function fetchListingContactCards(
139139

140140
const { data, error } = await supabase
141141
.from("listing_contact_cards")
142-
.select("*")
142+
.select(
143+
"id, owner_id, owner_first_name, owner_avatar, owner_has_multiple_non_residential_listings, type, area_name, name, slug, avatar"
144+
)
143145
.in("id", listingIds);
144146

145147
if (error) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- Follow-up fixes from Copilot review.
2+
3+
drop index if exists public.chat_messages_thread_id_created_at_idx;
4+
5+
create or replace function public.latest_chat_messages_for_threads(thread_ids uuid[])
6+
returns table(
7+
id uuid,
8+
content text,
9+
created_at timestamp with time zone,
10+
read_at timestamp with time zone,
11+
sender_id uuid,
12+
thread_id uuid
13+
)
14+
language sql
15+
security invoker
16+
stable
17+
set search_path = ''
18+
as $$
19+
select distinct on (chat_messages.thread_id)
20+
chat_messages.id,
21+
chat_messages.content,
22+
chat_messages.created_at,
23+
chat_messages.read_at,
24+
chat_messages.sender_id,
25+
chat_messages.thread_id
26+
from public.chat_messages
27+
where (
28+
(select auth.role()) = 'service_role'
29+
or (select auth.uid()) is not null
30+
)
31+
and chat_messages.thread_id = any(thread_ids)
32+
order by chat_messages.thread_id, chat_messages.created_at desc, chat_messages.id desc
33+
$$;
34+
35+
alter function public.latest_chat_messages_for_threads(uuid[]) owner to postgres;
36+
37+
revoke all privileges on function public.latest_chat_messages_for_threads(uuid[])
38+
from anon, authenticated, public;
39+
40+
grant execute on function public.latest_chat_messages_for_threads(uuid[])
41+
to authenticated, service_role;

0 commit comments

Comments
 (0)