selfprivacy.org.app/lib/logic/models/message.dart

76 lines
1.7 KiB
Dart
Raw Normal View History

import 'package:graphql/client.dart';
2021-01-14 21:48:05 +00:00
import 'package:intl/intl.dart';
/// TODO(misterfourtytwo): add equality override
2021-01-14 21:48:05 +00:00
class Message {
Message({this.text, this.severity = MessageSeverity.normal})
: time = DateTime.now();
Message.warn({this.text})
: severity = MessageSeverity.warning,
time = DateTime.now();
2021-01-14 21:48:05 +00:00
2021-03-15 15:39:44 +00:00
final String? text;
2021-01-14 21:48:05 +00:00
final DateTime time;
final MessageSeverity severity;
static final DateFormat _formatter = DateFormat('hh:mm');
String get timeString => _formatter.format(time);
2021-01-18 10:21:55 +00:00
}
enum MessageSeverity {
2021-01-18 10:21:55 +00:00
normal,
warning,
2021-01-14 21:48:05 +00:00
}
class RestApiRequestMessage extends Message {
RestApiRequestMessage({
this.method,
this.uri,
this.data,
this.headers,
}) : super(text: 'request-uri: $uri\nheaders: $headers\ndata: $data');
final String? method;
final Uri? uri;
final String? data;
final Map<String, dynamic>? headers;
}
class RestApiResponseMessage extends Message {
RestApiResponseMessage({
this.method,
this.uri,
this.statusCode,
this.data,
}) : super(text: 'response-uri: $uri\ncode: $statusCode\ndata: $data');
final String? method;
final Uri? uri;
final int? statusCode;
final String? data;
}
class GraphQlResponseMessage extends Message {
GraphQlResponseMessage({
this.data,
this.errors,
this.context,
}) : super(text: 'GraphQL Response\ndata: $data');
final Map<String, dynamic>? data;
final List<GraphQLError>? errors;
final Context? context;
}
class GraphQlRequestMessage extends Message {
GraphQlRequestMessage({
this.operation,
this.variables,
this.context,
}) : super(text: 'GraphQL Request\noperation: $operation');
final Operation? operation;
final Map<String, dynamic>? variables;
final Context? context;
}