Implementation of the PartialEq trait for Message

During the community bonding period, I was working on a bug that was preventing the “New messages” divider from being displayed when I found out that the structure Message needed a manual implementation of the PartialEq trait.

When we were opening the application, the last viewed message was loaded from its local cache and the rooms’ messages were synced from homeservers. Fractal then tried to find “equality” (thanks to the PartialEq trait) between the cached messages and the newly synced ones in order to be able to place the divider in the room history. However, this equality could never happen because the structure Message was deriving the PartialEq trait, So in order to be seen as equal, two messages must had identical dates but it was never possible because each time you fetch messages from a homeserver, their timestamps changes by some milliseconds (maybe because of things like the latency of the network or an offset between the clocks of the client and the sever). Hence, the last messages stored in the local cache were never recognized as such and the divider was not displayed when starting the application.

My solution was to simply manually implement the PartialEq trait in order to just compare the IDs of the messages. When one of the messages doesn’t have an ID in Fractal, it is because it hasn’t been sent yet and in this case, I compare the senders and their bodies. Here is the merge request I did to fix this bug.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s