Added visibility configuration
This commit is contained in:
parent
52cb0c5ea2
commit
4fcb8a9771
37
README.md
37
README.md
|
@ -39,17 +39,44 @@ This default uses the `Misskey` publisher. If you want to publish to Mastodon, P
|
|||
|
||||
The publisher can currently hold one of two JSON objects, named either `Mastodon` or `Misskey`, which determines which posting API it will use. Whether the object is `Misskey` or `Mastodon`, it has the following members:
|
||||
|
||||
| Name | Value |
|
||||
|------------|------------------------------------------------------------------------------------------------------------|
|
||||
| `base_url` | The base URL of the instance |
|
||||
| `token` | The auth token for the account, leave empty for `Mastodon` as you will be prompted to log in and authorize |
|
||||
| Name | Value |
|
||||
|--------------|------------------------------------------------------------------------------------------------------------|
|
||||
| `base_url` | The base URL of the instance |
|
||||
| `token` | The auth token for the account, leave empty for `Mastodon` as you will be prompted to log in and authorize |
|
||||
| `visibility` | The visibility scope of the statuses to be posted. These differ between publishers, see the list below |
|
||||
|
||||
**Misskey visibility values**
|
||||
|
||||
* `Public` (Global)
|
||||
* `Home`
|
||||
* `Followers`
|
||||
* `Specified` (DMs)
|
||||
|
||||
**Mastodon-comptaibles visibility values**
|
||||
|
||||
* `public` (Global)
|
||||
* `unlisted` (Home)
|
||||
* `private` (Followers only)
|
||||
* `direct` (DMs)
|
||||
|
||||
An example `Misskey` publisher entry looks like this:
|
||||
```json
|
||||
"publisher": {
|
||||
"Misskey": {
|
||||
"base_url": "",
|
||||
"token": ""
|
||||
"token": "",
|
||||
"visibility": "Public"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And for mastodon/pleroma:
|
||||
```json
|
||||
"publisher": {
|
||||
"Mastodon": {
|
||||
// Token will be set by izzilis on authentication (requires interactive)
|
||||
"base_url": "",
|
||||
"visibility": "public"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -25,14 +25,15 @@ pub struct MinMax {
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum Publisher {
|
||||
Misskey(FediverseConfig<String>),
|
||||
Mastodon(FediverseConfig<Option<mammut::Data>>),
|
||||
Misskey(FediverseConfig<String, misskey::model::note::Visibility>),
|
||||
Mastodon(FediverseConfig<Option<mammut::Data>, mammut::status_builder::Visibility>),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct FediverseConfig<T> {
|
||||
pub struct FediverseConfig<T, V> {
|
||||
pub base_url: String,
|
||||
pub token: T,
|
||||
pub visibility: V,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -53,6 +54,7 @@ impl Default for Config {
|
|||
publisher: Publisher::Misskey(FediverseConfig {
|
||||
base_url: "".to_string(),
|
||||
token: "".to_string(),
|
||||
visibility: misskey::model::note::Visibility::Public,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ async fn resolve_publisher(
|
|||
) -> Result<Either<MisskeyPublisher, MastodonPublisher>, Box<dyn Error>> {
|
||||
let publisher = match &config.publisher {
|
||||
config::Publisher::Misskey(cfg) => {
|
||||
Either::Left(MisskeyPublisher::new(&cfg.base_url, cfg.token.clone())?)
|
||||
Either::Left(MisskeyPublisher::new(&cfg.base_url, cfg.token.clone(), cfg.visibility)?)
|
||||
}
|
||||
config::Publisher::Mastodon(cfg) => {
|
||||
let app = AppBuilder {
|
||||
|
@ -158,6 +158,7 @@ async fn resolve_publisher(
|
|||
|
||||
let mut registration = Registration::new(cfg.base_url.clone());
|
||||
registration.register(app)?;
|
||||
let vis = cfg.visibility;
|
||||
|
||||
let mastodon = if let Some(data) = cfg.token.clone() {
|
||||
Mastodon::from_data(data.clone())
|
||||
|
@ -173,13 +174,14 @@ async fn resolve_publisher(
|
|||
config.publisher = Publisher::Mastodon(FediverseConfig {
|
||||
base_url: cfg.base_url.clone(),
|
||||
token: Some(fedi.data.clone()),
|
||||
visibility: vis.clone(),
|
||||
});
|
||||
config.save(CONFIG_PATH)?;
|
||||
|
||||
fedi
|
||||
};
|
||||
|
||||
Either::Right(MastodonPublisher::new(mastodon))
|
||||
Either::Right(MastodonPublisher::new(mastodon, vis))
|
||||
}
|
||||
};
|
||||
Ok(publisher)
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
use std::{error::Error, pin::Pin, task::{Context, Poll}};
|
||||
use std::{
|
||||
error::Error,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use futures::Sink;
|
||||
use mammut::{status_builder::Visibility, Mastodon, StatusBuilder};
|
||||
|
||||
pub struct MastodonPublisher {
|
||||
mastodon: Mastodon,
|
||||
post_visibility: Visibility,
|
||||
}
|
||||
|
||||
impl MastodonPublisher {
|
||||
pub fn new(mastodon: Mastodon) -> Self {
|
||||
Self { mastodon }
|
||||
pub fn new(mastodon: Mastodon, vis: Visibility) -> Self {
|
||||
Self {
|
||||
mastodon: mastodon,
|
||||
post_visibility: vis,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +30,7 @@ impl Sink<String> for MastodonPublisher {
|
|||
|
||||
fn start_send(self: Pin<&mut Self>, item: String) -> Result<(), Self::Error> {
|
||||
let mut post = StatusBuilder::new(item);
|
||||
post.visibility = Some(Visibility::Public);
|
||||
post.visibility = Some(self.post_visibility);
|
||||
self.mastodon.new_status(post)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
use futures::Sink;
|
||||
use misskey::{ClientExt, HttpClient};
|
||||
use misskey::{Client, ClientExt, HttpClient, model::note::Visibility};
|
||||
use std::{error::Error, task::Poll};
|
||||
use url::Url;
|
||||
|
||||
pub struct MisskeyPublisher {
|
||||
client: HttpClient,
|
||||
post_visibility: Visibility,
|
||||
}
|
||||
|
||||
impl MisskeyPublisher {
|
||||
pub fn new(url: &String, token: String) -> Result<Self, Box<dyn Error>> {
|
||||
pub fn new(url: &String, token: String, vis: Visibility) -> Result<Self, Box<dyn Error>> {
|
||||
Ok(Self {
|
||||
client: HttpClient::with_token(Url::parse(url)?, token)?,
|
||||
post_visibility: vis,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +28,9 @@ impl Sink<String> for MisskeyPublisher {
|
|||
}
|
||||
|
||||
fn start_send(self: std::pin::Pin<&mut Self>, item: String) -> Result<(), Self::Error> {
|
||||
smol::block_on(self.client.create_note(item))?;
|
||||
let mut req = self.client.build_note();
|
||||
let req = req.text(item).visibility(self.post_visibility).as_request();
|
||||
smol::block_on(self.client.request(req))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue