Skip to content

Commit c06b6d9

Browse files
committed
timeline: get rid of the indirection for the Unsupported* errors
No idea why we had these wrappers, and IMO they just add unnecessary noise, so let's get rid of them.
1 parent fd9d3bd commit c06b6d9

File tree

3 files changed

+17
-60
lines changed

3 files changed

+17
-60
lines changed

crates/matrix-sdk-ui/src/timeline/error.rs

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::fmt;
16-
1715
use matrix_sdk::{
1816
event_cache::{paginator::PaginatorError, EventCacheError},
1917
send_queue::RoomSendQueueError,
@@ -81,28 +79,8 @@ pub enum PaginationError {
8179
Paginator(#[source] PaginatorError),
8280
}
8381

84-
#[derive(Error)]
85-
#[error("{0}")]
86-
pub struct UnsupportedReplyItem(UnsupportedReplyItemInner);
87-
88-
impl UnsupportedReplyItem {
89-
pub(super) const MISSING_EVENT_ID: Self = Self(UnsupportedReplyItemInner::MissingEventId);
90-
pub(super) const MISSING_JSON: Self = Self(UnsupportedReplyItemInner::MissingJson);
91-
pub(super) const MISSING_EVENT: Self = Self(UnsupportedReplyItemInner::MissingEvent);
92-
pub(super) const FAILED_TO_DESERIALIZE_EVENT: Self =
93-
Self(UnsupportedReplyItemInner::FailedToDeserializeEvent);
94-
pub(super) const STATE_EVENT: Self = Self(UnsupportedReplyItemInner::StateEvent);
95-
}
96-
97-
#[cfg(not(tarpaulin_include))]
98-
impl fmt::Debug for UnsupportedReplyItem {
99-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
100-
self.0.fmt(f)
101-
}
102-
}
103-
10482
#[derive(Debug, Error)]
105-
enum UnsupportedReplyItemInner {
83+
pub enum UnsupportedReplyItem {
10684
#[error("local messages whose event ID is not known can't be replied to currently")]
10785
MissingEventId,
10886
#[error("redacted events whose JSON form isn't available can't be replied")]
@@ -115,29 +93,8 @@ enum UnsupportedReplyItemInner {
11593
StateEvent,
11694
}
11795

118-
#[derive(Error)]
119-
#[error("{0}")]
120-
pub struct UnsupportedEditItem(UnsupportedEditItemInner);
121-
122-
impl UnsupportedEditItem {
123-
pub(super) const MISSING_EVENT_ID: Self = Self(UnsupportedEditItemInner::MissingEventId);
124-
pub(super) const NOT_ROOM_MESSAGE: Self = Self(UnsupportedEditItemInner::NotRoomMessage);
125-
pub(super) const NOT_POLL_EVENT: Self = Self(UnsupportedEditItemInner::NotPollEvent);
126-
pub(super) const NOT_OWN_EVENT: Self = Self(UnsupportedEditItemInner::NotOwnEvent);
127-
pub(super) const MISSING_EVENT: Self = Self(UnsupportedEditItemInner::MissingEvent);
128-
pub(super) const FAILED_TO_DESERIALIZE_EVENT: Self =
129-
Self(UnsupportedEditItemInner::FailedToDeserializeEvent);
130-
}
131-
132-
#[cfg(not(tarpaulin_include))]
133-
impl fmt::Debug for UnsupportedEditItem {
134-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135-
self.0.fmt(f)
136-
}
137-
}
138-
13996
#[derive(Debug, Error)]
140-
enum UnsupportedEditItemInner {
97+
pub enum UnsupportedEditItem {
14198
#[error("local messages whose event ID is not known can't be edited currently")]
14299
MissingEventId,
143100
#[error("tried to edit a non-message event")]

crates/matrix-sdk-ui/src/timeline/event_item/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ impl EventTimelineItem {
429429
TimelineItemContent::Message(msg) => ReplyContent::Message(msg.to_owned()),
430430
_ => {
431431
let Some(raw_event) = self.latest_json() else {
432-
return Err(UnsupportedReplyItem::MISSING_JSON);
432+
return Err(UnsupportedReplyItem::MissingJson);
433433
};
434434

435435
ReplyContent::Raw(raw_event.clone())
436436
}
437437
};
438438

439439
let Some(event_id) = self.event_id() else {
440-
return Err(UnsupportedReplyItem::MISSING_EVENT_ID);
440+
return Err(UnsupportedReplyItem::MissingEventId);
441441
};
442442

443443
Ok(RepliedToInfo {
@@ -451,15 +451,15 @@ impl EventTimelineItem {
451451
/// Gives the information needed to edit the event of the item.
452452
pub fn edit_info(&self) -> Result<EditInfo, UnsupportedEditItem> {
453453
if !self.is_own() {
454-
return Err(UnsupportedEditItem::NOT_OWN_EVENT);
454+
return Err(UnsupportedEditItem::NotOwnEvent);
455455
}
456456
// Early returns here must be in sync with
457457
// `EventTimelineItem::can_be_edited`
458458
let Some(event_id) = self.event_id() else {
459-
return Err(UnsupportedEditItem::MISSING_EVENT_ID);
459+
return Err(UnsupportedEditItem::MissingEventId);
460460
};
461461
let TimelineItemContent::Message(original_content) = self.content() else {
462-
return Err(UnsupportedEditItem::NOT_ROOM_MESSAGE);
462+
return Err(UnsupportedEditItem::NotRoomMessage);
463463
};
464464
Ok(EditInfo { event_id: event_id.to_owned(), original_message: original_content.clone() })
465465
}

crates/matrix-sdk-ui/src/timeline/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl Timeline {
414414

415415
let event = self.room().event(event_id).await.map_err(|error| {
416416
error!("Failed to fetch event with ID {event_id} with error: {error}");
417-
UnsupportedReplyItem::MISSING_EVENT
417+
UnsupportedReplyItem::MissingEvent
418418
})?;
419419

420420
// We need to get the content and we can do that by casting the event as a
@@ -424,7 +424,7 @@ impl Timeline {
424424
let raw_sync_event: Raw<AnySyncTimelineEvent> = event.event.cast();
425425
let sync_event = raw_sync_event.deserialize().map_err(|error| {
426426
error!("Failed to deserialize event with ID {event_id} with error: {error}");
427-
UnsupportedReplyItem::FAILED_TO_DESERIALIZE_EVENT
427+
UnsupportedReplyItem::FailedToDeserializeEvent
428428
})?;
429429

430430
let reply_content = match &sync_event {
@@ -442,7 +442,7 @@ impl Timeline {
442442
ReplyContent::Raw(raw_sync_event)
443443
}
444444
}
445-
AnySyncTimelineEvent::State(_) => return Err(UnsupportedReplyItem::STATE_EVENT),
445+
AnySyncTimelineEvent::State(_) => return Err(UnsupportedReplyItem::StateEvent),
446446
};
447447

448448
Ok(RepliedToInfo {
@@ -514,7 +514,7 @@ impl Timeline {
514514

515515
let event = self.room().event(event_id).await.map_err(|error| {
516516
error!("Failed to fetch event with ID {event_id} with error: {error}");
517-
UnsupportedEditItem::MISSING_EVENT
517+
UnsupportedEditItem::MissingEvent
518518
})?;
519519

520520
// We need to get the content and we can do that by casting
@@ -524,11 +524,11 @@ impl Timeline {
524524
let raw_sync_event: Raw<AnySyncTimelineEvent> = event.event.cast();
525525
let event = raw_sync_event.deserialize().map_err(|error| {
526526
error!("Failed to deserialize event with ID {event_id} with error: {error}");
527-
UnsupportedEditItem::FAILED_TO_DESERIALIZE_EVENT
527+
UnsupportedEditItem::FailedToDeserializeEvent
528528
})?;
529529

530530
if event.sender() != self.room().own_user_id() {
531-
return Err(UnsupportedEditItem::NOT_OWN_EVENT);
531+
return Err(UnsupportedEditItem::NotOwnEvent);
532532
};
533533

534534
if let AnySyncTimelineEvent::MessageLike(message_like_event) = &event {
@@ -545,7 +545,7 @@ impl Timeline {
545545
}
546546
}
547547

548-
Err(UnsupportedEditItem::NOT_ROOM_MESSAGE)
548+
Err(UnsupportedEditItem::NotRoomMessage)
549549
}
550550

551551
pub async fn edit_poll(
@@ -559,14 +559,14 @@ impl Timeline {
559559

560560
// Early returns here must be in sync with `EventTimelineItem::is_editable`.
561561
if !edit_item.is_own() {
562-
return Err(UnsupportedEditItem::NOT_OWN_EVENT.into());
562+
return Err(UnsupportedEditItem::NotOwnEvent.into());
563563
}
564564
let Some(event_id) = edit_item.event_id() else {
565-
return Err(UnsupportedEditItem::MISSING_EVENT_ID.into());
565+
return Err(UnsupportedEditItem::MissingEvent.into());
566566
};
567567

568568
let TimelineItemContent::Poll(_) = edit_item.content() else {
569-
return Err(UnsupportedEditItem::NOT_POLL_EVENT.into());
569+
return Err(UnsupportedEditItem::NotPollEvent.into());
570570
};
571571

572572
let content = ReplacementUnstablePollStartEventContent::plain_text(

0 commit comments

Comments
 (0)