diff options
| author | Zeyla Hellyer <[email protected]> | 2017-10-09 17:22:15 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-10-09 17:22:15 -0700 |
| commit | eb9e8dfbc9d778de405d7369579d90c49a2bf90c (patch) | |
| tree | 670260a6b61a0d9e5ea1c3f4f76e17c9a98f6cd3 /src/gateway | |
| parent | Make webhook_id a majour parameter in ratelimiting (diff) | |
| download | serenity-eb9e8dfbc9d778de405d7369579d90c49a2bf90c.tar.xz serenity-eb9e8dfbc9d778de405d7369579d90c49a2bf90c.zip | |
Resume on resumable session invalidations
Session invalidations include whether the session may be resumable.
Previously, this was not parsed by serenity. This data is now contained
in `GatewayEvent::InvalidateSession` as a boolean, which constitutes a
breaking change for users that manually handle gateway events.
Upgrade path:
Instead of pattern matching on simply the variant like so:
```rust
use serenity::model::event::GatewayEvent;
match gateway_event {
GatewayEvent::InvalidateSession => {
// work here
},
// other matching arms here
_ => {},
}
```
Instead pattern match it as a single field tuple-struct:
```rust
use serenity::model::event::GatewayEvent;
match gateway_event {
GatewayEvent::InvalidateSession(resumable) => {
// work here
},
// other matching arms here
_ => {},
}
```
Diffstat (limited to 'src/gateway')
| -rw-r--r-- | src/gateway/shard.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/gateway/shard.rs b/src/gateway/shard.rs index fbe1572..7e81813 100644 --- a/src/gateway/shard.rs +++ b/src/gateway/shard.rs @@ -434,16 +434,17 @@ impl Shard { self.autoreconnect().and(Ok(None)) } }, - Ok(GatewayEvent::InvalidateSession) => { + Ok(GatewayEvent::InvalidateSession(resumable)) => { info!( - "[Shard {:?}] Received session invalidation; re-identifying", - self.shard_info + "[Shard {:?}] Received session invalidation", + self.shard_info, ); - self.seq = 0; - self.session_id = None; - - self.identify().and(Ok(None)) + if resumable { + self.resume().and(Ok(None)) + } else { + self.identify().and(Ok(None)) + } }, Ok(GatewayEvent::Reconnect) => self.reconnect().and(Ok(None)), Err(Error::Gateway(GatewayError::Closed(data))) => { @@ -981,6 +982,7 @@ impl Shard { self.heartbeat_instants = (Some(Instant::now()), None); self.heartbeat_interval = None; self.last_heartbeat_acknowledged = true; + self.session_id = None; self.stage = ConnectionStage::Disconnected; self.seq = 0; } |