From 9d847906be67874acb88ad39fd5cf5f557291fd7 Mon Sep 17 00:00:00 2001 From: kozabrada123 Date: Fri, 9 Aug 2024 09:29:48 +0200 Subject: [PATCH] feat: recent_mentions endpoints Adds GET /users/@me/mentions and DELETE /users/@me/mentions/{message.id} --- src/api/users/users.rs | 56 ++++++++++++++++++++++++++++++++++++++-- src/types/schema/user.rs | 29 +++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/api/users/users.rs b/src/api/users/users.rs index 6d47303..6596782 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -13,8 +13,8 @@ use crate::{ ratelimiter::ChorusRequest, types::{ DeleteDisableUserSchema, GetPomeloEligibilityReturn, GetPomeloSuggestionsReturn, - GetUserProfileSchema, LimitType, PublicUser, Snowflake, User, UserModifyProfileSchema, - UserModifySchema, UserProfile, UserProfileMetadata, UserSettings, + GetRecentMentionsSchema, GetUserProfileSchema, LimitType, PublicUser, Snowflake, User, + UserModifyProfileSchema, UserModifySchema, UserProfile, UserProfileMetadata, UserSettings, VerifyUserEmailChangeResponse, VerifyUserEmailChangeSchema, }, }; @@ -358,6 +358,58 @@ impl ChorusUser { ChorusResult::Err(result.err().unwrap()) } + + /// Fetches a list of [Message](crate::types::Message)s that the current user has been + /// mentioned in during the last 7 days. + /// + /// As of 2024/08/09, Spacebar does not yet implement this endpoint. + /// + /// See + pub async fn get_recent_mentions( + &mut self, + query_parameters: GetRecentMentionsSchema, + ) -> ChorusResult> { + let request = Client::new() + .get(format!( + "{}/users/@me/mentions", + self.belongs_to.read().unwrap().urls.api + )) + .header("Authorization", self.token()) + .query(&query_parameters); + + let chorus_request = ChorusRequest { + request, + limit_type: LimitType::default(), + }; + + chorus_request + .deserialize_response::>(self) + .await + } + + /// Acknowledges a message the current user has been mentioned in. + /// + /// Fires a RecentMentionDelete gateway event. (Note: yet to be implemented in chorus, see [#545](https://github.com/polyphony-chat/chorus/issues/545)) + /// + /// As of 2024/08/09, Spacebar does not yet implement this endpoint. + /// + /// See + pub async fn delete_recent_mention(&mut self, message_id: Snowflake) -> ChorusResult<()> { + let request = Client::new() + .delete(format!( + "{}/users/@me/mentions/{}", + self.belongs_to.read().unwrap().urls.api, + message_id + )) + .header("Authorization", self.token()); + + let chorus_request = ChorusRequest { + request, + limit_type: LimitType::default(), + }; + + chorus_request.handle_request_as_result(self).await + } } impl User { diff --git a/src/types/schema/user.rs b/src/types/schema/user.rs index b336a63..f7a97d2 100644 --- a/src/types/schema/user.rs +++ b/src/types/schema/user.rs @@ -228,3 +228,32 @@ pub(crate) struct GetPomeloSuggestionsReturn { pub(crate) struct GetPomeloEligibilityReturn { pub taken: bool } + +#[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq, Eq)] +/// Query string parameters for the route GET /users/@me/mentions +/// ([crate::instance::ChorusUser::get_recent_mentions]) +/// +/// See +pub struct GetRecentMentionsSchema { + /// Only fetch messages before this message id + /// + /// Due to the nature of snowflakes, this can be easily used to fetch + /// messages before a certain timestamp + pub before: Option, + /// Max number of messages to return + /// + /// Should be between 1 and 100. + /// + /// If unset the limit is 25 messages + pub limit: Option, + /// Limit messages to a specific guild + pub guild_id: Option, + /// Whether to include role mentions. + /// + /// If unset the server assumes true + pub roles: Option, + /// Whether to include @everyone and @here mentions. + /// + /// If unset the server assumes true + pub everyone: Option, +}