mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Improvements to Flutter client (#1042)
* Chat improvements * Delete/reset account via API for Flutter app * Fix tests. * Add "contact us" to settings * Update mobile/lib/screens/chat_conversation_screen.dart Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Juan José Mata <jjmata@jjmata.com> * Improve LLM special token detection * Deactivated user shouldn't have API working * Fix tests * API-Key usage * Flutter app launch failure on no network * Handle deletion/reset delays * Local cached data may become stale * Use X-Api-Key correctly! --------- Signed-off-by: Juan José Mata <jjmata@jjmata.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -118,14 +118,11 @@ class ChatService {
|
||||
required String accessToken,
|
||||
String? title,
|
||||
String? initialMessage,
|
||||
String model = 'gpt-4',
|
||||
}) async {
|
||||
try {
|
||||
final url = Uri.parse('${ApiConfig.baseUrl}/api/v1/chats');
|
||||
|
||||
final body = <String, dynamic>{
|
||||
'model': model,
|
||||
};
|
||||
final body = <String, dynamic>{};
|
||||
|
||||
if (title != null) {
|
||||
body['title'] = title;
|
||||
|
||||
71
mobile/lib/services/user_service.dart
Normal file
71
mobile/lib/services/user_service.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'api_config.dart';
|
||||
|
||||
class UserService {
|
||||
Future<Map<String, dynamic>> resetAccount({
|
||||
required String accessToken,
|
||||
}) async {
|
||||
try {
|
||||
final url = Uri.parse('${ApiConfig.baseUrl}/api/v1/users/reset');
|
||||
|
||||
final response = await http.delete(
|
||||
url,
|
||||
headers: ApiConfig.getAuthHeaders(accessToken),
|
||||
).timeout(const Duration(seconds: 30));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return {'success': true};
|
||||
} else if (response.statusCode == 401) {
|
||||
return {
|
||||
'success': false,
|
||||
'error': 'Session expired. Please login again.',
|
||||
};
|
||||
} else {
|
||||
final responseData = jsonDecode(response.body);
|
||||
return {
|
||||
'success': false,
|
||||
'error': responseData['error'] ?? 'Failed to reset account',
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
'success': false,
|
||||
'error': 'Network error: ${e.toString()}',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> deleteAccount({
|
||||
required String accessToken,
|
||||
}) async {
|
||||
try {
|
||||
final url = Uri.parse('${ApiConfig.baseUrl}/api/v1/users/me');
|
||||
|
||||
final response = await http.delete(
|
||||
url,
|
||||
headers: ApiConfig.getAuthHeaders(accessToken),
|
||||
).timeout(const Duration(seconds: 30));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return {'success': true};
|
||||
} else if (response.statusCode == 401) {
|
||||
return {
|
||||
'success': false,
|
||||
'error': 'Session expired. Please login again.',
|
||||
};
|
||||
} else {
|
||||
final responseData = jsonDecode(response.body);
|
||||
return {
|
||||
'success': false,
|
||||
'error': responseData['error'] ?? 'Failed to delete account',
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
return {
|
||||
'success': false,
|
||||
'error': 'Network error: ${e.toString()}',
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user