feat: recent_mentions endpoints

Adds GET /users/@me/mentions and DELETE /users/@me/mentions/{message.id}
This commit is contained in:
kozabrada123 2024-08-09 09:29:48 +02:00
parent fa70c55944
commit 9d847906be
2 changed files with 83 additions and 2 deletions

View File

@ -13,8 +13,8 @@ use crate::{
ratelimiter::ChorusRequest, ratelimiter::ChorusRequest,
types::{ types::{
DeleteDisableUserSchema, GetPomeloEligibilityReturn, GetPomeloSuggestionsReturn, DeleteDisableUserSchema, GetPomeloEligibilityReturn, GetPomeloSuggestionsReturn,
GetUserProfileSchema, LimitType, PublicUser, Snowflake, User, UserModifyProfileSchema, GetRecentMentionsSchema, GetUserProfileSchema, LimitType, PublicUser, Snowflake, User,
UserModifySchema, UserProfile, UserProfileMetadata, UserSettings, UserModifyProfileSchema, UserModifySchema, UserProfile, UserProfileMetadata, UserSettings,
VerifyUserEmailChangeResponse, VerifyUserEmailChangeSchema, VerifyUserEmailChangeResponse, VerifyUserEmailChangeSchema,
}, },
}; };
@ -358,6 +358,58 @@ impl ChorusUser {
ChorusResult::Err(result.err().unwrap()) 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 <https://docs.discord.sex/resources/user#get-recent-mentions>
pub async fn get_recent_mentions(
&mut self,
query_parameters: GetRecentMentionsSchema,
) -> ChorusResult<Vec<crate::types::Message>> {
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::<Vec<crate::types::Message>>(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 <https://docs.discord.sex/resources/user#delete-recent-mention>
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 { impl User {

View File

@ -228,3 +228,32 @@ pub(crate) struct GetPomeloSuggestionsReturn {
pub(crate) struct GetPomeloEligibilityReturn { pub(crate) struct GetPomeloEligibilityReturn {
pub taken: bool 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 <https://docs.discord.sex/resources/user#get-recent-mentions>
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<Snowflake>,
/// Max number of messages to return
///
/// Should be between 1 and 100.
///
/// If unset the limit is 25 messages
pub limit: Option<u8>,
/// Limit messages to a specific guild
pub guild_id: Option<Snowflake>,
/// Whether to include role mentions.
///
/// If unset the server assumes true
pub roles: Option<bool>,
/// Whether to include @everyone and @here mentions.
///
/// If unset the server assumes true
pub everyone: Option<bool>,
}