sojorn/sojorn_app/lib/providers/quip_upload_provider.dart
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

128 lines
3.7 KiB
Dart

import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart';
import 'package:ffmpeg_kit_flutter_new/return_code.dart';
import 'package:path_provider/path_provider.dart';
import '../services/auth_service.dart';
import '../services/api_service.dart';
import '../services/image_upload_service.dart';
// Define the state class
class QuipUploadState {
final bool isUploading;
final double progress;
final String? error;
final String? successMessage;
QuipUploadState({
required this.isUploading,
required this.progress,
this.error,
this.successMessage,
});
QuipUploadState copyWith({
bool? isUploading,
double? progress,
String? error,
String? successMessage,
}) {
return QuipUploadState(
isUploading: isUploading ?? this.isUploading,
progress: progress ?? this.progress,
error: error,
successMessage: successMessage,
);
}
}
// Create a Notifier class for Riverpod 3.2.0+
class QuipUploadNotifier extends Notifier<QuipUploadState> {
@override
QuipUploadState build() {
return QuipUploadState(isUploading: false, progress: 0.0);
}
Future<void> startUpload(File videoFile, String caption) async {
try {
state = state.copyWith(
isUploading: true, progress: 0.0, error: null, successMessage: null);
final auth = AuthService.instance;
final uid = auth.currentUser?.id;
if (uid == null) {
throw Exception('User not authenticated');
}
final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
// Generate thumbnail using FFmpeg
final tempDir = await getTemporaryDirectory();
final thumbnailPath = '${tempDir.path}/${timestamp}_thumb.jpg';
final session = await FFmpegKit.execute(
'-y -ss 00:00:01 -i "${videoFile.path}" -vframes 1 -q:v 5 "$thumbnailPath"'
);
final returnCode = await session.getReturnCode();
if (!ReturnCode.isSuccess(returnCode)) {
throw Exception('Failed to generate thumbnail via FFmpeg');
}
final thumbnail = File(thumbnailPath);
if (!await thumbnail.exists()) {
throw Exception('Thumbnail file mismatch');
}
state = state.copyWith(progress: 0.1);
final uploadService = ImageUploadService();
// Upload video to Go Backend / R2
final videoUrl = await uploadService.uploadVideo(
videoFile,
onProgress: (p) => state = state.copyWith(progress: 0.1 + (p * 0.4)),
);
state = state.copyWith(progress: 0.5);
// Upload thumbnail to Go Backend / R2
String? thumbnailUrl;
try {
thumbnailUrl = await uploadService.uploadImage(
thumbnail,
onProgress: (p) => state = state.copyWith(progress: 0.5 + (p * 0.3)),
);
print('Thumbnail uploaded: $thumbnailUrl');
} catch (e) {
print('Thumbnail upload failed: $e');
// Continue without thumbnail - video is more important
}
state = state.copyWith(progress: 0.8);
// Publish post via Go API
// Video goes to video_url, thumbnail to thumbnail_url
await ApiService.instance.publishPost(
body: caption,
videoUrl: videoUrl,
thumbnailUrl: thumbnailUrl,
categoryId: null, // Default
);
state = state.copyWith(
isUploading: false,
progress: 1.0,
successMessage: 'Upload successful');
} catch (e) {
state = state.copyWith(isUploading: false, error: e.toString());
}
}
}
// Create the provider using the new Riverpod 3.2.0+ syntax
final quipUploadProvider =
NotifierProvider<QuipUploadNotifier, QuipUploadState>(
QuipUploadNotifier.new,
);