Skip to content

Commit

Permalink
updated to version 1.0.1+24
Browse files Browse the repository at this point in the history
  • Loading branch information
nixrajput committed Nov 9, 2022
1 parent 58eda89 commit 0f18ce3
Show file tree
Hide file tree
Showing 31 changed files with 696 additions and 1,640 deletions.
592 changes: 327 additions & 265 deletions lib/apis/providers/api_provider.dart

Large diffs are not rendered by default.

88 changes: 19 additions & 69 deletions lib/apis/services/auth_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:math' show Random;

import 'package:connectivity/connectivity.dart';
Expand Down Expand Up @@ -235,101 +234,52 @@ class AuthService extends GetxService {
}

Future<void> saveDeviceIdToServer(String deviceId) async {
AppUtility.log("Save DeviceId Request");
var body = {'deviceId': deviceId};

try {
final response = await _apiProvider.saveDeviceId(
token,
{'deviceId': deviceId},
);
final response = await _apiProvider.saveDeviceId(token, body);

final decodedData = jsonDecode(utf8.decode(response.bodyBytes));

if (response.statusCode == 200) {
AppUtility.log("Save DeviceId Success");
AppUtility.log(decodedData[StringValues.message], tag: 'info');
if (response.isSuccessful) {
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message]);
} else {
AppUtility.log("Save DeviceId Error");
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message], tag: 'error');
}
} on SocketException {
AppUtility.log("Save DeviceId Error");
AppUtility.log(StringValues.internetConnError, tag: 'error');
} on TimeoutException {
AppUtility.log("Save DeviceId Error");
AppUtility.log(StringValues.connTimedOut, tag: 'error');
} on FormatException catch (e) {
AppUtility.log("Save DeviceId Error");
AppUtility.log('Format Exception: $e', tag: 'error');
} catch (exc) {
AppUtility.printLog("Save DeviceId Error");
AppUtility.log('Error: $exc', tag: 'error');
AppUtility.log('Error: ${exc.toString()}', tag: 'error');
}
}

Future<void> savePreKeyBundle(Map<String, dynamic> preKeyBundle) async {
AppUtility.printLog("Save PreKeyBundle Request");

var body = {'preKeyBundle': preKeyBundle};
try {
final response = await _apiProvider.savePreKeyBundle(
_token,
{'preKeyBundle': preKeyBundle},
);

final decodedData = jsonDecode(utf8.decode(response.bodyBytes));
final response = await _apiProvider.savePreKeyBundle(_token, body);

if (response.statusCode == 200) {
AppUtility.printLog(decodedData[StringValues.message]);
AppUtility.printLog("Save PreKeyBundle Success");
if (response.isSuccessful) {
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message]);
} else {
AppUtility.printLog(decodedData[StringValues.message]);
AppUtility.printLog("Save PreKeyBundle Error");
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message], tag: 'error');
}
} on SocketException {
AppUtility.printLog("Save PreKeyBundle Error");
AppUtility.printLog(StringValues.internetConnError);
} on TimeoutException {
AppUtility.printLog("Save PreKeyBundle Error");
AppUtility.printLog(StringValues.connTimedOut);
} on FormatException catch (e) {
AppUtility.log("Save DeviceId Error");
AppUtility.log('Format Exception: $e', tag: 'error');
} catch (exc) {
AppUtility.printLog("Save DeviceId Error");
AppUtility.log('Error: $exc', tag: 'error');
}
}

Future<void> saveFcmToken(String fcmToken) async {
AppUtility.log("Save FcmToken Request");

try {
final response = await _apiProvider.saveFcmToken(
_token,
fcmToken,
);

final decodedData = jsonDecode(utf8.decode(response.bodyBytes));
final response = await _apiProvider.saveFcmToken(_token, fcmToken);

if (response.statusCode == 200) {
if (response.isSuccessful) {
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message]);
AppUtility.printLog("Save FcmToken Success");
} else {
AppUtility.log(
"Save FcmToken Error: ${decodedData[StringValues.message]}",
tag: 'error');
final decodedData = response.data;
AppUtility.log("${decodedData[StringValues.message]}", tag: 'error');
}
} on SocketException {
AppUtility.log("Save FcmToken Error");
AppUtility.log(StringValues.internetConnError);
} on TimeoutException {
AppUtility.log("Save FcmToken Error");
AppUtility.log(StringValues.connTimedOut);
} on FormatException catch (e) {
AppUtility.log("Save DeviceId Error");
AppUtility.log('Format Exception: $e', tag: 'error');
} catch (exc) {
AppUtility.printLog("Save DeviceId Error");
AppUtility.log('Error: $exc', tag: 'error');
}
}
Expand Down
12 changes: 5 additions & 7 deletions lib/e2ee/signal_protocol_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ class SignalProtocolManager {
remoteAddress,
);

// Get preKeyBundleFromServer
AppUtility.printLog('Get PreKeyBundle Request');
/// Get preKeyBundle From Server
var response =
await _apiProvider.getPreKeyBundle(_auth.token, remoteUserId);
final decodedData = jsonDecode(utf8.decode(response.bodyBytes));

if (response.statusCode == 200) {
AppUtility.printLog('Get PreKeyBundle Success');
if (response.isSuccessful) {
final decodedData = response.data;
AppUtility.printLog(decodedData[StringValues.message]);
var serverKey = ServerKey.fromJson(decodedData['data']['preKeyBundle']);
var preKeyBundle =
Expand All @@ -50,8 +48,8 @@ class SignalProtocolManager {
var sessionCipher = SessionCipher.fromStore(store, remoteAddress);
await store.storeSessionCipher(remoteUserId, sessionCipher);
} else {
AppUtility.printLog('Get PreKeyBundle Error');
AppUtility.printLog(decodedData[StringValues.message]);
final decodedData = response.data;
AppUtility.log(decodedData[StringValues.message], tag: 'error');
throw Exception(decodedData[StringValues.message]);
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/extensions/date_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,23 @@ extension DateHelper on DateTime {

if (!is24Hour) {
if (hr >= 13) {
hr -= 12;
hrStr = (hr - 12).toString();
hrStr = hrStr.length == 1 ? '0$hrStr' : hrStr;
}
if (hr == 0) {
hr = 12;
hrStr = '12';
}
time = '$hr:$minStr';
time += ' ${hr >= 12 ? 'PM' : 'AM'}';
time = '$hrStr:$minStr';
}

if (showSeconds) {
time += ':$secStr';
}

if (!is24Hour) {
time += ' ${hr >= 12 ? 'PM' : 'AM'}';
}

return time;
}

Expand Down
82 changes: 11 additions & 71 deletions lib/modules/auth/controllers/reactivate_account_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -64,18 +62,15 @@ class ReactivateAccountController extends GetxController {
'password': password,
};

AppUtility.printLog("Send Reactivate Account OTP Request");
AppUtility.showLoadingDialog();
_isLoading.value = true;
update();

try {
final response = await _apiProvider.sendReactivateAccountOtp(body);

final decodedData = jsonDecode(utf8.decode(response.bodyBytes));

if (response.statusCode == 200) {
AppUtility.printLog("Send Reactivate Account OTP Success");
if (response.isSuccessful) {
final decodedData = response.data;
AppUtility.closeDialog();
_isLoading.value = false;
_otpSent.value = true;
Expand All @@ -85,46 +80,21 @@ class ReactivateAccountController extends GetxController {
StringValues.success,
);
} else {
final decodedData = response.data;
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Send Reactivate Account OTP Error");
AppUtility.showSnackBar(
decodedData[StringValues.message],
StringValues.error,
);
}
} on SocketException {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Send Reactivate Account OTP Error");
AppUtility.printLog(StringValues.internetConnError);
AppUtility.showSnackBar(
StringValues.internetConnError, StringValues.error);
} on TimeoutException {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Send Reactivate Account OTP Error");
AppUtility.printLog(StringValues.connTimedOut);
AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error);
} on FormatException catch (e) {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Send Reactivate Account OTP Error");
AppUtility.printLog(StringValues.formatExcError);
AppUtility.printLog(e);
AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error);
} catch (exc) {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Send Reactivate Account OTP Error");
AppUtility.printLog(StringValues.errorOccurred);
AppUtility.printLog(exc);
AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error);
AppUtility.log('Error: $exc', tag: 'error');
AppUtility.showSnackBar('Error: $exc', StringValues.error);
}
}

Expand All @@ -143,69 +113,39 @@ class ReactivateAccountController extends GetxController {
'otp': otp,
};

AppUtility.printLog("Reactivate Account Request");
AppUtility.showLoadingDialog();
_isLoading.value = true;
update();

try {
final response = await _apiProvider.reactivateAccount(body);

final decodedData = jsonDecode(utf8.decode(response.bodyBytes));

if (response.statusCode == 200) {
if (response.isSuccessful) {
final decodedData = response.data;
_clearTextControllers();
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Success");
RouteManagement.goToBack();
RouteManagement.goToLoginView();
AppUtility.showSnackBar(
decodedData[StringValues.message],
StringValues.success,
);
} else {
final decodedData = response.data;
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Error");
AppUtility.showSnackBar(
decodedData[StringValues.message],
StringValues.error,
);
decodedData[StringValues.message], StringValues.error);
}
} on SocketException {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Error");
AppUtility.printLog(StringValues.internetConnError);
AppUtility.showSnackBar(
StringValues.internetConnError, StringValues.error);
} on TimeoutException {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Error");
AppUtility.printLog(StringValues.connTimedOut);
AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error);
} on FormatException catch (e) {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Error");
AppUtility.printLog(StringValues.formatExcError);
AppUtility.printLog(e);
AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error);
} catch (exc) {
AppUtility.closeDialog();
_isLoading.value = false;
update();
AppUtility.printLog("Reactivate Account Error");
AppUtility.printLog(StringValues.errorOccurred);
AppUtility.printLog(exc);
AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error);
AppUtility.log('Error: $exc', tag: 'error');
AppUtility.showSnackBar('Error: $exc', StringValues.error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/chat/controllers/p2p_chat_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class P2PChatController extends GetxController {
"mediaType": "image"
};
} catch (err) {
AppUtility.log(err);
AppUtility.log('Image upload failed. Error: $err', tag: 'error');
AppUtility.showSnackBar('Image upload failed.', StringValues.error);
return null;
}
Expand Down
Loading

0 comments on commit 0f18ce3

Please sign in to comment.