|
|
|
|
@ -3,10 +3,12 @@ import 'dart:io';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/consts.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/exceptions/api_exception.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/main.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/chat/chat_user_image_model.dart';
|
|
|
|
|
@ -22,6 +24,7 @@ class ChatApiClient {
|
|
|
|
|
factory ChatApiClient() => _instance;
|
|
|
|
|
|
|
|
|
|
Future<user.UserAutoLoginModel> getUserLoginToken() async {
|
|
|
|
|
user.UserAutoLoginModel userLoginResponse = user.UserAutoLoginModel();
|
|
|
|
|
Response response = await ApiClient().postJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatLoginTokenUrl}externaluserlogin",
|
|
|
|
|
{
|
|
|
|
|
@ -32,7 +35,14 @@ class ChatApiClient {
|
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
|
logger.i("res: " + response.body);
|
|
|
|
|
}
|
|
|
|
|
user.UserAutoLoginModel userLoginResponse = user.userAutoLoginModelFromJson(response.body);
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
userLoginResponse = user.userAutoLoginModelFromJson(response.body);
|
|
|
|
|
} else if (response.statusCode == 504) {
|
|
|
|
|
getUserLoginToken();
|
|
|
|
|
} else {
|
|
|
|
|
userLoginResponse = user.userAutoLoginModelFromJson(response.body);
|
|
|
|
|
Utils.showToast(userLoginResponse.errorResponses!.first.message!);
|
|
|
|
|
}
|
|
|
|
|
return userLoginResponse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -141,6 +151,7 @@ class ChatApiClient {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<List<ChatUserImageModel>> getUsersImages({required List<String> encryptedEmails}) async {
|
|
|
|
|
List<ChatUserImageModel> imagesData = [];
|
|
|
|
|
Response response = await ApiClient().postJsonForResponse(
|
|
|
|
|
"${ApiConsts.chatUserImages}images",
|
|
|
|
|
{"encryptedEmails": encryptedEmails, "fromClient": false},
|
|
|
|
|
@ -148,7 +159,16 @@ class ChatApiClient {
|
|
|
|
|
);
|
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
|
logger.i("res: " + response.body);
|
|
|
|
|
print("Images Status Coe is ============== " + response.statusCode.toString());
|
|
|
|
|
}
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
|
imagesData = chatUserImageModelFromJson(response.body);
|
|
|
|
|
} else if (response.statusCode == 504 || response.statusCode == 500) {
|
|
|
|
|
getUsersImages(encryptedEmails: encryptedEmails);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("Something went wrong while loading images");
|
|
|
|
|
imagesData = [];
|
|
|
|
|
}
|
|
|
|
|
return chatUserImageModelFromJson(response.body);
|
|
|
|
|
return imagesData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|