Skip to content

Commit e20fa5e

Browse files
committed
api: Add unregister{Apns,Fcm}Token; link to new docs for register-token fns
It's no longer true that these endpoints are undocumented, so, link to them.
1 parent 1147845 commit e20fa5e

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

lib/api/route/notifications.dart

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11

22
import '../core.dart';
33

4-
// This endpoint is undocumented. Compare zulip-mobile:
5-
// https://github.com/zulip/zulip-mobile/blob/86d94fa89/src/api/notifications/savePushToken.js
6-
// and see the server implementation:
7-
// https://github.com/zulip/zulip/blob/34ceafadd/zproject/urls.py#L383
8-
// https://github.com/zulip/zulip/blob/34ceafadd/zerver/views/push_notifications.py#L47
4+
/// https://zulip.com/api/add-fcm-token
95
Future<void> registerFcmToken(ApiConnection connection, {
106
required String token,
117
}) {
@@ -14,11 +10,16 @@ Future<void> registerFcmToken(ApiConnection connection, {
1410
});
1511
}
1612

17-
// This endpoint is undocumented. Compare zulip-mobile:
18-
// https://github.com/zulip/zulip-mobile/blob/86d94fa89/src/api/notifications/savePushToken.js
19-
// and see the server implementation:
20-
// https://github.com/zulip/zulip/blob/34ceafadd/zproject/urls.py#L378-L381
21-
// https://github.com/zulip/zulip/blob/34ceafadd/zerver/views/push_notifications.py#L34
13+
/// https://zulip.com/api/remove-fcm-token
14+
Future<void> unregisterFcmToken(ApiConnection connection, {
15+
required String token,
16+
}) {
17+
return connection.delete('unregisterFcmToken', (_) {}, 'users/me/android_gcm_reg_id', {
18+
'token': RawParameter(token),
19+
});
20+
}
21+
22+
/// https://zulip.com/api/add-apns-token
2223
Future<void> registerApnsToken(ApiConnection connection, {
2324
required String token,
2425
String? appid,
@@ -28,3 +29,12 @@ Future<void> registerApnsToken(ApiConnection connection, {
2829
if (appid != null) 'appid': RawParameter(appid),
2930
});
3031
}
32+
33+
/// https://zulip.com/api/remove-apns-token
34+
Future<void> unregisterApnsToken(ApiConnection connection, {
35+
required String token,
36+
}) {
37+
return connection.delete('unregisterApnsToken', (_) {}, 'users/me/apns_device_token', {
38+
'token': RawParameter(token),
39+
});
40+
}

test/api/route/notifications_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,27 @@ void main() {
2828
});
2929
});
3030

31+
group('unregisterFcmToken', () {
32+
Future<void> checkUnregisterFcmToken(FakeApiConnection connection, {
33+
required String token,
34+
}) async {
35+
connection.prepare(json: {});
36+
await unregisterFcmToken(connection, token: token);
37+
check(connection.lastRequest).isA<http.Request>()
38+
..method.equals('DELETE')
39+
..url.path.equals('/api/v1/users/me/android_gcm_reg_id')
40+
..bodyFields.deepEquals({
41+
'token': token,
42+
});
43+
}
44+
45+
test('smoke', () {
46+
return FakeApiConnection.with_((connection) async {
47+
await checkUnregisterFcmToken(connection, token: 'asdf');
48+
});
49+
});
50+
});
51+
3152
group('registerApnsToken', () {
3253
Future<void> checkRegisterApnsToken(FakeApiConnection connection, {
3354
required String token,
@@ -56,4 +77,25 @@ void main() {
5677
});
5778
});
5879
});
80+
81+
group('unregisterApnsToken', () {
82+
Future<void> checkUnregisterApnsToken(FakeApiConnection connection, {
83+
required String token,
84+
}) async {
85+
connection.prepare(json: {});
86+
await unregisterApnsToken(connection, token: token);
87+
check(connection.lastRequest).isA<http.Request>()
88+
..method.equals('DELETE')
89+
..url.path.equals('/api/v1/users/me/apns_device_token')
90+
..bodyFields.deepEquals({
91+
'token': token,
92+
});
93+
}
94+
95+
test('smoke', () {
96+
return FakeApiConnection.with_((connection) async {
97+
await checkUnregisterApnsToken(connection, token: 'asdf');
98+
});
99+
});
100+
});
59101
}

0 commit comments

Comments
 (0)