mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Bump matrix-sdk dependency to 0.8 (#386)
This commit is contained in:
parent
9a9bdb4862
commit
e66a8c6716
11 changed files with 586 additions and 436 deletions
|
@ -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()
|
||||
|
|
|
@ -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(¬ify_via, &store, &summary, body.as_deref()).await;
|
||||
},
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to extract notification data: {err}")
|
||||
send_notification(¬ify_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()
|
||||
|
|
|
@ -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) =
|
||||
|
|
|
@ -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)?;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue