Browse Source

misc: Fix new clippy warnings

fractal-12
Kévin Commaille 12 months ago
parent
commit
6035b4ee37
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 8
      src/session/view/content/room_history/message_toolbar/composer_state.rs
  2. 2
      src/session/view/content/room_history/message_toolbar/mod.rs
  3. 16
      src/utils/matrix/media_message.rs
  4. 20
      src/utils/matrix/mod.rs

8
src/session/view/content/room_history/message_toolbar/composer_state.rs

@ -517,7 +517,7 @@ impl ComposerState {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) enum RelationInfo { pub(crate) enum RelationInfo {
/// Send a reply to the given event. /// Send a reply to the given event.
Reply(MessageEventSource), Reply(Box<MessageEventSource>),
/// Send an edit to the event with the given ID. /// Send an edit to the event with the given ID.
Edit(OwnedEventId), Edit(OwnedEventId),
@ -551,7 +551,7 @@ impl RelationInfo {
return None; return None;
}; };
Some(RelationInfo::Reply(message_event)) Some(RelationInfo::Reply(message_event.into()))
} }
ComposerDraftType::Edit { event_id } => Some(RelationInfo::Edit(event_id)), ComposerDraftType::Edit { event_id } => Some(RelationInfo::Edit(event_id)),
} }
@ -648,7 +648,7 @@ struct DetectedMention {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) enum MessageEventSource { pub(crate) enum MessageEventSource {
/// An original event. /// An original event.
OriginalEvent(OriginalSyncRoomMessageEvent), OriginalEvent(Box<OriginalSyncRoomMessageEvent>),
/// An [`Event`]. /// An [`Event`].
Event(Event), Event(Event),
} }
@ -663,7 +663,7 @@ impl MessageEventSource {
match event { match event {
AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage( AnySyncTimelineEvent::MessageLike(AnySyncMessageLikeEvent::RoomMessage(
SyncMessageLikeEvent::Original(message_event), SyncMessageLikeEvent::Original(message_event),
)) => Some(Self::OriginalEvent(message_event)), )) => Some(Self::OriginalEvent(message_event.into())),
_ => None, _ => None,
} }
} }

2
src/session/view/content/room_history/message_toolbar/mod.rs

@ -573,7 +573,7 @@ mod imp {
}; };
self.current_composer_state() self.current_composer_state()
.set_related_to(Some(RelationInfo::Reply(message_event))); .set_related_to(Some(RelationInfo::Reply(message_event.into())));
self.message_entry.grab_focus(); self.message_entry.grab_focus();
} }

16
src/utils/matrix/media_message.rs

@ -56,7 +56,7 @@ pub(crate) enum MediaMessage {
/// A video. /// A video.
Video(VideoMessageEventContent), Video(VideoMessageEventContent),
/// A sticker. /// A sticker.
Sticker(StickerEventContent), Sticker(Box<StickerEventContent>),
} }
impl MediaMessage { impl MediaMessage {
@ -104,7 +104,7 @@ impl MediaMessage {
let media = client.media(); let media = client.media();
macro_rules! content { macro_rules! content {
($event_content:ident) => {{ ($event_content:expr) => {{
Ok( Ok(
$crate::spawn_tokio!( $crate::spawn_tokio!(
async move { media.get_file(&$event_content, true).await } async move { media.get_file(&$event_content, true).await }
@ -121,7 +121,7 @@ impl MediaMessage {
Self::File(c) => content!(c), Self::File(c) => content!(c),
Self::Image(c) => content!(c), Self::Image(c) => content!(c),
Self::Video(c) => content!(c), Self::Video(c) => content!(c),
Self::Sticker(c) => content!(c), Self::Sticker(c) => content!(*c),
} }
} }
@ -199,7 +199,7 @@ impl From<FileMessageEventContent> for MediaMessage {
impl From<StickerEventContent> for MediaMessage { impl From<StickerEventContent> for MediaMessage {
fn from(value: StickerEventContent) -> Self { fn from(value: StickerEventContent) -> Self {
Self::Sticker(value) Self::Sticker(value.into())
} }
} }
@ -211,7 +211,7 @@ pub(crate) enum VisualMediaMessage {
/// A video. /// A video.
Video(VideoMessageEventContent), Video(VideoMessageEventContent),
/// A sticker. /// A sticker.
Sticker(StickerEventContent), Sticker(Box<StickerEventContent>),
} }
impl VisualMediaMessage { impl VisualMediaMessage {
@ -373,6 +373,12 @@ impl From<VideoMessageEventContent> for VisualMediaMessage {
impl From<StickerEventContent> for VisualMediaMessage { impl From<StickerEventContent> for VisualMediaMessage {
fn from(value: StickerEventContent) -> Self { fn from(value: StickerEventContent) -> Self {
Self::Sticker(value.into())
}
}
impl From<Box<StickerEventContent>> for VisualMediaMessage {
fn from(value: Box<StickerEventContent>) -> Self {
Self::Sticker(value) Self::Sticker(value)
} }
} }

20
src/utils/matrix/mod.rs

@ -113,9 +113,9 @@ pub(crate) fn validate_password(password: &str) -> PasswordValidity {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) enum AnySyncOrStrippedTimelineEvent { pub(crate) enum AnySyncOrStrippedTimelineEvent {
/// An event from a joined or left room. /// An event from a joined or left room.
Sync(AnySyncTimelineEvent), Sync(Box<AnySyncTimelineEvent>),
/// An event from an invited room. /// An event from an invited room.
Stripped(AnyStrippedStateEvent), Stripped(Box<AnyStrippedStateEvent>),
} }
impl AnySyncOrStrippedTimelineEvent { impl AnySyncOrStrippedTimelineEvent {
@ -124,8 +124,10 @@ impl AnySyncOrStrippedTimelineEvent {
raw: &RawAnySyncOrStrippedTimelineEvent, raw: &RawAnySyncOrStrippedTimelineEvent,
) -> Result<Self, serde_json::Error> { ) -> Result<Self, serde_json::Error> {
let ev = match raw { let ev = match raw {
RawAnySyncOrStrippedTimelineEvent::Sync(ev) => Self::Sync(ev.deserialize()?), RawAnySyncOrStrippedTimelineEvent::Sync(ev) => Self::Sync(ev.deserialize()?.into()),
RawAnySyncOrStrippedTimelineEvent::Stripped(ev) => Self::Stripped(ev.deserialize()?), RawAnySyncOrStrippedTimelineEvent::Stripped(ev) => {
Self::Stripped(ev.deserialize()?.into())
}
}; };
Ok(ev) Ok(ev)
@ -161,10 +163,12 @@ pub(crate) fn get_event_body(
show_sender: bool, show_sender: bool,
) -> Option<String> { ) -> Option<String> {
match event { match event {
AnySyncOrStrippedTimelineEvent::Sync(AnySyncTimelineEvent::MessageLike(message)) => { AnySyncOrStrippedTimelineEvent::Sync(sync_event) => match &**sync_event {
get_message_event_body(message, sender_name, show_sender) AnySyncTimelineEvent::MessageLike(message) => {
} get_message_event_body(message, sender_name, show_sender)
AnySyncOrStrippedTimelineEvent::Sync(_) => None, }
AnySyncTimelineEvent::State(_) => None,
},
AnySyncOrStrippedTimelineEvent::Stripped(state) => { AnySyncOrStrippedTimelineEvent::Stripped(state) => {
get_stripped_state_event_body(state, sender_name, own_user) get_stripped_state_event_body(state, sender_name, own_user)
} }

Loading…
Cancel
Save