deleteUserPhone method
- UserPhone phone, {
- UserPassword? password,
- ConfirmationCode? confirmation,
override
Deletes the given phone
from MyUser.phones for the authenticated
MyUser.
Implementation
@override
Future<void> deleteUserPhone(
UserPhone phone, {
UserPassword? password,
ConfirmationCode? confirmation,
}) async {
Log.debug(
'deleteUserPhone($phone, password: ${password?.obscured}, confirmation: $confirmation)',
'$runtimeType',
);
if (myUser.value?.phones.unconfirmed == phone) {
await _debounce(
field: MyUserField.phone,
current: () => myUser.value?.phones.unconfirmed,
saved: () async => (await _active)?.value.phones.unconfirmed,
value: null,
mutation: (value, previous) async {
if (previous != null) {
return await _graphQlProvider.deleteUserPhone(
previous,
confirmation:
confirmation == null && password == null
? null
: MyUserCredentials(
code: confirmation,
password: password,
),
);
} else if (value != null) {
return await _graphQlProvider.addUserPhone(
value,
confirmation: confirmation,
);
}
return null;
},
update:
(v, p) => myUser.update(
(u) =>
p != null
? u?.phones.unconfirmed = null
: u?.phones.unconfirmed = v,
),
);
} else {
int i = myUser.value?.phones.confirmed.indexOf(phone) ?? -1;
if (i != -1) {
myUser.update((u) => u?.phones.confirmed.remove(phone));
}
try {
await _graphQlProvider.deleteUserPhone(
phone,
confirmation:
confirmation == null && password == null
? null
: MyUserCredentials(code: confirmation, password: password),
);
} catch (_) {
if (i != -1) {
i = min(i, myUser.value?.phones.confirmed.length ?? 0);
myUser.update((u) => myUser.value?.phones.confirmed.insert(i, phone));
}
rethrow;
}
}
}