fluffychat/lib/pangea/models/tokens_event_content_model.dart
wcjord a1f9e6a243
Toolbar practice (#702)
* drafting toolbar with practice

* moved some code around

* turning overlay message content into text buttons for selection, updated toolbar buttons progress bar

* activities displaying and forwarding toolbar

* experimenting with using choice value rather than index for logic

* reimplementation of wordnet results and translation for individual words

* cache and timer

* mostly done with activities in toolbar flow

---------

Co-authored-by: ggurdin <ggurdin@gmail.com>
Co-authored-by: choreo development <williamjordan-cooley@Williams-MacBook-Pro-3.local>
2024-09-25 17:01:58 -04:00

41 lines
1.2 KiB
Dart

import 'dart:convert';
import 'package:fluffychat/pangea/models/pangea_token_model.dart';
/// this class lives within a [PangeaTokensEvent]
/// it always has a [RepresentationEvent] parent
/// These live as separate event so that anyone can add and edit tokens to
/// representation
class PangeaMessageTokens {
List<PangeaToken> tokens;
PangeaMessageTokens({
required this.tokens,
});
factory PangeaMessageTokens.fromJson(Map<String, dynamic> json) {
// "tokens" was accidentally used as the key in the first implementation
// _tokensKey is the correct key
final something = json[_tokensKey] ?? json["tokens"];
final Iterable tokensIterable = something is Iterable
? something
: something is String
? jsonDecode(json[_tokensKey])
: null;
return PangeaMessageTokens(
tokens: tokensIterable
.map((e) => PangeaToken.fromJson(e))
.toList()
.cast<PangeaToken>(),
);
}
static const _tokensKey = "tkns";
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data[_tokensKey] = jsonEncode(tokens.map((e) => e.toJson()).toList());
return data;
}
}