chat support download updated
This commit is contained in:
@@ -24,27 +24,25 @@ class ChatService {
|
||||
Future<void> sendMessage(
|
||||
int ticketId, {
|
||||
String? message,
|
||||
String? filePath,
|
||||
String? clientId,
|
||||
}) async {
|
||||
final form = FormData();
|
||||
|
||||
if (message != null) form.fields.add(MapEntry('message', message));
|
||||
if (filePath != null) {
|
||||
form.files.add(
|
||||
MapEntry(
|
||||
'file',
|
||||
await MultipartFile.fromFile(filePath),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (clientId != null) form.fields.add(MapEntry('client_id', clientId));
|
||||
|
||||
await dio.post('/user/chat/send/$ticketId', data: form);
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------
|
||||
// SEND FILE (image/video/pdf/excel)
|
||||
// ---------------------------
|
||||
Future<void> sendFile(int ticketId, File file) async {
|
||||
Future<Map<String, dynamic>> sendFile(
|
||||
int ticketId,
|
||||
File file, {
|
||||
required Function(double) onProgress,
|
||||
}) async {
|
||||
final formData = FormData.fromMap({
|
||||
'file': await MultipartFile.fromFile(
|
||||
file.path,
|
||||
@@ -52,13 +50,20 @@ class ChatService {
|
||||
),
|
||||
});
|
||||
|
||||
await dio.post(
|
||||
final res = await dio.post(
|
||||
"/user/chat/send/$ticketId",
|
||||
|
||||
data: formData,
|
||||
options: Options(
|
||||
headers: {'Content-Type': 'multipart/form-data'},
|
||||
),
|
||||
onSendProgress: (sent, total) {
|
||||
if (total > 0) {
|
||||
onProgress(sent / total);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return Map<String, dynamic>.from(res.data['message']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'token_interceptor.dart';
|
||||
class DioClient {
|
||||
static Dio? _dio;
|
||||
|
||||
static const String baseUrl = "http://10.11.236.74:8000";
|
||||
static const String baseUrl = "http://10.119.0.74:8000";
|
||||
|
||||
static Dio getInstance(BuildContext context) {
|
||||
if (_dio == null) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class ReverbSocketService {
|
||||
_onAdminMessage = onAdminMessage; // 👈 SAVE
|
||||
|
||||
final uri = Uri.parse(
|
||||
'ws://10.11.236.74:8080/app/q5fkk5rvcnatvbgadwvl'
|
||||
'ws://10.119.0.74:8080/app/q5fkk5rvcnatvbgadwvl'
|
||||
'?protocol=7&client=flutter&version=1.0',
|
||||
);
|
||||
|
||||
@@ -60,6 +60,7 @@ class ReverbSocketService {
|
||||
Future<void> _handleMessage(dynamic raw) async {
|
||||
debugPrint("📥 RAW: $raw");
|
||||
|
||||
|
||||
final payload = jsonDecode(raw);
|
||||
final event = payload['event']?.toString() ?? '';
|
||||
|
||||
@@ -91,13 +92,15 @@ class ReverbSocketService {
|
||||
event == 'NewChatMessage' ||
|
||||
event.endsWith('.NewChatMessage') ||
|
||||
event.contains('NewChatMessage')) {
|
||||
|
||||
dynamic data = payload['data'];
|
||||
if (data is String) data = jsonDecode(data);
|
||||
|
||||
final int msgId = data['id'];
|
||||
final String senderType = data['sender_type'] ?? '';
|
||||
final String? incomingClientId = data['client_id']; // ✅ HERE
|
||||
|
||||
// 🔁 Prevent duplicates
|
||||
// 🔁 Prevent duplicates by DB id
|
||||
if (_receivedIds.contains(msgId)) {
|
||||
debugPrint("🔁 DUPLICATE MESSAGE IGNORED: $msgId");
|
||||
return;
|
||||
@@ -106,20 +109,19 @@ class ReverbSocketService {
|
||||
|
||||
debugPrint("📩 NEW MESSAGE");
|
||||
debugPrint("🆔 id=$msgId");
|
||||
debugPrint("🧩 client_id=$incomingClientId");
|
||||
debugPrint("👤 sender=$senderType");
|
||||
debugPrint("💬 text=${data['message']}");
|
||||
|
||||
// Always push message to UI
|
||||
// ✅ Forward FULL payload (with client_id) to UI
|
||||
_onMessage(Map<String, dynamic>.from(data));
|
||||
|
||||
// 🔔 Increment unread ONLY if ADMIN sent message
|
||||
// 🔔 Increment unread ONLY if ADMIN sent message
|
||||
// 🔔 Unread count only for admin messages
|
||||
if (senderType == 'App\\Models\\Admin') {
|
||||
debugPrint("🔔 ADMIN MESSAGE → UNREAD +1");
|
||||
_onAdminMessage(); // ✅ ACTUAL INCREMENT
|
||||
_onAdminMessage();
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user