Skip to content

Commit ed5f68e

Browse files
committed
submessage: Extract OptionKey.
Semantically, we expect strings of a specific shape to be the key for options. This make it clearer to the reader without complicating things with extra validation. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 2bfbff0 commit ed5f68e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/api/model/submessage.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ sealed class PollEventSubmessage extends SubmessageData {
173173
///
174174
/// For options that are a part of the initial [PollWidgetData], the
175175
/// [senderId] should be `null`.
176-
static String optionKey({required int? senderId, required int idx}) =>
176+
static OptionKey optionKey({required int? senderId, required int idx}) =>
177177
// "canned" is a canonical constant coined by the web client:
178178
// https://github.com/zulip/zulip/blob/40f59a05c/web/shared/src/poll_data.ts#L238
179179
'${senderId ?? 'canned'},$idx';
@@ -205,6 +205,8 @@ enum PollEventSubmessageType {
205205
.map((key, value) => MapEntry(value, key));
206206
}
207207

208+
typedef OptionKey = String;
209+
208210
/// A poll event when an option is added.
209211
///
210212
/// See: https://github.com/zulip/zulip/blob/40f59a05c/web/shared/src/poll_data.ts#L112-L159
@@ -264,7 +266,7 @@ class PollVoteEventSubmessage extends PollEventSubmessage {
264266
/// The key of the affected option.
265267
///
266268
/// See [PollEventSubmessage.optionKey].
267-
final String key;
269+
final OptionKey key;
268270
@JsonKey(name: 'vote', unknownEnumValue: PollVoteOp.unknown)
269271
final PollVoteOp op;
270272

0 commit comments

Comments
 (0)