BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / skin_tone.rs

skin_tone.rs

fb874ac1 History
skin_tone.rs 843 B Download Raw
1use store::Store;
2
3use crate::error::Result;
4
5const META_ACCOUNT_SKIN_TONE: &str = "skin_tone_account";
6
7pub fn store_account_skin_tone(store: &Store, tone: u8) -> Result<()> {
8 Ok(store.set_meta(META_ACCOUNT_SKIN_TONE, &tone.to_string())?)
9}
10
11/// The account setting `preferredSkinToneIndex`: 0 is the default yellow, 1 to 5 light to dark.
12pub fn skin_tone(store: &Store) -> u8 {
13 store
14 .meta(META_ACCOUNT_SKIN_TONE)
15 .ok()
16 .flatten()
17 .and_then(|value| value.parse().ok())
18 .unwrap_or(0)
19}
20
21#[cfg(test)]
22mod tests {
23 use super::*;
24
25 #[test]
26 fn the_account_tone_is_stored_and_read_back() {
27 let store = Store::open_in_memory().unwrap();
28 assert_eq!(skin_tone(&store), 0);
29 store_account_skin_tone(&store, 2).unwrap();
30 assert_eq!(skin_tone(&store), 2);
31 }
32}