refactor: make LoginAction a bit safer
We make LoginAction a simple wrapper around processing the unknown
action to expose too much internal logic. This allows us to have a
must_use on our LoginAction type, otherwise the SingleUnkIdAction's
must_use will be lost when returned in the login action.
Fixes: a5cdddbb2b ("user can upgrade their npub -> nsec")
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
use enostr::{FilledKeypair, FullKeypair, Keypair};
|
use enostr::{FilledKeypair, FullKeypair, Keypair};
|
||||||
use nostrdb::Ndb;
|
use nostrdb::{Ndb, Transaction};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
column::Columns,
|
column::Columns,
|
||||||
@@ -14,6 +14,7 @@ use crate::{
|
|||||||
accounts::{AccountsView, AccountsViewResponse},
|
accounts::{AccountsView, AccountsViewResponse},
|
||||||
},
|
},
|
||||||
unknowns::SingleUnkIdAction,
|
unknowns::SingleUnkIdAction,
|
||||||
|
unknowns::UnknownIds,
|
||||||
user_account::UserAccount,
|
user_account::UserAccount,
|
||||||
};
|
};
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
@@ -245,11 +246,22 @@ pub fn process_login_view_response(
|
|||||||
login_action.unk
|
login_action.unk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use = "You must call process_login_action on this to handle unknown ids"]
|
||||||
pub struct LoginAction {
|
pub struct LoginAction {
|
||||||
pub unk: SingleUnkIdAction,
|
unk: SingleUnkIdAction,
|
||||||
pub switch_to_index: usize,
|
pub switch_to_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LoginAction {
|
||||||
|
// Simple wrapper around processing the unknown action to expose too
|
||||||
|
// much internal logic. This allows us to have a must_use on our
|
||||||
|
// LoginAction type, otherwise the SingleUnkIdAction's must_use will
|
||||||
|
// be lost when returned in the login action
|
||||||
|
pub fn process_action(&mut self, ids: &mut UnknownIds, ndb: &Ndb, txn: &Transaction) {
|
||||||
|
self.unk.process_action(ids, ndb, txn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ContainsAccount {
|
struct ContainsAccount {
|
||||||
pub has_nsec: bool,
|
pub has_nsec: bool,
|
||||||
|
|||||||
@@ -429,7 +429,6 @@ impl Damus {
|
|||||||
info!("adding account: {}", key.pubkey);
|
info!("adding account: {}", key.pubkey);
|
||||||
accounts
|
accounts
|
||||||
.add_account(key)
|
.add_account(key)
|
||||||
.unk
|
|
||||||
.process_action(&mut unknown_ids, &ndb, &txn);
|
.process_action(&mut unknown_ids, &ndb, &txn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,11 +102,9 @@ pub fn test_app() -> Damus {
|
|||||||
let accounts = get_test_accounts();
|
let accounts = get_test_accounts();
|
||||||
let txn = Transaction::new(&app.ndb).expect("txn");
|
let txn = Transaction::new(&app.ndb).expect("txn");
|
||||||
for account in accounts {
|
for account in accounts {
|
||||||
app.accounts_mut().add_account(account).unk.process_action(
|
app.accounts_mut()
|
||||||
&mut app.unknown_ids,
|
.add_account(account)
|
||||||
&app.ndb,
|
.process_action(&mut app.unknown_ids, &app.ndb, &txn)
|
||||||
&txn,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app
|
app
|
||||||
|
|||||||
Reference in New Issue
Block a user