4.5 KiB
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- AddedDeleteConversation()andDeleteMessage()methodsgo-backend/internal/handlers/chat_handler.go- Added DELETE handler endpointsgo-backend/cmd/api/main.go- Registered DELETE routes
New API Endpoints:
DELETE /api/v1/conversations/:id- Permanently deletes conversation and all messagesDELETE /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- AddeddeleteConversation()anddeleteMessage()API methodssojorn_app/lib/services/secure_chat_service.dart- Updated to call backend DELETE APIsojorn_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:
- In your browser, press
Ror refresh the page - Or run:
flutter run -d chrome --web-port 8080
Testing the Fix
- Start a new conversation with another user
- Send a few test messages
- Click the 3-dot menu in the chat screen
- Select "Delete Chat"
- Verify the warning dialog shows:
- Red warning icon
- "PERMANENT DELETION" title
- List of what will be deleted
- Red warning box
- "DELETE PERMANENTLY" button
- Click "DELETE PERMANENTLY"
- 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