41 lines
1022 B
Rust
41 lines
1022 B
Rust
use std::{
|
|
pin::Pin,
|
|
task::{Context, Poll},
|
|
};
|
|
|
|
use futures::Sink;
|
|
use mammut::{status_builder::Visibility, Mastodon, StatusBuilder};
|
|
|
|
pub struct MastodonPublisher {
|
|
mastodon: Mastodon,
|
|
}
|
|
|
|
impl MastodonPublisher {
|
|
pub fn new(mastodon: Mastodon) -> Self {
|
|
Self { mastodon }
|
|
}
|
|
}
|
|
|
|
impl Sink<String> for MastodonPublisher {
|
|
type Error = mammut::Error;
|
|
|
|
fn poll_ready(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
Poll::Ready(Ok(()))
|
|
}
|
|
|
|
fn start_send(self: Pin<&mut Self>, item: String) -> Result<(), Self::Error> {
|
|
let mut post = StatusBuilder::new(item);
|
|
post.visibility = Some(Visibility::Public);
|
|
self.mastodon.new_status(post)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
Poll::Ready(Ok(()))
|
|
}
|
|
|
|
fn poll_close(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
Poll::Ready(Ok(()))
|
|
}
|
|
}
|