Skip to content

Commit

Permalink
Merge pull request #131 from dscottboggs/fix/notification-dismiss-route
Browse files Browse the repository at this point in the history
Fix: notification dismiss route
  • Loading branch information
dscottboggs committed Oct 21, 2023
2 parents b0b620f + f22ee6a commit 2e07180
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- uses: swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.65.0
toolchain: 1.67.0
components: clippy
- run: cargo clippy --all-features -- -D warnings

Expand All @@ -51,7 +51,7 @@ jobs:
- uses: swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.65.0
toolchain: 1.67.0
components: rustfmt
- run: cargo fmt --check

9 changes: 2 additions & 7 deletions entities/src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::Deserialize;
use serde::Serialize;

/// The visibility of a status.
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq, is_enum_variant)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq, is_enum_variant)]
#[serde(rename_all = "lowercase")]
pub enum Visibility {
/// A Direct message to a user
Expand All @@ -13,15 +13,10 @@ pub enum Visibility {
/// Not shown in public timelines
Unlisted,
/// Posted to public timelines
#[default]
Public,
}

impl Default for Visibility {
fn default() -> Self {
Visibility::Public
}
}

impl std::str::FromStr for Visibility {
type Err = crate::error::Error;

Expand Down
5 changes: 1 addition & 4 deletions examples/log_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ async fn run() -> Result<()> {
info!("watching mastodon for events. This will run forever, press Ctrl+C to kill the program.");
stream
.try_for_each(|(event, _client)| async move {
match event {
// fill in how you want to handle events here.
_ => warn!(event = as_serde!(event); "unrecognized event received"),
}
warn!(event = as_serde!(event); "unrecognized event received");
Ok(())
})
.await?;
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub struct ApiError {

impl fmt::Display for ApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/event_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ pub(crate) fn make_event(lines: &[String]) -> Result<Event> {
Event::Delete(data)
}
"filters_changed" => Event::FiltersChanged,
_ => return Err(Error::Other(format!("Unknown event `{}`", event))),
_ => return Err(Error::Other(format!("Unknown event `{event}`"))),
})
}
2 changes: 1 addition & 1 deletion src/helpers/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn authenticate(registration: Registered) -> Result<Mastodon> {
let mut stdout = stdout.lock();
let mut stdin = stdin.lock();

writeln!(&mut stdout, "Click this link to authorize: {}", url)?;
writeln!(&mut stdout, "Click this link to authorize: {url}")?;
write!(&mut stdout, "Paste the returned authorization code: ")?;
stdout.flush()?;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod tests {

#[test]
fn test_from_env_no_prefix() {
let desered = withenv(None, || from_env()).expect("Couldn't deser");
let desered = withenv(None, from_env).expect("Couldn't deser");
assert_eq!(
desered,
Data {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
use std::{fs::OpenOptions, io::Cursor};
use tempfile::{tempdir, NamedTempFile};

const DOC: &'static str = indoc!(
const DOC: &str = indoc!(
r#"
{
"base": "https://example.com",
Expand Down Expand Up @@ -108,7 +108,7 @@ mod tests {
#[test]
fn test_from_slice() {
let doc = DOC.as_bytes();
let desered = from_slice(&doc).expect("Couldn't deserialize Data");
let desered = from_slice(doc).expect("Couldn't deserialize Data");
assert_eq!(
desered,
Data {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {
use std::{fs::OpenOptions, io::Cursor};
use tempfile::{tempdir, NamedTempFile};

const DOC: &'static str = indoc!(
const DOC: &str = indoc!(
r#"
base = "https://example.com"
client_id = "adbc01234"
Expand All @@ -106,7 +106,7 @@ mod tests {
#[test]
fn test_from_slice() {
let doc = DOC.as_bytes();
let desered = from_slice(&doc).expect("Couldn't deserialize Data");
let desered = from_slice(doc).expect("Couldn't deserialize Data");
assert_eq!(
desered,
Data {
Expand Down
8 changes: 4 additions & 4 deletions src/mastodon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ impl Mastodon {
(get (local: bool,)) get_public_timeline: "timelines/public" => Vec<Status>,
(post (uri: Cow<'static, str>,)) follows: "follows" => Account,
(post) clear_notifications: "notifications/clear" => Empty,
(post (id: &str,)) dismiss_notification: "notifications/dismiss" => Empty,
(get) get_push_subscription: "push/subscription" => Subscription,
(delete) delete_push_subscription: "push/subscription" => Empty,
(get) get_filters: "filters" => Vec<Filter>,
Expand All @@ -109,6 +108,7 @@ impl Mastodon {
(get) mute[AccountId]: "accounts/{}/mute" => Relationship,
(get) unmute[AccountId]: "accounts/{}/unmute" => Relationship,
(get) get_notification[NotificationId]: "notifications/{}" => Notification,
(post) dismiss_notification[NotificationId]: "notifications/{}/dismiss" => Empty,
(get) get_status[StatusId]: "statuses/{}" => Status,
(get) get_context[StatusId]: "statuses/{}/context" => Context,
(get) get_card[StatusId]: "statuses/{}/card" => Card,
Expand Down Expand Up @@ -171,7 +171,7 @@ impl Mastodon {

/// PUT /api/v1/filters/:id
pub async fn update_filter(&self, id: &str, request: &mut AddFilterRequest) -> Result<Filter> {
let url = self.route(format!("/api/v1/filters/{}", id));
let url = self.route(format!("/api/v1/filters/{id}"));
let response = self.client.put(&url).json(&request).send().await?;

read_response(response).await
Expand Down Expand Up @@ -207,9 +207,9 @@ impl Mastodon {
pub async fn get_tagged_timeline(&self, hashtag: String, local: bool) -> Result<Vec<Status>> {
let base = "/api/v1/timelines/tag/";
let url = if local {
self.route(format!("{}{}?local=1", base, hashtag))
self.route(format!("{base}{hashtag}?local=1"))
} else {
self.route(format!("{}{}", base, hashtag))
self.route(format!("{base}{hashtag}"))
};

self.get(url).await
Expand Down
19 changes: 7 additions & 12 deletions src/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Serialize for Scopes {
where
S: Serializer,
{
let repr = format!("{}", self);
let repr = format!("{self}");
serializer.serialize_str(&repr)
}
}
Expand Down Expand Up @@ -178,12 +178,7 @@ impl Scopes {
/// let read_write = read.and(write);
/// ```
pub fn and(self, other: Scopes) -> Scopes {
let new_set: HashSet<_> = self
.scopes
.union(&other.scopes)
.into_iter()
.copied()
.collect();
let new_set: HashSet<_> = self.scopes.union(&other.scopes).copied().collect();
Scopes { scopes: new_set }
}

Expand Down Expand Up @@ -342,7 +337,7 @@ impl fmt::Display for Scope {
Follow => "follow",
Push => "push",
};
write!(f, "{}", s)
write!(f, "{s}")
}
}

Expand Down Expand Up @@ -419,8 +414,8 @@ impl PartialOrd for Read {

impl Ord for Read {
fn cmp(&self, other: &Read) -> Ordering {
let a = format!("{:?}", self);
let b = format!("{:?}", other);
let a = format!("{self:?}");
let b = format!("{other:?}");
a.cmp(&b)
}
}
Expand Down Expand Up @@ -514,8 +509,8 @@ impl PartialOrd for Write {

impl Ord for Write {
fn cmp(&self, other: &Write) -> Ordering {
let a = format!("{:?}", self);
let b = format!("{:?}", other);
let a = format!("{self:?}");
let b = format!("{other:?}");
a.cmp(&b)
}
}
Expand Down

0 comments on commit 2e07180

Please sign in to comment.