refactor: Update SDK and enable login with email and phone
This commit is contained in:
parent
f19e83cf88
commit
39421fae32
8 changed files with 47 additions and 12 deletions
|
|
@ -79,7 +79,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
|
||||
File wallpaper;
|
||||
|
||||
void _initWithStore() async {
|
||||
void _initWithStore() {
|
||||
try {
|
||||
client.init();
|
||||
} catch (e, s) {
|
||||
|
|
@ -344,7 +344,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
.where((e) =>
|
||||
e.type == EventUpdateType.timeline &&
|
||||
[EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
|
||||
.contains(e.eventType) &&
|
||||
.contains(e.content['type']) &&
|
||||
e.content['sender'] != client.userID)
|
||||
.listen(_showLocalNotification);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class UrlLauncher {
|
|||
final response = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
matrix.client.requestRoomAliasInformations(roomIdOrAlias),
|
||||
matrix.client.requestRoomAliasInformation(roomIdOrAlias),
|
||||
);
|
||||
if (response.error != null) {
|
||||
return; // nothing to do, the alias doesn't exist
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class _ChatDetailsState extends State<ChatDetails> {
|
|||
newAliases.add(canonicalAlias);
|
||||
final response = await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => room.client.requestRoomAliasInformations(canonicalAlias),
|
||||
future: () => room.client.requestRoomAliasInformation(canonicalAlias),
|
||||
);
|
||||
if (response.error != null) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
|
|
@ -327,8 +327,7 @@ class _ChatDetailsState extends State<ChatDetails> {
|
|||
// okay, we need to test if there are any emote state events other than the default one
|
||||
// if so, we need to be directed to a selection screen for which pack we want to look at
|
||||
// otherwise, we just open the normal one.
|
||||
if ((room.states
|
||||
.states['im.ponies.room_emotes'] ??
|
||||
if ((room.states['im.ponies.room_emotes'] ??
|
||||
<String, Event>{})
|
||||
.keys
|
||||
.any((String s) => s.isNotEmpty)) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ class _HomeserverPickerState extends State<HomeserverPicker> {
|
|||
context: context,
|
||||
future: () => Matrix.of(context).client.login(
|
||||
type: AuthenticationTypes.token,
|
||||
userIdentifierType: null,
|
||||
token: token,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -42,8 +42,28 @@ class _LoginState extends State<Login> {
|
|||
|
||||
setState(() => loading = true);
|
||||
try {
|
||||
final username = usernameController.text;
|
||||
AuthenticationIdentifier identifier;
|
||||
if (username.isEmail) {
|
||||
identifier = AuthenticationThirdPartyIdentifier(
|
||||
medium: 'email',
|
||||
address: username,
|
||||
);
|
||||
} else if (username.isPhoneNumber) {
|
||||
identifier = AuthenticationThirdPartyIdentifier(
|
||||
medium: 'msisdn',
|
||||
address: username,
|
||||
);
|
||||
} else {
|
||||
identifier = AuthenticationUserIdentifier(user: username);
|
||||
}
|
||||
await matrix.client.login(
|
||||
user: usernameController.text,
|
||||
identifier: identifier,
|
||||
// To stay compatible with older server versions
|
||||
// ignore: deprecated_member_use
|
||||
user: identifier.type == AuthenticationIdentifierTypes.userId
|
||||
? username
|
||||
: null,
|
||||
password: passwordController.text,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName);
|
||||
} on MatrixException catch (exception) {
|
||||
|
|
@ -255,3 +275,12 @@ class _LoginState extends State<Login> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
extension on String {
|
||||
static final RegExp _emailRegex = RegExp(
|
||||
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+");
|
||||
static final RegExp _phoneRegex =
|
||||
RegExp(r'^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$');
|
||||
bool get isEmail => _emailRegex.hasMatch(this);
|
||||
bool get isPhoneNumber => _phoneRegex.hasMatch(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class MultipleEmotesSettings extends StatelessWidget {
|
|||
stream: room.onUpdate.stream,
|
||||
builder: (context, snapshot) {
|
||||
final packs =
|
||||
room.states.states['im.ponies.room_emotes'] ?? <String, Event>{};
|
||||
room.states['im.ponies.room_emotes'] ?? <String, Event>{};
|
||||
if (!packs.containsKey('')) {
|
||||
packs[''] = null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue