-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirc_message.dart
More file actions
55 lines (51 loc) · 1.46 KB
/
irc_message.dart
File metadata and controls
55 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
enum IrcMessageKind { chat, system, raw }
class IrcMessage {
const IrcMessage({
required this.id,
required this.tabId,
required this.sender,
required this.content,
required this.timestamp,
this.tags = const <String, String?>{},
this.isPlayback = false,
this.isOwn = false,
this.kind = IrcMessageKind.chat,
});
final String id;
final String tabId;
final String sender;
final String content;
final DateTime timestamp;
final Map<String, String?> tags;
final bool isPlayback;
final bool isOwn;
final IrcMessageKind kind;
Map<String, Object?> toJson() {
return {
'id': id,
'tabId': tabId,
'sender': sender,
'content': content,
'timestamp': timestamp.toIso8601String(),
'tags': tags,
'isPlayback': isPlayback,
'isOwn': isOwn,
'kind': kind.name,
};
}
factory IrcMessage.fromJson(Map<String, Object?> json) {
return IrcMessage(
id: json['id']! as String,
tabId: json['tabId']! as String,
sender: json['sender']! as String,
content: json['content']! as String,
timestamp: DateTime.parse(json['timestamp']! as String),
tags: Map<String, String?>.from((json['tags'] as Map?) ?? const <String, String?>{}),
isPlayback: (json['isPlayback'] as bool?) ?? false,
isOwn: (json['isOwn'] as bool?) ?? false,
kind: IrcMessageKind.values.byName(
(json['kind'] as String?) ?? IrcMessageKind.chat.name,
),
);
}
}