|
1 | 1 | import 'package:json_annotation/json_annotation.dart'; |
2 | 2 |
|
3 | 3 | import '../core.dart'; |
| 4 | +import '../model/model.dart'; |
4 | 5 |
|
5 | 6 | part 'users.g.dart'; |
6 | 7 |
|
@@ -32,3 +33,49 @@ class GetOwnUserResult { |
32 | 33 |
|
33 | 34 | Map<String, dynamic> toJson() => _$GetOwnUserResultToJson(this); |
34 | 35 | } |
| 36 | + |
| 37 | +/// https://zulip.com/api/update-presence |
| 38 | +/// |
| 39 | +/// Passes true for `slim_presence` to avoid getting an ancient data format |
| 40 | +/// in the response. |
| 41 | +// TODO(#1611) Passing `slim_presence` is the old, deprecated way to avoid |
| 42 | +// getting an ancient data format. Pass `last_update_id` to new servers to get |
| 43 | +// that effect (make lastUpdateId required?) and update the dartdoc. |
| 44 | +// (Passing `slim_presence`, for now, shouldn't break things, but we'd like to |
| 45 | +// stop; see discussion: |
| 46 | +// https://chat.zulip.org/#narrow/channel/378-api-design/topic/presence.20rewrite/near/2201035 ) |
| 47 | +Future<UpdatePresenceResult> updatePresence(ApiConnection connection, { |
| 48 | + int? lastUpdateId, |
| 49 | + int? historyLimitDays, |
| 50 | + bool? newUserInput, |
| 51 | + bool? pingOnly, |
| 52 | + required PresenceStatus status, |
| 53 | +}) { |
| 54 | + return connection.post('updatePresence', UpdatePresenceResult.fromJson, 'users/me/presence', { |
| 55 | + if (lastUpdateId != null) 'last_update_id': lastUpdateId, |
| 56 | + if (historyLimitDays != null) 'history_limit_days': historyLimitDays, |
| 57 | + if (newUserInput != null) 'new_user_input': newUserInput, |
| 58 | + if (pingOnly != null) 'ping_only': pingOnly, |
| 59 | + 'status': RawParameter(status.toJson()), |
| 60 | + 'slim_presence': true, |
| 61 | + }); |
| 62 | +} |
| 63 | + |
| 64 | +@JsonSerializable(fieldRename: FieldRename.snake) |
| 65 | +class UpdatePresenceResult { |
| 66 | + final int? presenceLastUpdateId; // TODO(server-9.0) new in FL 263 |
| 67 | + final double? serverTimestamp; // 1656958539.6287155 in the example response |
| 68 | + final Map<int, PerUserPresence>? presences; |
| 69 | + // final bool zephyrMirrorActive; // deprecated, ignore |
| 70 | + |
| 71 | + UpdatePresenceResult({ |
| 72 | + required this.presenceLastUpdateId, |
| 73 | + required this.serverTimestamp, |
| 74 | + required this.presences, |
| 75 | + }); |
| 76 | + |
| 77 | + factory UpdatePresenceResult.fromJson(Map<String, dynamic> json) => |
| 78 | + _$UpdatePresenceResultFromJson(json); |
| 79 | + |
| 80 | + Map<String, dynamic> toJson() => _$UpdatePresenceResultToJson(this); |
| 81 | +} |
0 commit comments