Commit 2c08bcfa authored by Erfan Jazeb Nikoo's avatar Erfan Jazeb Nikoo
Browse files

Merge branch...

Merge branch 'CU-2ww0dnu_300w2_data_connect_whatsapp_QR--Whatsapp-QR-code-is-not-recognized-by--Android-phone_Erfan-Jazeb-Nikoo' into 'dev'

CU-2ww0dnu_300w2_data_connect_whatsapp_QR--Whatsapp-QR-code-is-not-recognized

See merge request !403
parents cbbdacd1 3c5eab83
Pipeline #10018 passed with stages
in 6 minutes and 40 seconds
Showing with 75 additions and 29 deletions
+75 -29
......@@ -213,4 +213,16 @@ class PodAPI extends BaseAPI {
checkResponseError(response);
return jsonDecode(response.toString());
}
Future<dynamic> getQrCodeSvg(String webserverUrl) async {
String endpoint = '$webserverUrl/qr_svg';
Response response;
try {
response = await dio.get(endpoint);
} on DioError catch (_) {
return null;
}
checkResponseError(response);
return response.data;
}
}
......@@ -35,4 +35,9 @@ class OAuthService extends ApiService<PodAPI> {
_setConfig();
return await api.oauthRequestToken(service, callback_url);
}
Future<dynamic> getQrCodeSvg(String webserverUrl) async {
_setConfig();
return await api.getQrCodeSvg(webserverUrl);
}
}
......@@ -45,8 +45,10 @@ class OAuthProvider with ChangeNotifier {
String? whatsappStatus;
Uint8List? whatsappQrSvg;
late StreamSubscription<Item>? _whatsappOAuthStreamSubscription;
StreamSubscription<Item>? _whatsappOAuthStreamSubscription;
StreamSubscription<dynamic>? _whatsappQrCodeStreamSubscription;
Stream<Item>? _whatsappOAuthStream;
Stream<dynamic>? _whatsappQrCodeStream;
bool gitlabAuthFailed = false;
Item? _gitlabOAuthItem;
......@@ -360,31 +362,39 @@ class OAuthProvider with ChangeNotifier {
_whatsappOAuthStream ??= _whatsappItemStream(id);
_whatsappOAuthStreamSubscription =
_whatsappOAuthStream!.listen((item) async {
var status = item.get('status');
if (status != whatsappStatus) {
AnalyticsService().logImporterStatus(status);
}
oAuthCompleted[DataSource.whatsapp] =
(status == 'daemon' || status == 'done');
if (!oAuthCompleted[DataSource.whatsapp]!) {
String? svg = item.get('authImage');
if (svg != null) {
whatsappQrSvg = base64.decode(svg.split(',').last);
cancelWhatsappStreamSubs();
String? webserverUrl = item.get('webserverUrl');
if (webserverUrl != null) {
_whatsappQrCodeStream ??= _whatsappQrStream(webserverUrl);
_whatsappQrCodeStreamSubscription ??=
_whatsappQrCodeStream!.listen((dynamic res) async {
if (res != null) {
oAuthCompleted[DataSource.whatsapp] = res['authenticated'];
if (oAuthCompleted[DataSource.whatsapp]!) {
RouteNavigator.navigateTo(
context: context,
route: Routes.importerDownloading,
param: {'id': id, 'name': 'whatsapp'},
replace: true,
);
} else {
String? svg = res['qr'];
if (svg != null) {
whatsappQrSvg = base64.decode(svg.split(',').last);
notifyListeners();
}
}
}
});
var status = item.get('status');
if (status != whatsappStatus) {
AnalyticsService().logImporterStatus(status);
}
}
whatsappStatus = status;
AppLogger.info(whatsappStatus);
notifyListeners();
whatsappStatus = status;
AppLogger.info(whatsappStatus);
if (oAuthCompleted[DataSource.whatsapp]!) {
RouteNavigator.navigateTo(
context: context,
route: Routes.importerDownloading,
param: {'id': id, 'name': 'whatsapp'},
replace: true,
);
notifyListeners();
}
});
} catch (error) {
......@@ -399,6 +409,13 @@ class OAuthProvider with ChangeNotifier {
}
}
void cancelWhatsappQrCodeStreamSubs() {
_whatsappQrCodeStream = null;
if (_whatsappQrCodeStreamSubscription != null) {
_whatsappQrCodeStreamSubscription!.cancel();
}
}
Stream<Item> _whatsappItemStream(String id) async* {
while (true) {
await Future.delayed(Duration(seconds: 1));
......@@ -410,24 +427,36 @@ class OAuthProvider with ChangeNotifier {
if (res != null) {
yield res;
if (res.get('status') == 'daemon' ||
res.get('status') == 'done' ||
res.get('status') == 'aborted') {
if (res.get('webserverUrl') != null) {
cancelWhatsappStreamSubs();
}
}
}
}
Stream<dynamic> _whatsappQrStream(String webserverUrl) async* {
while (true) {
await Future.delayed(Duration(seconds: 1));
dynamic res = await _oAuthService.getQrCodeSvg(webserverUrl);
if (res != null) {
yield res;
if (res['authenticated']) {
cancelWhatsappQrCodeStreamSubs();
}
}
}
}
///
void reset() {
cancelWhatsappStreamSubs();
cancelWhatsappQrCodeStreamSubs();
_gitlabOAuthStream = null;
_gitlabOAuthItem = null;
whatsappQrSvg = null;
whatsappStatus = null;
oAuthCompleted = {};
_whatsappOAuthStream = null;
gitlabAuthFailed = false;
service = '';
responseMessage = '';
......
......@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 2.2.0+1
version: 2.2.1+0
environment:
sdk: ">=2.12.0 <3.0.0"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment