sojorn/sojorn_docs/legacy/CHAT_DELETE_DEPLOYMENT.md
Patrick Britton 38653f5854 Sojorn Backend Finalization & Cleanup - Complete Migration from Supabase
##  Phase 1: Critical Feature Completion (Beacon Voting)
- Add VouchBeacon, ReportBeacon, RemoveBeaconVote methods to PostRepository
- Implement beacon voting HTTP handlers with confidence score calculations
- Register new beacon routes: /beacons/:id/vouch, /beacons/:id/report, /beacons/:id/vouch (DELETE)
- Auto-flag beacons at 5+ reports, confidence scoring (0.5 base + 0.1 per vouch)

##  Phase 2: Feed Logic & Post Distribution Integrity
- Verify unified feed logic supports all content types (Standard, Quips, Beacons)
- Ensure proper distribution: Profile Feed + Main/Home Feed for followers
- Beacon Map integration for location-based content
- Video content filtering for Quips feed

##  Phase 3: The Notification System
- Create comprehensive NotificationService with FCM integration
- Add CreateNotification method to NotificationRepository
- Implement smart deep linking: beacon_map, quip_feed, main_feed
- Trigger notifications for beacon interactions and cross-post comments
- Push notification logic with proper content type detection

##  Phase 4: The Great Supabase Purge
- Delete function_proxy.go and remove /functions/:name route
- Remove SupabaseURL, SupabaseKey from config.go
- Remove SupabaseID field from User model
- Clean all Supabase imports and dependencies
- Sanitize codebase of legacy Supabase references

##  Phase 5: Flutter Frontend Integration
- Implement vouchBeacon(), reportBeacon(), removeBeaconVote() in ApiService
- Replace TODO delay in video_comments_sheet.dart with actual publishComment call
- Fix compilation errors (named parameters, orphaned child properties)
- Complete frontend integration with Go API endpoints

##  Additional Improvements
- Fix compilation errors in threaded_comment_widget.dart (orphaned child property)
- Update video_comments_sheet.dart to use proper named parameters
- Comprehensive error handling and validation
- Production-ready notification system with deep linking

##  Migration Status: 100% Complete
- Backend: Fully migrated from Supabase to custom Go/Gin API
- Frontend: Integrated with new Go endpoints
- Notifications: Complete FCM integration with smart routing
- Database: Clean of all Supabase dependencies
- Features: All functionality preserved and enhanced

Ready for VPS deployment and production testing!
2026-01-30 09:24:31 -06:00

4.5 KiB

Chat Deletion Feature - Deployment Guide

Summary

Fixed the chat deletion functionality to make it permanent with proper warnings. Users now get a clear warning dialog before deletion, and the system removes data from both the server database and local IndexedDB storage.


Changes Made

1. Backend (Go) - DELETE Endpoints Added

Files Modified:

  • go-backend/internal/repository/chat_repository.go - Added DeleteConversation() and DeleteMessage() methods
  • go-backend/internal/handlers/chat_handler.go - Added DELETE handler endpoints
  • go-backend/cmd/api/main.go - Registered DELETE routes

New API Endpoints:

  • DELETE /api/v1/conversations/:id - Permanently deletes conversation and all messages
  • DELETE /api/v1/messages/:id - Permanently deletes a single message

Security:

  • Verifies user is a participant before allowing deletion
  • Returns 401 Unauthorized if user doesn't have permission

2. Flutter App - Permanent Deletion

Files Modified:

  • sojorn_app/lib/services/api_service.dart - Added deleteConversation() and deleteMessage() API methods
  • sojorn_app/lib/services/secure_chat_service.dart - Updated to call backend DELETE API
  • sojorn_app/lib/screens/secure_chat/secure_chat_screen.dart - Enhanced warning dialog

Key Changes:

  • Delete now removes data from both server database and local IndexedDB
  • New warning dialog with:
    • ⚠️ Red warning icon and "PERMANENT DELETION" title
    • Bullet points showing what will be deleted
    • Red warning box stating "THIS ACTION CANNOT BE UNDONE"
    • Red "DELETE PERMANENTLY" button
    • Cannot be dismissed by tapping outside
  • Loading indicator during deletion
  • Success/error feedback

Deployment Steps

Step 1: Delete All Existing Chats from Database

SSH into your server:

ssh -i "C:\Users\Patrick\.ssh\mpls.pem" patrick@194.238.28.122

Password: P22k154ever!

Run the SQL script:

sudo -u postgres psql sojorn

Then paste this SQL:

BEGIN;

-- Delete all messages first (foreign key dependency)
DELETE FROM public.secure_messages;

-- Delete all conversations
DELETE FROM public.encrypted_conversations;

COMMIT;

-- Verify deletion
SELECT COUNT(*) as message_count FROM public.secure_messages;
SELECT COUNT(*) as conversation_count FROM public.encrypted_conversations;

Expected output:

message_count: 0
conversation_count: 0

Type \q to exit psql.

Step 2: Deploy Go Backend

From your local machine, deploy the updated backend:

cd c:\Webs\Sojorn\go-backend
.\scripts\deploy.sh

Or manually:

# On server
cd /home/patrick/sojorn-backend
git pull
go build -o sojorn-api ./cmd/api
sudo systemctl restart sojorn-api
sudo systemctl status sojorn-api

Step 3: Hot Restart Flutter App

No deployment needed - just hot restart the Flutter web app:

  1. In your browser, press R or refresh the page
  2. Or run: flutter run -d chrome --web-port 8080

Testing the Fix

  1. Start a new conversation with another user
  2. Send a few test messages
  3. Click the 3-dot menu in the chat screen
  4. Select "Delete Chat"
  5. Verify the warning dialog shows:
    • Red warning icon
    • "PERMANENT DELETION" title
    • List of what will be deleted
    • Red warning box
    • "DELETE PERMANENTLY" button
  6. Click "DELETE PERMANENTLY"
  7. Verify:
    • Loading indicator appears
    • Success message shows
    • Chat screen closes
    • Conversation is removed from list
    • Messages are gone from database (check with SQL)
    • Messages are gone from IndexedDB (check browser DevTools > Application > IndexedDB)

What's Fixed

Before:

  • Delete only removed local IndexedDB data
  • Server data remained (encrypted messages still in DB)
  • Weak warning dialog
  • Deletion wasn't permanent
  • Other user could still see messages

After:

  • Deletes from both server database and local storage
  • Strong warning dialog with multiple warnings
  • PERMANENT deletion - cannot be undone
  • Both users lose all messages
  • Proper loading and error handling
  • Authorization checks (only participants can delete)

SQL Script Location

The SQL script to delete all chats is saved at: c:\Webs\Sojorn\migrations_archive\delete_all_chats.sql


Notes

  • The E2EE key fixes from earlier are still in place
  • Users will need to hot restart to get the new OTK fixes
  • After deleting all chats, users can start fresh with properly working E2EE
  • The delete function now works correctly for future conversations