| @@ -1668,6 +1668,95 @@ impl InnerServer { |
| 1668 | 1668 | } |
| 1669 | 1669 | } |
| 1670 | 1670 | AnyToDeviceEvent::RoomKeyRequest(_) => {} |
| 1671 | AnyToDeviceEvent::RoomKeyWithheld(e) => { |
| 1672 | use matrix_sdk::ruma::events::room_key::withheld::{ |
| 1673 | RoomKeyWithheldCodeInfo, RoomKeyWithheldSessionData, |
| 1674 | }; |
| 1675 | |
| 1676 | // The sender's client proactively told us it will not share |
| 1677 | // the room key. Surface an actionable hint, routed to the |
| 1678 | // room buffer when we know which room the key belongs to. |
| 1679 | // Each recognized code gets its own remediation; the raw |
| 1680 | // reason is only shown when the code is unknown, as ruma |
| 1681 | // documents `reason` as a fallback for unrecognized codes. |
| 1682 | let code = &e.content.code; |
| 1683 | let session_data: Option<&RoomKeyWithheldSessionData> = |
| 1684 | match code { |
| 1685 | RoomKeyWithheldCodeInfo::Blacklisted(data) => { |
| 1686 | Some(data) |
| 1687 | } |
| 1688 | RoomKeyWithheldCodeInfo::Unverified(data) => Some(data), |
| 1689 | RoomKeyWithheldCodeInfo::Unauthorized(data) => { |
| 1690 | Some(data) |
| 1691 | } |
| 1692 | RoomKeyWithheldCodeInfo::Unavailable(data) => { |
| 1693 | Some(data) |
| 1694 | } |
| 1695 | RoomKeyWithheldCodeInfo::NoOlm => None, |
| 1696 | _ => None, |
| 1697 | }; |
| 1698 | |
| 1699 | let message = match code { |
| 1700 | RoomKeyWithheldCodeInfo::Unavailable(_) => format!( |
| 1701 | "{} withheld the room key: the room key is not \ |
| 1702 | available on their device. Ask them to re-send \ |
| 1703 | their message or forward the room key from another \ |
| 1704 | of their devices.", |
| 1705 | e.sender |
| 1706 | ), |
| 1707 | RoomKeyWithheldCodeInfo::Unverified(_) => format!( |
| 1708 | "{} withheld the room key: your device is not \ |
| 1709 | verified and they only share keys with verified \ |
| 1710 | devices. Verify your device with them so the room \ |
| 1711 | key gets shared.", |
| 1712 | e.sender |
| 1713 | ), |
| 1714 | RoomKeyWithheldCodeInfo::Blacklisted(_) => format!( |
| 1715 | "{} withheld the room key: your device is \ |
| 1716 | blacklisted. Ask them to unblacklist your device to \ |
| 1717 | receive the room key.", |
| 1718 | e.sender |
| 1719 | ), |
| 1720 | RoomKeyWithheldCodeInfo::Unauthorized(_) => format!( |
| 1721 | "{} withheld the room key: your device is not \ |
| 1722 | allowed to receive it. Ask them to share the room \ |
| 1723 | key with you.", |
| 1724 | e.sender |
| 1725 | ), |
| 1726 | RoomKeyWithheldCodeInfo::NoOlm => format!( |
| 1727 | "{} withheld the room key: no Olm session could be \ |
| 1728 | established with your device. Make sure both \ |
| 1729 | devices are online so an Olm session can be \ |
| 1730 | established, then ask them to share the room key \ |
| 1731 | again.", |
| 1732 | e.sender |
| 1733 | ), |
| 1734 | other => { |
| 1735 | let mut message = format!( |
| 1736 | "{} withheld the room key with code: {}.", |
| 1737 | e.sender, |
| 1738 | other.code() |
| 1739 | ); |
| 1740 | if let Some(reason) = &e.content.reason { |
| 1741 | message |
| 1742 | .push_str(&format!(" Reason given: {reason}")); |
| 1743 | } |
| 1744 | message |
| 1745 | } |
| 1746 | }; |
| 1747 | |
| 1748 | let buffer = session_data.and_then(|data| { |
| 1749 | self.rooms |
| 1750 | .borrow() |
| 1751 | .get(&data.room_id) |
| 1752 | .map(|room| room.buffer_handle()) |
| 1753 | }); |
| 1754 | self.print_with_prefix_to( |
| 1755 | buffer.as_ref(), |
| 1756 | &Weechat::prefix(Prefix::Network), |
| 1757 | &message, |
| 1758 | ); |
| 1759 | } |
| 1671 | 1760 | AnyToDeviceEvent::KeyVerificationRequest(e) => { |
| 1672 | 1761 | refresh_status_bar = true; |
| 1673 | 1762 | if let Some(client) = self.get_client() { |