diff --git a/lib/src/client.dart b/lib/src/client.dart index 2990bd3e..d8be4c69 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -54,6 +54,7 @@ import 'sync/user_update.dart'; import 'user.dart'; import 'utils/matrix_exception.dart'; import 'utils/profile.dart'; +import 'utils/pusher.dart'; typedef RoomSorter = int Function(Room a, Room b); @@ -523,6 +524,17 @@ class Client { ? PushRules.fromJson(accountData['m.push_rules'].content) : null; + /// Gets all currently active pushers for the authenticated user. + Future> getPushers() async { + final response = + await jsonRequest(type: HTTPType.GET, action: '/client/r0/pushers'); + var list = []; + for (final pusherJson in response['pushers']) { + list.add(Pusher.fromJson(pusherJson)); + } + return list; + } + /// This endpoint allows the creation, modification and deletion of pushers for this user ID. Future setPushers(String pushKey, String kind, String appId, String appDisplayName, String deviceDisplayName, String lang, String url, diff --git a/lib/src/utils/pusher.dart b/lib/src/utils/pusher.dart new file mode 100644 index 00000000..b4283caa --- /dev/null +++ b/lib/src/utils/pusher.dart @@ -0,0 +1,62 @@ +class Pusher { + String pushkey; + String kind; + String appId; + String appDisplayName; + String deviceDisplayName; + String profileTag; + String lang; + PusherData data; + + Pusher( + {this.pushkey, + this.kind, + this.appId, + this.appDisplayName, + this.deviceDisplayName, + this.profileTag, + this.lang, + this.data}); + + Pusher.fromJson(Map json) { + pushkey = json['pushkey']; + kind = json['kind']; + appId = json['app_id']; + appDisplayName = json['app_display_name']; + deviceDisplayName = json['device_display_name']; + profileTag = json['profile_tag']; + lang = json['lang']; + data = json['data'] != null ? PusherData.fromJson(json['data']) : null; + } + + Map toJson() { + final data = {}; + data['pushkey'] = pushkey; + data['kind'] = kind; + data['app_id'] = appId; + data['app_display_name'] = appDisplayName; + data['device_display_name'] = deviceDisplayName; + data['profile_tag'] = profileTag; + data['lang'] = lang; + if (this.data != null) { + data['data'] = this.data.toJson(); + } + return data; + } +} + +class PusherData { + String url; + + PusherData({this.url}); + + PusherData.fromJson(Map json) { + url = json['url']; + } + + Map toJson() { + final data = {}; + data['url'] = url; + return data; + } +}