coord-e / misskey-rs

:v: Client library for Misskey :smiling_face_with_three_hearts:
Apache License 2.0
59 stars 7 forks source link

Support for additional Calckey API endpoints #52

Closed ThatOneCalculator closed 1 year ago

ThatOneCalculator commented 1 year ago

Calckey adds a few new endpoints to Misskey, most notably the recommended timeline. It can be called in the exact same way the social/local/global timelines can, and instances have a recommendedTimelineEnabled property.

coord-e commented 1 year ago

Thank you for your feedback. But misskey-rs is intended for misskey-dev/misskey implementation only and support for forked instances is out of project scope.

Nevertheless, you can implement your own channel without modifying misskey-rs itself. Given the module as follows,

// not tested but should work in this way
mod recommended_timeline {
  use crate::model::note::Note;
  use crate::streaming::channel::NoOutgoing;

  use serde::{Deserialize, Serialize};

  #[derive(Deserialize, Debug, Clone)]
  #[serde(rename_all = "camelCase", tag = "type", content = "body")]
  pub enum RecommendedTimelineEvent {
      Note(Note),
  }

  #[derive(Serialize, Default, Debug, Clone)]
  pub struct Request {}

  impl misskey::streaming::ConnectChannelRequest for Request {
      type Incoming = RecommendedTimelineEvent;
      type Outgoing = NoOutgoing;

      const NAME: &'static str = "recommendedTimeline";
  }
}

You can connect and obtain the channel stream with WebSocketClient::channel.

client.channel(recommended_timeline::Request::default()).await

Likewise for endpoints, you can create your own struct and implement Request to use Client::request. You can refer misskey-api sources for examples. e.g. https://github.com/coord-e/misskey-rs/blob/aa40e899fdb553b3b33072e4177ea7c3f1c242e0/misskey-api/src/endpoint/notes/delete.rs#L1-L14