diff --git a/lib/src/generated/model.dart b/lib/src/generated/model.dart index b4883db6..edc8d356 100644 --- a/lib/src/generated/model.dart +++ b/lib/src/generated/model.dart @@ -1312,50 +1312,80 @@ class PusherData { } @_NameSource('spec') -class Pusher { - Pusher({ - required this.appDisplayName, +class PusherId { + PusherId({ required this.appId, + required this.pushkey, + }); + + PusherId.fromJson(Map json) + : appId = json['app_id'] as String, + pushkey = json['pushkey'] as String; + Map toJson() => { + 'app_id': appId, + 'pushkey': pushkey, + }; + + /// This is a reverse-DNS style identifier for the application. + /// Max length, 64 chars. + String appId; + + /// This is a unique identifier for this pusher. See `/set` for + /// more detail. + /// Max length, 512 bytes. + String pushkey; +} + +@_NameSource('spec') +class Pusher implements PusherId { + Pusher({ + required this.appId, + required this.pushkey, + required this.appDisplayName, required this.data, required this.deviceDisplayName, required this.kind, required this.lang, this.profileTag, - required this.pushkey, }); Pusher.fromJson(Map json) - : appDisplayName = json['app_display_name'] as String, - appId = json['app_id'] as String, + : appId = json['app_id'] as String, + pushkey = json['pushkey'] as String, + appDisplayName = json['app_display_name'] as String, data = PusherData.fromJson(json['data']), deviceDisplayName = json['device_display_name'] as String, kind = json['kind'] as String, lang = json['lang'] as String, profileTag = - ((v) => v != null ? v as String : null)(json['profile_tag']), - pushkey = json['pushkey'] as String; + ((v) => v != null ? v as String : null)(json['profile_tag']); Map toJson() { final profileTag = this.profileTag; return { - 'app_display_name': appDisplayName, 'app_id': appId, + 'pushkey': pushkey, + 'app_display_name': appDisplayName, 'data': data.toJson(), 'device_display_name': deviceDisplayName, 'kind': kind, 'lang': lang, if (profileTag != null) 'profile_tag': profileTag, - 'pushkey': pushkey, }; } - /// A string that will allow the user to identify what application - /// owns this pusher. - String appDisplayName; - /// This is a reverse-DNS style identifier for the application. /// Max length, 64 chars. String appId; + /// This is a unique identifier for this pusher. See `/set` for + /// more detail. + /// Max length, 512 bytes. + String pushkey; + + /// A string that will allow the user to identify what application + /// owns this pusher. + String appDisplayName; + /// A dictionary of information for the pusher implementation /// itself. PusherData data; @@ -1375,11 +1405,6 @@ class Pusher { /// This string determines which set of device specific rules this /// pusher executes. String? profileTag; - - /// This is a unique identifier for this pusher. See `/set` for - /// more detail. - /// Max length, 512 bytes. - String pushkey; } @_NameSource('spec') diff --git a/lib/src/matrix_api.dart b/lib/src/matrix_api.dart index 9494289f..f0fd488f 100644 --- a/lib/src/matrix_api.dart +++ b/lib/src/matrix_api.dart @@ -173,6 +173,9 @@ class MatrixApi extends Api { /// This endpoint allows the creation, modification and deletion of pushers /// for this user ID. The behaviour of this endpoint varies depending on the /// values in the JSON body. + /// + /// See [deletePusher] to issue requests with `kind: null`. + /// /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-pushers-set Future postPusher(Pusher pusher, {bool? append}) async { final data = pusher.toJson(); @@ -187,6 +190,20 @@ class MatrixApi extends Api { return; } + /// Variant of postPusher operation that deletes pushers by setting `kind: null`. + /// + /// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-pushers-set + Future deletePusher(PusherId pusher) async { + final data = PusherData.fromJson(pusher.toJson()).toJson(); + data['kind'] = null; + await request( + RequestType.POST, + '/client/r0/pushers/set', + data: data, + ); + return; + } + /// This API provides credentials for the client to use when initiating /// calls. @override