Skip to content

Commit c27b222

Browse files
committed
WIP read ints directly in remaining fields userId, senderId, time; TODO tests
1 parent 5fcb83e commit c27b222

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lib/api/notifications.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ sealed class FcmMessageWithIdentity extends FcmMessage {
8484
///
8585
/// Useful mainly in the case where the user has multiple accounts in the
8686
/// same realm.
87-
@_IntConverter()
87+
@JsonKey(readValue: _readIntOrString) // TODO(server-12)
8888
final int userId;
8989

9090
FcmMessageWithIdentity({
@@ -110,7 +110,7 @@ class MessageFcmMessage extends FcmMessageWithIdentity {
110110
@JsonKey(includeToJson: true)
111111
String get type => 'message';
112112

113-
@_IntConverter()
113+
@JsonKey(readValue: _readIntOrString) // TODO(server-12)
114114
final int senderId;
115115
// final String senderEmail; // obsolete; ignore
116116
final Uri senderAvatarUrl;
@@ -121,7 +121,7 @@ class MessageFcmMessage extends FcmMessageWithIdentity {
121121

122122
@JsonKey(readValue: _readMessageId)
123123
final int messageId;
124-
@_IntConverter()
124+
@JsonKey(readValue: _readIntOrString) // TODO(server-12)
125125
final int time; // in Unix seconds UTC, like [Message.timestamp]
126126

127127
/// The content of the Zulip message, rendered as plain text.
@@ -301,4 +301,10 @@ class _IntConverter extends JsonConverter<int, String> {
301301
String toJson(int value) => value.toString();
302302
}
303303

304+
Object? _readIntOrString(Map<dynamic, dynamic> json, String key) {
305+
final jsonValue = json[key];
306+
if (jsonValue is String) return _parseInt(jsonValue);
307+
return jsonValue;
308+
}
309+
304310
int _parseInt(String string) => int.parse(string, radix: 10);

lib/api/notifications.g.dart

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

test/api/notifications_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import '../stdlib_checks.dart';
88
void main() {
99
final baseBaseJson = <String, Object?>{
1010
"realm_url": "https://zulip.example.com/",
11-
"user_id": "234",
11+
"user_id": 234,
1212
};
1313

1414
// Before E2EE notifications, the data comes directly as FCM payloads,
@@ -39,12 +39,12 @@ void main() {
3939
...baseBaseJson,
4040
"type": "message",
4141

42-
"sender_id": "123",
42+
"sender_id": 123,
4343
"sender_email": "[email protected]",
4444
"sender_avatar_url": "https://zulip.example.com/avatar/123.jpeg",
4545
"sender_full_name": "A Sender",
4646

47-
"time": "1546300800",
47+
"time": 1546300800,
4848
"message_id": 12345,
4949

5050
"content": "This is a message",

0 commit comments

Comments
 (0)