ccedfb41f3
In some cases, restoring client state from backups may cause Olm sessions to become corrupted, resulting in a backward ratchet. As a consequence, the receiving side is unable to decrypt messages. To address this issue, the failed side initiates a new Olm session and sends a dummy encrypted message. However, this dummy message also creates a new Olm session on the sender's side. To ensure that both sides use the same new session, we must sort sessions by their creation timestamp before encrypting new messages. Although the session list was sorted correctly previously, we selected the wrong side of the list, resulting in an outdated session being selected instead of the newest one. This patch resolves the issue by selecting the newest Olm session and adds a test to the session getter logic to prevent reintroduction of this bug.