Bump matrix-sdk dependency to 0.8 (#386)

This commit is contained in:
Stu Black 2025-02-17 22:22:16 -05:00 committed by GitHub
parent 9a9bdb4862
commit e66a8c6716
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 586 additions and 436 deletions

View file

@ -22,8 +22,8 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
submodules: true submodules: true
- name: Install Rust (1.74 w/ clippy) - name: Install Rust (1.76 w/ clippy)
uses: dtolnay/rust-toolchain@1.74 uses: dtolnay/rust-toolchain@1.76
with: with:
components: clippy components: clippy
- name: Install Rust (nightly w/ rustfmt) - name: Install Rust (nightly w/ rustfmt)

863
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@ license = "Apache-2.0"
exclude = [".github", "CONTRIBUTING.md"] exclude = [".github", "CONTRIBUTING.md"]
keywords = ["matrix", "chat", "tui", "vim"] keywords = ["matrix", "chat", "tui", "vim"]
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
rust-version = "1.74" rust-version = "1.76"
build = "build.rs" build = "build.rs"
[features] [features]
@ -87,7 +87,7 @@ version = "0.0.20"
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272" #rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"
[dependencies.matrix-sdk] [dependencies.matrix-sdk]
version = "0.7.1" version = "0.8.0"
default-features = false default-features = false
features = ["e2e-encryption", "sqlite", "sso-login"] features = ["e2e-encryption", "sqlite", "sso-login"]

View file

@ -53,7 +53,7 @@ user_id = "@user:example.com"
## Installation (via `crates.io`) ## Installation (via `crates.io`)
Install Rust (1.74.0 or above) and Cargo, and then run: Install Rust (1.76.0 or above) and Cargo, and then run:
``` ```
cargo install --locked iamb cargo install --locked iamb

58
flake.lock generated
View file

@ -5,29 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1709126324, "lastModified": 1731533236,
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "d465f4819400de7c8d874d50b982301f28a84605", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -38,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1709703039, "lastModified": 1736883708,
"narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", "narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", "rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -54,11 +36,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1706487304, "lastModified": 1736320768,
"narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "90f456026d284c22b3e3497be980b2e47d0b28ac", "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -77,15 +59,14 @@
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1709863839, "lastModified": 1736994333,
"narHash": "sha256-QpEL5FmZNi2By3sKZY55wGniFXc4wEn9PQczlE8TG0o=", "narHash": "sha256-v4Jrok5yXsZ6dwj2+2uo5cSyUi9fBTurHqHvNHLT1XA=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "e5ab9ee98f479081ad971473d2bc13c59e9fbc0a", "rev": "848db855cb9e88785996e961951659570fc58814",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -108,21 +89,6 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -1096,9 +1096,9 @@ impl Message {
let padding = user_gutter - 2 - width; let padding = user_gutter - 2 - width;
let sender = if align_right { let sender = if align_right {
space(padding) + &truncated + " " format!("{}{} ", space(padding), truncated)
} else { } else {
truncated.into_owned() + &space(padding) + " " format!("{}{} ", truncated, space(padding))
}; };
Span::styled(sender, style).into() Span::styled(sender, style).into()

View file

@ -1,11 +1,12 @@
use std::time::SystemTime; use std::time::SystemTime;
use matrix_sdk::{ use matrix_sdk::{
deserialized_responses::RawAnySyncOrStrippedTimelineEvent,
notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode}, notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode},
room::Room as MatrixRoom, room::Room as MatrixRoom,
ruma::{ ruma::{
api::client::push::get_notifications::v3::Notification,
events::{room::message::MessageType, AnyMessageLikeEventContent, AnySyncTimelineEvent}, events::{room::message::MessageType, AnyMessageLikeEventContent, AnySyncTimelineEvent},
serde::Raw,
MilliSecondsSinceUnixEpoch, MilliSecondsSinceUnixEpoch,
RoomId, RoomId,
}, },
@ -53,7 +54,9 @@ pub async fn register_notifications(
return; return;
} }
match parse_notification(notification, room, show_message).await { match notification.event {
RawAnySyncOrStrippedTimelineEvent::Sync(e) => {
match parse_full_notification(e, room, show_message).await {
Ok((summary, body, server_ts)) => { Ok((summary, body, server_ts)) => {
if server_ts < startup_ts { if server_ts < startup_ts {
return; return;
@ -63,12 +66,19 @@ pub async fn register_notifications(
return; return;
} }
send_notification(&notify_via, &store, &summary, body.as_deref()).await; send_notification(&notify_via, &store, &summary, body.as_deref())
.await;
}, },
Err(err) => { Err(err) => {
tracing::error!("Failed to extract notification data: {err}") tracing::error!("Failed to extract notification data: {err}")
}, },
} }
},
// Stripped events may be dropped silently because they're
// only relevant if we're not in a room, and we presumably
// don't want notifications for rooms we're not in.
RawAnySyncOrStrippedTimelineEvent::Stripped(_) => (),
}
} }
}) })
.await; .await;
@ -171,12 +181,12 @@ async fn is_visible_room(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
is_focused(&locked) && is_open(&mut locked, room_id) is_focused(&locked) && is_open(&mut locked, room_id)
} }
pub async fn parse_notification( pub async fn parse_full_notification(
notification: Notification, event: Raw<AnySyncTimelineEvent>,
room: MatrixRoom, room: MatrixRoom,
show_body: bool, show_body: bool,
) -> IambResult<(String, Option<String>, MilliSecondsSinceUnixEpoch)> { ) -> IambResult<(String, Option<String>, MilliSecondsSinceUnixEpoch)> {
let event = notification.event.deserialize().map_err(IambError::from)?; let event = event.deserialize().map_err(IambError::from)?;
let server_ts = event.origin_server_ts(); let server_ts = event.origin_server_ts();
@ -188,7 +198,7 @@ pub async fn parse_notification(
.and_then(|m| m.display_name()) .and_then(|m| m.display_name())
.unwrap_or_else(|| sender_id.localpart()); .unwrap_or_else(|| sender_id.localpart());
let summary = if let Ok(room_name) = room.display_name().await { let summary = if let Some(room_name) = room.cached_display_name() {
format!("{sender_name} in {room_name}") format!("{sender_name} in {room_name}")
} else { } else {
sender_name.to_string() sender_name.to_string()

View file

@ -5,7 +5,7 @@ use std::{
}; };
use matrix_sdk::{ use matrix_sdk::{
media::{MediaFormat, MediaRequest}, media::{MediaFormat, MediaRequestParameters},
ruma::{ ruma::{
events::{ events::{
room::{ room::{
@ -157,7 +157,10 @@ async fn download_or_load(
}, },
Err(_) => { Err(_) => {
media media
.get_media_content(&MediaRequest { source, format: MediaFormat::File }, true) .get_media_content(
&MediaRequestParameters { source, format: MediaFormat::File },
true,
)
.await .await
.and_then(|buffer| { .and_then(|buffer| {
if let Err(err) = if let Err(err) =

View file

@ -14,7 +14,7 @@ use url::Url;
use matrix_sdk::{ use matrix_sdk::{
attachment::AttachmentConfig, attachment::AttachmentConfig,
media::{MediaFormat, MediaRequest}, media::{MediaFormat, MediaRequestParameters},
room::Room as MatrixRoom, room::Room as MatrixRoom,
ruma::{ ruma::{
events::reaction::ReactionEventContent, events::reaction::ReactionEventContent,
@ -276,7 +276,7 @@ impl ChatState {
} }
if !filename.exists() || flags.contains(DownloadFlags::FORCE) { if !filename.exists() || flags.contains(DownloadFlags::FORCE) {
let req = MediaRequest { source, format: MediaFormat::File }; let req = MediaRequestParameters { source, format: MediaFormat::File };
let bytes = let bytes =
media.get_media_content(&req, true).await.map_err(IambError::from)?; media.get_media_content(&req, true).await.map_err(IambError::from)?;

View file

@ -26,7 +26,7 @@ use matrix_sdk::{
OwnedUserId, OwnedUserId,
RoomId, RoomId,
}, },
DisplayName, RoomDisplayName,
RoomState as MatrixRoomState, RoomState as MatrixRoomState,
}; };
@ -139,7 +139,7 @@ impl RoomState {
pub fn new( pub fn new(
room: MatrixRoom, room: MatrixRoom,
thread: Option<OwnedEventId>, thread: Option<OwnedEventId>,
name: DisplayName, name: RoomDisplayName,
tags: Option<Tags>, tags: Option<Tags>,
store: &mut ProgramStore, store: &mut ProgramStore,
) -> Self { ) -> Self {

View file

@ -13,6 +13,7 @@ use std::time::{Duration, Instant};
use futures::{stream::FuturesUnordered, StreamExt}; use futures::{stream::FuturesUnordered, StreamExt};
use gethostname::gethostname; use gethostname::gethostname;
use matrix_sdk::ruma::events::AnySyncTimelineEvent;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tokio::sync::Semaphore; use tokio::sync::Semaphore;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
@ -21,6 +22,7 @@ use url::Url;
use matrix_sdk::{ use matrix_sdk::{
config::{RequestConfig, SyncSettings}, config::{RequestConfig, SyncSettings},
deserialized_responses::DisplayName,
encryption::verification::{SasVerification, Verification}, encryption::verification::{SasVerification, Verification},
encryption::{BackupDownloadStrategy, EncryptionSettings}, encryption::{BackupDownloadStrategy, EncryptionSettings},
event_handler::Ctx, event_handler::Ctx,
@ -58,7 +60,6 @@ use matrix_sdk::{
typing::SyncTypingEvent, typing::SyncTypingEvent,
AnyInitialStateEvent, AnyInitialStateEvent,
AnyMessageLikeEvent, AnyMessageLikeEvent,
AnyTimelineEvent,
EmptyStateKey, EmptyStateKey,
InitialStateEvent, InitialStateEvent,
SyncEphemeralRoomEvent, SyncEphemeralRoomEvent,
@ -78,8 +79,8 @@ use matrix_sdk::{
}, },
Client, Client,
ClientBuildError, ClientBuildError,
DisplayName,
Error as MatrixError, Error as MatrixError,
RoomDisplayName,
RoomMemberships, RoomMemberships,
}; };
@ -293,10 +294,10 @@ async fn load_older_one(
let mut msgs = vec![]; let mut msgs = vec![];
for ev in chunk.into_iter() { for ev in chunk.into_iter() {
let msg = match ev.event.deserialize() { let deserialized = ev.into_raw().deserialize().map_err(IambError::Serde)?;
Ok(AnyTimelineEvent::MessageLike(msg)) => msg, let msg: AnyMessageLikeEvent = match deserialized {
Ok(AnyTimelineEvent::State(_)) => continue, AnySyncTimelineEvent::MessageLike(e) => e.into_full_event(room_id.to_owned()),
Err(_) => continue, AnySyncTimelineEvent::State(_) => continue,
}; };
let event_id = msg.event_id(); let event_id = msg.event_id();
@ -440,7 +441,7 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore) {
let mut dms = vec![]; let mut dms = vec![];
for room in client.invited_rooms().into_iter() { for room in client.invited_rooms().into_iter() {
let name = room.display_name().await.unwrap_or(DisplayName::Empty).to_string(); let name = room.cached_display_name().unwrap_or(RoomDisplayName::Empty).to_string();
let tags = room.tags().await.unwrap_or_default(); let tags = room.tags().await.unwrap_or_default();
names.push((room.room_id().to_owned(), name)); names.push((room.room_id().to_owned(), name));
@ -455,7 +456,7 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore) {
} }
for room in client.joined_rooms().into_iter() { for room in client.joined_rooms().into_iter() {
let name = room.display_name().await.unwrap_or(DisplayName::Empty).to_string(); let name = room.cached_display_name().unwrap_or(RoomDisplayName::Empty).to_string();
let tags = room.tags().await.unwrap_or_default(); let tags = room.tags().await.unwrap_or_default();
names.push((room.room_id().to_owned(), name)); names.push((room.room_id().to_owned(), name));
@ -603,7 +604,7 @@ fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) {
return (reply, response); return (reply, response);
} }
pub type FetchedRoom = (MatrixRoom, DisplayName, Option<Tags>); pub type FetchedRoom = (MatrixRoom, RoomDisplayName, Option<Tags>);
pub enum WorkerTask { pub enum WorkerTask {
Init(AsyncProgramStore, ClientReply<()>), Init(AsyncProgramStore, ClientReply<()>),
@ -1076,11 +1077,12 @@ impl ClientWorker {
let room_id = room.room_id(); let room_id = room.room_id();
let user_id = ev.state_key; let user_id = ev.state_key;
let ambiguous_name = let ambiguous_name = DisplayName::new(
ev.content.displayname.as_deref().unwrap_or_else(|| user_id.localpart()); ev.content.displayname.as_deref().unwrap_or_else(|| user_id.as_str()),
);
let ambiguous = client let ambiguous = client
.store() .store()
.get_users_with_display_name(room_id, ambiguous_name) .get_users_with_display_name(room_id, &ambiguous_name)
.await .await
.map(|users| users.len() > 1) .map(|users| users.len() > 1)
.unwrap_or_default(); .unwrap_or_default();
@ -1346,7 +1348,7 @@ impl ClientWorker {
async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<FetchedRoom> { async fn get_room(&mut self, room_id: OwnedRoomId) -> IambResult<FetchedRoom> {
if let Some(room) = self.client.get_room(&room_id) { if let Some(room) = self.client.get_room(&room_id) {
let name = room.display_name().await.map_err(IambError::from)?; let name = room.cached_display_name().ok_or_else(|| IambError::UnknownRoom(room_id))?;
let tags = room.tags().await.map_err(IambError::from)?; let tags = room.tags().await.map_err(IambError::from)?;
Ok((room, name, tags)) Ok((room, name, tags))