feat(sdk): LocalEventTimelineItem has a new send_state field
#1419
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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::sendmethod just returned the error but it wasn't reflected inside theLocalEventTimelineItemtype itself. It's easy to loss this information.So now, there is a new enum:
LocalEventTimelineItemSendStatewith 3 states:NotSentYet, when the local event has not been sent yet, it's theorically the initial state,SendingFailed, when the local event has been sent but it's failed!Sent, when the local event has been sent successfully.Therefore, the
LocalEventTimelineItemstruct has a new field:send_state. The send state is managed by itswith_event_idmethod which now receives anOption<OwnedEventId>(prev.OwnedEventIddirectly):Some(_), then it means we got a successful response from the server after the sending, so the send state is set toSent,None, then it means we got an error response from the server, so the send state is set toSentFailed.(A small change: The method
TimelineInner::add_event_idhas been renamedTimelineInner::update_event_id_of_local_event.)The
Timeline::sendstill returns aResult, but the server's response is passed to a new method:TimelinerInner::handle_local_event_send_response(it's logically named after thehandle_local_eventmethod), which is responsible to callTimelineInner:update_event_id_of_local_event(which was previously called directly byTimeline::send).And
TimelineInner::update_event_id_of_local_eventwas already callingLocalEventTimelineItem::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