|
| 1 | +create or replace view public.chat_threads_with_participants |
| 2 | +with (security_invoker = on) as |
| 3 | +select |
| 4 | + chat_threads.id, |
| 5 | + chat_threads.created_at, |
| 6 | + chat_threads.listing_id, |
| 7 | + chat_threads.initiator_id, |
| 8 | + chat_threads.owner_id, |
| 9 | + initiator.first_name as initiator_first_name, |
| 10 | + owner.first_name as owner_first_name, |
| 11 | + listings.slug as listing_slug, |
| 12 | + listings.avatar as listing_avatar, |
| 13 | + listings.name as listing_name, |
| 14 | + listings.type as listing_type, |
| 15 | + listings.area_name as listing_area_name, |
| 16 | + owner.avatar as owner_avatar, |
| 17 | + initiator.avatar as initiator_avatar, |
| 18 | + ( |
| 19 | + select count(*) >= 2 |
| 20 | + from public.listings as owner_listings |
| 21 | + where owner_listings.owner_id = chat_threads.owner_id |
| 22 | + and owner_listings.type in ('community', 'business') |
| 23 | + ) as owner_has_multiple_non_residential_listings |
| 24 | +from public.chat_threads |
| 25 | +join public.profiles as initiator on chat_threads.initiator_id = initiator.id |
| 26 | +join public.profiles as owner on chat_threads.owner_id = owner.id |
| 27 | +join public.listings on chat_threads.listing_id = listings.id; |
| 28 | + |
| 29 | +alter view public.chat_threads_with_participants owner to postgres; |
| 30 | + |
| 31 | +revoke all on table public.chat_threads_with_participants |
| 32 | + from anon, authenticated, service_role; |
| 33 | + |
| 34 | +grant select on table public.chat_threads_with_participants |
| 35 | + to authenticated, service_role; |
0 commit comments