Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nfc] Fix formatting from early-prototype code #115

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/api/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ApiConnection {
Future<T> get<T>(String routeName, T Function(Map<String, dynamic>) fromJson,
String path, Map<String, dynamic>? params) async {
final url = realmUrl.replace(
path: "/api/v1/$path", queryParameters: encodeParameters(params));
path: "/api/v1/$path", queryParameters: encodeParameters(params));
final request = http.Request('GET', url);
return send(routeName, fromJson, request);
}
Expand Down Expand Up @@ -167,5 +167,5 @@ Map<String, String> authHeader({required String email, required String apiKey})

Map<String, String>? encodeParameters(Map<String, dynamic>? params) {
return params?.map((k, v) =>
MapEntry(k, v is RawParameter ? v.value : jsonEncode(v)));
MapEntry(k, v is RawParameter ? v.value : jsonEncode(v)));
}
18 changes: 9 additions & 9 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UnexpectedEvent extends Event {
UnexpectedEvent({required super.id, required this.json});

factory UnexpectedEvent.fromJson(Map<String, dynamic> json) =>
UnexpectedEvent(id: json['id'] as int, json: json);
UnexpectedEvent(id: json['id'] as int, json: json);

@override
Map<String, dynamic> toJson() => json;
Expand All @@ -63,7 +63,7 @@ class AlertWordsEvent extends Event {
AlertWordsEvent({required super.id, required this.alertWords});

factory AlertWordsEvent.fromJson(Map<String, dynamic> json) =>
_$AlertWordsEventFromJson(json);
_$AlertWordsEventFromJson(json);

@override
Map<String, dynamic> toJson() => _$AlertWordsEventToJson(this);
Expand Down Expand Up @@ -199,12 +199,12 @@ class MessageEvent extends Event {
MessageEvent({required super.id, required this.message});

factory MessageEvent.fromJson(Map<String, dynamic> json) => MessageEvent(
id: json['id'] as int,
message: Message.fromJson({
...json['message'] as Map<String, dynamic>,
'flags':
(json['flags'] as List<dynamic>).map((e) => e as String).toList(),
}),
id: json['id'] as int,
message: Message.fromJson({
...json['message'] as Map<String, dynamic>,
'flags':
(json['flags'] as List<dynamic>).map((e) => e as String).toList(),
}),
);

@override
Expand All @@ -225,7 +225,7 @@ class HeartbeatEvent extends Event {
HeartbeatEvent({required super.id});

factory HeartbeatEvent.fromJson(Map<String, dynamic> json) =>
_$HeartbeatEventFromJson(json);
_$HeartbeatEventFromJson(json);

@override
Map<String, dynamic> toJson() => _$HeartbeatEventToJson(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/api/model/initial_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InitialSnapshot {
});

factory InitialSnapshot.fromJson(Map<String, dynamic> json) =>
_$InitialSnapshotFromJson(json);
_$InitialSnapshotFromJson(json);

Map<String, dynamic> toJson() => _$InitialSnapshotToJson(this);
}
12 changes: 6 additions & 6 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CustomProfileField {
});

factory CustomProfileField.fromJson(Map<String, dynamic> json) =>
_$CustomProfileFieldFromJson(json);
_$CustomProfileFieldFromJson(json);

Map<String, dynamic> toJson() => _$CustomProfileFieldToJson(this);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ class User {
}

static bool? _readIsSystemBot(Map json, String key) =>
json[key] ?? json['is_cross_realm_bot'];
json[key] ?? json['is_cross_realm_bot'];

User({
required this.userId,
Expand Down Expand Up @@ -183,7 +183,7 @@ class Subscription {
});

factory Subscription.fromJson(Map<String, dynamic> json) =>
_$SubscriptionFromJson(json);
_$SubscriptionFromJson(json);

Map<String, dynamic> toJson() => _$SubscriptionToJson(this);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ class StreamMessage extends Message {
});

factory StreamMessage.fromJson(Map<String, dynamic> json) =>
_$StreamMessageFromJson(json);
_$StreamMessageFromJson(json);

@override
Map<String, dynamic> toJson() => _$StreamMessageToJson(this);
Expand All @@ -299,7 +299,7 @@ class PmRecipient {
PmRecipient({required this.id, required this.email, required this.fullName});

factory PmRecipient.fromJson(Map<String, dynamic> json) =>
_$PmRecipientFromJson(json);
_$PmRecipientFromJson(json);

Map<String, dynamic> toJson() => _$PmRecipientToJson(this);
}
Expand Down Expand Up @@ -334,7 +334,7 @@ class PmMessage extends Message {
});

factory PmMessage.fromJson(Map<String, dynamic> json) =>
_$PmMessageFromJson(json);
_$PmMessageFromJson(json);

@override
Map<String, dynamic> toJson() => _$PmMessageToJson(this);
Expand Down
2 changes: 1 addition & 1 deletion lib/api/route/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GetEventsResult {
});

factory GetEventsResult.fromJson(Map<String, dynamic> json) =>
_$GetEventsResultFromJson(json);
_$GetEventsResultFromJson(json);

Map<String, dynamic> toJson() => _$GetEventsResultToJson(this);
}
4 changes: 2 additions & 2 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SendMessageResult {
});

factory SendMessageResult.fromJson(Map<String, dynamic> json) =>
_$SendMessageResultFromJson(json);
_$SendMessageResultFromJson(json);

Map<String, dynamic> toJson() => _$SendMessageResultToJson(this);
}
Expand All @@ -114,7 +114,7 @@ class UploadFileResult {
});

factory UploadFileResult.fromJson(Map<String, dynamic> json) =>
_$UploadFileResultFromJson(json);
_$UploadFileResultFromJson(json);

Map<String, dynamic> toJson() => _$UploadFileResultToJson(this);
}
32 changes: 16 additions & 16 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LineBreakNode extends BlockContentNode {
// See also [parseImplicitParagraphBlockContentList].
class ParagraphNode extends BlockContentNode {
const ParagraphNode(
{super.debugHtmlNode, this.wasImplicit = false, required this.nodes});
{super.debugHtmlNode, this.wasImplicit = false, required this.nodes});

/// True when there was no corresponding `p` element in the original HTML.
final bool wasImplicit;
Expand Down Expand Up @@ -227,7 +227,7 @@ final _emojiClassRegexp = RegExp(r"^emoji(-[0-9a-f]+)?$");
InlineContentNode parseInlineContent(dom.Node node) {
final debugHtmlNode = kDebugMode ? node : null;
InlineContentNode unimplemented() =>
UnimplementedInlineContentNode(htmlNode: node);
UnimplementedInlineContentNode(htmlNode: node);

if (node is dom.Text) {
return TextNode(node.text, debugHtmlNode: debugHtmlNode);
Expand All @@ -240,7 +240,7 @@ InlineContentNode parseInlineContent(dom.Node node) {
final localName = element.localName;
final classes = element.classes;
List<InlineContentNode> nodes() =>
element.nodes.map(parseInlineContent).toList(growable: false);
element.nodes.map(parseInlineContent).toList(growable: false);

if (localName == 'br' && classes.isEmpty) {
return LineBreakInlineNode(debugHtmlNode: debugHtmlNode);
Expand Down Expand Up @@ -317,9 +317,9 @@ BlockContentNode parseListNode(dom.Element element) {

BlockContentNode parseCodeBlock(dom.Element divElement) {
final mainElement = () {
assert(divElement.localName == 'div' &&
divElement.classes.length == 1 &&
divElement.classes.contains("codehilite"));
assert(divElement.localName == 'div'
&& divElement.classes.length == 1
&& divElement.classes.contains("codehilite"));

if (divElement.nodes.length != 1) return null;
final child = divElement.nodes[0];
Expand All @@ -329,9 +329,9 @@ BlockContentNode parseCodeBlock(dom.Element divElement) {
if (child.nodes.length > 2) return null;
if (child.nodes.length == 2) {
final first = child.nodes[0];
if (first is! dom.Element ||
first.localName != 'span' ||
first.nodes.isNotEmpty) return null;
if (first is! dom.Element
|| first.localName != 'span'
|| first.nodes.isNotEmpty) return null;
}
final grandchild = child.nodes[child.nodes.length - 1];
if (grandchild is! dom.Element) return null;
Expand Down Expand Up @@ -371,8 +371,8 @@ BlockContentNode parseCodeBlock(dom.Element divElement) {
BlockContentNode parseImageNode(dom.Element divElement) {
final imgElement = () {
assert(divElement.localName == 'div'
&& divElement.classes.length == 1
&& divElement.classes.contains('message_inline_image'));
&& divElement.classes.length == 1
&& divElement.classes.contains('message_inline_image'));

if (divElement.nodes.length != 1) return null;
final child = divElement.nodes[0];
Expand Down Expand Up @@ -411,7 +411,7 @@ BlockContentNode parseBlockContent(dom.Node node) {
final classes = element.classes;
List<BlockContentNode> blockNodes() => parseBlockContentList(element.nodes);
List<InlineContentNode> inlineNodes() =>
element.nodes.map(parseInlineContent).toList(growable: false);
element.nodes.map(parseInlineContent).toList(growable: false);

if (localName == 'br' && classes.isEmpty) {
return LineBreakNode(debugHtmlNode: debugHtmlNode);
Expand All @@ -437,7 +437,7 @@ BlockContentNode parseBlockContent(dom.Node node) {
if (headingLevel == HeadingLevel.h6 && classes.isEmpty) {
// TODO handle h1, h2, h3, h4, h5
return HeadingNode(
headingLevel!, inlineNodes(), debugHtmlNode: debugHtmlNode);
headingLevel!, inlineNodes(), debugHtmlNode: debugHtmlNode);
}

if (localName == 'blockquote' && classes.isEmpty) {
Expand Down Expand Up @@ -488,9 +488,9 @@ List<BlockContentNode> parseImplicitParagraphBlockContentList(dom.NodeList nodes
final List<dom.Node> currentParagraph = [];
void consumeParagraph() {
result.add(ParagraphNode(
wasImplicit: true,
nodes:
currentParagraph.map(parseInlineContent).toList(growable: false)));
wasImplicit: true,
nodes:
currentParagraph.map(parseInlineContent).toList(growable: false)));
currentParagraph.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MessageListView extends ChangeNotifier {
assert(contents.isEmpty);
// TODO schedule all this in another isolate
final result =
await getMessages(store.connection, numBefore: 100, numAfter: 10);
await getMessages(store.connection, numBefore: 100, numAfter: 10);
messages.addAll(result.messages);
contents.addAll(_contentsOfMessages(result.messages));
_fetched = true;
Expand Down
34 changes: 17 additions & 17 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export 'database.dart' show Account, AccountsCompanion;
/// we use outside of tests.
abstract class GlobalStore extends ChangeNotifier {
GlobalStore({required Map<int, Account> accounts})
: _accounts = accounts;
: _accounts = accounts;

/// A cache of the [Accounts] table in the underlying data store.
final Map<int, Account> _accounts;
Expand Down Expand Up @@ -148,14 +148,14 @@ class PerAccountStore extends ChangeNotifier {
required this.account,
required this.connection,
required InitialSnapshot initialSnapshot,
}) : zulipVersion = initialSnapshot.zulipVersion,
users = Map.fromEntries(initialSnapshot.realmUsers
.followedBy(initialSnapshot.realmNonActiveUsers)
.followedBy(initialSnapshot.crossRealmBots)
.map((user) => MapEntry(user.userId, user))),
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
(subscription) => MapEntry(subscription.streamId, subscription))),
maxFileUploadSizeMib = initialSnapshot.maxFileUploadSizeMib;
}) : zulipVersion = initialSnapshot.zulipVersion,
users = Map.fromEntries(initialSnapshot.realmUsers
.followedBy(initialSnapshot.realmNonActiveUsers)
.followedBy(initialSnapshot.crossRealmBots)
.map((user) => MapEntry(user.userId, user))),
subscriptions = Map.fromEntries(initialSnapshot.subscriptions.map(
(subscription) => MapEntry(subscription.streamId, subscription))),
maxFileUploadSizeMib = initialSnapshot.maxFileUploadSizeMib;

final Account account;
final ApiConnection connection;
Expand Down Expand Up @@ -324,13 +324,13 @@ class LivePerAccountStore extends PerAccountStore {
required super.account,
required super.connection,
required super.initialSnapshot,
}) : queueId = initialSnapshot.queueId ?? (() {
// The queueId is optional in the type, but should only be missing in the
// case of unauthenticated access to a web-public realm. We authenticated.
throw Exception("bad initial snapshot: missing queueId");
})(),
lastEventId = initialSnapshot.lastEventId,
super.fromInitialSnapshot();
}) : queueId = initialSnapshot.queueId ?? (() {
// The queueId is optional in the type, but should only be missing in the
// case of unauthenticated access to a web-public realm. We authenticated.
throw Exception("bad initial snapshot: missing queueId");
})(),
lastEventId = initialSnapshot.lastEventId,
super.fromInitialSnapshot();

/// Load the user's data from the server, and start an event queue going.
///
Expand Down Expand Up @@ -360,7 +360,7 @@ class LivePerAccountStore extends PerAccountStore {
void poll() async {
while (true) {
final result = await getEvents(connection,
queueId: queueId, lastEventId: lastEventId);
queueId: queueId, lastEventId: lastEventId);
// TODO handle errors on get-events; retry with backoff
// TODO abort long-poll and close ApiConnection on [dispose]
final events = result.events;
Expand Down
49 changes: 23 additions & 26 deletions lib/widgets/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@ void showMessageActionSheet({required BuildContext context, required Message mes
showDraggableScrollableModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Column(
children: [
MenuItemButton(
leadingIcon: Icon(Icons.adaptive.share),
onPressed: () async {
// Close the message action sheet; we're about to show the share
// sheet. (We could do this after the sharing Future settles, but
// on iOS I get impatient with how slowly our action sheet
// dismisses in that case.)
// TODO(#24): Fix iOS bug where this call causes the keyboard to
// reopen (if it was open at the time of this
// `showMessageActionSheet` call) and cover a large part of the
// share sheet.
Navigator.of(context).pop();
return Column(children: [
MenuItemButton(
leadingIcon: Icon(Icons.adaptive.share),
onPressed: () async {
// Close the message action sheet; we're about to show the share
// sheet. (We could do this after the sharing Future settles, but
// on iOS I get impatient with how slowly our action sheet
// dismisses in that case.)
// TODO(#24): Fix iOS bug where this call causes the keyboard to
// reopen (if it was open at the time of this
// `showMessageActionSheet` call) and cover a large part of the
// share sheet.
Navigator.of(context).pop();

// TODO: to support iPads, we're asked to give a
// `sharePositionOrigin` param, or risk crashing / hanging:
// https://pub.dev/packages/share_plus#ipad
// Perhaps a wart in the API; discussion:
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
// TODO: Share raw Markdown, not HTML
await Share.shareWithResult(message.content);
},
child: const Text('Share'),
),
]
);
// TODO: to support iPads, we're asked to give a
// `sharePositionOrigin` param, or risk crashing / hanging:
// https://pub.dev/packages/share_plus#ipad
// Perhaps a wart in the API; discussion:
// https://github.com/zulip/zulip-flutter/pull/12#discussion_r1130146231
// TODO: Share raw Markdown, not HTML
await Share.shareWithResult(message.content);
},
child: const Text('Share')),
]);
});
}
Loading