Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump matrix-sdk dependency to 0.8. #386

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
857 changes: 513 additions & 344 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
4 changes: 2 additions & 2 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
44 changes: 27 additions & 17 deletions src/notifications.rs
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down Expand Up @@ -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(_) => (),
}
}
})
Expand Down Expand Up @@ -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();

Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions src/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use matrix_sdk::{
media::{MediaFormat, MediaRequest},
media::{MediaFormat, MediaRequestParameters},
ruma::{
events::{
room::{
Expand Down Expand Up @@ -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) =
Expand Down
4 changes: 2 additions & 2 deletions src/windows/room/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/windows/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use matrix_sdk::{
OwnedUserId,
RoomId,
},
DisplayName,
RoomDisplayName,
RoomState as MatrixRoomState,
};

Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 15 additions & 13 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -58,7 +60,6 @@ use matrix_sdk::{
typing::SyncTypingEvent,
AnyInitialStateEvent,
AnyMessageLikeEvent,
AnyTimelineEvent,
EmptyStateKey,
InitialStateEvent,
SyncEphemeralRoomEvent,
Expand All @@ -78,8 +79,8 @@ use matrix_sdk::{
},
Client,
ClientBuildError,
DisplayName,
Error as MatrixError,
RoomDisplayName,
RoomMemberships,
};

Expand Down Expand Up @@ -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(|e| IambError::Serde(e))?;
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();
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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<()>),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down