Skip to content

Commit 2191b9d

Browse files
committed
Merge remote-tracking branch 'pr/1041'
2 parents 453639b + 9c8316f commit 2191b9d

22 files changed

+1091
-59
lines changed

assets/icons/ZulipIcons.ttf

820 Bytes
Binary file not shown.

assets/icons/follow.svg

+1
Loading

assets/icons/inherit.svg

+4
Loading

assets/icons/mute.svg

+1-5
Loading

assets/icons/unmute.svg

+4-4
Loading

assets/l10n/app_en.arb

+32
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@
7272
"@permissionsDeniedReadExternalStorage": {
7373
"description": "Message for dialog asking the user to grant permissions for external storage read access."
7474
},
75+
"actionSheetOptionMuteTopic": "Mute topic",
76+
"@actionSheetOptionMuteTopic": {
77+
"description": "Label for muting a topic on action sheet."
78+
},
79+
"actionSheetOptionUnmuteTopic": "Unmute topic",
80+
"@actionSheetOptionUnmuteTopic": {
81+
"description": "Label for unmuting a topic on action sheet."
82+
},
83+
"actionSheetOptionFollowTopic": "Follow topic",
84+
"@actionSheetOptionFollowTopic": {
85+
"description": "Label for following a topic on action sheet."
86+
},
87+
"actionSheetOptionUnfollowTopic": "Unfollow topic",
88+
"@actionSheetOptionUnfollowTopic": {
89+
"description": "Label for unfollowing a topic on action sheet."
90+
},
7591
"actionSheetOptionCopyMessageText": "Copy message text",
7692
"@actionSheetOptionCopyMessageText": {
7793
"description": "Label for copy message text button on action sheet."
@@ -214,6 +230,22 @@
214230
"event": {"type": "String", "example": "UpdateMessageEvent(id: 123, messageIds: [2345, 3456], newTopic: 'dinner')"}
215231
}
216232
},
233+
"errorMuteTopicFailed": "Failed to mute topic",
234+
"@errorMuteTopicFailed": {
235+
"description": "Error message when muting a topic failed."
236+
},
237+
"errorUnmuteTopicFailed": "Failed to unmute topic",
238+
"@errorUnmuteTopicFailed": {
239+
"description": "Error message when unmuting a topic failed."
240+
},
241+
"errorFollowTopicFailed": "Failed to follow topic",
242+
"@errorFollowTopicFailed": {
243+
"description": "Error message when following a topic failed."
244+
},
245+
"errorUnfollowTopicFailed": "Failed to unfollow topic",
246+
"@errorUnfollowTopicFailed": {
247+
"description": "Error message when unfollowing a topic failed."
248+
},
217249
"errorSharingFailed": "Sharing failed",
218250
"@errorSharingFailed": {
219251
"description": "Error message when sharing a message failed."

lib/api/core.dart

+10
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ class ApiConnection {
224224
return send(routeName, fromJson, request);
225225
}
226226

227+
Future<T> patch<T>(String routeName, T Function(Map<String, dynamic>) fromJson,
228+
String path, Map<String, dynamic>? params) async {
229+
final url = realmUrl.replace(path: "/api/v1/$path");
230+
final request = http.Request('PATCH', url);
231+
if (params != null) {
232+
request.bodyFields = encodeParameters(params)!;
233+
}
234+
return send(routeName, fromJson, request);
235+
}
236+
227237
Future<T> delete<T>(String routeName, T Function(Map<String, dynamic>) fromJson,
228238
String path, Map<String, dynamic>? params) async {
229239
final url = realmUrl.replace(path: "/api/v1/$path");

lib/api/model/model.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ enum UserTopicVisibilityPolicy {
493493
muted(apiValue: 1),
494494
unmuted(apiValue: 2), // TODO(server-7) newly added
495495
followed(apiValue: 3), // TODO(server-8) newly added
496-
unknown(apiValue: null);
496+
unknown(apiValue: null); // TODO(#1074) remove this
497497

498498
const UserTopicVisibilityPolicy({required this.apiValue});
499499

lib/api/route/channels.dart

+48
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:json_annotation/json_annotation.dart';
22

33
import '../core.dart';
4+
import '../model/model.dart';
45
part 'channels.g.dart';
56

67
/// https://zulip.com/api/get-stream-topics
@@ -38,3 +39,50 @@ class GetStreamTopicsEntry {
3839

3940
Map<String, dynamic> toJson() => _$GetStreamTopicsEntryToJson(this);
4041
}
42+
43+
/// Update a topic's visibility policy.
44+
///
45+
/// This encapsulates a server-feature check.
46+
// TODO(server-7): remove this and just use updateUserTopic
47+
Future<void> updateUserTopicCompat(ApiConnection connection, {
48+
required int streamId,
49+
required String topic,
50+
required UserTopicVisibilityPolicy visibilityPolicy,
51+
}) {
52+
final useLegacyApi = connection.zulipFeatureLevel! < 170;
53+
if (useLegacyApi) {
54+
assert(visibilityPolicy == UserTopicVisibilityPolicy.none
55+
|| visibilityPolicy == UserTopicVisibilityPolicy.muted);
56+
final op = visibilityPolicy == UserTopicVisibilityPolicy.none ? 'remove'
57+
: 'add';
58+
// https://zulip.com/api/mute-topic
59+
return connection.patch('muteTopic', (_) {}, 'users/me/subscriptions/muted_topics', {
60+
'stream_id': streamId,
61+
'topic': RawParameter(topic),
62+
'op': RawParameter(op),
63+
});
64+
} else {
65+
return updateUserTopic(connection,
66+
streamId: streamId,
67+
topic: topic,
68+
visibilityPolicy: visibilityPolicy);
69+
}
70+
}
71+
72+
/// https://zulip.com/api/update-user-topic
73+
///
74+
/// This binding only supports feature levels 170+.
75+
// TODO(server-7) remove FL 170+ mention in doc, and the related `assert`
76+
Future<void> updateUserTopic(ApiConnection connection, {
77+
required int streamId,
78+
required String topic,
79+
required UserTopicVisibilityPolicy visibilityPolicy,
80+
}) {
81+
assert(visibilityPolicy != UserTopicVisibilityPolicy.unknown);
82+
assert(connection.zulipFeatureLevel! >= 170);
83+
return connection.post('updateUserTopic', (_) {}, 'user_topics', {
84+
'stream_id': streamId,
85+
'topic': RawParameter(topic),
86+
'visibility_policy': visibilityPolicy,
87+
});
88+
}

lib/generated/l10n/zulip_localizations.dart

+48
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ abstract class ZulipLocalizations {
205205
/// **'To upload files, please grant Zulip additional permissions in Settings.'**
206206
String get permissionsDeniedReadExternalStorage;
207207

208+
/// Label for muting a topic on action sheet.
209+
///
210+
/// In en, this message translates to:
211+
/// **'Mute topic'**
212+
String get actionSheetOptionMuteTopic;
213+
214+
/// Label for unmuting a topic on action sheet.
215+
///
216+
/// In en, this message translates to:
217+
/// **'Unmute topic'**
218+
String get actionSheetOptionUnmuteTopic;
219+
220+
/// Label for following a topic on action sheet.
221+
///
222+
/// In en, this message translates to:
223+
/// **'Follow topic'**
224+
String get actionSheetOptionFollowTopic;
225+
226+
/// Label for unfollowing a topic on action sheet.
227+
///
228+
/// In en, this message translates to:
229+
/// **'Unfollow topic'**
230+
String get actionSheetOptionUnfollowTopic;
231+
208232
/// Label for copy message text button on action sheet.
209233
///
210234
/// In en, this message translates to:
@@ -373,6 +397,30 @@ abstract class ZulipLocalizations {
373397
/// **'Error handling a Zulip event from {serverUrl}; will retry.\n\nError: {error}\n\nEvent: {event}'**
374398
String errorHandlingEventDetails(String serverUrl, String error, String event);
375399

400+
/// Error message when muting a topic failed.
401+
///
402+
/// In en, this message translates to:
403+
/// **'Failed to mute topic'**
404+
String get errorMuteTopicFailed;
405+
406+
/// Error message when unmuting a topic failed.
407+
///
408+
/// In en, this message translates to:
409+
/// **'Failed to unmute topic'**
410+
String get errorUnmuteTopicFailed;
411+
412+
/// Error message when following a topic failed.
413+
///
414+
/// In en, this message translates to:
415+
/// **'Failed to follow topic'**
416+
String get errorFollowTopicFailed;
417+
418+
/// Error message when unfollowing a topic failed.
419+
///
420+
/// In en, this message translates to:
421+
/// **'Failed to unfollow topic'**
422+
String get errorUnfollowTopicFailed;
423+
376424
/// Error message when sharing a message failed.
377425
///
378426
/// In en, this message translates to:

lib/generated/l10n/zulip_localizations_ar.dart

+24
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMuteTopic => 'Mute topic';
69+
70+
@override
71+
String get actionSheetOptionUnmuteTopic => 'Unmute topic';
72+
73+
@override
74+
String get actionSheetOptionFollowTopic => 'Follow topic';
75+
76+
@override
77+
String get actionSheetOptionUnfollowTopic => 'Unfollow topic';
78+
6779
@override
6880
String get actionSheetOptionCopyMessageText => 'Copy message text';
6981

@@ -176,6 +188,18 @@ class ZulipLocalizationsAr extends ZulipLocalizations {
176188
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
177189
}
178190

191+
@override
192+
String get errorMuteTopicFailed => 'Failed to mute topic';
193+
194+
@override
195+
String get errorUnmuteTopicFailed => 'Failed to unmute topic';
196+
197+
@override
198+
String get errorFollowTopicFailed => 'Failed to follow topic';
199+
200+
@override
201+
String get errorUnfollowTopicFailed => 'Failed to unfollow topic';
202+
179203
@override
180204
String get errorSharingFailed => 'Sharing failed';
181205

lib/generated/l10n/zulip_localizations_en.dart

+24
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMuteTopic => 'Mute topic';
69+
70+
@override
71+
String get actionSheetOptionUnmuteTopic => 'Unmute topic';
72+
73+
@override
74+
String get actionSheetOptionFollowTopic => 'Follow topic';
75+
76+
@override
77+
String get actionSheetOptionUnfollowTopic => 'Unfollow topic';
78+
6779
@override
6880
String get actionSheetOptionCopyMessageText => 'Copy message text';
6981

@@ -176,6 +188,18 @@ class ZulipLocalizationsEn extends ZulipLocalizations {
176188
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
177189
}
178190

191+
@override
192+
String get errorMuteTopicFailed => 'Failed to mute topic';
193+
194+
@override
195+
String get errorUnmuteTopicFailed => 'Failed to unmute topic';
196+
197+
@override
198+
String get errorFollowTopicFailed => 'Failed to follow topic';
199+
200+
@override
201+
String get errorUnfollowTopicFailed => 'Failed to unfollow topic';
202+
179203
@override
180204
String get errorSharingFailed => 'Sharing failed';
181205

lib/generated/l10n/zulip_localizations_ja.dart

+24
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
6464
@override
6565
String get permissionsDeniedReadExternalStorage => 'To upload files, please grant Zulip additional permissions in Settings.';
6666

67+
@override
68+
String get actionSheetOptionMuteTopic => 'Mute topic';
69+
70+
@override
71+
String get actionSheetOptionUnmuteTopic => 'Unmute topic';
72+
73+
@override
74+
String get actionSheetOptionFollowTopic => 'Follow topic';
75+
76+
@override
77+
String get actionSheetOptionUnfollowTopic => 'Unfollow topic';
78+
6779
@override
6880
String get actionSheetOptionCopyMessageText => 'Copy message text';
6981

@@ -176,6 +188,18 @@ class ZulipLocalizationsJa extends ZulipLocalizations {
176188
return 'Error handling a Zulip event from $serverUrl; will retry.\n\nError: $error\n\nEvent: $event';
177189
}
178190

191+
@override
192+
String get errorMuteTopicFailed => 'Failed to mute topic';
193+
194+
@override
195+
String get errorUnmuteTopicFailed => 'Failed to unmute topic';
196+
197+
@override
198+
String get errorFollowTopicFailed => 'Failed to follow topic';
199+
200+
@override
201+
String get errorUnfollowTopicFailed => 'Failed to unfollow topic';
202+
179203
@override
180204
String get errorSharingFailed => 'Sharing failed';
181205

0 commit comments

Comments
 (0)