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

feat(sdk): LocalEventTimelineItem has a new send_state field #1419

Merged
merged 3 commits into from
Jan 30, 2023

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jan 30, 2023

Address #1103.

This patch is trying to resolve the following issue:

When a local event is sent to the server, in case of an error, the Timeline::send method just returned the error but it wasn't reflected inside the LocalEventTimelineItem type itself. It's easy to loss this information.

So now, there is a new enum: LocalEventTimelineItemSendState with 3 states:

  1. NotSentYet, when the local event has not been sent yet, it's theorically the initial state,
  2. SendingFailed, when the local event has been sent but it's failed!
  3. Sent, when the local event has been sent successfully.

Therefore, the LocalEventTimelineItem struct has a new field: send_state. The send state is managed by its with_event_id method which now receives an Option<OwnedEventId> (prev. OwnedEventId directly):

  • If it's Some(_), then it means we got a successful response from the server after the sending, so the send state is set to Sent,
  • If it's None, then it means we got an error response from the server, so the send state is set to SentFailed.

(A small change: The method TimelineInner::add_event_id has been renamed TimelineInner::update_event_id_of_local_event.)

The Timeline::send still returns a Result, but the server's response is passed to a new method: TimelinerInner::handle_local_event_send_response (it's logically named after the handle_local_event method), which is responsible to call TimelineInner:update_event_id_of_local_event (which was previously called directly by Timeline::send).

And TimelineInner::update_event_id_of_local_event was already calling LocalEventTimelineItem::with_event_id. So everything works like a charm here.

The local send state is closely managed by LocalEventTimelineItem, I hope it will avoid state breakage as much as possible.

Progression

  • Add new local send state type
  • Update tests
  • Update FFI

This patch is trying to resolve the following issue:

When a local event is sent to the server, in case of an error, the
`Timeline::send` method just returned the error but it wasn't reflected inside
the `LocalEventTimelineItem` type itself. It's easy to loss this information.

So now, there is a new enum: `LocalEventTimelineItemSendState` with 3 states:

1. `NotSentYet`, when the local event has not been sent yet, it's theorically
   the initial state,
2. `SendingFailed`, when the local event has been sent but it's failed!
3. `Sent`, when the local event has been sent successfully.

Therefore, the `LocalEventTimelineItem` struct has a new field: `send_state`.

The send state is managed by its `with_event_id` method which now receives an
`Option<OwnedEventId>` (prev. `OwnedEventId` directly):

* If it's `Some(_)`, then it means we got a successful response from the server
  after the sending, so the send state is set to `Sent`,
* If it's `None`, then it means we got an error response from the server, so
  the send state is set to `SentFailed`.

(A small change: The method `TimelineInner::add_event_id` has been renamed
`TimelineInner::update_event_id_of_local_event`.)

The `Timeline::send` still returns a `Result`, but the server's response is
passed to a new method: `TimelinerInner::handle_local_event_send_response`
(it's logically named after the `handle_local_event` method), which is
responsible to call `TimelineInner:update_event_id_of_local_event` (which was
previously called directly by `Timeline::send`).

And `TimelineInner::update_event_id_of_local_event` was already calling
`LocalEventTimelineItem::with_event_id`. So everything works like a charm here.

The local send state is closely managed by `LocalEventTimelineItem`, I hope it
will avoid state breakage as much as possible.
@Hywan Hywan marked this pull request as ready for review January 30, 2023 12:51
@Hywan Hywan mentioned this pull request Jan 30, 2023
29 tasks
Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds sensible.

@Hywan Hywan enabled auto-merge January 30, 2023 12:56
@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 72.71% // Head: 72.71% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (274bc20) compared to base (0a7193d).
Patch coverage: 73.80% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1419   +/-   ##
=======================================
  Coverage   72.71%   72.71%           
=======================================
  Files         116      116           
  Lines       13124    13140   +16     
=======================================
+ Hits         9543     9555   +12     
- Misses       3581     3585    +4     
Impacted Files Coverage Δ
crates/matrix-sdk/src/room/timeline/to_device.rs 14.28% <0.00%> (-0.53%) ⬇️
crates/matrix-sdk/src/room/timeline/mod.rs 83.20% <50.00%> (+0.49%) ⬆️
crates/matrix-sdk/src/room/timeline/inner.rs 76.06% <78.78%> (-0.10%) ⬇️
...ates/matrix-sdk/src/room/timeline/event_handler.rs 69.62% <100.00%> (+0.08%) ⬆️
crates/matrix-sdk/src/room/timeline/event_item.rs 47.23% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Hywan Hywan merged commit 38dfa90 into matrix-org:main Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants