-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from polyphony-chat/gateway
Obligatory merge from gateway to main
- Loading branch information
Showing
26 changed files
with
2,230 additions
and
243 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
...5869cd4456e849b3527c9bfbe342879d4418.json → ...d0e4ca3b479d01ea7446ac7c120435c52584.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
str | ||
&message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Qreturn Ok(Event::Heartbeat(from_str(&message)?))\\E$"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# To-do list for bitfl0wer | ||
|
||
- Take care of gateway_task | ||
- Find out how sequence numbers work and increment them properly | ||
- Find out where the stupid opcode 2 send comes from | ||
- On death of connection: Remove session id from database | ||
- Maybe this and the "create resumable" thing can be consolidated? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
BEGIN; | ||
INSERT INTO user_settings ( | ||
index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers, | ||
contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted, | ||
detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command, | ||
explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play, | ||
guild_folders, guild_positions, inline_attachment_media, inline_embed_media, | ||
locale, message_display_compact, native_phone_integration_enabled, render_embeds, | ||
render_reactions, restricted_guilds, show_current_game, status, | ||
stream_notifications_enabled, theme, timezone_offset | ||
) | ||
VALUES | ||
(7251169922837909504, 300, true, true, 1, true, true, 'Working on project', false, true, true, false, | ||
true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, | ||
'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true, | ||
'dark', -7), | ||
(7251169922837909505, 600, false, false, 0, false, false, 'Available', false, false, false, true, | ||
false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false, | ||
false, false, NULL, false, 'away', false, 'light', 1); | ||
|
||
INSERT INTO users ( | ||
id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns, | ||
phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed, | ||
mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, | ||
premium_since, verified, disabled, deleted, email, flags, public_flags, | ||
purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings, | ||
settings_index, relevant_events | ||
) | ||
VALUES | ||
(7250861145186111490, 'john_doe_notes', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL, | ||
'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false, | ||
true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', | ||
'2024-01-02 12:00:00', true, false, false, '[email protected]', 100, 10, | ||
5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7251169922837909504, | ||
'[]'), | ||
(7250861145186111491, 'jane_smith_notes', '5678', 'avatar2.png', 123456, NULL, NULL, | ||
'she/her', NULL, false, true, false, 0, false, '', false, | ||
false, false, false, NULL, NULL, '2024-02-01 15:30:00', | ||
NULL, false, false, false, '[email protected]', 50, 5, | ||
0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7251169922837909505, | ||
'[]'); | ||
COMMIT; | ||
|
||
INSERT INTO notes ( | ||
content, author_id, target_id | ||
) | ||
VALUES | ||
('This is a note', 7250861145186111490, 7250861145186111491), | ||
('This is another note', 7250861145186111491, 7250861145186111490); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- Create two users with two respective user_settings, one DM channel, and add both users to that DM channel. | ||
BEGIN; | ||
INSERT INTO user_settings ( | ||
index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers, | ||
contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted, | ||
detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command, | ||
explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play, | ||
guild_folders, guild_positions, inline_attachment_media, inline_embed_media, | ||
locale, message_display_compact, native_phone_integration_enabled, render_embeds, | ||
render_reactions, restricted_guilds, show_current_game, status, | ||
stream_notifications_enabled, theme, timezone_offset | ||
) | ||
VALUES | ||
(7250861145186111495, 300, true, true, 1, true, true, 'Working on project', false, true, true, false, | ||
true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true, | ||
'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true, | ||
'dark', -7), | ||
(7250861145186111496, 600, false, false, 0, false, false, 'Available', false, false, false, true, | ||
false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false, | ||
false, false, NULL, false, 'away', false, 'light', 1); | ||
|
||
INSERT INTO users ( | ||
id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns, | ||
phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed, | ||
mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at, | ||
premium_since, verified, disabled, deleted, email, flags, public_flags, | ||
purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings, | ||
settings_index, relevant_events | ||
) | ||
VALUES | ||
(7250861145186111490, 'john_doe_private_channels', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL, | ||
'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false, | ||
true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00', | ||
'2024-01-02 12:00:00', true, false, false, '[email protected]', 100, 10, | ||
5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7250861145186111495, | ||
'[]'), | ||
(7250861145186111491, 'jane_smith_private_channels', '5678', 'avatar2.png', 123456, NULL, NULL, | ||
'she/her', NULL, false, true, false, 0, false, '', false, | ||
false, false, false, NULL, NULL, '2024-02-01 15:30:00', | ||
NULL, false, false, false, '[email protected]', 50, 5, | ||
0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7250861145186111496, | ||
'[]'); | ||
COMMIT; | ||
|
||
INSERT INTO channels ( | ||
id, created_at, name, icon, type, last_message_id, guild_id, parent_id, owner_id, last_pin_timestamp, | ||
default_auto_archive_duration, "position", permission_overwrites, video_quality_mode, bitrate, user_limit, nsfw, | ||
rate_limit_per_user, topic, retention_policy_id, flags, default_thread_rate_limit_per_user | ||
) | ||
VALUES ( | ||
7250859537236758528, current_timestamp, NULL, NULL, 1, NULL, NULL, NULL, | ||
NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, false, 0, NULL, NULL, | ||
0, 0 | ||
); | ||
|
||
INSERT INTO recipients (id, channel_id, user_id, closed) VALUES | ||
(7250860729446699008, 7250859537236758528, 7250861145186111490, false), | ||
(7250861145186111494, 7250859537236758528, 7250861145186111491, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
CREATE SEQUENCE notes_index_seq; | ||
|
||
create table if not exists notes | ||
( | ||
id varchar(255) not null primary key, | ||
content varchar(255) not null, | ||
owner_id numeric(20, 0) null constraint chk_owner_id_range check (owner_id >= 0 AND owner_id <= 18446744073709551615), | ||
index numeric(20, 0) not null default nextval('notes_index_seq') constraint chk_index_range check (index >= 0 and index <= 18446744073709551615) primary key, | ||
content varchar(256) not null, | ||
author_id numeric(20, 0) null constraint chk_author_id_range check (author_id >= 0 AND author_id <= 18446744073709551615), | ||
target_id numeric(20, 0) null constraint chk_target_id_range check (target_id >= 0 AND target_id <= 18446744073709551615), | ||
constraint IDX_74e6689b9568cc965b8bfc9150 | ||
unique (owner_id, target_id), | ||
unique (author_id, target_id), | ||
constraint FK_23e08e5b4481711d573e1abecdc | ||
foreign key (target_id) references users (id) | ||
on delete cascade, | ||
constraint FK_f9e103f8ae67cb1787063597925 | ||
foreign key (owner_id) references users (id) | ||
foreign key (author_id) references users (id) | ||
on delete cascade | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
#!/bin/bash | ||
|
||
if git diff --quiet HEAD -- "./migrations"; then | ||
echo "No changes in migrations folder" | ||
exit 0 | ||
else | ||
echo "Changes in migrations folder detected, running sqlx prepare" | ||
cargo sqlx prepare --all -- --all-targets --all-features | ||
git add .sqlx/* | ||
exit_code=$? | ||
cargo sqlx prepare --all -- --all-targets --all-features | ||
git add .sqlx/* | ||
exit_code=$? | ||
|
||
exit $exit_code | ||
fi | ||
exit $exit_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
use chorus::types::{Snowflake, UserNote}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::errors::Error; | ||
|
||
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize)] | ||
/// A note that a user has written about another user. The target user may be the author of the note. | ||
pub struct Note { | ||
#[sqlx(flatten)] | ||
inner: UserNote, | ||
} | ||
|
||
impl Deref for Note { | ||
type Target = UserNote; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
impl DerefMut for Note { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.inner | ||
} | ||
} | ||
|
||
impl Note { | ||
pub fn into_inner(self) -> UserNote { | ||
self.inner | ||
} | ||
|
||
pub fn as_inner(&self) -> &UserNote { | ||
&self.inner | ||
} | ||
|
||
pub fn as_inner_mut(&mut self) -> &mut UserNote { | ||
&mut self.inner | ||
} | ||
|
||
/// Retrieve all notes from a user by their ID | ||
pub async fn get_by_author_id( | ||
author_id: Snowflake, | ||
db: &sqlx::PgPool, | ||
) -> Result<Vec<Self>, Error> { | ||
sqlx::query_as("SELECT * from notes WHERE author_id = $1") | ||
.bind(author_id) | ||
.fetch_all(db) | ||
.await | ||
.map_err(Error::Sqlx) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod note_unit_tests { | ||
#[sqlx::test(fixtures(path = "../../../fixtures", scripts("notes")))] | ||
async fn test_get_by_author_id(db: sqlx::PgPool) { | ||
let notes = super::Note::get_by_author_id(7250861145186111490.into(), &db) | ||
.await | ||
.unwrap(); | ||
assert_eq!(notes.len(), 1); | ||
let note = notes[0].as_inner(); | ||
assert_eq!(note.author_id, 7250861145186111490.into()); | ||
assert_eq!(note.target_id, 7250861145186111491.into()); | ||
assert_eq!(note.content, "This is a note"); | ||
} | ||
} |
Oops, something went wrong.