Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking for Release v0.17.0 #562

Merged
merged 183 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 181 commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
c7af410
add WebSocketEvent macro derive, bump chorus-macros to 0.3.0 (#490)
kozabrada123 Apr 19, 2024
319748c
Use WebSocketEvent derive instead of impl WebSocketEvent for .. (#491)
kozabrada123 Apr 28, 2024
b2fd3e1
Move Shared<T> to types/mod.rs, bump some dependencies (#492)
kozabrada123 Apr 28, 2024
aac3172
Reuse gateway backends, don't duplicate them for voice gateway (#493)
kozabrada123 Apr 30, 2024
03f1e7d
Refactor / fix login and register (#495)
kozabrada123 May 5, 2024
c44dd26
Add the repository field to Cargo.toml
szabgab May 10, 2024
4be7ea6
Add the repository field to Cargo.toml (#496)
bitfl0wer May 10, 2024
d4377c5
Ci improvements (#498)
kozabrada123 Jun 2, 2024
f876f25
Update poem dependency
Quat3rnion Jun 2, 2024
d1b3a9a
Convert timestamp fields to DateTime's
Quat3rnion Jun 2, 2024
c445213
Feature lock different types for UserSettings::status
Quat3rnion Jun 2, 2024
7b72944
Make config register_configuration use Rights bitflag object
Quat3rnion Jun 2, 2024
ab4435a
Update tests to use DateTime's for timestamps
Quat3rnion Jun 2, 2024
08952db
Fix tests
Quat3rnion Jun 2, 2024
8c5d80d
Allow joined_at to default if field is not in responses.
Quat3rnion Jun 2, 2024
a75701d
Allow last_pin_timestamp to default if field is not in responses.
Quat3rnion Jun 3, 2024
eefdd4a
Remove serde(with) for message timestamps
Quat3rnion Jun 3, 2024
eb08793
Fix some iso timestamps being strings, not DateTime<Utc> (#499)
kozabrada123 Jun 3, 2024
0bc54ce
Add sqlx::FromRow derive to GuildMember
Quat3rnion Jun 3, 2024
d6ad68c
remove dep: prefix in backend feature list
Quat3rnion Jun 3, 2024
7548f0e
merge latest dev
Quat3rnion Jun 3, 2024
85aa854
Implement sqlx Encode, Decode, Type for Rights bitflag object.
Quat3rnion Jun 4, 2024
7d55bbe
Use Snowflake in Claims
Quat3rnion Jun 4, 2024
179b8d2
Use ChannelType enum on ChannelModifySchema
Quat3rnion Jun 4, 2024
40bdafd
Feature lock Shared, so backend feature gets a facade type
Quat3rnion Jun 4, 2024
4d75aa8
Remove erroneous serde with attributes
Quat3rnion Jun 4, 2024
97f10aa
Add From<Vec<GuildFeatures>> impl for GuildFeaturesList
Quat3rnion Jun 4, 2024
2b06742
Add feature sqlx locks for user, roles on GuildMember
Quat3rnion Jun 4, 2024
f178e51
Use distinct type for explicit_content_filter
Quat3rnion Jun 4, 2024
2b4e9fa
Remove unused imports
Quat3rnion Jun 4, 2024
119a09a
Revert c4452132
Quat3rnion Jun 4, 2024
fcda4cc
Remove final usages of erroneous serde impl
Quat3rnion Jun 4, 2024
2db91e8
Fix errors in documentation tests
Quat3rnion Jun 4, 2024
50c5c29
update dev-dependencies
Quat3rnion Jun 4, 2024
32677b8
actually fix linux tests
Quat3rnion Jun 4, 2024
0c9e9cf
clear warnings
Quat3rnion Jun 4, 2024
82c8f57
Update Cargo.lock
Quat3rnion Jun 4, 2024
cb905d0
Expand documentation to explain facade type
Quat3rnion Jun 4, 2024
0bf5091
Fix oversight for premium_since
Quat3rnion Jun 4, 2024
a5a0459
Backend related updates (#501)
Quat3rnion Jun 4, 2024
c96dcd5
Distinguish InviteType and InviteTargetType
Quat3rnion Jun 5, 2024
6c1493f
Add sqlx Type, Encode, Decode impl for InviteFlags bitflag object.
Quat3rnion Jun 5, 2024
133b03f
Use distinct type `DefaultReaction`
Quat3rnion Jun 5, 2024
450aa9f
Update fields for backend/sqlx compatibility.
Quat3rnion Jun 5, 2024
9f28187
Update derive for backend/sqlx compatibility.
Quat3rnion Jun 5, 2024
cab4cb1
Write custom serialize/deserialize impl's for InviteFlags
Quat3rnion Jun 5, 2024
0f1e693
Clear warnings
Quat3rnion Jun 5, 2024
c34b1da
Add InviteFlags::VIEWED
Quat3rnion Jun 5, 2024
0d01536
Remove double bound for E
Quat3rnion Jun 5, 2024
dfd6b37
Merge branch 'dev' into backend
Quat3rnion Jun 5, 2024
5154d04
Invites (#502)
kozabrada123 Jun 5, 2024
c8bde0c
Use distinct types in `InviteGuild` object.
Quat3rnion Jun 5, 2024
5110e9b
Implement `From<Guild> for InviteGuild`
Quat3rnion Jun 5, 2024
eb87bd6
Add `GetInvitesSchema`
Quat3rnion Jun 5, 2024
556fbb9
Add forgotten import and pub use.
Quat3rnion Jun 5, 2024
a0cddbf
Fix compile error
Quat3rnion Jun 6, 2024
83a8f08
Update docs aesthetics
Quat3rnion Jun 7, 2024
3237db7
Backend/invites (#503)
kozabrada123 Jun 7, 2024
0468292
Add type locks
Quat3rnion Jun 7, 2024
ed5365a
Fix inverted type wrapping
Quat3rnion Jun 7, 2024
96c3f53
Merge branch 'dev' into backend/messages
Quat3rnion Jun 7, 2024
c203558
Update Cargo.lock
Quat3rnion Jun 7, 2024
656e5e3
Add SqlxBitFlags derive macro
Quat3rnion Jun 7, 2024
d899758
Utilize new macros and use distinct Flag types
Quat3rnion Jun 7, 2024
d3e2ef9
Add distinct MessageType enum
Quat3rnion Jun 7, 2024
9bd55b9
Fix error in macro
Quat3rnion Jun 7, 2024
590a6d6
Make UserFlags deserialize from string
Quat3rnion Jun 7, 2024
bec0269
Add partial emoji and custom reaction types, refine SQLx mapping
Quat3rnion Jun 17, 2024
d856009
Use chorus_macros from path, since it's there anyway
Quat3rnion Jun 18, 2024
6261ceb
Fix test
Quat3rnion Jun 18, 2024
dfffcf4
Add forgotten feature locks
Quat3rnion Jun 18, 2024
3810170
Remove unused imports, feature locks in macro
Quat3rnion Jun 18, 2024
06b4dc3
forgot a file :(
Quat3rnion Jun 18, 2024
77004ab
Feature lock the macro
Quat3rnion Jun 18, 2024
abc4608
Dirty hack
Quat3rnion Jun 18, 2024
c27bc8d
Fix test
Quat3rnion Jun 18, 2024
d7de1d2
Fix compilation for real, no dirty hack
Quat3rnion Jun 18, 2024
c9a36ce
Maybe fix tests, make UserFlags able to be deserialized from String o…
Quat3rnion Jun 18, 2024
e553d10
Add new SerdeBitFlags derive macro, to help reduce repetitive code
Quat3rnion Jun 18, 2024
a8b7d9d
u8 -> u64
Quat3rnion Jun 18, 2024
4430a7c
Fix deserialization error w/ guild features list
kozabrada123 Jun 18, 2024
3aec588
Merge Quat3rnion/backend/messages (#505)
kozabrada123 Jun 18, 2024
8d56259
chorus macros 0.4.0
kozabrada123 Jun 18, 2024
b3e62b2
always update to latest release of macros
kozabrada123 Jun 18, 2024
a7fc00d
Bump chorus macros to 0.4.0 (#506)
kozabrada123 Jun 18, 2024
b4a8082
Update and add some types in support of the backend (#507)
Quat3rnion Jun 19, 2024
89333d6
Implement gateway options, zlib-stream compression (#508)
kozabrada123 Jun 23, 2024
39e7f89
Backend/guilds (#509)
Quat3rnion Jun 27, 2024
d591616
Add custom deserializer for PermissionOverwriteType (#512)
Quat3rnion Jun 27, 2024
743f106
Miscellaneous fixes (#514)
kozabrada123 Jun 28, 2024
484c692
No openssl (#522)
bitfl0wer Jul 13, 2024
7554f90
Replace `Observer` and `GatewayEvent` with `pubserve` crate
bitfl0wer Jul 13, 2024
ebcb6b6
Fix voice, voice_udp features
bitfl0wer Jul 13, 2024
b0667a3
Replace `Observer` and `GatewayEvent` with `pubserve` crate (#524)
bitfl0wer Jul 13, 2024
491cd25
Add one BILLION derives
bitfl0wer Jul 18, 2024
cd0230e
Provide alternative implementations for PartialEq for some types when…
bitfl0wer Jul 20, 2024
98b129a
Provide alternative implementations for PartialEq for some types when…
bitfl0wer Jul 20, 2024
599969e
Merge branch 'one-billion-derives' of https://github.com/polyphony-ch…
bitfl0wer Jul 20, 2024
0beb448
Fix: Wrong function name
bitfl0wer Jul 20, 2024
88efef6
Fix: Turn unconditional import of sqlx::types::Json into conditional one
bitfl0wer Jul 20, 2024
76146b0
Fix: Compile error with no default features
bitfl0wer Jul 20, 2024
1285d70
Derives (#526)
bitfl0wer Jul 20, 2024
7a2666b
Update CONTRIBUTING.md
bitfl0wer Jul 24, 2024
6cd3c10
Use cargo nextest
bitfl0wer Jul 24, 2024
0bfab58
Use cargo nextest
bitfl0wer Jul 24, 2024
6bc6651
Remove redundant "build" step
bitfl0wer Jul 24, 2024
dd85a7d
Fix/Correct UnavailableGuild object
bitfl0wer Jul 24, 2024
f0fc6ea
Fix testcase that relied on false behavior implemented by older space…
bitfl0wer Jul 24, 2024
7bb35e5
Increase limit integer size to match spacebars' possibilities
bitfl0wer Jul 24, 2024
cc7ed62
Merge branch 'dev' into nextest
bitfl0wer Jul 24, 2024
f32b306
Cargo nextest on wasm, Parallelize "Check common non-default feat. cfg."
bitfl0wer Jul 24, 2024
31509b9
forgor installing nextest
bitfl0wer Jul 24, 2024
d15dfc3
Revert: nextest on wasm
bitfl0wer Jul 24, 2024
e8469c8
Use cargo nextest (#529)
bitfl0wer Jul 24, 2024
feb2b1b
Bump browser_version according to https://www.useragents.me/#most-com…
bitfl0wer Jul 24, 2024
539460a
Fix voice_simple example
kozabrada123 Jul 25, 2024
832576d
Update documentation in gateway_observers example
kozabrada123 Jul 25, 2024
b9bc37f
Readd Observer trait as reexport
kozabrada123 Jul 25, 2024
d829537
remove cargo lock from example
kozabrada123 Jul 25, 2024
a27b488
Publically reexport Subscriber as Observer (#530)
kozabrada123 Jul 25, 2024
4292ab8
Fix #525 (pr #532)
kozabrada123 Jul 26, 2024
111a8c4
change theme_colors from Vec<u32> to (u32, u32)
bitfl0wer Jul 26, 2024
ffcf15d
Custom ThemeColors type with sqlx::Encode and sqlx::Decode impls
bitfl0wer Jul 26, 2024
9dbb5ea
impl sqlx::Type for ThemeColors
bitfl0wer Jul 26, 2024
537b025
Theme colors patch (#533)
bitfl0wer Jul 26, 2024
d4f6a7e
More accurate "GatewayHello::default()"
bitfl0wer Jul 26, 2024
274b9ab
More accurate "GatewayHello::default()" (#534)
bitfl0wer Jul 26, 2024
7bba7c6
Manually implement std::default::Default for GatewayHeartbeat and Gat…
bitfl0wer Jul 27, 2024
5821732
Manually implement std::default::Default for GatewayHeartbeat and Gat…
bitfl0wer Jul 28, 2024
f2f45b4
bump versions of packages to latest compatible versions
bitfl0wer Jul 28, 2024
2bd9fba
bump versions of packages to latest compatible versions (#536)
bitfl0wer Jul 28, 2024
ab82a5d
Update MSRV (#540)
bitfl0wer Aug 2, 2024
e4dd31e
sqlx related improvements (#542)
bitfl0wer Aug 4, 2024
ec9541f
CI/CD: add cargo-doc job (#544)
kozabrada123 Aug 9, 2024
86b0229
Initial support for PostgreSQL (#548)
bitfl0wer Aug 21, 2024
cfccae8
Bump sqlx-pg-uint
bitfl0wer Aug 21, 2024
e9b3de2
Uncomment and update decode_token()
bitfl0wer Aug 22, 2024
ebea18c
Snowflake: PgU64 as base for sqlx (#551)
bitfl0wer Aug 25, 2024
f0dbd34
sqlx_bitflag_derive: Use PgU64 as translation base (#552)
bitfl0wer Aug 25, 2024
5bee907
Prefer `&str` over `String` when possible (#553)
bitfl0wer Aug 26, 2024
9926f8a
Tungstenite: Match scheme for "ws" or "wss" (#554)
bitfl0wer Aug 26, 2024
05b9f1c
Add missing `impl From<Snowflake> for u64`, closes `From<Snowflake> f…
bitfl0wer Aug 26, 2024
72c5d13
Update README.md
bitfl0wer Aug 26, 2024
e316372
Bump package versions
bitfl0wer Aug 26, 2024
d846ce9
move up sending identify
bitfl0wer Aug 26, 2024
76186a0
Make instance GatewayOptions configurable for library consumers (#555)
bitfl0wer Aug 26, 2024
411db01
Revert d846ce9948ebb07988428250d6a02d2ea920a451
bitfl0wer Aug 26, 2024
1c90c8e
0.16.0: fix lints (#558)
kozabrada123 Aug 28, 2024
261fe45
Bump version to v0.16.0
bitfl0wer Aug 28, 2024
9f618f2
Bump sqlx-pg-uint
bitfl0wer Sep 24, 2024
8fc9f4c
Add Clone derive to GatewayRequestGuildMembers
bitfl0wer Sep 26, 2024
e7e3cb6
User routes update (#537)
kozabrada123 Sep 27, 2024
333dad8
Differentiate between instance softwares (#560)
kozabrada123 Sep 28, 2024
2a35429
Ready Event Updates (#561)
bitfl0wer Sep 28, 2024
4c2b307
Merge remote-tracking branch 'origin/main' into dev
bitfl0wer Sep 29, 2024
f30405d
Add "Merging" section
bitfl0wer Sep 29, 2024
b1b0738
Document all fields of GatewayReady and GatewayReadyBot
bitfl0wer Sep 29, 2024
7f0865b
Fix PostgreSQL compatibility of READY and some newer enum types
bitfl0wer Sep 29, 2024
f06929f
update Cargo.lock
bitfl0wer Sep 29, 2024
490e421
Bump sqlx and sqlx-pg-uint
bitfl0wer Sep 29, 2024
07c5530
Adjust premium_type field to be of type PremiumType (#563)
bitfl0wer Sep 30, 2024
b87df59
Implement custom sqlx::Postgres en-/decoding for PremiumType enum (#565)
bitfl0wer Oct 7, 2024
515750c
Make Relationship struct sqlx/symfonia-ready (#567)
bitfl0wer Oct 8, 2024
c52012e
#567: Append: Nickname *cannot* be derived from user id
bitfl0wer Oct 8, 2024
7b50d56
Move Shared<T> to types/mod.rs, bump some dependencies (#492)
kozabrada123 Apr 28, 2024
673181e
Refactor / fix login and register (#495)
kozabrada123 May 5, 2024
f5c4fc3
Implement gateway options, zlib-stream compression (#508)
kozabrada123 Jun 23, 2024
17e46db
Backend/guilds (#509)
Quat3rnion Jun 27, 2024
b6ca485
Initial support for PostgreSQL (#548)
bitfl0wer Aug 21, 2024
239f994
Add Clone derive to GatewayRequestGuildMembers
bitfl0wer Sep 26, 2024
0eea35a
User routes update (#537)
kozabrada123 Sep 27, 2024
08783cc
Differentiate between instance softwares (#560)
kozabrada123 Sep 28, 2024
3aac8ea
Ready Event Updates (#561)
bitfl0wer Sep 28, 2024
048d129
Add "Merging" section
bitfl0wer Sep 29, 2024
36a4ac9
Document all fields of GatewayReady and GatewayReadyBot
bitfl0wer Sep 29, 2024
e0c6fce
Fix PostgreSQL compatibility of READY and some newer enum types
bitfl0wer Sep 29, 2024
36073f1
Adjust premium_type field to be of type PremiumType (#563)
bitfl0wer Sep 30, 2024
9db77fb
Implement custom sqlx::Postgres en-/decoding for PremiumType enum (#565)
bitfl0wer Oct 7, 2024
7db34f7
Make Relationship struct sqlx/symfonia-ready (#567)
bitfl0wer Oct 8, 2024
720531d
#567: Append: Nickname *cannot* be derived from user id
bitfl0wer Oct 8, 2024
fa8e590
Merge branch 'dev' of https://github.com/polyphony-chat/chorus into dev
bitfl0wer Oct 10, 2024
dd4e7ae
i dont wanna talk about it
bitfl0wer Oct 10, 2024
a2f9f96
Bump version to 0.17.0
bitfl0wer Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
with:
cache-all-crates: "true"
prefix-key: "macos"
- uses: taiki-e/install-action@nextest
- name: Run WASM tests with Safari, Firefox, Chrome
run: |
rustup target add wasm32-unknown-unknown
Expand Down Expand Up @@ -126,6 +127,7 @@ jobs:
with:
cache-all-crates: "true"
prefix-key: "macos"
- uses: taiki-e/install-action@nextest
- name: Run WASM tests with Safari, Firefox, Chrome
run: |
rustup target add wasm32-unknown-unknown
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ ever since [we streamlined the process of doing so](https://github.com/polyphony

If you'd like to contribute new functionality, check out [The 'Meta'-issues.](https://github.com/polyphony-chat/chorus/issues?q=is%3Aissue+label%3A%22Type%3A+Meta%22+) They contain a comprehensive list of all features which are yet missing for full Discord.com compatibility.
Please feel free to open an Issue with the idea you have, or a Pull Request.

## Merging

All pull requests opened into the `dev` branch should be merged via the "Squash and Merge" option to keep the commit history small. Merging into the `main` branch should be done via a regular merge commit. This way, GitHub will correctly attribute contributors and count statistics for the insights tab.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/api/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,25 @@ impl Instance {
// We do not have a user yet, and the UserRateLimits will not be affected by a login
// request (since login is an instance wide limit), which is why we are just cloning the
// instances' limits to pass them on as user_rate_limits later.
<<<<<<< HEAD
let mut user = ChorusUser::shell(Arc::new(RwLock::new(self.clone())), "None").await;

let login_result = chorus_request
.deserialize_response::<LoginResult>(&mut user)
.await?;
user.set_token(&login_result.token);
=======
let mut user =
ChorusUser::shell(Arc::new(RwLock::new(self.clone())), "None".to_string()).await;

let login_result = chorus_request
.deserialize_response::<LoginResult>(&mut user)
.await?;
user.set_token(login_result.token);
>>>>>>> 03f1e7d (Refactor / fix login and register (#495))
user.settings = login_result.settings;

let object = User::get(&mut user, None).await?;
let object = User::get_current(&mut user).await?;
*user.object.write().unwrap() = object;

let mut identify = GatewayIdentifyPayload::common();
Expand Down
8 changes: 7 additions & 1 deletion src/api/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@

impl Instance {
/// Logs into an existing account on the spacebar server, using only a token.
<<<<<<< HEAD
Fixed Show fixed Hide fixed
pub async fn login_with_token(&mut self, token: &str) -> ChorusResult<ChorusUser> {
let mut user = ChorusUser::shell(Arc::new(RwLock::new(self.clone())), token).await;
=======
Fixed Show fixed Hide fixed
pub async fn login_with_token(&mut self, token: String) -> ChorusResult<ChorusUser> {
let mut user =
ChorusUser::shell(Arc::new(RwLock::new(self.clone())), token).await;
>>>>>>> 03f1e7d (Refactor / fix login and register (#495))
Fixed Show fixed Hide fixed

let object = User::get(&mut user, None).await?;
let object = User::get_current(&mut user).await?;
let settings = User::get_settings(&mut user).await?;

*user.object.write().unwrap() = object;
Expand Down
10 changes: 10 additions & 0 deletions src/api/auth/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ impl Instance {
// We do not have a user yet, and the UserRateLimits will not be affected by a login
// request (since register is an instance wide limit), which is why we are just cloning
// the instances' limits to pass them on as user_rate_limits later.
<<<<<<< HEAD
let mut user = ChorusUser::shell(Arc::new(RwLock::new(self.clone())), "None").await;

=======
let mut user =
ChorusUser::shell(Arc::new(RwLock::new(self.clone())), "None".to_string()).await;

>>>>>>> 03f1e7d (Refactor / fix login and register (#495))
let token = chorus_request
.deserialize_response::<Token>(&mut user)
.await?
.token;
<<<<<<< HEAD
user.set_token(&token);
=======
user.set_token(token);
>>>>>>> 03f1e7d (Refactor / fix login and register (#495))

let object = User::get(&mut user, None).await?;
let settings = User::get_settings(&mut user).await?;
Expand Down
104 changes: 104 additions & 0 deletions src/api/instance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

//! Contains miscellaneous api routes, such as /version and /ping
use serde_json::from_str;

use crate::errors::{ChorusError, ChorusResult};
use crate::instance::Instance;
use crate::types::{GeneralConfiguration, PingReturn, VersionReturn};

impl Instance {
/// Pings the instance, also fetches instance info.
///
/// See: [PingReturn]
///
/// # Notes
/// This is a Spacebar only endpoint.
///
/// # Reference
/// See <https://docs.spacebar.chat/routes/#get-/ping/>
pub async fn ping(&self) -> ChorusResult<PingReturn> {
let endpoint_url = format!("{}/ping", self.urls.api.clone());

let request = match self.client.get(&endpoint_url).send().await {
Ok(result) => result,
Err(e) => {
return Err(ChorusError::RequestFailed {
url: endpoint_url,
error: e.to_string(),
});
}
};

if !request.status().as_str().starts_with('2') {
return Err(ChorusError::ReceivedErrorCode {
error_code: request.status().as_u16(),
error: request.text().await.unwrap(),
});
}

let response_text = match request.text().await {
Ok(string) => string,
Err(e) => {
return Err(ChorusError::InvalidResponse {
error: format!(
"Error while trying to process the HTTP response into a String: {}",
e
),
});
}
};

match from_str::<PingReturn>(&response_text) {
Ok(return_value) => Ok(return_value),
Err(e) => Err(ChorusError::InvalidResponse { error: format!("Error while trying to deserialize the JSON response into requested type T: {}. JSON Response: {}",
e, response_text) })
}
}

/// Fetches the instance's software implementation and version.
///
/// See: [VersionReturn]
///
/// # Notes
/// This is a Symfonia only endpoint. (For now, we hope that spacebar will adopt it as well)
pub async fn get_version(&self) -> ChorusResult<VersionReturn> {
let endpoint_url = format!("{}/version", self.urls.api.clone());

let request = match self.client.get(&endpoint_url).send().await {
Ok(result) => result,
Err(e) => {
return Err(ChorusError::RequestFailed {
url: endpoint_url,
error: e.to_string(),
});
}
};

if !request.status().as_str().starts_with('2') {
return Err(ChorusError::ReceivedErrorCode {
error_code: request.status().as_u16(),
error: request.text().await.unwrap(),
});
}

let response_text = match request.text().await {
Ok(string) => string,
Err(e) => {
return Err(ChorusError::InvalidResponse {
error: format!(
"Error while trying to process the HTTP response into a String: {}",
e
),
});
}
};

match from_str::<VersionReturn>(&response_text) {
Ok(return_value) => Ok(return_value),
Err(e) => Err(ChorusError::InvalidResponse { error: format!("Error while trying to deserialize the JSON response into requested type T: {}. JSON Response: {}", e, response_text) })
}
}
}
2 changes: 2 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ pub use guilds::*;
pub use invites::*;
pub use policies::instance::instance::*;
pub use users::*;
pub use instance::*;

pub mod auth;
pub mod channels;
pub mod guilds;
pub mod invites;
pub mod policies;
pub mod users;
pub mod instance;
27 changes: 24 additions & 3 deletions src/api/policies/instance/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Instance {
/// # Reference
/// See <https://docs.spacebar.chat/routes/#get-/policies/instance/>
pub async fn general_configuration_schema(&self) -> ChorusResult<GeneralConfiguration> {
let endpoint_url = self.urls.api.clone() + "/policies/instance";
let endpoint_url = self.urls.api.clone() + "/policies/instance/";
let request = match self.client.get(&endpoint_url).send().await {
Ok(result) => result,
Err(e) => {
Expand All @@ -35,7 +35,28 @@ impl Instance {
});
}

let body = request.text().await.unwrap();
Ok(from_str::<GeneralConfiguration>(&body).unwrap())
let response_text = match request.text().await {
Ok(string) => string,
Err(e) => {
return Err(ChorusError::InvalidResponse {
error: format!(
"Error while trying to process the HTTP response into a String: {}",
e
),
});
}
};

match from_str::<GeneralConfiguration>(&response_text) {
Ok(object) => Ok(object),
Err(e) => {
Err(ChorusError::InvalidResponse {
error: format!(
"Error while trying to deserialize the JSON response into requested type T: {}. JSON Response: {}",
e, response_text
),
})
}
}
}
}
Loading
Loading