setup method
Loads messages from the conversation and sorts them by date.
Implementation
Future<void> setup() async {
var c = conversation;
if (c == null) {
VitGptFlutterConfiguration.logger
.w('Aborting messages load: no original conversation');
return;
}
if (c.messages.isNotEmpty) {
VitGptFlutterConfiguration.logger
.w('Aborting load messages: messages already found');
return;
}
var id = c.id;
if (id == null) {
VitGptFlutterConfiguration.logger.w('Unable to load messages: no id');
return;
}
var messages = await loadThreadMessages(id);
VitGptFlutterConfiguration.logger.i('Found ${messages.length} messages');
messages.sortByDate((x) => x.date);
c.messages.addAll(messages);
notifyListeners();
}