Fix PR remarks

This commit is contained in:
ismailgulek
2022-09-13 15:47:26 +03:00
parent 18a8b2f275
commit 2591bcbca9
4 changed files with 16 additions and 20 deletions

View File

@@ -31,7 +31,7 @@ interface Client {
void set_delegate(ClientDelegate? delegate);
[Throws=ClientError]
void login(string username, string password, string initial_device_name, string? device_id);
void login(string username, string password, string? initial_device_name, string? device_id);
[Throws=ClientError]
void restore_login(string restore_token);
@@ -181,7 +181,7 @@ interface AuthenticationService {
void configure_homeserver(string server_name);
[Throws=AuthenticationError]
Client login(string username, string password, string initial_device_name, string? device_id);
Client login(string username, string password, string? initial_device_name, string? device_id);
[Throws=AuthenticationError]
Client restore_with_access_token(string token, string device_id);

View File

@@ -96,7 +96,7 @@ impl AuthenticationService {
&self,
username: String,
password: String,
initial_device_name: String,
initial_device_name: Option<String>,
device_id: Option<String>,
) -> Result<Arc<Client>, AuthenticationError> {
let client = match &*self.client.read().unwrap() {

View File

@@ -64,14 +64,14 @@ impl Client {
&self,
username: String,
password: String,
initial_device_name: String,
initial_device_name: Option<String>,
device_id: Option<String>,
) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
let mut builder = self
.client
.login_username(&username, &password)
.initial_device_display_name(&initial_device_name);
let mut builder = self.client.login_username(&username, &password);
if let Some(initial_device_name) = initial_device_name.as_ref() {
builder = builder.initial_device_display_name(initial_device_name);
}
if let Some(device_id) = device_id.as_ref() {
builder = builder.device_id(device_id);
}
@@ -290,8 +290,10 @@ impl Client {
/// Log out the current user
pub fn logout(&self) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
_ = self.client.logout().await;
Ok(())
match self.client.logout().await {
Ok(_) => Ok(()),
Err(error) => Err(anyhow!(error.to_string())),
}
})
}
@@ -302,19 +304,12 @@ impl Client {
RumaApiError::ClientApi(error),
)))) = sync_error
{
if matches!(error.kind, ErrorKind::UnknownToken { .. }) {
let is_soft_logout = match error.kind {
ErrorKind::UnknownToken { soft_logout } => soft_logout,
_ => unreachable!(),
};
self.state.write().unwrap().is_soft_logout = is_soft_logout;
if let ErrorKind::UnknownToken { soft_logout } = error.kind {
self.state.write().unwrap().is_soft_logout = soft_logout;
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_update_restore_token();
delegate.did_receive_auth_error(is_soft_logout);
delegate.did_receive_auth_error(soft_logout);
}
control = LoopCtrl::Break
}
}

View File

@@ -44,6 +44,7 @@ struct RestoreToken {
is_guest: bool,
homeurl: String,
session: Session,
#[serde(default)]
is_soft_logout: bool,
}