Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit 20a8711

Browse files
authored
Merge pull request #59 from polyphony-chat/gateway
Obligatory merge from gateway to main
2 parents f3d1914 + 463699a commit 20a8711

26 files changed

+2230
-243
lines changed

.sqlx/query-8d127613251411c2dae324bc92105869cd4456e849b3527c9bfbe342879d4418.json renamed to .sqlx/query-b8fccc1abcb63d1442a3136927d9d0e4ca3b479d01ea7446ac7c120435c52584.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/ltex.dictionary.en-US.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
str
2+
&message
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Qreturn Ok(Event::Heartbeat(from_str(&message)?))\\E$"}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tokio-tungstenite = { version = "0.23.1", features = [
7171
] }
7272
pubserve = { version = "1.1.0", features = ["async", "send"] }
7373
parking_lot = { version = "0.12.3", features = ["deadlock_detection"] }
74-
sqlx-pg-uint = { version = "0.7.2", features = ["serde"] }
74+
sqlx-pg-uint = { version = "0.8.0", features = ["serde"] }
7575

7676
[dev-dependencies]
7777
rusty-hook = "0.11.2"

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ Whether you are using Docker or not, you will need to have the following install
2828

2929
- [Rust](https://www.rust-lang.org/tools/install)
3030
- [git](https://git-scm.com/downloads)
31+
- [`sqlx-cli`](https://crates.io/crates/sqlx-cli)
32+
33+
If your development environment is hosted on a Windows machine, please additionally make sure that
34+
you have a bash shell available to execute pre-commit hooks. This can be done by installing
35+
[Git Bash](https://git-scm.com/downloads) or
36+
[Windows Subsystem for Linux 2](https://learn.microsoft.com/en-us/windows/wsl/install) and, additionally,
37+
configuring your IDE correctly.
38+
39+
See the instructions below for guidance on how to run the project.
3140

3241
### Non-Docker
3342

TODO.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# To-do list for bitfl0wer
2+
3+
- Take care of gateway_task
4+
- Find out how sequence numbers work and increment them properly
5+
- Find out where the stupid opcode 2 send comes from
6+
- On death of connection: Remove session id from database
7+
- Maybe this and the "create resumable" thing can be consolidated?

fixtures/notes.sql

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
BEGIN;
2+
INSERT INTO user_settings (
3+
index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers,
4+
contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted,
5+
detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command,
6+
explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play,
7+
guild_folders, guild_positions, inline_attachment_media, inline_embed_media,
8+
locale, message_display_compact, native_phone_integration_enabled, render_embeds,
9+
render_reactions, restricted_guilds, show_current_game, status,
10+
stream_notifications_enabled, theme, timezone_offset
11+
)
12+
VALUES
13+
(7251169922837909504, 300, true, true, 1, true, true, 'Working on project', false, true, true, false,
14+
true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true,
15+
'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true,
16+
'dark', -7),
17+
(7251169922837909505, 600, false, false, 0, false, false, 'Available', false, false, false, true,
18+
false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false,
19+
false, false, NULL, false, 'away', false, 'light', 1);
20+
21+
INSERT INTO users (
22+
id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns,
23+
phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed,
24+
mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at,
25+
premium_since, verified, disabled, deleted, email, flags, public_flags,
26+
purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings,
27+
settings_index, relevant_events
28+
)
29+
VALUES
30+
(7250861145186111490, 'john_doe_notes', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL,
31+
'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false,
32+
true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00',
33+
'2024-01-02 12:00:00', true, false, false, '[email protected]', 100, 10,
34+
5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7251169922837909504,
35+
'[]'),
36+
(7250861145186111491, 'jane_smith_notes', '5678', 'avatar2.png', 123456, NULL, NULL,
37+
'she/her', NULL, false, true, false, 0, false, '', false,
38+
false, false, false, NULL, NULL, '2024-02-01 15:30:00',
39+
NULL, false, false, false, '[email protected]', 50, 5,
40+
0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7251169922837909505,
41+
'[]');
42+
COMMIT;
43+
44+
INSERT INTO notes (
45+
content, author_id, target_id
46+
)
47+
VALUES
48+
('This is a note', 7250861145186111490, 7250861145186111491),
49+
('This is another note', 7250861145186111491, 7250861145186111490);

fixtures/private_channels.sql

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- Create two users with two respective user_settings, one DM channel, and add both users to that DM channel.
2+
BEGIN;
3+
INSERT INTO user_settings (
4+
index, afk_timeout, allow_accessibility_detection, animate_emoji, animate_stickers,
5+
contact_sync_enabled, convert_emoticons, custom_status, default_guilds_restricted,
6+
detect_platform_accounts, developer_mode, disable_games_tab, enable_tts_command,
7+
explicit_content_filter, friend_source_flags, gateway_connected, gif_auto_play,
8+
guild_folders, guild_positions, inline_attachment_media, inline_embed_media,
9+
locale, message_display_compact, native_phone_integration_enabled, render_embeds,
10+
render_reactions, restricted_guilds, show_current_game, status,
11+
stream_notifications_enabled, theme, timezone_offset
12+
)
13+
VALUES
14+
(7250861145186111495, 300, true, true, 1, true, true, 'Working on project', false, true, true, false,
15+
true, 2, 'friends', true, true, 'folder_data', 'positions_data', true, true,
16+
'en-US', false, true, true, true, 'restricted_guilds_data', true, 'online', true,
17+
'dark', -7),
18+
(7250861145186111496, 600, false, false, 0, false, false, 'Available', false, false, false, true,
19+
false, 0, NULL, false, false, NULL, NULL, false, false, 'fr-FR', true, false,
20+
false, false, NULL, false, 'away', false, 'light', 1);
21+
22+
INSERT INTO users (
23+
id, username, discriminator, avatar, accent_color, banner, theme_colors, pronouns,
24+
phone, desktop, mobile, premium, premium_type, bot, bio, system, nsfw_allowed,
25+
mfa_enabled, webauthn_enabled, totp_secret, totp_last_ticket, created_at,
26+
premium_since, verified, disabled, deleted, email, flags, public_flags,
27+
purchased_flags, premium_usage_flags, rights, data, fingerprints, extended_settings,
28+
settings_index, relevant_events
29+
)
30+
VALUES
31+
(7250861145186111490, 'john_doe_private_channels', '1296', 'avatar1.png', 16777215, 'banner1.png', NULL,
32+
'he/him', '+1234567890', true, false, true, 1, false, 'This is my bio', false,
33+
true, true, true, 'secret123', 'ticket456', '2024-01-01 12:00:00',
34+
'2024-01-02 12:00:00', true, false, false, '[email protected]', 100, 10,
35+
5, 1, 100, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint1', '{"setting": "value"}', 7250861145186111495,
36+
'[]'),
37+
(7250861145186111491, 'jane_smith_private_channels', '5678', 'avatar2.png', 123456, NULL, NULL,
38+
'she/her', NULL, false, true, false, 0, false, '', false,
39+
false, false, false, NULL, NULL, '2024-02-01 15:30:00',
40+
NULL, false, false, false, '[email protected]', 50, 5,
41+
0, 0, 50, '{"hash": "$2b$14$AbcNYTh5GcOYaB4v4P7OWeGW0hQkd/ysvmY4fGyIA/tyEnK0chGNu", "valid_tokens_since": "2024-10-07T20:22:06.162070616Z"}', 'fingerprint2', '{"setting": "another_value"}', 7250861145186111496,
42+
'[]');
43+
COMMIT;
44+
45+
INSERT INTO channels (
46+
id, created_at, name, icon, type, last_message_id, guild_id, parent_id, owner_id, last_pin_timestamp,
47+
default_auto_archive_duration, "position", permission_overwrites, video_quality_mode, bitrate, user_limit, nsfw,
48+
rate_limit_per_user, topic, retention_policy_id, flags, default_thread_rate_limit_per_user
49+
)
50+
VALUES (
51+
7250859537236758528, current_timestamp, NULL, NULL, 1, NULL, NULL, NULL,
52+
NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, false, 0, NULL, NULL,
53+
0, 0
54+
);
55+
56+
INSERT INTO recipients (id, channel_id, user_id, closed) VALUES
57+
(7250860729446699008, 7250859537236758528, 7250861145186111490, false),
58+
(7250861145186111494, 7250859537236758528, 7250861145186111491, false);

migrations/20231007011933_channels.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
create table if not exists channels
22
(
33
id numeric(20, 0) not null constraint chk_id_range check (id >= 0 AND id <= 18446744073709551615) primary key,
4-
created_at timestamp not null,
4+
created_at timestamptz not null,
55
name varchar(255) null,
66
icon text null,
77
type int not null,
@@ -12,6 +12,8 @@ create table if not exists channels
1212
last_pin_timestamp int null,
1313
default_auto_archive_duration int null,
1414
position int null,
15+
managed boolean null,
16+
rtc_region varchar(255) null,
1517
permission_overwrites text null,
1618
video_quality_mode int null,
1719
bitrate int null,
@@ -22,6 +24,14 @@ create table if not exists channels
2224
retention_policy_id varchar(255) null,
2325
flags int not null,
2426
default_thread_rate_limit_per_user int not null,
27+
default_sort_order numeric(3, 0) null constraint chk_default_sort_order check (default_sort_order >= 0 AND default_sort_order <= 255),
28+
-- v foreign key constraint is added in emojis migration
29+
-- TODO: I am unsure if deserializing a channel object from the database will work with the default_reaction_emoji field. Test it
30+
default_reaction_emoji numeric(20, 0) null constraint chk_default_reaction_emoji check (default_reaction_emoji >= 0 AND default_reaction_emoji <= 18446744073709551615),
31+
default_forum_layout numeric(3, 0) null constraint chk_default_forum_layout check (default_forum_layout >= 0 AND default_forum_layout <= 255),
32+
available_tags jsonb null constraint chk_available_tags check (jsonb_typeof(available_tags) = 'array') default '[]',
33+
applied_tags jsonb null constraint chk_applied_tags check (jsonb_typeof(applied_tags) = 'array') default '[]',
34+
application_id numeric(20, 0) null constraint chk_application_id_range check (application_id >= 0 AND application_id <= 18446744073709551615),
2535
constraint FK_3274522d14af40540b1a883fc80
2636
foreign key (parent_id) references channels (id),
2737
constraint FK_3873ed438575cce703ecff4fc7b

migrations/20231007012108_emojis.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ create table if not exists emojis
1515
on delete cascade,
1616
constraint FK_fa7ddd5f9a214e28ce596548421
1717
foreign key (user_id) references users (id)
18-
);
18+
);
19+
20+
ALTER TABLE channels
21+
ADD CONSTRAINT FK_emoji_id_emojis_id FOREIGN KEY (default_reaction_emoji) REFERENCES emojis(id);

0 commit comments

Comments
 (0)