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