Skip to content

Commit 397a938

Browse files
gnpricechrisbobbe
authored andcommitted
api [nfc]: Rename addFcmToken, addApnsToken to follow new API docs
When we originally wrote the bindings for these routes, they weren't yet documented, so we invented our own names for them. Now they are, so the API docs give canonical names. Switch to those.
1 parent 69ac00c commit 397a938

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

lib/api/route/notifications.dart

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
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
9-
Future<void> registerFcmToken(ApiConnection connection, {
4+
/// https://zulip.com/api/add-fcm-token
5+
Future<void> addFcmToken(ApiConnection connection, {
106
required String token,
117
}) {
12-
return connection.post('registerFcmToken', (_) {}, 'users/me/android_gcm_reg_id', {
8+
return connection.post('addFcmToken', (_) {}, 'users/me/android_gcm_reg_id', {
139
'token': RawParameter(token),
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
22-
Future<void> registerApnsToken(ApiConnection connection, {
13+
/// https://zulip.com/api/add-apns-token
14+
Future<void> addApnsToken(ApiConnection connection, {
2315
required String token,
2416
String? appid,
2517
}) {
26-
return connection.post('registerApnsToken', (_) {}, 'users/me/apns_device_token', {
18+
return connection.post('addApnsToken', (_) {}, 'users/me/apns_device_token', {
2719
'token': RawParameter(token),
2820
if (appid != null) 'appid': RawParameter(appid),
2921
});

lib/model/store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ class UpdateMachine {
924924
/// mean we actually sent the token). Make it just `void` once we fix the
925925
/// one test that relies on the future.
926926
// TODO(#322) save acked token, to dedupe updating it on the server
927-
// TODO(#323) track the registerFcmToken/etc request, warn if not succeeding
927+
// TODO(#323) track the addFcmToken/etc request, warn if not succeeding
928928
Future<void> registerNotificationToken() async {
929929
if (!debugEnableRegisterNotificationToken) {
930930
return;

lib/notifications/receive.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ class NotificationService {
145145
static Future<void> registerToken(ApiConnection connection, {required String token}) async {
146146
switch (defaultTargetPlatform) {
147147
case TargetPlatform.android:
148-
await registerFcmToken(connection, token: token);
148+
await addFcmToken(connection, token: token);
149149

150150
case TargetPlatform.iOS:
151151
const appBundleId = 'com.zulip.flutter'; // TODO(#407) find actual value live
152-
await registerApnsToken(connection, token: token, appid: appBundleId);
152+
await addApnsToken(connection, token: token, appid: appBundleId);
153153

154154
case TargetPlatform.linux:
155155
case TargetPlatform.macOS:

test/api/route/notifications_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import '../../stdlib_checks.dart';
77
import '../fake_api.dart';
88

99
void main() {
10-
group('registerFcmToken', () {
11-
Future<void> checkRegisterFcmToken(FakeApiConnection connection, {
10+
group('addFcmToken', () {
11+
Future<void> checkAddFcmToken(FakeApiConnection connection, {
1212
required String token,
1313
}) async {
1414
connection.prepare(json: {});
15-
await registerFcmToken(connection, token: token);
15+
await addFcmToken(connection, token: token);
1616
check(connection.lastRequest).isA<http.Request>()
1717
..method.equals('POST')
1818
..url.path.equals('/api/v1/users/me/android_gcm_reg_id')
@@ -23,18 +23,18 @@ void main() {
2323

2424
test('smoke', () {
2525
return FakeApiConnection.with_((connection) async {
26-
await checkRegisterFcmToken(connection, token: 'asdf');
26+
await checkAddFcmToken(connection, token: 'asdf');
2727
});
2828
});
2929
});
3030

31-
group('registerApnsToken', () {
32-
Future<void> checkRegisterApnsToken(FakeApiConnection connection, {
31+
group('addApnsToken', () {
32+
Future<void> checkAddApnsToken(FakeApiConnection connection, {
3333
required String token,
3434
required String? appid,
3535
}) async {
3636
connection.prepare(json: {});
37-
await registerApnsToken(connection, token: token, appid: appid);
37+
await addApnsToken(connection, token: token, appid: appid);
3838
check(connection.lastRequest).isA<http.Request>()
3939
..method.equals('POST')
4040
..url.path.equals('/api/v1/users/me/apns_device_token')
@@ -46,13 +46,13 @@ void main() {
4646

4747
test('no appid', () {
4848
return FakeApiConnection.with_((connection) async {
49-
await checkRegisterApnsToken(connection, token: 'asdf', appid: null);
49+
await checkAddApnsToken(connection, token: 'asdf', appid: null);
5050
});
5151
});
5252

5353
test('with appid', () {
5454
return FakeApiConnection.with_((connection) async {
55-
await checkRegisterApnsToken(connection, token: 'asdf', appid: 'qwer');
55+
await checkAddApnsToken(connection, token: 'asdf', appid: 'qwer');
5656
});
5757
});
5858
});

0 commit comments

Comments
 (0)