mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-24 01:08:09 +08:00

This greatly simplifies the entire data flow. Though, it comes at the risk of introducing bugs, but I think it's worth it. Plus, it makes everything far far more testable.
34 lines
786 B
Dart
34 lines
786 B
Dart
/*
|
|
* SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <me@vhanda.in>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
import 'package:flutter_emoji/flutter_emoji.dart';
|
|
|
|
import 'base.dart';
|
|
|
|
class EmojiTransformer implements NoteReadTransformer, NoteWriteTransformer {
|
|
static final _emojiParser = EmojiParser();
|
|
|
|
@override
|
|
Future<Note> onRead(Note note) async {
|
|
var title = note.title;
|
|
|
|
return note.copyWith(
|
|
body: _emojiParser.emojify(note.body),
|
|
title: title != null ? _emojiParser.emojify(title) : null,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<Note> onWrite(Note note) async {
|
|
var title = note.title;
|
|
|
|
return note.copyWith(
|
|
body: _emojiParser.unemojify(note.body),
|
|
title: title != null ? _emojiParser.unemojify(title) : null,
|
|
);
|
|
}
|
|
}
|