syncWith method

Message syncWith(
  1. Message? other
)

Returns a new Message that is other with local changes applied to it.

This ensures that the local sync changes are not lost when the message is updated on the server.

For example, when a message is sent, it is immediately shown optimistically in the UI. When the message is received from the server, it will not contain the local changes. This method can be used to merge the local changes back into the message.

This also helps in maintaining the order of the messages in the channel when the messages are sorted by the createdAt field.

Implementation

Message syncWith(Message? other) {
  if (other == null) return this;

  return copyWith(
    localCreatedAt: other.localCreatedAt,
    localUpdatedAt: other.localUpdatedAt,
    localDeletedAt: other.localDeletedAt,
  );
}