@@ -74,6 +74,7 @@ sealed class Event {
7474 }
7575 case 'submessage' : return SubmessageEvent .fromJson (json);
7676 case 'typing' : return TypingEvent .fromJson (json);
77+ case 'presence' : return PresenceEvent .fromJson (json);
7778 case 'reaction' : return ReactionEvent .fromJson (json);
7879 case 'heartbeat' : return HeartbeatEvent .fromJson (json);
7980 // TODO add many more event types
@@ -1195,6 +1196,69 @@ enum TypingOp {
11951196 String toJson () => _$TypingOpEnumMap [this ]! ;
11961197}
11971198
1199+ /// A Zulip event of type `presence` .
1200+ ///
1201+ /// See:
1202+ /// https://zulip.com/api/get-events#presence
1203+ @JsonSerializable (fieldRename: FieldRename .snake)
1204+ class PresenceEvent extends Event {
1205+ @override
1206+ @JsonKey (includeToJson: true )
1207+ String get type => 'presence' ;
1208+
1209+ final int userId;
1210+ // final String email; // deprecated; ignore
1211+ final int serverTimestamp;
1212+ final Map <String , PerClientPresence > presence;
1213+
1214+ PresenceEvent ({
1215+ required super .id,
1216+ required this .userId,
1217+ required this .serverTimestamp,
1218+ required this .presence,
1219+ });
1220+
1221+ factory PresenceEvent .fromJson (Map <String , dynamic > json) =>
1222+ _$PresenceEventFromJson (json);
1223+
1224+ @override
1225+ Map <String , dynamic > toJson () => _$PresenceEventToJson (this );
1226+ }
1227+
1228+ /// A value in [PresenceEvent.presence] .
1229+ ///
1230+ /// The "per client" name follows the event's structure,
1231+ /// but that structure is already an API wart; see the doc's "Changes" note
1232+ /// on [client] and on the `client_name` key of the map that holds these values:
1233+ ///
1234+ /// https://zulip.com/api/get-events#presence
1235+ /// > Starting with Zulip 7.0 (feature level 178), this will always be "website"
1236+ /// > as the server no longer stores which client submitted presence updates.
1237+ ///
1238+ /// This will probably be deprecated in favor of a form like [PerUserPresence] .
1239+ /// See #1611 and discussion:
1240+ /// https://chat.zulip.org/#narrow/channel/378-api-design/topic/presence.20rewrite/near/2200812
1241+ // TODO(#1611) update comment about #1611
1242+ @JsonSerializable (fieldRename: FieldRename .snake)
1243+ class PerClientPresence {
1244+ final String client; // always "website" (on 7.0+, so on all supported servers)
1245+ final PresenceStatus status;
1246+ final int timestamp;
1247+ final bool pushable; // always false (on 7.0+, so on all supported servers)
1248+
1249+ PerClientPresence ({
1250+ required this .client,
1251+ required this .status,
1252+ required this .timestamp,
1253+ required this .pushable,
1254+ });
1255+
1256+ factory PerClientPresence .fromJson (Map <String , dynamic > json) =>
1257+ _$PerClientPresenceFromJson (json);
1258+
1259+ Map <String , dynamic > toJson () => _$PerClientPresenceToJson (this );
1260+ }
1261+
11981262/// A Zulip event of type `reaction` , with op `add` or `remove` .
11991263///
12001264/// See:
0 commit comments