StreamingClientExt

Trait StreamingClientExt 

Source
pub trait StreamingClientExt: StreamingClient + Sync {
    // Provided methods
    fn subscribe_note(
        &self,
        note: impl EntityRef<Note>,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<NoteUpdateEvent, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn main_stream(
        &self,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<MainStreamEvent, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn home_timeline(
        &self,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn local_timeline(
        &self,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn social_timeline(
        &self,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn global_timeline(
        &self,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn hashtag_timeline(
        &self,
        query: impl Into<Query<String>>,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn antenna_timeline(
        &self,
        antenna: impl EntityRef<Antenna>,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn channel_timeline(
        &self,
        channel: impl EntityRef<Channel>,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
    fn user_list_timeline(
        &self,
        list: impl EntityRef<UserList>,
    ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>> { ... }
}
Expand description

An extension trait for StreamingClient that provides convenient high-level APIs.

§Streams

The methods of StreamingClientExt return (Future that outputs) a Stream that receives items from the server asynchronously. You can use methods from TryStreamExt or StreamExt to work with these streams.

Provided Methods§

Source

fn subscribe_note( &self, note: impl EntityRef<Note>, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<NoteUpdateEvent, Error<Self::Error>>>, Error<Self::Error>>>

Subscribes to the specified note and returns a stream to receive the events.

§Examples
use futures::stream::TryStreamExt;
use misskey::streaming::note::NoteUpdateEvent;

let note = client.create_note("Hello!").await?;
let mut note_stream = client.subscribe_note(&note).await?;
// Wait for the next event in the stream.
while let Some(event) = note_stream.try_next().await? {
    match event {
        // Check if the event is 'reacted'
        NoteUpdateEvent::Reacted { reaction, user_id } => {
            println!("reacted by {}: {}", user_id, reaction);
        }
        // other events are just ignored here
        _ => {}
   }
}
Source

fn main_stream( &self, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<MainStreamEvent, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the events from the main stream.

Note that currently it is not possible to have multiple connections to the main stream from the same client. If you try to do so, the Future returned by this method will not complete.

§Examples
use futures::stream::TryStreamExt;
use misskey::ClientExt;
use misskey::streaming::channel::main::MainStreamEvent;

let mut main_stream = client.main_stream().await?;
// Wait for the next event in the main stream.
while let Some(event) = main_stream.try_next().await? {
    match event {
        // Check if the event is 'followed'
        MainStreamEvent::Followed(user) => {
            // Follow back `user` if you haven't already.
            if !client.is_following(&user).await? {
                client.follow(&user).await?;
            }
        }
        // other events are just ignored here
        _ => {}
   }
}
Source

fn home_timeline( &self, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the notes in the home timeline.

Note that currently it is not possible to have multiple connections to the home timeline from the same client. If you try to do so, the Future returned by this method will not complete.

§Examples
use futures::stream::TryStreamExt;
use misskey::ClientExt;
use misskey::model::note::Note;

let mut home = client.home_timeline().await?;
// Wait for the next note in the home timeline.
while let Some(note) = home.try_next().await? {
    // if the note's text contains "Hello", react with "🙌".
    match note {
        Note { id, text: Some(text), .. } if text.contains("Hello") => {
            client.react(id, "🙌").await?;
        }
        _ => {}
    }
}
Source

fn local_timeline( &self, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the notes in the local timeline.

Note that currently it is not possible to have multiple connections to the local timeline from the same client. If you try to do so, the Future returned by this method will not complete.

Source

fn social_timeline( &self, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the notes in the social timeline.

Note that currently it is not possible to have multiple connections to the social timeline from the same client. If you try to do so, the Future returned by this method will not complete.

Source

fn global_timeline( &self, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the notes in the global timeline.

Note that currently it is not possible to have multiple connections to the global timeline from the same client. If you try to do so, the Future returned by this method will not complete.

Source

fn hashtag_timeline( &self, query: impl Into<Query<String>>, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive the notes with the given hashtags.

Source

fn antenna_timeline( &self, antenna: impl EntityRef<Antenna>, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive notes in the timeline of the specified antenna.

Source

fn channel_timeline( &self, channel: impl EntityRef<Channel>, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Available on crate feature 12-47-0 only.

Returns a stream to receive notes in the timeline of the specified channel.

Source

fn user_list_timeline( &self, list: impl EntityRef<UserList>, ) -> BoxFuture<'_, Result<BoxStream<'_, Result<Note, Error<Self::Error>>>, Error<Self::Error>>>

Returns a stream to receive notes in the timeline of the specified user list.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§