acter_core/
statics.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use matrix_sdk_base::ruma::{
    events::AnyInitialStateEvent, serde::Raw, OwnedRoomAliasId, RoomAliasId,
};
use serde_json::{json, value::to_raw_value};

pub static PURPOSE_FIELD: &str = "m.room.purpose";
pub static PURPOSE_FIELD_DEV: &str = "org.matrix.msc3088.room.purpose";
pub static PURPOSE_TEAM_VALUE: &str = "global.acter.team";

#[allow(non_snake_case)]
pub mod KEYS {
    pub mod TASKS {
        pub static TASKS: &str = "tasks";
        pub static MY_OPEN_TASKS: &str = "tasks_my_open";
        pub static MY_DONE_TASKS: &str = "tasks_my_done";
    }
    pub static CALENDAR: &str = "calendar";
    pub static NEWS: &str = "news";
    pub static STORIES: &str = "stories";
    pub static PINS: &str = "pins";
}

const HISTORY: &str = r#"{
    "type": "m.room.history_visibility",
    "state_key": "",
    "content": {
        "history_visibility": "shared"
    }
}"#;

const ENCRYPTION: &str = r#"{
    "type": "m.room.encryption",
    "state_key": "",
    "content": {
        "algorithm": "m.megolm.v1.aes-sha2",
        "rotation_period_ms": 604800000,
        "rotation_period_msgs": 100
    }
}"#;

/// Generate the default set ot initial states for acter teams
pub fn default_acter_space_states() -> Vec<Raw<AnyInitialStateEvent>> {
    let mut v = [HISTORY]
        .into_iter()
        .map(|a| serde_json::from_str::<Raw<AnyInitialStateEvent>>(a).expect("static don’t fail"))
        .collect::<Vec<Raw<AnyInitialStateEvent>>>();
    let r = to_raw_value(&json!({
        "type": PURPOSE_FIELD_DEV,
        "state_key": PURPOSE_TEAM_VALUE,
        "content": {
            "m.enabled": true,
            "m.importance_level": 50
        }
    }))
    .expect("static parsing of subtype doesn’t fail");

    v.push(Raw::from_json(r));
    v
}

pub fn default_acter_convo_states() -> Vec<Raw<AnyInitialStateEvent>> {
    [HISTORY, ENCRYPTION]
        .into_iter()
        .map(|a| serde_json::from_str::<Raw<AnyInitialStateEvent>>(a).expect("static don’t fail"))
        .collect()
}

pub fn initial_state_for_alias(
    main_alias: &RoomAliasId,
    alt_aliases: &Vec<OwnedRoomAliasId>,
) -> Raw<AnyInitialStateEvent> {
    let r = to_raw_value(&json!({
        "type": "m.room.canonical_alias",
        "state_key": "",
        "content": {
            "alias": Some(main_alias),
            "alt_aliases": alt_aliases,
        }
    }))
    .expect("static doesn’t fail");

    Raw::from_json(r)
}