readme, some fixes

This commit is contained in:
2021-08-27 00:19:43 +02:00
parent 2b84e5eeb0
commit 957f0dbb3b
10 changed files with 118 additions and 59 deletions
+13 -6
View File
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::error::Error;
use elefren::status_builder::Visibility;
@@ -24,14 +23,14 @@ pub(crate) fn acct_to_server(acct: &str) -> Option<&str> {
acct.trim_start_matches('@').split('@').nth(1)
}
pub(crate) fn normalize_acct<'a, 'g>(acct: &'a str, group: &'g str) -> Result<Cow<'a, str>, GroupError> {
let acct = acct.trim_start_matches('@');
if acct_to_server(acct).is_some() {
pub(crate) fn normalize_acct(acct: &str, group: &str) -> Result<String, GroupError> {
let acct = acct.trim_start_matches('@').to_lowercase();
if acct_to_server(&acct).is_some() {
// already has server
Ok(Cow::Borrowed(acct))
Ok(acct)
} else if let Some(gs) = acct_to_server(group) {
// attach server from the group actor
Ok(Cow::Owned(format!("{}@{}", acct, gs)))
Ok(format!("{}@{}", acct, gs))
} else {
Err(GroupError::BadConfig(
format!("Group acct {} is missing server!", group).into(),
@@ -81,6 +80,14 @@ mod test {
Ok("piggo@piggo.space".into()),
normalize_acct("piggo@piggo.space", "uhh")
);
assert_eq!(
Ok("piggo@piggo.space".into()),
normalize_acct("piGGgo@pIggo.spaCe", "uhh")
);
assert_eq!(
Ok("piggo@banana.nana".into()),
normalize_acct("piGGgo", "foo@baNANA.nana")
);
assert_eq!(Err(GroupError::BadConfig("_".into())), normalize_acct("piggo", "uhh"));
}
}