Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
OT-577 Unable to call contact (#342)
Browse files Browse the repository at this point in the history
* OT-577 Unable to call contact
  • Loading branch information
Boehrsi authored and phranck committed Dec 11, 2019
1 parent 46d9f64 commit bd46cd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lib/src/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import 'package:ox_coi/src/ui/strings.dart';
import 'package:ox_coi/src/utils/dialog_builder.dart';
import 'package:ox_coi/src/utils/keyMapping.dart';
import 'package:ox_coi/src/utils/key_generator.dart';
import 'package:ox_coi/src/utils/text.dart';
import 'package:ox_coi/src/utils/toast.dart';
import 'package:ox_coi/src/widgets/avatar.dart';
import 'package:ox_coi/src/widgets/state_info.dart';
Expand Down Expand Up @@ -741,7 +742,10 @@ class _ChatState extends State<Chat> with ChatComposer, ChatCreateMixin, InviteM
}
}

Future<bool> callNumber(String phoneNumber) => launch("tel://$phoneNumber");
void callNumber(String phoneNumber) {
String parsedPhoneNumber = getPhoneNumberFromString(phoneNumber);
launch("tel://$parsedPhoneNumber");
}
}

class MessageList extends StatelessWidget {
Expand Down
15 changes: 11 additions & 4 deletions lib/src/utils/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@

import 'dart:convert';

final RegExp matchInvertedNumericAndPlus = RegExp(r'[^0-9+]');

final RegExp matchEmail = RegExp(
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$');

isNullOrEmpty(String text) => text == null || text.isEmpty;

bool isEmail(String email) {
String source =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regExp = new RegExp(source);
return regExp.hasMatch(email);
return matchEmail.hasMatch(email);
}

bool isPort(String portString) {
Expand All @@ -74,3 +76,8 @@ String encodeBase64(String text) {
int getIndexAfterLastOf(String text, Pattern pattern) {
return text.lastIndexOf(pattern) + 1;
}

String getPhoneNumberFromString(String text) {
String phoneNumberWithoutOptionals = text.replaceFirst("(0)", '');
return phoneNumberWithoutOptionals.replaceAll(matchInvertedNumericAndPlus, '');
}

0 comments on commit bd46cd8

Please sign in to comment.