Skip to content

(Feat): v0.18#81

Open
vickz84259 wants to merge 24 commits into
mainfrom
feat/v0.18
Open

(Feat): v0.18#81
vickz84259 wants to merge 24 commits into
mainfrom
feat/v0.18

Conversation

@vickz84259

Copy link
Copy Markdown
Collaborator

A big part of this PR is refactors that I felt were needed just to make the codebase a bit easier to read through and comprehend. With the upcoming components SDK, I speculate that we won't be making many changes to this SDK any time soon. So now felt like a good time to make some of these changes.

Also, adding support for Swift Package Manager to talkjs_flutter_apns_only necessitated an increase in the minimum flutter version supported. Which subsequently also affects this SDK. With this being a breaking change, I felt that I could add a couple more breaking changes in this PR as well.

Here's a breakdown of the changes:

  • (Breaking Change) Refactoring Enums. Aside from some QOL updates gotten from updating the Dart version, I also noticed that we had defined MessageType in two different places. So I unified the two into one definition.
  • Add customEmojis, onLeaveConversation and onMarkConversationAsUnread to Chatbox widget. This also closes issue Unable to react to "Leave" conversation action.  #67.
  • Refactored the hashcode implementations. I realised that Object.hashAll() expects the iteration order to be consistent. However, our use case does not require this. For example: The following custom objects should be considered
    identical: { "a" : "b", "c" : "d" } & { "c" : "d", "a" : "b" }. Therefore it makes sense to use Object.hashAllUnordered() instead.
  • Add participants to ConversationData. I noticed it was missing.
  • (Breaking Change) Rename conversationData to conversation in ConversationActionEvent. I don't know if this changed in the JSSDK or we just missed it when implementing it the first time.
  • (Breaking Change) Rename BaseMessagePredicate and BaseConversationPredicate to SimpleMessagePredicate and SimpleConversationPredicate respectively. Similar to the previous change above, it aligns the naming with the other SDKs.

Reviewing

Go through it commit by commit. The commit messages should provide the additional context where necessary.

Also, I haven't migrated the Example app to AGP 9 yet. I'll do that later. I think I also have to upgrade our webview fork: pichillilorenzo/flutter_inappwebview#2846

After upgrading my local Flutter version, it autogenerated some files
and made updates to others. These changes were largely due to Swift
Package Manager becoming default over Cocoapods and Flutter supporting
UIScene lifecycle methods.

Signed-off-by: Victor Omondi <victor@slick.co.ke>
This commit also includes the switch from using `flutter_apns_only` to
using `talkjs_flutter_apns_only`. The reason is that the former does not
support Swift Package Manager and UIScene lifecycles.

Signed-off-by: Victor Omondi <victor@slick.co.ke>
Signed-off-by: Victor Omondi <victor@slick.co.ke>
The most important change is that I realised we had defined
`MessageType` in two separate places. One had the enum values starting
with a small case while the other with an upper case. This commit
unifies the two definitions. This is a breaking change for users but I
feel like it's valid and necessary.

The other changes are just quality of life changes that make the enum
related code much more ergonomic to use.

Also added the .types file that'll store the types used in multiple
places. This makes the imports simpler. Right now it wasn't clear what
was being imported from where.
These types are referenced in more than one file.
Specify the `@override` annotation to clearly show which methods are
being intentionally overridden.
While adding a new chatbox option, I realised that adding more would
cause the length of the function to become too long for comfort. This
refactor aims to make these functions easier to browse.
A lot of places used `Object.hashAll` which cares about the iteration
order. However, most of the objects in question don't really care about
the order.

For example: The following custom objects should be considered
identical: { "a" : "b", "c" : "d" } & { "c" : "d", "a" : "b" }

In that case it makes sense to use `Object.hashAllUnordered` instead.
Since every class in Dart extends `Object` there is no need to define
"operator ==" and "get hashCode" as part of the abstract classes:
BaseConversationPredicate and BaseMessagePredicate.

Similarly, since we have declared the abstract method `toJson()`, we can
specify the `toString()` override in the abstract classes.
In both instances we end up calling `json.encode()` which will in turn
call `toJson()` on the objects contained within.
Rename `conversationData` property to `conversation` to match the JSSDK
and React Native SDK
This is just to make their names identical to what we have in other
SDKs.
@vickz84259 vickz84259 requested a review from bugnano July 9, 2026 10:36
Comment thread lib/src/conversation.dart Outdated
This removes the custom `fromString()` method in favour of using
`Enum.values.byName()`

@bugnano bugnano left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great job😁

We realised that calling `Object.hashAllUnordered()` on MapEntry objects
does not result in identical hashCodes. To fix this, I ended up using
`MapEquality` instead.

While fixing the above, I realised that `listEquals()` expects the items
to be in the same order. This conflicts with how we were calculating the
hashCode for the same lists. So I replaced this with the use of
`UnorderedIterableEquality`.

I defined these as compile time constants since as an optimisation. No
need to create them everytime the hashcode is referenced or the `==`
operator is used.
The order of welcomeMessages matters hence we should be using
`ListEquality` instead of `UnorderedIterableEquality`
Signed-off-by: Victor Otieno <victor@slick.co.ke>
Signed-off-by: Victor Otieno <victor@slick.co.ke>
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