Commit Graph

932 Commits

Author SHA1 Message Date
Luna Mendes 1d3520876d gateway: more comments and docstrings 2018-10-13 17:30:02 -03:00
Luna Mendes 6be85ea305 litecord.pubsub: add docstrings for all methods 2018-10-13 16:30:05 -03:00
Luna Mendes 3f54f35dce gateway.websocket: only use pure zlib when payload is big
big here being more than 1024 characters.
2018-10-12 23:41:41 -03:00
Luna Mendes 3d96ccda35 blueprints.users: dispatch USER_UPDATE to guilds and friends
- dispatcher: add EventDispatcher.dispatch_many
2018-10-12 23:32:54 -03:00
Luna Mendes a62bc5af46 enums: add own Flags class
to help with understanding of user.flags and message.activity.type
2018-10-12 23:12:14 -03:00
Luna Mendes 1ab8dc0052 storage: only set mobile and phone when secure=True 2018-10-12 21:36:29 -03:00
Luna Mendes 051cdd8ff2 blueprints.users: finish user patch impl
- blueprints.auth: check availability of username on register
 - enums: add UserFlags
 - schemas: add DATA_REGEX, USER_UPDATE
 - storage: add dummy mobile and phone values on get_user
2018-10-12 21:34:45 -03:00
Luna Mendes 9aec27203b blueprints.auth: dispatch USER_UPDATE when setting verify status 2018-10-12 19:13:57 -03:00
Luna Mendes da4ce66a0c storage: multiple enhancements
storage:
 - don't use SELECT * when get_guild'ing
 - use field::text instead of the str() call madness
 - simplify get_member_data_one
 - fix parent_id being an int on get_channel_data
 - add Storage.get_role
 - better mention resolving on get_message
 - remove Storage.get_all_dms
2018-10-12 19:06:13 -03:00
Luna Mendes d28c0f1bc6 litecord.pubsub: add FriendDispatcher
- gateway.websocket: subscribe to friends on startup
 - presence: dispatch to friends on dispatch_pres
 - storage: add Storage.get_friend_ids
2018-10-12 16:17:29 -03:00
Luna Mendes 46fac95979 gateway.websocket: add presences field to ready payload
- presences: add PresenceManager.friend_presences
 - blueprints.auth: fix resend route
 - pubsub: add DispatcherWithState to decrease amount of
    repeated code between GuildDispatcher and ChannelDispatcher
 - storage: fix relationship id field
2018-10-12 02:10:31 -03:00
Luna Mendes c4db99aa9a blueprints.channels: use ChannelDispatcher
for CHANNEL_PINS_UPDATE and TYPING_START
2018-10-11 23:12:07 -03:00
Luna Mendes 919e5ff903 blueprints.channels: fix close_channel for dms
- dispatcher: add sub() and unsub() alias methods
2018-10-11 23:09:27 -03:00
Luna Mendes 20332805b8 blueprints.channels: support dms on message create
- storage: add Storage.get_dm_peer
 - gateway.websocket: subscribe to dms as well as guilds
2018-10-11 23:01:56 -03:00
Luna Mendes efefb0cc2f blueprints.channels: use ChannelDispatcher for MESSAGE_* events
- storage: add Storage.guild_from_channel
2018-10-11 22:12:51 -03:00
Luna Mendes 37d8114ae2 pubsub: add ChannelDispatcher
- pubsub: call ChannelDispatcher from GuildDispatcher when subbing a
    user
2018-10-11 18:56:40 -03:00
Luna Mendes 5372292f0d blueprints.channels: add route to delete read_state of a channel
- blueprints.checks: change return type from snowflake to (ChannelType,
    snowflake)
2018-10-11 17:53:32 -03:00
Luna Mendes b7f0bd1bb4 run: pass app instance to EventDispatcher
this should help with future DM channel pub/sub, as we'll
have to query the `dm_channel_state` table.
2018-10-11 16:52:15 -03:00
Luna Mendes b43b220882 blueprints.users: add profiles and mutual friends 2018-10-10 20:07:38 -03:00
Luna Mendes 76f3a9f868 storage: use premium_since instead of premium 2018-10-10 19:16:35 -03:00
Luna Mendes 28f33b0a95 schema: change premium to premium_since
sql for instances:

```sql
-- remove old nitro column
ALTER TABLE users DROP COLUMN premium;

-- add new nitro column
ALTER TABLE users ADD COLUMN premium_since timestamp without time zone DEFAULT NULL;
```
2018-10-10 19:13:59 -03:00
Luna Mendes dd74689224 blueprints.auth: add POST /api/v6/auth/verify/resend 2018-10-10 18:40:00 -03:00
Luna Mendes ebf16754af gateway.opcodes: add CALL_SYNC
- gateway.websocket: add dummy handler for CALL_SYNC
2018-10-10 18:21:18 -03:00
Luna Mendes 71d1adac53 blueprints.users: dispatch USER_NOTE_UPDATE
- gateway.websocket: show packet when bad op
2018-10-10 18:09:39 -03:00
Luna Mendes e210c20d0f various fixes to dms
- blueprints.checks: fix party fetching
 - blueprints.users: fix try_dm_state
 - blueprints.users: fix create_dm
 - blueprints.users: fix create_group_dm being used for 1-on-1 dm
 - gateway.websocket: add support for pure zlib
 - schemas: fix CREATE_GROUP_DM
 - storage: fix _filter_recipients, get_channel and get_dms
2018-10-10 17:53:31 -03:00
Luna Mendes 737129bd20 blueprints.channels: fix channel deletion
- blueprints.guilds: fix channel creation
 - blueprints.relationships: add POST /api/v6/users/@me/relationships
 - storage: add Storage.search_user, for ^
 - storage: fix bug with last_message_id returning "None" (as a str)
2018-10-10 17:09:39 -03:00
Luna Mendes adc6a58179 blueprints.channels: add channel and guild ack routes
SQL for instances: Rerun `schema.sql` for the new table.

 - gateway.websocket: add get_read_state to read_state's ready
 - gateway.websocket: add get_dms on private_channels' ready
 - storage: fix get_dms()
 - storage: add Storage.get_channel_ids()
 - storage: add Storage.get_read_state()
 - schema.sql: add user_read_state table
2018-10-09 22:52:12 -03:00
Luna Mendes 5edcc62be4 blueprints.guilds: fix GUILD_DELETE event when banning 2018-10-09 20:16:40 -03:00
Luna Mendes b0d1c9765c dispatcher: add some dispatch_* methods for backwards compatibility
- dispatcher: add EventDispatcher.remove()
 - blueprints.guilds: use remove() and unsub()
 - gateway.websocket: fix sub_many() call
2018-10-09 20:13:39 -03:00
Luna Mendes aa76cc2c7d litecord.dispatcher: change dispatch_* methods into pubsub backends
- litecord: add pubsub module
 - schemas: change type to snowflake in MESSAGE_CREATE's nonce
2018-10-09 18:56:34 -03:00
Luna Mendes 5afc15c4f6 storage: fix bug on last_message_id
- storage: better member.roles
 - presence: cast guild_id to str
2018-10-04 04:13:46 -03:00
Luna Mendes 0ebbc4cd37 schema.sql: add UNIQUE to dm_channels
This should fix the `schema.sql` errors on 61e36f244b.

```sql
DROP TABLE dm_channels;
```

Then rerun `schema.sql`.
2018-10-03 22:11:07 -03:00
Luna Mendes 61e36f244b blueprints.users, channels: basic dm operations
SQL for instances:

```sql
ALTER TABLE messages
ADD CONSTRAINT messages_channels_fkey
FOREIGN KEY (channel_id)
REFERENCES channels (id)
ON DELETE CASCADE;

ALTER TABLE channel_pins ADD CONSTRAINT pins_channels_fkey
FOREIGN KEY (channel_id)
REFERENCES channels (id)
ON DELETE CASCADE;

ALTER TABLE channel_pins ADD CONSTRAINT pins_messages_fkey
FOREIGN KEY (message_id)
REFERENCES messages (id)
ON DELETE CASCADE;
```

After that, rerun `schema.sql`.

blueprints.channels:
 - check dms on channel_check
 - add DELETE /api/v6/channels/<int:channel_id>

blueprints.users:
 - add event dispatching for leaving guilds
 - add GET /api/v6/users/@me/channels, for DM fetching
 - add POST /api/v6/users/@me/channels, for DM creation
 - add POST /api/v6/users/<int:user_id>/channels for DM / Group DM
    creation

 - schemas: add CREATE, CREATE_GROUP_DM
 - storage: add last_message_id fetching for channels
 - storage: add support for DMs in get_channel
 - storage: add Storage.get_dm, Storage.get_dms, Storage.get_all_dms
 - schema.sql: add dm_channel_state table
 - schema.sql: add constriants for messages.channel_id and channel_pins
2018-10-03 21:49:35 -03:00
Luna Mendes 88bc4ceca8 blueprints.relationships: fix dispatches 2018-10-02 19:16:00 -03:00
Luna Mendes 45559608f3 litecord.storage: fix _chan_overwrites since table changes 2018-10-02 18:37:53 -03:00
Luna Mendes fcddd46d47 schema.sql: add draft for dm_channels
also add name to group_dm_channels, and a group_dm_members table.

SQL for moving to latest schema:

```sql
DROP TABLE dm_channels;
DROP TABLE group_dm_channels;
DROP TABLE channel_overwrites;
DROP TABLE guild_features;
```

Then rerun `schema.sql`.

 - schema.sql: revamp channel_overwrites table
 - schema.sql: add features table
 - schema.sql: make guild_features use the features table
2018-10-02 17:56:20 -03:00
Luna Mendes d7cc5568bc schema.sql: fix possible bug with some message tables
Drop the unused tables:
```sql
DROP TABLE message_attachments;
DROP TABLE message_reactions;
DROP TABLE channel_pins;
```

Rerun `schema.sql` to recreate them with the proper constraints.
2018-10-02 16:51:01 -03:00
Luna Mendes c7923da124 relationship support!
friendships and blocks are possible, however presence code isn't ready
to handle presences of people who are friends.

SQL for instances, this is going to fix bad timestamps on the messages:

```sql
ALTER TABLE ONLY members ALTER COLUMN joined_at SET DEFAULT (now() at time zone 'utc');
 ALTER TABLE ONLY messages ALTER COLUMN created_at SET DEFAULT (now() at time zone 'utc');
ALTER TABLE ONLY invites ALTER COLUMN created_at SET DEFAULT (now() at time zone 'utc');
```

After that, rerun the schema.sql file to have the new relationships
table.

 - blueprints: add relationships blueprint
 - enums: add RelationshipType
 - storage: add get_relationships
 - storage: fix bug on lazy guild changes and messages
 - schemas: return validator.document instead of reqjson
 - gateway.websocket: use Storage.get_relationships
2018-10-02 03:43:57 -03:00
Luna Mendes b091bd5c49 Add hazmat impl for OP 8 Request Guild Members
- storage: add Storage.guild_exists, Storage.query_members
2018-10-01 18:07:29 -03:00
Luna Mendes 51f7ea5ad0 gateway.websocket: use Storage.get_user_settings 2018-09-29 23:54:01 -03:00
Luna Mendes bff5700d06 blueprints.users: add user setting patch impl
- schemas: add explicit type
 - schemas: add USER_SETTINGS
 - run: make Access-Control-Allow-Methods the same as Allow header when
    possible
2018-09-29 23:43:02 -03:00
Luna Mendes 624eb6eb0e blueprints.users: use Storage.get_user_settings
paving the way for user settings support.

 - storage: add Storage.get_user_settings
 - storage: add methods to fetch with json/jsonb codecs enabled
2018-09-29 23:10:42 -03:00
Luna Mendes 4841565f14 schema.sql: add user_settings table
rerunning the schema.sql file should get you up and running.

 - add POST /api/v6/users/@me/consent for consent changes (that get
    ignored)
2018-09-29 22:17:10 -03:00
Luna Mendes 993a2f3b08 blueprints.channels: add dummy search route 2018-09-28 20:08:07 -03:00
Luna Mendes 02f2ee6943 Add some lazy loading handling
Mostly adding guild_id to some events. It isn't complete support for
them, but its some of the way there.

 - storage: give guild_id on get_message

 - gateway.websocket: decrease logging for some stuff
    - a debug log for the whole packet is still there for development
       reasons, maybe i'll put it on a config option.

 - gateway.websocket: dispatch an offline presence when the user has no
    connections tied to them anymore
2018-09-28 19:34:50 -03:00
Luna Mendes b06c07c097 gateway.websocket: add handler for heartbeats
this should keep connections more stable since we reply and update
WebsocketState.last_seq
2018-09-28 17:50:18 -03:00
Luna Mendes d9506f450d schema.sql: change from varchar to text on some fields
unicode!

sql for instances to upgrade:

alter table users alter column username type text;
alter table guilds alter column name type text;
alter table members alter column nickname type text;
alter table roles alter column name type text;
alter table bans alter column reason type text;
2018-09-28 00:54:24 -03:00
Luna Mendes 37c61466a4 blueprints.channels: fix TYPING_START 2018-09-28 00:08:39 -03:00
Luna Mendes f5db1038eb blueprints.invites: fix typo on get_channel_invites 2018-09-27 23:29:55 -03:00
Luna Mendes e7d97ecdef run: have a fallback when Origin header is missing 2018-09-27 23:25:23 -03:00