sojorn/_legacy/supabase/migrations/20260121_create_user_settings.sql
Patrick Britton 3c4680bdd7 Initial commit: Complete threaded conversation system with inline replies
**Major Features Added:**
- **Inline Reply System**: Replace compose screen with inline reply boxes
- **Thread Navigation**: Parent/child navigation with jump functionality
- **Chain Flow UI**: Reply counts, expand/collapse animations, visual hierarchy
- **Enhanced Animations**: Smooth transitions, hover effects, micro-interactions

 **Frontend Changes:**
- **ThreadedCommentWidget**: Complete rewrite with animations and navigation
- **ThreadNode Model**: Added parent references and descendant counting
- **ThreadedConversationScreen**: Integrated navigation handlers
- **PostDetailScreen**: Replaced with threaded conversation view
- **ComposeScreen**: Added reply indicators and context
- **PostActions**: Fixed visibility checks for chain buttons

 **Backend Changes:**
- **API Route**: Added /posts/:id/thread endpoint
- **Post Repository**: Include allow_chain and visibility fields in feed
- **Thread Handler**: Support for fetching post chains

 **UI/UX Improvements:**
- **Reply Context**: Clear indication when replying to specific posts
- **Character Counting**: 500 character limit with live counter
- **Visual Hierarchy**: Depth-based indentation and styling
- **Smooth Animations**: SizeTransition, FadeTransition, hover states
- **Chain Navigation**: Parent/child buttons with visual feedback

 **Technical Enhancements:**
- **Animation Controllers**: Proper lifecycle management
- **State Management**: Clean separation of concerns
- **Navigation Callbacks**: Reusable navigation system
- **Error Handling**: Graceful fallbacks and user feedback

This creates a Reddit-style threaded conversation experience with smooth
animations, inline replies, and intuitive navigation between posts in a chain.
2026-01-30 07:40:19 -06:00

62 lines
1.8 KiB
PL/PgSQL

-- Create user_settings table (if missing) and backfill rows
create table if not exists user_settings (
user_id uuid primary key references profiles(id) on delete cascade,
default_post_ttl interval,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_user_settings_user_id on user_settings(user_id);
alter table user_settings enable row level security;
drop policy if exists user_settings_select on user_settings;
create policy user_settings_select on user_settings
for select using (auth.uid() = user_id);
drop policy if exists user_settings_insert on user_settings;
create policy user_settings_insert on user_settings
for insert with check (auth.uid() = user_id);
drop policy if exists user_settings_update on user_settings;
create policy user_settings_update on user_settings
for update using (auth.uid() = user_id);
drop policy if exists user_settings_delete on user_settings;
create policy user_settings_delete on user_settings
for delete using (auth.uid() = user_id);
-- Backfill missing settings rows for existing users
insert into user_settings (user_id)
select p.id
from profiles p
where not exists (
select 1 from user_settings us where us.user_id = p.id
);
-- Ensure new users get settings row
create or replace function handle_new_user()
returns trigger
language plpgsql
security definer
as $$
begin
insert into public.profiles (id, handle, display_name)
values (
new.id,
coalesce(new.raw_user_meta_data->>'handle', new.email),
coalesce(new.raw_user_meta_data->>'display_name', new.email)
);
insert into public.trust_state (user_id, harmony_score, tier, posts_today)
values (new.id, 50, 'new', 0);
insert into public.user_settings (user_id)
values (new.id)
on conflict (user_id) do nothing;
return new;
end;
$$;