Hive, requestlog, etc

This commit is contained in:
2024-05-25 18:09:39 +02:00
parent 227d7871c2
commit 7e347a70c2
23 changed files with 1149 additions and 355 deletions

View File

@@ -0,0 +1,22 @@
class APIError {
final String success;
final String error;
final String errhighlight;
final String message;
const APIError({
required this.success,
required this.error,
required this.errhighlight,
required this.message,
});
factory APIError.fromJson(Map<String, dynamic> json) {
return APIError(
success: json['success'],
error: json['error'],
errhighlight: json['errhighlight'],
message: json['message'],
);
}
}

View File

@@ -24,31 +24,17 @@ class Channel {
});
factory Channel.fromJson(Map<String, dynamic> json) {
return switch (json) {
{
'channel_id': String channelID,
'owner_user_id': String ownerUserID,
'internal_name': String internalName,
'display_name': String displayName,
'description_name': String? descriptionName,
'subscribe_key': String? subscribeKey,
'timestamp_created': String timestampCreated,
'timestamp_lastsent': String? timestampLastSent,
'messages_sent': int messagesSent,
} =>
Channel(
channelID: channelID,
ownerUserID: ownerUserID,
internalName: internalName,
displayName: displayName,
descriptionName: descriptionName,
subscribeKey: subscribeKey,
timestampCreated: timestampCreated,
timestampLastSent: timestampLastSent,
messagesSent: messagesSent,
),
_ => throw const FormatException('Failed to decode Channel.'),
};
return Channel(
channelID: json['channel_id'],
ownerUserID: json['owner_user_id'],
internalName: json['internal_name'],
displayName: json['display_name'],
descriptionName: json['description_name'],
subscribeKey: json['subscribe_key'],
timestampCreated: json['timestamp_created'],
timestampLastSent: json['timestamp_lastsent'],
messagesSent: json['messages_sent'],
);
}
}
@@ -69,32 +55,21 @@ class ChannelWithSubscription extends Channel {
});
factory ChannelWithSubscription.fromJson(Map<String, dynamic> json) {
return switch (json) {
{
'channel_id': String channelID,
'owner_user_id': String ownerUserID,
'internal_name': String internalName,
'display_name': String displayName,
'description_name': String? descriptionName,
'subscribe_key': String? subscribeKey,
'timestamp_created': String timestampCreated,
'timestamp_lastsent': String? timestampLastSent,
'messages_sent': int messagesSent,
'subscription': dynamic subscription,
} =>
ChannelWithSubscription(
channelID: channelID,
ownerUserID: ownerUserID,
internalName: internalName,
displayName: displayName,
descriptionName: descriptionName,
subscribeKey: subscribeKey,
timestampCreated: timestampCreated,
timestampLastSent: timestampLastSent,
messagesSent: messagesSent,
subscription: Subscription.fromJson(subscription),
),
_ => throw const FormatException('Failed to decode Channel.'),
};
return ChannelWithSubscription(
channelID: json['channel_id'],
ownerUserID: json['owner_user_id'],
internalName: json['internal_name'],
displayName: json['display_name'],
descriptionName: json['description_name'],
subscribeKey: json['subscribe_key'],
timestampCreated: json['timestamp_created'],
timestampLastSent: json['timestamp_lastsent'],
messagesSent: json['messages_sent'],
subscription: Subscription.fromJson(json['subscription']),
);
}
static List<ChannelWithSubscription> fromJsonArray(List<dynamic> jsonArr) {
return jsonArr.map<ChannelWithSubscription>((e) => ChannelWithSubscription.fromJson(e)).toList();
}
}

View File

@@ -30,38 +30,28 @@ class Message {
});
factory Message.fromJson(Map<String, dynamic> json) {
return switch (json) {
{
'message_id': String messageID,
'sender_user_id': String senderUserID,
'channel_internal_name': String channelInternalName,
'channel_id': String channelID,
'sender_name': String? senderName,
'sender_ip': String senderIP,
'timestamp': String timestamp,
'title': String title,
'content': String? content,
'priority': int priority,
'usr_message_id': String? userMessageID,
'used_key_id': String usedKeyID,
'trimmed': bool trimmed,
} =>
Message(
messageID: messageID,
senderUserID: senderUserID,
channelInternalName: channelInternalName,
channelID: channelID,
senderName: senderName,
senderIP: senderIP,
timestamp: timestamp,
title: title,
content: content,
priority: priority,
userMessageID: userMessageID,
usedKeyID: usedKeyID,
trimmed: trimmed,
),
_ => throw const FormatException('Failed to decode Message.'),
};
return Message(
messageID: json['message_id'],
senderUserID: json['sender_user_id'],
channelInternalName: json['channel_internal_name'],
channelID: json['channel_id'],
senderName: json['sender_name'],
senderIP: json['sender_ip'],
timestamp: json['timestamp'],
title: json['title'],
content: json['content'],
priority: json['priority'],
userMessageID: json['usr_message_id'],
usedKeyID: json['used_key_id'],
trimmed: json['trimmed'],
);
}
static fromPaginatedJsonArray(Map<String, dynamic> data, String keyMessages, String keyToken) {
final npt = data[keyToken] as String;
final messages = (data[keyMessages] as List<dynamic>).map<Message>((e) => Message.fromJson(e)).toList();
return (npt, messages);
}
}

View File

@@ -18,26 +18,14 @@ class Subscription {
});
factory Subscription.fromJson(Map<String, dynamic> json) {
return switch (json) {
{
'subscription_id': String subscriptionID,
'subscriber_user_id': String subscriberUserID,
'channel_owner_user_id': String channelOwnerUserID,
'channel_id': String channelID,
'channel_internal_name': String channelInternalName,
'timestamp_created': String timestampCreated,
'confirmed': bool confirmed,
} =>
Subscription(
subscriptionID: subscriptionID,
subscriberUserID: subscriberUserID,
channelOwnerUserID: channelOwnerUserID,
channelID: channelID,
channelInternalName: channelInternalName,
timestampCreated: timestampCreated,
confirmed: confirmed,
),
_ => throw const FormatException('Failed to decode Subscription.'),
};
return Subscription(
subscriptionID: json['subscription_id'],
subscriberUserID: json['subscriber_user_id'],
channelOwnerUserID: json['channel_owner_user_id'],
channelID: json['channel_id'],
channelInternalName: json['channel_internal_name'],
timestampCreated: json['timestamp_created'],
confirmed: json['confirmed'],
);
}
}

View File

@@ -40,48 +40,25 @@ class User {
});
factory User.fromJson(Map<String, dynamic> json) {
return switch (json) {
{
'user_id': String userID,
'username': String? username,
'timestamp_created': String timestampCreated,
'timestamp_lastread': String? timestampLastRead,
'timestamp_lastsent': String? timestampLastSent,
'messages_sent': int messagesSent,
'quota_used': int quotaUsed,
'quota_remaining': int quotaRemaining,
'quota_max': int quotaPerDay,
'is_pro': bool isPro,
'default_channel': String defaultChannel,
'max_body_size': int maxBodySize,
'max_title_length': int maxTitleLength,
'default_priority': int defaultPriority,
'max_channel_name_length': int maxChannelNameLength,
'max_channel_description_length': int maxChannelDescriptionLength,
'max_sender_name_length': int maxSenderNameLength,
'max_user_message_id_length': int maxUserMessageIDLength,
} =>
User(
userID: userID,
username: username,
timestampCreated: timestampCreated,
timestampLastRead: timestampLastRead,
timestampLastSent: timestampLastSent,
messagesSent: messagesSent,
quotaUsed: quotaUsed,
quotaRemaining: quotaRemaining,
quotaPerDay: quotaPerDay,
isPro: isPro,
defaultChannel: defaultChannel,
maxBodySize: maxBodySize,
maxTitleLength: maxTitleLength,
defaultPriority: defaultPriority,
maxChannelNameLength: maxChannelNameLength,
maxChannelDescriptionLength: maxChannelDescriptionLength,
maxSenderNameLength: maxSenderNameLength,
maxUserMessageIDLength: maxUserMessageIDLength,
),
_ => throw const FormatException('Failed to decode User.'),
};
return User(
userID: json['user_id'],
username: json['username'],
timestampCreated: json['timestamp_created'],
timestampLastRead: json['timestamp_lastread'],
timestampLastSent: json['timestamp_lastsent'],
messagesSent: json['messages_sent'],
quotaUsed: json['quota_used'],
quotaRemaining: json['quota_remaining'],
quotaPerDay: json['quota_max'],
isPro: json['is_pro'],
defaultChannel: json['default_channel'],
maxBodySize: json['max_body_size'],
maxTitleLength: json['max_title_length'],
defaultPriority: json['default_priority'],
maxChannelNameLength: json['max_channel_name_length'],
maxChannelDescriptionLength: json['max_channel_description_length'],
maxSenderNameLength: json['max_sender_name_length'],
maxUserMessageIDLength: json['max_user_message_id_length'],
);
}
}