chore (backend-rs): prefer to_owned() over to_string()
This commit is contained in:
parent
96cd5b8103
commit
e1ad96aac4
20 changed files with 140 additions and 142 deletions
|
@ -346,7 +346,7 @@ pub fn load_config() -> Config {
|
|||
hostname,
|
||||
redis_key_prefix,
|
||||
scheme,
|
||||
ws_scheme: ws_scheme.to_string(),
|
||||
ws_scheme: ws_scheme.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ fn wildcard(category: Category) -> String {
|
|||
/// # use backend_rs::database::cache;
|
||||
/// # async fn f() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let key = "apple";
|
||||
/// let data = "I want to cache this string".to_string();
|
||||
/// let data = "I want to cache this string".to_owned();
|
||||
///
|
||||
/// // caches the data for 10 seconds
|
||||
/// cache::set(key, &data, 10).await?;
|
||||
|
@ -106,7 +106,7 @@ pub async fn set<V: for<'a> Deserialize<'a> + Serialize>(
|
|||
/// # use backend_rs::database::cache;
|
||||
/// # async fn f() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let key = "banana";
|
||||
/// let data = "I want to cache this string".to_string();
|
||||
/// let data = "I want to cache this string".to_owned();
|
||||
///
|
||||
/// // set cache
|
||||
/// cache::set(key, &data, 10).await?;
|
||||
|
@ -145,7 +145,7 @@ pub async fn get<V: for<'a> Deserialize<'a> + Serialize>(key: &str) -> Result<Op
|
|||
/// # use backend_rs::database::cache;
|
||||
/// # async fn f() -> Result<(), Box<dyn std::error::Error>> {
|
||||
/// let key = "chocolate";
|
||||
/// let value = "I want to cache this string".to_string();
|
||||
/// let value = "I want to cache this string".to_owned();
|
||||
///
|
||||
/// // set cache
|
||||
/// cache::set(key, &value, 10).await?;
|
||||
|
@ -248,12 +248,12 @@ mod unit_test {
|
|||
let value_1: Vec<i32> = vec![1, 2, 3, 4, 5];
|
||||
|
||||
let key_2 = "CARGO_TEST_CACHE_KEY_2";
|
||||
let value_2 = "Hello fedizens".to_string();
|
||||
let value_2 = "Hello fedizens".to_owned();
|
||||
|
||||
let key_3 = "CARGO_TEST_CACHE_KEY_3";
|
||||
let value_3 = Data {
|
||||
id: 1000000007,
|
||||
kind: "prime number".to_string(),
|
||||
kind: "prime number".to_owned(),
|
||||
};
|
||||
|
||||
set(key_1, &value_1, 1).await.unwrap();
|
||||
|
@ -287,7 +287,7 @@ mod unit_test {
|
|||
let key_2 = "fish";
|
||||
let key_3 = "awawa";
|
||||
|
||||
let value_1 = "hello".to_string();
|
||||
let value_1 = "hello".to_owned();
|
||||
let value_2 = 998244353u32;
|
||||
let value_3 = 'あ';
|
||||
|
||||
|
|
|
@ -57,12 +57,12 @@ async fn init_conn_pool() -> Result<(), RedisError> {
|
|||
};
|
||||
|
||||
if let Some(user) = &redis.user {
|
||||
params.push(user.to_string())
|
||||
params.push(user.to_owned())
|
||||
}
|
||||
if let Some(pass) = &redis.pass {
|
||||
params.push(format!(":{}@", urlencoding::encode(pass)))
|
||||
}
|
||||
params.push(redis.host.to_string());
|
||||
params.push(redis.host.to_owned());
|
||||
params.push(format!(":{}", redis.port));
|
||||
params.push(format!("/{}", redis.db));
|
||||
|
||||
|
@ -111,8 +111,8 @@ pub async fn get_conn() -> Result<PooledConnection<'static, RedisConnectionManag
|
|||
|
||||
/// prefix Redis key
|
||||
#[inline]
|
||||
pub fn key(key: impl ToString) -> String {
|
||||
format!("{}:{}", CONFIG.redis_key_prefix, key.to_string())
|
||||
pub fn key(key: impl std::fmt::Display) -> String {
|
||||
format!("{}:{}", CONFIG.redis_key_prefix, key)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -25,11 +25,11 @@ impl FromStr for Acct {
|
|||
.collect();
|
||||
|
||||
Ok(Self {
|
||||
username: split[0].to_string(),
|
||||
username: split[0].to_owned(),
|
||||
host: if split.len() == 1 {
|
||||
None
|
||||
} else {
|
||||
Some(split[1].to_string())
|
||||
Some(split[1].to_owned())
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -70,11 +70,11 @@ mod unit_test {
|
|||
#[test]
|
||||
fn acct_to_string() {
|
||||
let remote_acct = Acct {
|
||||
username: "firefish".to_string(),
|
||||
host: Some("example.com".to_string()),
|
||||
username: "firefish".to_owned(),
|
||||
host: Some("example.com".to_owned()),
|
||||
};
|
||||
let local_acct = Acct {
|
||||
username: "MisakaMikoto".to_string(),
|
||||
username: "MisakaMikoto".to_owned(),
|
||||
host: None,
|
||||
};
|
||||
|
||||
|
@ -87,11 +87,11 @@ mod unit_test {
|
|||
#[test]
|
||||
fn string_to_acct() {
|
||||
let remote_acct = Acct {
|
||||
username: "firefish".to_string(),
|
||||
host: Some("example.com".to_string()),
|
||||
username: "firefish".to_owned(),
|
||||
host: Some("example.com".to_owned()),
|
||||
};
|
||||
let local_acct = Acct {
|
||||
username: "MisakaMikoto".to_string(),
|
||||
username: "MisakaMikoto".to_owned(),
|
||||
host: None,
|
||||
};
|
||||
|
||||
|
|
|
@ -109,12 +109,12 @@ mod unit_test {
|
|||
let links_1 = NodeinfoLinks {
|
||||
links: vec![
|
||||
NodeinfoLink {
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_string(),
|
||||
href: "https://example.com/dummy".to_string(),
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_owned(),
|
||||
href: "https://example.com/dummy".to_owned(),
|
||||
},
|
||||
NodeinfoLink {
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_string(),
|
||||
href: "https://example.com/real".to_string(),
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(),
|
||||
href: "https://example.com/real".to_owned(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -126,12 +126,12 @@ mod unit_test {
|
|||
let links_2 = NodeinfoLinks {
|
||||
links: vec![
|
||||
NodeinfoLink {
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_string(),
|
||||
href: "https://example.com/dummy".to_string(),
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_owned(),
|
||||
href: "https://example.com/dummy".to_owned(),
|
||||
},
|
||||
NodeinfoLink {
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1".to_string(),
|
||||
href: "https://example.com/real".to_string(),
|
||||
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1".to_owned(),
|
||||
href: "https://example.com/real".to_owned(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -143,12 +143,12 @@ mod unit_test {
|
|||
let links_3 = NodeinfoLinks {
|
||||
links: vec![
|
||||
NodeinfoLink {
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_string(),
|
||||
href: "https://example.com/dummy/2.0".to_string(),
|
||||
rel: "https://example.com/incorrect/schema/2.0".to_owned(),
|
||||
href: "https://example.com/dummy/2.0".to_owned(),
|
||||
},
|
||||
NodeinfoLink {
|
||||
rel: "https://example.com/incorrect/schema/2.1".to_string(),
|
||||
href: "https://example.com/dummy/2.1".to_string(),
|
||||
rel: "https://example.com/incorrect/schema/2.1".to_owned(),
|
||||
href: "https://example.com/dummy/2.1".to_owned(),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -68,45 +68,45 @@ async fn generate_nodeinfo_2_1() -> Result<Nodeinfo21, DbErr> {
|
|||
let meta = local_server_info().await?;
|
||||
let mut metadata = HashMap::from([
|
||||
(
|
||||
"nodeName".to_string(),
|
||||
"nodeName".to_owned(),
|
||||
json!(meta.name.unwrap_or_else(|| CONFIG.host.clone())),
|
||||
),
|
||||
("nodeDescription".to_string(), json!(meta.description)),
|
||||
("repositoryUrl".to_string(), json!(meta.repository_url)),
|
||||
("nodeDescription".to_owned(), json!(meta.description)),
|
||||
("repositoryUrl".to_owned(), json!(meta.repository_url)),
|
||||
(
|
||||
"enableLocalTimeline".to_string(),
|
||||
"enableLocalTimeline".to_owned(),
|
||||
json!(!meta.disable_local_timeline),
|
||||
),
|
||||
(
|
||||
"enableRecommendedTimeline".to_string(),
|
||||
"enableRecommendedTimeline".to_owned(),
|
||||
json!(!meta.disable_recommended_timeline),
|
||||
),
|
||||
(
|
||||
"enableGlobalTimeline".to_string(),
|
||||
"enableGlobalTimeline".to_owned(),
|
||||
json!(!meta.disable_global_timeline),
|
||||
),
|
||||
(
|
||||
"enableGuestTimeline".to_string(),
|
||||
"enableGuestTimeline".to_owned(),
|
||||
json!(meta.enable_guest_timeline),
|
||||
),
|
||||
(
|
||||
"maintainer".to_string(),
|
||||
"maintainer".to_owned(),
|
||||
json!({"name":meta.maintainer_name,"email":meta.maintainer_email}),
|
||||
),
|
||||
("proxyAccountName".to_string(), json!(meta.proxy_account_id)),
|
||||
("proxyAccountName".to_owned(), json!(meta.proxy_account_id)),
|
||||
(
|
||||
"themeColor".to_string(),
|
||||
json!(meta.theme_color.unwrap_or_else(|| "#31748f".to_string())),
|
||||
"themeColor".to_owned(),
|
||||
json!(meta.theme_color.unwrap_or_else(|| "#31748f".to_owned())),
|
||||
),
|
||||
]);
|
||||
metadata.shrink_to_fit();
|
||||
|
||||
Ok(Nodeinfo21 {
|
||||
software: Software21 {
|
||||
name: "firefish".to_string(),
|
||||
name: "firefish".to_owned(),
|
||||
version: CONFIG.version.clone(),
|
||||
repository: Some(meta.repository_url),
|
||||
homepage: Some("https://firefish.dev/firefish/firefish".to_string()),
|
||||
homepage: Some("https://firefish.dev/firefish/firefish".to_owned()),
|
||||
},
|
||||
protocols: vec![Protocol::Activitypub],
|
||||
services: Services {
|
||||
|
|
|
@ -18,15 +18,15 @@ pub fn initialize_logger() {
|
|||
});
|
||||
} else if let Some(levels) = &CONFIG.log_level {
|
||||
// `logLevel` config is Deprecated
|
||||
if levels.contains(&"trace".to_string()) {
|
||||
if levels.contains(&"trace".to_owned()) {
|
||||
builder = builder.with_max_level(Level::TRACE);
|
||||
} else if levels.contains(&"debug".to_string()) {
|
||||
} else if levels.contains(&"debug".to_owned()) {
|
||||
builder = builder.with_max_level(Level::DEBUG);
|
||||
} else if levels.contains(&"info".to_string()) {
|
||||
} else if levels.contains(&"info".to_owned()) {
|
||||
builder = builder.with_max_level(Level::INFO);
|
||||
} else if levels.contains(&"warning".to_string()) {
|
||||
} else if levels.contains(&"warning".to_owned()) {
|
||||
builder = builder.with_max_level(Level::WARN);
|
||||
} else if levels.contains(&"error".to_string()) {
|
||||
} else if levels.contains(&"error".to_owned()) {
|
||||
builder = builder.with_max_level(Level::ERROR);
|
||||
} else {
|
||||
// Fallback
|
||||
|
|
|
@ -26,19 +26,19 @@ pub fn show_server_info() -> Result<(), SysinfoPoisonError> {
|
|||
|
||||
tracing::info!(
|
||||
"Hostname: {}",
|
||||
System::host_name().unwrap_or_else(|| "unknown".to_string())
|
||||
System::host_name().unwrap_or_else(|| "unknown".to_owned())
|
||||
);
|
||||
tracing::info!(
|
||||
"OS: {}",
|
||||
System::long_os_version().unwrap_or_else(|| "unknown".to_string())
|
||||
System::long_os_version().unwrap_or_else(|| "unknown".to_owned())
|
||||
);
|
||||
tracing::info!(
|
||||
"Kernel: {}",
|
||||
System::kernel_version().unwrap_or_else(|| "unknown".to_string())
|
||||
System::kernel_version().unwrap_or_else(|| "unknown".to_owned())
|
||||
);
|
||||
tracing::info!(
|
||||
"CPU architecture: {}",
|
||||
System::cpu_arch().unwrap_or_else(|| "unknown".to_string())
|
||||
System::cpu_arch().unwrap_or_else(|| "unknown".to_owned())
|
||||
);
|
||||
tracing::info!("CPU threads: {}", system_info.cpus().len());
|
||||
tracing::info!("Total memory: {} MiB", system_info.total_memory() / 1048576);
|
||||
|
|
|
@ -81,7 +81,7 @@ pub async fn is_allowed_server(host: &str) -> Result<bool, sea_orm::DbErr> {
|
|||
return Ok(true);
|
||||
}
|
||||
if let Some(allowed_hosts) = meta.allowed_hosts {
|
||||
return Ok(allowed_hosts.contains(&host.to_string()));
|
||||
return Ok(allowed_hosts.contains(&host.to_owned()));
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
|
|
@ -73,114 +73,114 @@ mod unit_test {
|
|||
#[test]
|
||||
fn word_mute_match() {
|
||||
let texts = [
|
||||
"The quick brown fox jumps over the lazy dog.".to_string(),
|
||||
"色は匂へど 散りぬるを 我が世誰ぞ 常ならむ".to_string(),
|
||||
"😇".to_string(),
|
||||
"The quick brown fox jumps over the lazy dog.".to_owned(),
|
||||
"色は匂へど 散りぬるを 我が世誰ぞ 常ならむ".to_owned(),
|
||||
"😇".to_owned(),
|
||||
];
|
||||
|
||||
let hiragana_1 = r"/[\u{3040}-\u{309f}]/u".to_string();
|
||||
let hiragana_2 = r"/[あ-ん]/u".to_string();
|
||||
let katakana_1 = r"/[\u{30a1}-\u{30ff}]/u".to_string();
|
||||
let katakana_2 = r"/[ア-ン]/u".to_string();
|
||||
let emoji = r"/[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/u".to_string();
|
||||
let hiragana_1 = r"/[\u{3040}-\u{309f}]/u".to_owned();
|
||||
let hiragana_2 = r"/[あ-ん]/u".to_owned();
|
||||
let katakana_1 = r"/[\u{30a1}-\u{30ff}]/u".to_owned();
|
||||
let katakana_2 = r"/[ア-ン]/u".to_owned();
|
||||
let emoji = r"/[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}]/u".to_owned();
|
||||
|
||||
assert!(check_word_mute_impl(&texts, &[], &["/the/i".to_string()]));
|
||||
assert!(check_word_mute_impl(&texts, &[], &["/the/i".to_owned()]));
|
||||
|
||||
assert!(!check_word_mute_impl(&texts, &[], &["/the/".to_string()]));
|
||||
assert!(!check_word_mute_impl(&texts, &[], &["/the/".to_owned()]));
|
||||
|
||||
assert!(check_word_mute_impl(&texts, &[], &["/QuICk/i".to_string()]));
|
||||
assert!(check_word_mute_impl(&texts, &[], &["/QuICk/i".to_owned()]));
|
||||
|
||||
assert!(!check_word_mute_impl(&texts, &[], &["/QuICk/".to_string()]));
|
||||
assert!(!check_word_mute_impl(&texts, &[], &["/QuICk/".to_owned()]));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&[
|
||||
"我".to_string(),
|
||||
"有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_string()
|
||||
"我".to_owned(),
|
||||
"有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_owned()
|
||||
],
|
||||
&[]
|
||||
));
|
||||
|
||||
assert!(!check_word_mute_impl(
|
||||
&texts,
|
||||
&["有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_string()],
|
||||
&["有為の奥山 今日越えて 浅き夢見し 酔ひもせず".to_owned()],
|
||||
&[]
|
||||
));
|
||||
|
||||
assert!(!check_word_mute_impl(
|
||||
&texts,
|
||||
&[
|
||||
"有為の奥山".to_string(),
|
||||
"今日越えて".to_string(),
|
||||
"浅き夢見し".to_string(),
|
||||
"酔ひもせず".to_string()
|
||||
"有為の奥山".to_owned(),
|
||||
"今日越えて".to_owned(),
|
||||
"浅き夢見し".to_owned(),
|
||||
"酔ひもせず".to_owned()
|
||||
],
|
||||
&[]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "mastodon".to_string()],
|
||||
&["yellow fox".to_owned(), "mastodon".to_owned()],
|
||||
&[hiragana_1.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "mastodon".to_string()],
|
||||
&["yellow fox".to_owned(), "mastodon".to_owned()],
|
||||
&[hiragana_2.clone()]
|
||||
));
|
||||
|
||||
assert!(!check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "mastodon".to_string()],
|
||||
&["yellow fox".to_owned(), "mastodon".to_owned()],
|
||||
&[katakana_1.clone()]
|
||||
));
|
||||
|
||||
assert!(!check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "mastodon".to_string()],
|
||||
&["yellow fox".to_owned(), "mastodon".to_owned()],
|
||||
&[katakana_2.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["brown fox".to_string(), "mastodon".to_string()],
|
||||
&["brown fox".to_owned(), "mastodon".to_owned()],
|
||||
&[katakana_1.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["brown fox".to_string(), "mastodon".to_string()],
|
||||
&["brown fox".to_owned(), "mastodon".to_owned()],
|
||||
&[katakana_2.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "dog".to_string()],
|
||||
&["yellow fox".to_owned(), "dog".to_owned()],
|
||||
&[katakana_1.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "dog".to_string()],
|
||||
&["yellow fox".to_owned(), "dog".to_owned()],
|
||||
&[katakana_2.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["yellow fox".to_string(), "mastodon".to_string()],
|
||||
&["yellow fox".to_owned(), "mastodon".to_owned()],
|
||||
&[hiragana_1.clone(), katakana_1.clone()]
|
||||
));
|
||||
|
||||
assert!(check_word_mute_impl(
|
||||
&texts,
|
||||
&["😇".to_string(), "🥲".to_string(), "🥴".to_string()],
|
||||
&["😇".to_owned(), "🥲".to_owned(), "🥴".to_owned()],
|
||||
&[]
|
||||
));
|
||||
|
||||
assert!(!check_word_mute_impl(
|
||||
&texts,
|
||||
&["🙂".to_string(), "🥲".to_string(), "🥴".to_string()],
|
||||
&["🙂".to_owned(), "🥲".to_owned(), "🥴".to_owned()],
|
||||
&[]
|
||||
));
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ pub async fn get_image_size_from_url(url: &str) -> Result<ImageSize, Error> {
|
|||
|
||||
if attempted {
|
||||
tracing::warn!("attempt limit exceeded: {}", url);
|
||||
return Err(Error::TooManyAttempts(url.to_string()));
|
||||
return Err(Error::TooManyAttempts(url.to_owned()));
|
||||
}
|
||||
|
||||
tracing::info!("retrieving image from {}", url);
|
||||
|
|
|
@ -15,12 +15,12 @@ pub fn summarize_impl(
|
|||
|
||||
match file_ids.len() {
|
||||
0 => (),
|
||||
1 => buf.push("📎".to_string()),
|
||||
1 => buf.push("📎".to_owned()),
|
||||
n => buf.push(format!("📎 ({})", n)),
|
||||
};
|
||||
|
||||
if has_poll {
|
||||
buf.push("📊".to_string())
|
||||
buf.push("📊".to_owned())
|
||||
}
|
||||
|
||||
buf.join(" ")
|
||||
|
@ -94,7 +94,7 @@ mod unit_test {
|
|||
fn summarize_note() {
|
||||
let note = NoteLike {
|
||||
file_ids: vec![],
|
||||
text: Some("Hello world!".to_string()),
|
||||
text: Some("Hello world!".to_owned()),
|
||||
cw: None,
|
||||
has_poll: false,
|
||||
};
|
||||
|
@ -102,26 +102,26 @@ mod unit_test {
|
|||
|
||||
let note_with_cw = NoteLike {
|
||||
file_ids: vec![],
|
||||
text: Some("Hello world!".to_string()),
|
||||
cw: Some("Content warning".to_string()),
|
||||
text: Some("Hello world!".to_owned()),
|
||||
cw: Some("Content warning".to_owned()),
|
||||
has_poll: false,
|
||||
};
|
||||
assert_eq!(summarize!(note_with_cw), "Content warning");
|
||||
|
||||
let note_with_file_and_cw = NoteLike {
|
||||
file_ids: vec!["9s7fmcqogiq4igin".to_string()],
|
||||
file_ids: vec!["9s7fmcqogiq4igin".to_owned()],
|
||||
text: None,
|
||||
cw: Some("Selfie, no ec".to_string()),
|
||||
cw: Some("Selfie, no ec".to_owned()),
|
||||
has_poll: false,
|
||||
};
|
||||
assert_eq!(summarize!(note_with_file_and_cw), "Selfie, no ec 📎");
|
||||
|
||||
let note_with_files_only = NoteLike {
|
||||
file_ids: vec![
|
||||
"9s7fmcqogiq4igin".to_string(),
|
||||
"9s7qrld5u14cey98".to_string(),
|
||||
"9s7gebs5zgts4kca".to_string(),
|
||||
"9s5z3e4vefqd29ee".to_string(),
|
||||
"9s7fmcqogiq4igin".to_owned(),
|
||||
"9s7qrld5u14cey98".to_owned(),
|
||||
"9s7gebs5zgts4kca".to_owned(),
|
||||
"9s5z3e4vefqd29ee".to_owned(),
|
||||
],
|
||||
text: None,
|
||||
cw: None,
|
||||
|
@ -131,13 +131,13 @@ mod unit_test {
|
|||
|
||||
let note_all = NoteLike {
|
||||
file_ids: vec![
|
||||
"9s7fmcqogiq4igin".to_string(),
|
||||
"9s7qrld5u14cey98".to_string(),
|
||||
"9s7gebs5zgts4kca".to_string(),
|
||||
"9s5z3e4vefqd29ee".to_string(),
|
||||
"9s7fmcqogiq4igin".to_owned(),
|
||||
"9s7qrld5u14cey98".to_owned(),
|
||||
"9s7gebs5zgts4kca".to_owned(),
|
||||
"9s5z3e4vefqd29ee".to_owned(),
|
||||
],
|
||||
text: Some("Hello world!".to_string()),
|
||||
cw: Some("Content warning".to_string()),
|
||||
text: Some("Hello world!".to_owned()),
|
||||
cw: Some("Content warning".to_owned()),
|
||||
has_poll: true,
|
||||
};
|
||||
assert_eq!(summarize!(note_all), "Content warning 📎 (4) 📊");
|
||||
|
|
|
@ -128,12 +128,12 @@ mod unit_test {
|
|||
#[test]
|
||||
fn decode_reaction() {
|
||||
let unicode_emoji_1 = DecodedReaction {
|
||||
reaction: "⭐".to_string(),
|
||||
reaction: "⭐".to_owned(),
|
||||
name: None,
|
||||
host: None,
|
||||
};
|
||||
let unicode_emoji_2 = DecodedReaction {
|
||||
reaction: "🩷".to_string(),
|
||||
reaction: "🩷".to_owned(),
|
||||
name: None,
|
||||
host: None,
|
||||
};
|
||||
|
@ -145,23 +145,23 @@ mod unit_test {
|
|||
assert_ne!(super::decode_reaction("🩷"), unicode_emoji_1);
|
||||
|
||||
let unicode_emoji_3 = DecodedReaction {
|
||||
reaction: "🖖🏿".to_string(),
|
||||
reaction: "🖖🏿".to_owned(),
|
||||
name: None,
|
||||
host: None,
|
||||
};
|
||||
assert_eq!(super::decode_reaction("🖖🏿"), unicode_emoji_3);
|
||||
|
||||
let local_emoji = DecodedReaction {
|
||||
reaction: ":meow_melt_tears@.:".to_string(),
|
||||
name: Some("meow_melt_tears".to_string()),
|
||||
reaction: ":meow_melt_tears@.:".to_owned(),
|
||||
name: Some("meow_melt_tears".to_owned()),
|
||||
host: None,
|
||||
};
|
||||
assert_eq!(super::decode_reaction(":meow_melt_tears:"), local_emoji);
|
||||
|
||||
let remote_emoji_1 = DecodedReaction {
|
||||
reaction: ":meow_uwu@some-domain.example.org:".to_string(),
|
||||
name: Some("meow_uwu".to_string()),
|
||||
host: Some("some-domain.example.org".to_string()),
|
||||
reaction: ":meow_uwu@some-domain.example.org:".to_owned(),
|
||||
name: Some("meow_uwu".to_owned()),
|
||||
host: Some("some-domain.example.org".to_owned()),
|
||||
};
|
||||
assert_eq!(
|
||||
super::decode_reaction(":meow_uwu@some-domain.example.org:"),
|
||||
|
@ -169,9 +169,9 @@ mod unit_test {
|
|||
);
|
||||
|
||||
let remote_emoji_2 = DecodedReaction {
|
||||
reaction: ":C++23@xn--eckwd4c7c.example.org:".to_string(),
|
||||
name: Some("C++23".to_string()),
|
||||
host: Some("xn--eckwd4c7c.example.org".to_string()),
|
||||
reaction: ":C++23@xn--eckwd4c7c.example.org:".to_owned(),
|
||||
name: Some("C++23".to_owned()),
|
||||
host: Some("xn--eckwd4c7c.example.org".to_owned()),
|
||||
};
|
||||
assert_eq!(
|
||||
super::decode_reaction(":C++23@xn--eckwd4c7c.example.org:"),
|
||||
|
@ -179,14 +179,14 @@ mod unit_test {
|
|||
);
|
||||
|
||||
let invalid_reaction_1 = DecodedReaction {
|
||||
reaction: ":foo".to_string(),
|
||||
reaction: ":foo".to_owned(),
|
||||
name: None,
|
||||
host: None,
|
||||
};
|
||||
assert_eq!(super::decode_reaction(":foo"), invalid_reaction_1);
|
||||
|
||||
let invalid_reaction_2 = DecodedReaction {
|
||||
reaction: ":foo&@example.com:".to_string(),
|
||||
reaction: ":foo&@example.com:".to_owned(),
|
||||
name: None,
|
||||
host: None,
|
||||
};
|
||||
|
|
|
@ -38,9 +38,9 @@ pub fn cpu_info() -> Result<Cpu, SysinfoPoisonError> {
|
|||
model: match system_info.cpus() {
|
||||
[] => {
|
||||
tracing::debug!("failed to get CPU info");
|
||||
"unknown".to_string()
|
||||
"unknown".to_owned()
|
||||
}
|
||||
cpus => cpus[0].brand().to_string(),
|
||||
cpus => cpus[0].brand().to_owned(),
|
||||
},
|
||||
cores: system_info.cpus().len() as u16,
|
||||
})
|
||||
|
|
|
@ -71,7 +71,7 @@ async fn add_note_to_antenna(antenna_id: &str, note: &Note) -> Result<(), Error>
|
|||
.await?;
|
||||
|
||||
// for streaming API
|
||||
stream::antenna::publish(antenna_id.to_string(), note).await?;
|
||||
stream::antenna::publish(antenna_id.to_owned(), note).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ pub async fn watch_note(
|
|||
note_watching::Entity::insert(note_watching::ActiveModel {
|
||||
id: ActiveValue::set(gen_id_at(now)),
|
||||
created_at: ActiveValue::set(now.into()),
|
||||
user_id: ActiveValue::Set(watcher_id.to_string()),
|
||||
note_user_id: ActiveValue::Set(note_author_id.to_string()),
|
||||
note_id: ActiveValue::Set(note_id.to_string()),
|
||||
user_id: ActiveValue::Set(watcher_id.to_owned()),
|
||||
note_user_id: ActiveValue::Set(note_author_id.to_owned()),
|
||||
note_id: ActiveValue::Set(note_id.to_owned()),
|
||||
})
|
||||
.exec(db_conn().await?)
|
||||
.await?;
|
||||
|
|
|
@ -55,7 +55,7 @@ pub enum PushNotificationKind {
|
|||
|
||||
fn compact_content(mut content: serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
if !content.is_object() {
|
||||
return Err(Error::InvalidContent("not a JSON object".to_string()));
|
||||
return Err(Error::InvalidContent("not a JSON object".to_owned()));
|
||||
}
|
||||
|
||||
let object = content.as_object_mut().unwrap();
|
||||
|
@ -69,9 +69,7 @@ fn compact_content(mut content: serde_json::Value) -> Result<serde_json::Value,
|
|||
.get("note")
|
||||
.unwrap()
|
||||
.get("renote")
|
||||
.ok_or(Error::InvalidContent(
|
||||
"renote object is missing".to_string(),
|
||||
))?
|
||||
.ok_or(Error::InvalidContent("renote object is missing".to_owned()))?
|
||||
} else {
|
||||
object.get("note").unwrap()
|
||||
}
|
||||
|
@ -79,7 +77,7 @@ fn compact_content(mut content: serde_json::Value) -> Result<serde_json::Value,
|
|||
|
||||
if !note.is_object() {
|
||||
return Err(Error::InvalidContent(
|
||||
"(re)note is not an object".to_string(),
|
||||
"(re)note is not an object".to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -101,8 +99,8 @@ fn compact_content(mut content: serde_json::Value) -> Result<serde_json::Value,
|
|||
note_object.remove("reply");
|
||||
note_object.remove("renote");
|
||||
note_object.remove("user");
|
||||
note_object.insert("text".to_string(), text.into());
|
||||
object.insert("note".to_string(), note);
|
||||
note_object.insert("text".to_owned(), text.into());
|
||||
object.insert("note".to_owned(), note);
|
||||
|
||||
Ok(serde_json::from_value(Json::Object(object.clone()))?)
|
||||
}
|
||||
|
@ -121,14 +119,14 @@ async fn get_mastodon_subscription_info(
|
|||
if token.is_none() {
|
||||
unsubscribe(db, subscription_id).await?;
|
||||
return Err(Error::InvalidSubscription(
|
||||
"access token not found".to_string(),
|
||||
"access token not found".to_owned(),
|
||||
));
|
||||
}
|
||||
let token = token.unwrap();
|
||||
|
||||
if token.app_id.is_none() {
|
||||
unsubscribe(db, subscription_id).await?;
|
||||
return Err(Error::InvalidSubscription("no app ID".to_string()));
|
||||
return Err(Error::InvalidSubscription("no app ID".to_owned()));
|
||||
}
|
||||
let app_id = token.app_id.unwrap();
|
||||
|
||||
|
@ -139,7 +137,7 @@ async fn get_mastodon_subscription_info(
|
|||
|
||||
if client.is_none() {
|
||||
unsubscribe(db, subscription_id).await?;
|
||||
return Err(Error::InvalidSubscription("app not found".to_string()));
|
||||
return Err(Error::InvalidSubscription("app not found".to_owned()));
|
||||
}
|
||||
|
||||
Ok((token.token, client.unwrap().name))
|
||||
|
@ -152,11 +150,11 @@ async fn encode_mastodon_payload(
|
|||
) -> Result<String, Error> {
|
||||
let object = content
|
||||
.as_object_mut()
|
||||
.ok_or(Error::InvalidContent("not a JSON object".to_string()))?;
|
||||
.ok_or(Error::InvalidContent("not a JSON object".to_owned()))?;
|
||||
|
||||
if subscription.app_access_token_id.is_none() {
|
||||
unsubscribe(db, &subscription.id).await?;
|
||||
return Err(Error::InvalidSubscription("no access token".to_string()));
|
||||
return Err(Error::InvalidSubscription("no access token".to_owned()));
|
||||
}
|
||||
|
||||
let (token, client_name) = get_mastodon_subscription_info(
|
||||
|
@ -166,7 +164,7 @@ async fn encode_mastodon_payload(
|
|||
)
|
||||
.await?;
|
||||
|
||||
object.insert("access_token".to_string(), serde_json::to_value(token)?);
|
||||
object.insert("access_token".to_owned(), serde_json::to_value(token)?);
|
||||
|
||||
// Some apps expect notification_id to be an integer,
|
||||
// but doesn’t break when the ID doesn’t match the rest of API.
|
||||
|
@ -187,7 +185,7 @@ async fn encode_mastodon_payload(
|
|||
.transpose()?
|
||||
.unwrap_or_default();
|
||||
|
||||
object.insert("notification_id".to_string(), timestamp.into());
|
||||
object.insert("notification_id".to_owned(), timestamp.into());
|
||||
}
|
||||
|
||||
let res = serde_json::to_string(&content)?;
|
||||
|
@ -273,7 +271,7 @@ pub async fn send_push_notification(
|
|||
// TODO: refactoring
|
||||
let mut payload = if use_mastodon_api {
|
||||
// Content generated per subscription
|
||||
"".to_string()
|
||||
"".to_owned()
|
||||
} else {
|
||||
// Format the `content` passed from the TypeScript backend
|
||||
// for Firefish push notifications
|
||||
|
|
|
@ -80,13 +80,13 @@ pub async fn publish_to_stream(
|
|||
value: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
let channel = match stream {
|
||||
Stream::Internal => "internal".to_string(),
|
||||
Stream::CustomEmoji => "broadcast".to_string(),
|
||||
Stream::Internal => "internal".to_owned(),
|
||||
Stream::CustomEmoji => "broadcast".to_owned(),
|
||||
Stream::Moderation { moderator_id } => format!("adminStream:{moderator_id}"),
|
||||
Stream::User { user_id } => format!("user:{user_id}"),
|
||||
Stream::Channel { channel_id } => format!("channelStream:{channel_id}"),
|
||||
Stream::Note { note_id } => format!("noteStream:{note_id}"),
|
||||
Stream::Notes => "notesStream".to_string(),
|
||||
Stream::Notes => "notesStream".to_owned(),
|
||||
Stream::UserList { list_id } => format!("userListStream:{list_id}"),
|
||||
Stream::Main { user_id } => format!("mainStream:{user_id}"),
|
||||
Stream::Drive { user_id } => format!("driveStream:{user_id}"),
|
||||
|
@ -103,7 +103,7 @@ pub async fn publish_to_stream(
|
|||
format!(
|
||||
"{{\"type\":\"{}\",\"body\":{}}}",
|
||||
kind,
|
||||
value.unwrap_or_else(|| "null".to_string()),
|
||||
value.unwrap_or_else(|| "null".to_owned()),
|
||||
)
|
||||
} else {
|
||||
value.ok_or(Error::InvalidContent)?
|
||||
|
|
|
@ -46,7 +46,7 @@ mod unit_test {
|
|||
Err(InnerError1)
|
||||
}
|
||||
fn causes_inner_error_2() -> Result<(), InnerError2> {
|
||||
Err(InnerError2("foo".to_string()))
|
||||
Err(InnerError2("foo".to_owned()))
|
||||
}
|
||||
|
||||
fn causes_error_1() -> Result<(), ErrorVariants> {
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn get_timestamp(id: &str) -> Result<i64, InvalidIdError> {
|
|||
if let Some(n) = n {
|
||||
Ok(n as i64 + TIME_2000)
|
||||
} else {
|
||||
Err(InvalidIdError { id: id.to_string() })
|
||||
Err(InvalidIdError { id: id.to_owned() })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue