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

Utilize EventStatus for message state #1170

Merged
merged 14 commits into from
Apr 19, 2024

Conversation

FadhlanR
Copy link
Contributor

Ticket: CS-6704

Screenshot 2024-04-16 at 11 11 49

@FadhlanR FadhlanR requested a review from a team April 16, 2024 04:14
Copy link

github-actions bot commented Apr 16, 2024

Test Results

589 tests  +3   585 ✔️ +3   8m 6s ⏱️ -19s
    1 suites ±0       4 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 2ef2c55. ± Comparison against base commit dd75e87.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@jurgenwerk jurgenwerk left a comment

Choose a reason for hiding this comment

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

Can you describe which scenarios you identified that would mean a failed message send? Is it only a network error or something else too?

There are duplicated messages. If I write "I am writing this without internet connection" while being offline it looks like one message got sent and one failed:

image

@jurgenwerk jurgenwerk requested a review from a team April 16, 2024 07:35
Comment on lines 385 to 386
this.messagesToSend.set(roomId, undefined);
this.cardsToSend.set(roomId, undefined);
Copy link
Contributor

@habdelra habdelra Apr 16, 2024

Choose a reason for hiding this comment

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

I know it's not directly related to your PR, but i think the initialization of these two Maps is probably better performed inside of this.setPendingMessage(). Is there ever a time when you set a pending message that you would not want to initialize this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I can move these initializations to setPendingMessage

@@ -377,114 +379,149 @@ export default class MatrixService extends Service {
body: string | undefined,
attachedCards: CardDef[] = [],
context?: OperatorModeContext,
clientGeneratedId?: string, // used to resend failed messages
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clientGeneratedId is generated in setPendingMessage and so for non-"resend" scenario, clientGeneratedId will be undefined.

@FadhlanR
Copy link
Contributor Author

FadhlanR commented Apr 17, 2024

Please hold off the review. I was investigating the bug that @jurgenwerk found, then I noticed that events have status ("sending", "sent", and "not_sent"). I think we can use it for pending messages and messages failed to send. And it will look cleaner than adding states in matrix-service.

@FadhlanR
Copy link
Contributor Author

This PR is ready for review again, @habdelra , @jurgenwerk . I've made a few updates:

  • I used EventStatus to determine the message states.
  • I added a listener for LocalEchoUpdated to track the event status and update message states accordingly.

I've also tested scenarios involving pending messages and messages that failed to send in staging. Here are screenshots of those tests.

Screen.Recording.2024-04-18.at.13.10.40.mov
Screen.Recording.2024-04-18.at.13.11.42.mov

@FadhlanR FadhlanR requested review from habdelra and jurgenwerk April 18, 2024 08:45
@FadhlanR FadhlanR changed the title Add error message if message fails to send Utilize EventStatus for message state Apr 18, 2024
event.content.data = JSON.parse(event.content.data);
}
let { event_id: eventId, room_id: roomId, state_key: stateKey } = event;
eventId = eventId ?? stateKey; // room state may not necessary have an event ID
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing to me - how can event id be two different things?

Copy link
Contributor

@habdelra habdelra Apr 18, 2024

Choose a reason for hiding this comment

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

I think this is highlighting the difference between a message event and room state. the event ID is not necessarily guranteed. the state key is the closest thing room state has to an event ID. (consider an "event" where a user joins a room--this is actually a room state event, and we receive these objects thru the matrix event listener the same as actuall message events)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @habdelra for the explanation. I didn't add this line, it comes from legacy code.


export function onUpdateEventStatus(context: Context) {
return (e: MatrixEvent, _room: Room, oldEventId?: string) => {
if (typeof oldEventId !== 'string' || !e.status) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you checking for the type of the oldEventId? Isn't the event id always a string?

Copy link
Contributor

@habdelra habdelra Apr 18, 2024

Choose a reason for hiding this comment

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

I am curious about this as well--what other type are we expecting here? if this is a fancy check for undefined or null then let's use:

Suggested change
if (typeof oldEventId !== 'string' || !e.status) {
if (oldEvent == null || !e.status) {

this is more clear about what you mean then a typeof check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the event listener type: type AnyListener = (...args: any) => any;. I noticed that sometimes the third item in ...args is not oldEventId. However, I updated the parameter to maybeOldEventId: unknown to mitigate confusion e0932ee.

@jurgenwerk jurgenwerk requested a review from a team April 18, 2024 14:01
@FadhlanR FadhlanR merged commit e606e2d into main Apr 19, 2024
23 checks passed
@delete-merged-branch delete-merged-branch bot deleted the cs-6704-error-message-if-fails-to-send branch April 19, 2024 07:21
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.

3 participants