Skip to content

Commit 7bbca10

Browse files
author
Franco Bugnano
committed
Implemented the notification property for participants
1 parent 4e86e06 commit 7bbca10

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/src/chatbox.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ class ChatBoxState extends State<ChatBox> {
520520
result['notify'] = participant.notify;
521521
}
522522

523+
// This overrides the deprecated `notify` property if provided
524+
if (participant.notification != null) {
525+
result['notify'] = participant.notification!.getValue();
526+
}
527+
523528
execute('$variableName.setParticipant($userVariableName, ${json.encode(result)});');
524529
}
525530
}

lib/src/conversation.dart

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,41 @@ extension ParticipantAccessString on ParticipantAccess {
2020
}
2121
}
2222

23+
/// Possible values for participants' notifications
24+
enum ParticipantNotification { off, on, mentionsOnly }
25+
26+
extension ParticipantNotificationString on ParticipantNotification {
27+
/// Converts this enum's values to String.
28+
dynamic getValue() {
29+
switch (this) {
30+
case ParticipantNotification.off:
31+
return false;
32+
case ParticipantNotification.on:
33+
return true;
34+
case ParticipantNotification.mentionsOnly:
35+
return 'MentionsOnly';
36+
}
37+
}
38+
}
39+
2340
// Participants are users + options relative to this conversation
2441
class Participant {
2542
final User user;
2643

2744
final ParticipantAccess? access;
2845

46+
/// Deprecated. Use the notification property instead
2947
final bool? notify;
3048

31-
const Participant(this.user, {this.access, this.notify});
49+
final ParticipantNotification? notification;
50+
51+
const Participant(this.user, {this.access, this.notify, this.notification});
3252

3353
Participant.of(Participant other)
3454
: user = User.of(other.user),
3555
access = other.access,
36-
notify = other.notify;
56+
notify = other.notify,
57+
notification = other.notification;
3758

3859
bool operator ==(Object other) {
3960
if (identical(this, other)) {
@@ -56,10 +77,14 @@ class Participant {
5677
return false;
5778
}
5879

80+
if (notification != other.notification) {
81+
return false;
82+
}
83+
5984
return true;
6085
}
6186

62-
int get hashCode => hashValues(user, access, notify);
87+
int get hashCode => hashValues(user, access, notify, notification);
6388
}
6489

6590
/// This represents a conversation that is about to be created, fetched, or

0 commit comments

Comments
 (0)