Skip to content

Commit

Permalink
Add Snowflake aliases for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
novacrazy committed Apr 15, 2024
1 parent 1f51e75 commit adcc911
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/api/commands/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ command! {
+struct GetFilesystemStatus -> One FilesystemStatus: OPTIONS("file") {}

+struct GetFileStatus -> One FileStatus: HEAD("file" / file_id) {
pub file_id: Snowflake,
pub file_id: FileId,
}
}

Expand Down
46 changes: 23 additions & 23 deletions src/api/commands/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

command! {
+struct GetParty -> One Party: GET("party" / party_id) {
pub party_id: Snowflake,
pub party_id: PartyId,
}

+struct CreateParty -> One Party: POST[5000 ms, 1]("party") {
Expand All @@ -24,7 +24,7 @@ command! {
}

+struct PatchParty -> One Party: PATCH[500 ms, 1]("party" / party_id) {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[derive(Default, PartialEq)]
Expand All @@ -45,7 +45,7 @@ command! {

#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default, setter(into)))]
pub default_room: Option<Snowflake>,
pub default_room: Option<RoomId>,

#[serde(default, skip_serializing_if = "Nullable::is_undefined")]
#[cfg_attr(feature = "builder", builder(default, setter(into)))]
Expand All @@ -58,17 +58,17 @@ command! {
}

+struct DeleteParty -> One (): DELETE("party" / party_id) {
pub party_id: Snowflake,
pub party_id: PartyId,
}

// TODO: Use same command for accepting?
+struct TransferOwnership -> One (): PUT("party" / party_id / "owner" / user_id) {
pub party_id: Snowflake,
pub user_id: Snowflake,
pub party_id: PartyId,
pub user_id: UserId,
}

+struct CreateRole -> One Role: POST[1000 ms, 1]("party" / party_id / "roles") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -79,8 +79,8 @@ command! {
}

+struct PatchRole -> One Role: PATCH("party" / party_id / "roles" / role_id) {
pub party_id: Snowflake,
pub role_id: Snowflake,
pub party_id: PartyId,
pub role_id: RoleId,

;
#[derive(Default, PartialEq)]
Expand Down Expand Up @@ -114,34 +114,34 @@ command! {
}

+struct DeleteRole -> One (): DELETE("party" / party_id / "roles" / role_id) {
pub party_id: Snowflake,
pub role_id: Snowflake,
pub party_id: PartyId,
pub role_id: RoleId,
}

+struct GetPartyMembers -> Many PartyMember: GET("party" / party_id / "members") {
pub party_id: Snowflake,
pub party_id: PartyId,
}

+struct GetPartyMember -> One PartyMember: GET("party" / party_id / "member" / member_id) {
pub party_id: Snowflake,
pub member_id: Snowflake,
pub party_id: PartyId,
pub member_id: UserId,
}

+struct GetPartyRooms -> Many Room: GET("party" / party_id / "rooms") {
pub party_id: Snowflake,
pub party_id: PartyId,
}

+struct GetPartyInvites -> Many Invite: GET("party" / party_id / "invites") {
pub party_id: Snowflake,
pub party_id: PartyId,
}

+struct GetMemberProfile -> One UserProfile: GET("party" / party_id / "members" / user_id / "profile") {
pub party_id: Snowflake,
pub user_id: Snowflake,
pub party_id: PartyId,
pub user_id: UserId,
}

+struct UpdateMemberProfile -> One UserProfile: PATCH("party" / party_id / "members" / "profile") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -152,7 +152,7 @@ command! {
}

+struct CreatePartyInvite -> One Invite: POST[2000 ms, 1]("party" / party_id / "invites") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
/// Infinite parameters may only be used with appropriate permissions
Expand All @@ -175,7 +175,7 @@ command! {
}

+struct CreatePinFolder -> One PinFolder: POST("party" / party_id / "pins") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -190,7 +190,7 @@ command! {
}

+struct CreateRoom -> One Room: POST[5000 ms, 1]("party" / party_id / "rooms") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -217,7 +217,7 @@ command! {
}

+struct SearchParty -> One (): POST("party" / party_id / "search") {
pub party_id: Snowflake,
pub party_id: PartyId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand Down
75 changes: 38 additions & 37 deletions src/api/commands/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
command! {
/// Create message command
+struct CreateMessage -> One Message: POST[100 ms, 2]("room" / room_id / "messages") where SEND_MESSAGES {
pub room_id: Snowflake,
pub room_id: RoomId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -14,7 +14,7 @@ command! {

#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
pub parent: Option<Snowflake>,
pub parent: Option<RoomId>,

#[serde(default, skip_serializing_if = "ThinVec::is_empty")]
#[cfg_attr(feature = "builder", builder(default, setter(into)))]
Expand All @@ -36,8 +36,8 @@ command! {
}

+struct EditMessage -> One Message: PATCH[500 ms, 2]("room" / room_id / "messages" / msg_id) where SEND_MESSAGES {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -54,30 +54,30 @@ command! {
}

+struct DeleteMessage -> One (): DELETE("room" / room_id / "messages" / msg_id) where READ_MESSAGE_HISTORY {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
}

+struct GetMessage -> One Message: GET("room" / room_id / "messages" / msg_id) where READ_MESSAGE_HISTORY {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
}

+struct StartTyping -> One (): POST[100 ms]("room" / room_id / "typing") where SEND_MESSAGES {
pub room_id: Snowflake,
pub room_id: RoomId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
#[derive(Default)] struct StartTypingBody {
/// Will only show within the parent context if set
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
pub parent: Option<Snowflake>,
pub parent: Option<MessageId>,
}
}

+struct GetMessages -> Many Message: GET("room" / room_id / "messages") where READ_MESSAGE_HISTORY {
pub room_id: Snowflake,
pub room_id: RoomId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand All @@ -88,7 +88,7 @@ command! {

#[serde(default, alias = "thread", skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
pub parent: Option<Snowflake>,
pub parent: Option<MessageId>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
Expand All @@ -97,7 +97,7 @@ command! {
#[serde(default, alias = "pins", skip_serializing_if = "ThinVec::is_empty")]
#[cfg_attr(feature = "builder", builder(default, setter(into)))]
#[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))]
pub pinned: ThinVec<Snowflake>,
pub pinned: ThinVec<FolderId>,

/// If true, return only messages in the channel which have been starred by us
#[serde(default, skip_serializing_if = "crate::models::is_false")]
Expand All @@ -116,55 +116,55 @@ command! {
}

+struct PinMessage -> One (): PUT("room" / room_id / "messages" / msg_id / "pins" / pin_tag) {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub pin_tag: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub pin_tag: FolderId,
}

+struct UnpinMessage -> One (): DELETE("room" / room_id / "messages" / msg_id / "pins" / pin_tag) {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub pin_tag: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub pin_tag: FolderId,
}

+struct StarMessage -> One (): PUT("room" / room_id / "messages" / msg_id / "star") {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
}

+struct UnstarMessage -> One (): DELETE("room" / room_id / "messages" / msg_id / "star") {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
}

+struct PutReaction -> One (): PUT("room" / room_id / "messages" / msg_id / "reactions" / emote_id / "@me") {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub emote_id: EmoteOrEmoji,
}

+struct DeleteOwnReaction -> One (): DELETE("room" / room_id / "messages" / msg_id / "reactions" / emote_id / "@me") {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub emote_id: EmoteOrEmoji,
}

+struct DeleteUserReaction -> One (): DELETE("room" / room_id / "messages" / msg_id / "reactions" / emote_id / user_id) {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub emote_id: EmoteOrEmoji,
pub user_id: Snowflake,
pub user_id: UserId,
}

+struct DeleteAllReactions -> One (): DELETE("room" / room_id / "messages" / msg_id / "reactions") {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
}

// TODO
+struct GetReactions -> Many (): GET("room" / room_id / "messages" / msg_id / "reactions" / emote_id) {
pub room_id: Snowflake,
pub msg_id: Snowflake,
pub room_id: RoomId,
pub msg_id: MessageId,
pub emote_id: EmoteOrEmoji,

;
Expand All @@ -173,18 +173,19 @@ command! {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
after: Option<Snowflake>,

#[serde(default, skip_serializing_if = "Option::is_none")]
#[cfg_attr(feature = "builder", builder(default))]
limit: Option<i8>,
}
}

+struct GetRoom -> One FullRoom: GET("room" / room_id) {
pub room_id: Snowflake,
pub room_id: RoomId,
}

+struct PatchRoom -> One FullRoom: PATCH[500 ms, 1]("room" / room_id) {
pub room_id: Snowflake,
pub room_id: RoomId,

;
/// `Nullable::Undefined` or `Option::None` fields indicate no change
Expand Down Expand Up @@ -225,6 +226,6 @@ command! {
}

+struct DeleteRoom -> One (): DELETE[500 ms, 1]("room" / room_id) {
pub room_id: Snowflake,
pub room_id: RoomId,
}
}
4 changes: 2 additions & 2 deletions src/api/commands/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ command! {
+struct GetRelationships -> Many Relationship: GET("user" / "@me" / "relationships") {}

+struct PatchRelationship -> One Relationship: PATCH[1000 ms, 1]("user" / "@me" / "relationships" / user_id) {
pub user_id: Snowflake,
pub user_id: UserId,

;
#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
Expand Down Expand Up @@ -167,7 +167,7 @@ command! {

/// Fetches full user information, including profile data
+struct GetUser -> One User: GET("user" / user_id) {
pub user_id: Snowflake,
pub user_id: UserId,
}

+struct UpdateUserPrefs -> One (): PATCH[200 ms]("user" / "@me" / "prefs") {
Expand Down
4 changes: 2 additions & 2 deletions src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use error::DriverError;

use crate::{
api::{Command, CommandFlags},
models::{AuthToken, Snowflake},
models::{AuthToken, FileId},
};

#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -215,7 +215,7 @@ where
use base64::engine::{general_purpose::STANDARD, Engine};

impl Driver {
pub async fn patch_file(&self, file_id: Snowflake, offset: u64, chunk: bytes::Bytes) -> Result<u64, DriverError> {
pub async fn patch_file(&self, file_id: FileId, offset: u64, chunk: bytes::Bytes) -> Result<u64, DriverError> {
let auth = match self.auth {
Some(ref auth) => auth.1.clone(),
None => return Err(DriverError::MissingAuthorization),
Expand Down
6 changes: 3 additions & 3 deletions src/models/emote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ common::impl_sql_for_bitflags!(EmoteFlags);
#[cfg_attr(feature = "rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
pub struct CustomEmote {
pub id: Snowflake,
pub party_id: Snowflake,
pub asset: Snowflake,
pub id: EmoteId,
pub party_id: PartyId,
pub asset: FileId,
pub name: SmolStr,
pub flags: EmoteFlags,
pub aspect_ratio: f32,
Expand Down
2 changes: 1 addition & 1 deletion src/models/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
#[cfg_attr(feature = "rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
#[cfg_attr(feature = "rkyv", archive(check_bytes))]
pub struct File {
pub id: Snowflake,
pub id: FileId,
pub filename: SmolStr,
pub size: i64,

Expand Down
Loading

0 comments on commit adcc911

Please sign in to comment.