Rearrange macro; fix quoting issue

This commit is contained in:
D. Scott Boggs 2022-12-22 12:28:08 -05:00
parent ca7f9c86a6
commit 94b7cd4087
2 changed files with 27 additions and 15 deletions

View File

@ -440,7 +440,7 @@ macro_rules! paged_routes_with_id {
} }
macro_rules! streaming { macro_rules! streaming {
($stream:literal@$fn_name:ident ($desc:tt), $($rest:tt)*) => { ($desc:tt $fn_name:ident@$stream:literal, $($rest:tt)*) => {
doc_comment! { doc_comment! {
concat!( concat!(
$desc, $desc,
@ -468,7 +468,7 @@ tokio_test::block_on(async {
});" });"
), ),
pub async fn $fn_name(&self) -> Result<impl TryStream<Ok=Event, Error=Error>> { pub async fn $fn_name(&self) -> Result<impl TryStream<Ok=Event, Error=Error>> {
let url = self.route(concat!("/api/v1/streaming/", stringify!($stream))); let url = self.route(&format!("/api/v1/streaming/{}", $stream));
let response = self.authenticated(self.client.get(&url)).send().await?; let response = self.authenticated(self.client.get(&url)).send().await?;
debug!( debug!(
status = log_serde!(response Status), url = &url, status = log_serde!(response Status), url = &url,
@ -480,7 +480,7 @@ tokio_test::block_on(async {
} }
streaming! { $($rest)* } streaming! { $($rest)* }
}; };
($stream:literal($param:ident: $param_type:ty, like $param_doc_val:literal)@$fn_name:ident ($desc:tt), $($rest:tt)*) => { ($desc:tt $fn_name:ident($param:ident: $param_type:ty, like $param_doc_val:literal)@$stream:literal, $($rest:tt)*) => {
doc_comment! { doc_comment! {
concat!( concat!(
$desc, $desc,

View File

@ -130,18 +130,30 @@ impl Mastodon {
} }
streaming! { streaming! {
"user"@stream_user ("returns events that are relevant to the authorized user, i.e. home timeline & notifications"), "returns events that are relevant to the authorized user, i.e. home timeline & notifications"
"public"@stream_public ("All public posts known to the server. Analogous to the federated timeline."), stream_user@"user",
"public:media"@stream_public_media ("All public posts known to the server, filtered for media attachments. Analogous to the federated timeline with 'only media' enabled."), "All public posts known to the server. Analogous to the federated timeline."
"public:local"@stream_local ("All public posts originating from this server."), stream_public@"public",
"public:local:media"@stream_local_media ("All public posts originating from this server, filtered for media attachments. Analogous to the local timeline with 'only media' enabled."), "All public posts known to the server, filtered for media attachments. Analogous to the federated timeline with 'only media' enabled."
"public:remote"@stream_remote ("All public posts originating from other servers."), stream_public_media@"public:media",
"public:remote:media"@stream_remote_media ("All public posts originating from other servers, filtered for media attachments."), "All public posts originating from this server."
"hashtag"(tag: impl AsRef<str>, like "#bots")@stream_hashtag ("All public posts using a certain hashtag."), stream_local@"public:local",
"hashtag:local"(tag: impl AsRef<str>, like "#bots")@stream_local_hashtag ("All public posts using a certain hashtag, originating from this server."), "All public posts originating from this server, filtered for media attachments. Analogous to the local timeline with 'only media' enabled."
"user:notification"@stream_notifications ("Notifications for the current user."), stream_local_media@"public:local:media",
"list"(list: impl AsRef<str>, like "12345")@stream_list ("Updates to a specific list."), "All public posts originating from other servers."
"direct"@stream_direct ("Updates to direct conversations."), stream_remote@"public:remote",
"All public posts originating from other servers, filtered for media attachments."
stream_remote_media@"public:remote:media",
"All public posts using a certain hashtag."
stream_hashtag(tag: impl AsRef<str>, like "#bots")@"hashtag",
"All public posts using a certain hashtag, originating from this server."
stream_local_hashtag(tag: impl AsRef<str>, like "#bots")@"hashtag:local",
"Notifications for the current user."
stream_notifications@"user:notification",
"Updates to a specific list."
stream_list(list: impl AsRef<str>, like "12345")@"list",
"Updates to direct conversations."
stream_direct@"direct",
} }
/// Create a new Mastodon Client /// Create a new Mastodon Client