⬆️ Support some new server stuff

This commit is contained in:
2024-05-10 23:17:01 +08:00
parent c1d3bac0c8
commit 40aa16e971
41 changed files with 105 additions and 69 deletions

View File

@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:solian/models/account.dart';
import 'package:solian/models/channel.dart';
import 'package:solian/models/post.dart';
@ -7,9 +9,9 @@ class Message {
DateTime createdAt;
DateTime updatedAt;
DateTime? deletedAt;
String content;
String rawContent;
Map<String, dynamic>? metadata;
int type;
String type;
List<Attachment>? attachments;
Channel? channel;
Sender sender;
@ -20,12 +22,16 @@ class Message {
bool isSending = false;
Map<String, dynamic> get decodedContent {
return jsonDecode(utf8.fuse(base64).decode(rawContent));
}
Message({
required this.id,
required this.createdAt,
required this.updatedAt,
this.deletedAt,
required this.content,
required this.rawContent,
required this.metadata,
required this.type,
this.attachments,
@ -42,18 +48,14 @@ class Message {
createdAt: DateTime.parse(json['created_at']),
updatedAt: DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'],
content: json['content'],
rawContent: json['content'],
metadata: json['metadata'],
type: json['type'],
attachments: List<Attachment>.from(
json['attachments']?.map((x) => Attachment.fromJson(x)) ??
List.empty()),
attachments: List<Attachment>.from(json['attachments']?.map((x) => Attachment.fromJson(x)) ?? List.empty()),
channel: Channel.fromJson(json['channel']),
sender: Sender.fromJson(json['sender']),
replyId: json['reply_id'],
replyTo: json['reply_to'] != null
? Message.fromJson(json['reply_to'])
: null,
replyTo: json['reply_to'] != null ? Message.fromJson(json['reply_to']) : null,
channelId: json['channel_id'],
senderId: json['sender_id'],
);
@ -63,11 +65,10 @@ class Message {
'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt,
'content': content,
'content': rawContent,
'metadata': metadata,
'type': type,
'attachments': List<dynamic>.from(
attachments?.map((x) => x.toJson()) ?? List.empty()),
'attachments': List<dynamic>.from(attachments?.map((x) => x.toJson()) ?? List.empty()),
'channel': channel?.toJson(),
'sender': sender.toJson(),
'reply_id': replyId,