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
extern crate blake2;
extern crate json;
extern crate reqwest;
extern crate url;

use blake2::{Blake2b, Digest};
use std::collections::HashMap;

pub struct Endpoints {
    pub misskey_key: String,
    pub mastodon_key: String,
    pub misskey_url: String,
    pub mastodon_url: String,
}

pub fn submit(api: &Endpoints, status: &String) {
    // mastodon api, pleroma etc
    {
        let fedi_parems = [("visibility", "unlisted"), ("status", status)];
        let idempotency = Blake2b::new()
            .chain(status)
            .chain(&api.mastodon_key)
            .chain(&api.mastodon_url)
            .result();

        match reqwest::Client::new()
            .post(&api.mastodon_url.to_string())
            .header("idempotency-key", format!("{:x}", idempotency))
            .header("authorization", api.mastodon_key.to_owned())
            .form(&fedi_parems)
            .send()
        {
            Ok(_) => {}
            Err(e) => println!("{:?}", e),
        };
    }

    // misskey api
    {
        let mut misskey_parems = HashMap::new();
        misskey_parems.insert("visibility", "home");
        misskey_parems.insert("text", &status);
        misskey_parems.insert("i", &api.misskey_key);

        let client = reqwest::Client::new()
            .post(&api.misskey_url.to_string())
            // TODO: replace with normal form when misskey supports it
            .json(&misskey_parems);

        match client.send() {
            Ok(_) => {}
            Err(e) => println!("{:?}", e),
        };
    }
}