refactor: resultify token::lookup_or_new()

This commit is contained in:
link2xt
2024-05-14 18:14:03 +00:00
parent c349bf8e0c
commit 07ceabdf85
2 changed files with 7 additions and 7 deletions

View File

@@ -65,8 +65,8 @@ pub async fn get_securejoin_qr(context: &Context, group: Option<ChatId>) -> Resu
let sync_token = token::lookup(context, Namespace::InviteNumber, group)
.await?
.is_none();
let invitenumber = token::lookup_or_new(context, Namespace::InviteNumber, group).await;
let auth = token::lookup_or_new(context, Namespace::Auth, group).await;
let invitenumber = token::lookup_or_new(context, Namespace::InviteNumber, group).await?;
let auth = token::lookup_or_new(context, Namespace::Auth, group).await?;
let self_addr = context.get_primary_self_addr().await?;
let self_name = context
.get_config(Config::Displayname)

View File

@@ -93,14 +93,14 @@ pub async fn lookup_or_new(
context: &Context,
namespace: Namespace,
foreign_id: Option<ChatId>,
) -> String {
if let Ok(Some(token)) = lookup(context, namespace, foreign_id).await {
return token;
) -> Result<String> {
if let Some(token) = lookup(context, namespace, foreign_id).await? {
return Ok(token);
}
let token = create_id();
save(context, namespace, foreign_id, &token).await.ok();
token
save(context, namespace, foreign_id, &token).await?;
Ok(token)
}
pub async fn exists(context: &Context, namespace: Namespace, token: &str) -> Result<bool> {