Skip to content

Commit 3d814d2

Browse files
sm-sayedichrisbobbe
andcommitted
api: Add user_status event
Co-authored-by: Chris Bobbe <[email protected]>
1 parent 368df50 commit 3d814d2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/api/model/events.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ sealed class Event {
6969
default: return UnexpectedEvent.fromJson(json);
7070
}
7171
// case 'muted_topics': … // TODO(#422) we ignore this feature on older servers
72+
case 'user_status': return UserStatusEvent.fromJson(json);
7273
case 'user_topic': return UserTopicEvent.fromJson(json);
7374
case 'muted_users': return MutedUsersEvent.fromJson(json);
7475
case 'message': return MessageEvent.fromJson(json);
@@ -797,6 +798,41 @@ class SubscriptionPeerRemoveEvent extends SubscriptionEvent {
797798
Map<String, dynamic> toJson() => _$SubscriptionPeerRemoveEventToJson(this);
798799
}
799800

801+
/// A Zulip event of type `user_status`: https://zulip.com/api/get-events#user_status
802+
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
803+
class UserStatusEvent extends Event {
804+
@override
805+
@JsonKey(includeToJson: true)
806+
String get type => 'user_status';
807+
808+
final int userId;
809+
810+
@JsonKey(readValue: _readChange)
811+
final UserStatusChange change;
812+
813+
static Object? _readChange(Map<dynamic, dynamic> json, String key) {
814+
assert(json is Map<String, dynamic>); // value came through `fromJson` with this type
815+
return json;
816+
}
817+
818+
UserStatusEvent({
819+
required super.id,
820+
required this.userId,
821+
required this.change,
822+
});
823+
824+
factory UserStatusEvent.fromJson(Map<String, dynamic> json) =>
825+
_$UserStatusEventFromJson(json);
826+
827+
@override
828+
Map<String, dynamic> toJson() => {
829+
'id': id,
830+
'type': type,
831+
'user_id': userId,
832+
...change.toJson(),
833+
};
834+
}
835+
800836
/// A Zulip event of type `user_topic`: https://zulip.com/api/get-events#user_topic
801837
@JsonSerializable(fieldRename: FieldRename.snake)
802838
class UserTopicEvent extends Event {

lib/api/model/events.g.dart

Lines changed: 9 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
@@ -959,6 +959,10 @@ class PerAccountStore extends PerAccountStoreBase with
959959
_channels.handleSubscriptionEvent(event);
960960
notifyListeners();
961961

962+
case UserStatusEvent():
963+
// TODO: handle
964+
break;
965+
962966
case UserTopicEvent():
963967
assert(debugLog("server event: user_topic"));
964968
_messages.handleUserTopicEvent(event);

0 commit comments

Comments
 (0)