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) let sync_token = token::lookup(context, Namespace::InviteNumber, group)
.await? .await?
.is_none(); .is_none();
let invitenumber = token::lookup_or_new(context, Namespace::InviteNumber, 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 auth = token::lookup_or_new(context, Namespace::Auth, group).await?;
let self_addr = context.get_primary_self_addr().await?; let self_addr = context.get_primary_self_addr().await?;
let self_name = context let self_name = context
.get_config(Config::Displayname) .get_config(Config::Displayname)

View File

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