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
with:
submodules: true
- name: Install Rust (1.74 w/ clippy)
uses: dtolnay/rust-toolchain@1.74
- name: Install Rust (1.76 w/ clippy)
uses: dtolnay/rust-toolchain@1.76
with:
components: clippy
- 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"]
keywords = ["matrix", "chat", "tui", "vim"]
categories = ["command-line-utilities"]
rust-version = "1.74"
rust-version = "1.76"
build = "build.rs"
[features]
@ -87,7 +87,7 @@ version = "0.0.20"
#rev = "24f3ec11c7f634005a27b26878d0fbbdcc08f272"
[dependencies.matrix-sdk]
version = "0.7.1"
version = "0.8.0"
default-features = false
features = ["e2e-encryption", "sqlite", "sso-login"]

View file

@ -53,7 +53,7 @@ user_id = "@user:example.com"
## 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

58
flake.lock generated
View file

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

View file

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

View file

@ -1,11 +1,12 @@
use std::time::SystemTime;
use matrix_sdk::{
deserialized_responses::RawAnySyncOrStrippedTimelineEvent,
notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode},
room::Room as MatrixRoom,
ruma::{
api::client::push::get_notifications::v3::Notification,
events::{room::message::MessageType, AnyMessageLikeEventContent, AnySyncTimelineEvent},
serde::Raw,
MilliSecondsSinceUnixEpoch,
RoomId,
},
@ -53,21 +54,30 @@ pub async fn register_notifications(
return;
}
match parse_notification(notification, room, show_message).await {
Ok((summary, body, server_ts)) => {
if server_ts < startup_ts {
return;
}
match notification.event {
RawAnySyncOrStrippedTimelineEvent::Sync(e) => {
match parse_full_notification(e, room, show_message).await {
Ok((summary, body, server_ts)) => {
if server_ts < startup_ts {
return;
}
if is_missing_mention(&body, mode, &client) {
return;
}
if is_missing_mention(&body, mode, &client) {
return;
}
send_notification(&notify_via, &store, &summary, body.as_deref()).await;
},
Err(err) => {
tracing::error!("Failed to extract notification data: {err}")
send_notification(&notify_via, &store, &summary, body.as_deref())
.await;
},
Err(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(_) => (),
}
}
})
@ -171,12 +181,12 @@ async fn is_visible_room(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
is_focused(&locked) && is_open(&mut locked, room_id)
}
pub async fn parse_notification(
notification: Notification,
pub async fn parse_full_notification(
event: Raw<AnySyncTimelineEvent>,
room: MatrixRoom,
show_body: bool,
) -> 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();
@ -188,7 +198,7 @@ pub async fn parse_notification(
.and_then(|m| m.display_name())
.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}")
} else {
sender_name.to_string()

View file

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

View file

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

View file

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

View file

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