From 7bbca1005d7f43de3534d4777ad58c45431bbedb Mon Sep 17 00:00:00 2001 From: Franco Bugnano Date: Wed, 15 Jun 2022 10:21:50 +0200 Subject: [PATCH 1/3] Implemented the notification property for participants --- lib/src/chatbox.dart | 5 +++++ lib/src/conversation.dart | 31 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/src/chatbox.dart b/lib/src/chatbox.dart index 3c95660..9b9cea9 100644 --- a/lib/src/chatbox.dart +++ b/lib/src/chatbox.dart @@ -520,6 +520,11 @@ class ChatBoxState extends State { result['notify'] = participant.notify; } + // This overrides the deprecated `notify` property if provided + if (participant.notification != null) { + result['notify'] = participant.notification!.getValue(); + } + execute('$variableName.setParticipant($userVariableName, ${json.encode(result)});'); } } diff --git a/lib/src/conversation.dart b/lib/src/conversation.dart index 39787df..09ef589 100644 --- a/lib/src/conversation.dart +++ b/lib/src/conversation.dart @@ -20,20 +20,41 @@ extension ParticipantAccessString on ParticipantAccess { } } +/// Possible values for participants' notifications +enum ParticipantNotification { off, on, mentionsOnly } + +extension ParticipantNotificationString on ParticipantNotification { + /// Converts this enum's values to String. + dynamic getValue() { + switch (this) { + case ParticipantNotification.off: + return false; + case ParticipantNotification.on: + return true; + case ParticipantNotification.mentionsOnly: + return 'MentionsOnly'; + } + } +} + // Participants are users + options relative to this conversation class Participant { final User user; final ParticipantAccess? access; + /// Deprecated. Use the notification property instead final bool? notify; - const Participant(this.user, {this.access, this.notify}); + final ParticipantNotification? notification; + + const Participant(this.user, {this.access, this.notify, this.notification}); Participant.of(Participant other) : user = User.of(other.user), access = other.access, - notify = other.notify; + notify = other.notify, + notification = other.notification; bool operator ==(Object other) { if (identical(this, other)) { @@ -56,10 +77,14 @@ class Participant { return false; } + if (notification != other.notification) { + return false; + } + return true; } - int get hashCode => hashValues(user, access, notify); + int get hashCode => hashValues(user, access, notify, notification); } /// This represents a conversation that is about to be created, fetched, or From 3f41cffc501f20f424dc857baa402154b63091fe Mon Sep 17 00:00:00 2001 From: Franco Bugnano Date: Wed, 15 Jun 2022 11:00:23 +0200 Subject: [PATCH 2/3] Break compatibility by changing the type of notify --- lib/src/chatbox.dart | 7 +------ lib/src/conversation.dart | 16 ++++------------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/src/chatbox.dart b/lib/src/chatbox.dart index 9b9cea9..5533348 100644 --- a/lib/src/chatbox.dart +++ b/lib/src/chatbox.dart @@ -517,12 +517,7 @@ class ChatBoxState extends State { } if (participant.notify != null) { - result['notify'] = participant.notify; - } - - // This overrides the deprecated `notify` property if provided - if (participant.notification != null) { - result['notify'] = participant.notification!.getValue(); + result['notify'] = participant.notify!.getValue(); } execute('$variableName.setParticipant($userVariableName, ${json.encode(result)});'); diff --git a/lib/src/conversation.dart b/lib/src/conversation.dart index 09ef589..883eb26 100644 --- a/lib/src/conversation.dart +++ b/lib/src/conversation.dart @@ -43,18 +43,14 @@ class Participant { final ParticipantAccess? access; - /// Deprecated. Use the notification property instead - final bool? notify; + final ParticipantNotification? notify; - final ParticipantNotification? notification; - - const Participant(this.user, {this.access, this.notify, this.notification}); + const Participant(this.user, {this.access, this.notify}); Participant.of(Participant other) : user = User.of(other.user), access = other.access, - notify = other.notify, - notification = other.notification; + notify = other.notify; bool operator ==(Object other) { if (identical(this, other)) { @@ -77,14 +73,10 @@ class Participant { return false; } - if (notification != other.notification) { - return false; - } - return true; } - int get hashCode => hashValues(user, access, notify, notification); + int get hashCode => hashValues(user, access, notify); } /// This represents a conversation that is about to be created, fetched, or From 19d1e4192151e6b5c9c22a82acf504e1e089962b Mon Sep 17 00:00:00 2001 From: Franco Bugnano Date: Mon, 20 Jun 2022 14:40:55 +0200 Subject: [PATCH 3/3] Prepared for version 0.4.0 --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 595a9af..e05fa57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.0 + +- BREAKING CHANGE: Changed the `notify` property of the `Participant` to allow for mentions only + ## 0.3.1 - Added explicit support for Android and iOS in pubspec.yaml diff --git a/pubspec.yaml b/pubspec.yaml index 3c34958..44860ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: talkjs_flutter description: Official TalkJS SDK for Flutter -version: 0.3.1 +version: 0.4.0 homepage: https://talkjs.com environment: