Skip to content

Commit aa20532

Browse files
sm-sayedichrisbobbe
andcommitted
api: Add user_status event
Co-authored-by: Chris Bobbe <[email protected]>
1 parent 69a1542 commit aa20532

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

lib/api/model/events.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ sealed class Event {
6161
default: return UnexpectedEvent.fromJson(json);
6262
}
6363
// case 'muted_topics': … // TODO(#422) we ignore this feature on older servers
64+
case 'user_status': return UserStatusEvent.fromJson(json);
6465
case 'user_topic': return UserTopicEvent.fromJson(json);
6566
case 'muted_users': return MutedUsersEvent.fromJson(json);
6667
case 'message': return MessageEvent.fromJson(json);
@@ -708,6 +709,40 @@ class SubscriptionPeerRemoveEvent extends SubscriptionEvent {
708709
Map<String, dynamic> toJson() => _$SubscriptionPeerRemoveEventToJson(this);
709710
}
710711

712+
/// A Zulip event of type `user_status`: https://zulip.com/api/get-events#user_status
713+
@JsonSerializable(fieldRename: FieldRename.snake)
714+
class UserStatusEvent extends Event {
715+
@override
716+
@JsonKey(includeToJson: true)
717+
String get type => 'user_status';
718+
719+
final int userId;
720+
721+
@JsonKey(readValue: _readChange, includeToJson: false)
722+
final UserStatusChange change;
723+
724+
static Object? _readChange(Map<dynamic, dynamic> json, String key) {
725+
assert(json is Map<String, dynamic>); // value came through `fromJson` with this type
726+
json['status_text'] as String?;
727+
json['reaction_type'] as String?;
728+
json['emoji_code'] as String?;
729+
json['emoji_name'] as String?;
730+
return json;
731+
}
732+
733+
UserStatusEvent({
734+
required super.id,
735+
required this.userId,
736+
required this.change,
737+
});
738+
739+
factory UserStatusEvent.fromJson(Map<String, dynamic> json) =>
740+
_$UserStatusEventFromJson(json);
741+
742+
@override
743+
Map<String, dynamic> toJson() => _$UserStatusEventToJson(this);
744+
}
745+
711746
/// A Zulip event of type `user_topic`: https://zulip.com/api/get-events#user_topic
712747
@JsonSerializable(fieldRename: FieldRename.snake)
713748
class UserTopicEvent extends Event {

lib/api/model/events.g.dart

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/model/store.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,10 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
929929
_channels.handleSubscriptionEvent(event);
930930
notifyListeners();
931931

932+
case UserStatusEvent():
933+
// TODO: handle
934+
break;
935+
932936
case UserTopicEvent():
933937
assert(debugLog("server event: user_topic"));
934938
_messages.handleUserTopicEvent(event);

0 commit comments

Comments
 (0)