Before this change, Pantalaimon users would always appear online because
that is the default state when the /sync endpoint's set_presence
parameter is not set. By explicitly setting the parameter to "offline",
only the user-facing client (which executes its own /sync request)
affects the presence state.
Suppose that Alice logs in using Element. Before this change, when Bob
would send a DM to Alice through Pantalaimon, Alice would not be able to
decrypt Bob's initial message. Instead, she would see "Unable to
decrypt: The sender's device has not sent us the keys for this message."
and Pantalaimon's olmsessions table would have no associated records.
Any future messages would be visible however. On the other hand, when
Alice (using Element) is the one to send the first DM to Bob, he can
decrypt the initial message.
For Pantalaimon to execute /keys/claim, get_missing_sessions must return
the invitee's device (and log "Missing session for device"). If
Pantalaimon calls this method too soon, then self.device_store will not
have the device. To populate self.device_store before Pantalaimon calls
get_missing_sessions, it must execute /keys/query (and invoke
_handle_key_query) earlier, during the /createRoom request. Pantalaimon
does execute the /keys/query request during a sync after the server
finishes creating the DM (and logs "Adding new device to the device
store for user"), but only after checking unsuccessfully for the device
in self.device_store.
After this change, Pantalaimon executes /keys/claim, there is one record
in olmsessions, and Alice can decrypt Bob's initial message.
If the original path had quoted slash characters (`%2F`), the code
decoded them and then left them unquoted, causing the forwarded request
to fail.
An example is trying to ban a user with a slash in their name using
Mjolnir, which PUTs a state event with `rule:<username>` in the URL.
Use the undecoded path to avoid this.
Pantalaimon depends on the room state to be present to decide correctly
if a message should be encrypted or now. The room state is fetched from
the server every time we restart, this means that failure to fetch room
states from the server would hinder us from doing the correct decision.
This patch prevents a downgrade to sending unencrypted messages if we're
unable to sync at least once with the server.