addUserPhone method
- UserPhone phone, {
- ConfirmationCode? confirmation,
- String? locale,
override
Adds a new phone
number for the authenticated MyUser.
Sets the given phone
number as an MyUserPhones.unconfirmed sub-field
of a MyUser.phones field and sends to this number SMS with a
ConfirmationCode.
Implementation
@override
Future<void> addUserPhone(
UserPhone phone, {
ConfirmationCode? confirmation,
String? locale,
}) async {
Log.debug(
'addUserPhone($phone, confirmation: $confirmation)',
'$runtimeType',
);
await _debounce(
field: MyUserField.phone,
current: () => myUser.value?.phones.unconfirmed,
saved: () async => (await _active)?.value.phones.unconfirmed,
value: phone,
mutation: (value, previous) async {
if (previous != null) {
return await _graphQlProvider.deleteUserPhone(
previous,
confirmation:
confirmation == null
? null
: MyUserCredentials(code: confirmation),
);
} else if (value != null) {
return await _graphQlProvider.addUserPhone(
value,
confirmation: confirmation,
locale: locale,
);
}
return null;
},
update:
(v, p) => myUser.update(
(u) =>
p != null
? u?.phones.unconfirmed = null
: u?.phones.unconfirmed = v,
),
);
}