getTopicMessages method
Implementation
Future<List<Message>> getTopicMessages(
String? topic, String? currentUid, int? page, int? size) async {
// debugPrint('1: ' + topic! + ' currentUid:' + currentUid!);
// FIXME: 暂不支持web
if (BytedeskUtils.isWeb) {
return [];
}
// debugPrint('2');
//
List<Map> maps = await database!.query(tableMessage!,
columns: [
columnMid!,
columnContent!,
columnImageUrl!,
columnVoiceUrl!,
columnVideoUrl!,
columnFileUrl!,
columnType!,
columnTopic!,
columnStatus!,
columnTimestamp!,
columnNickname!,
columnAvatar!,
columnIsSend!,
columnClient!,
columnAnswers!,
columnCategories!
],
where: '$columnTopic = ? and $columnCurrentUid = ?',
whereArgs: [topic, currentUid],
orderBy: '$columnTimestamp DESC, $columnIsSend ASC',
limit: size,
offset: page! * size!);
//
// debugPrint('3');
// BytedeskUtils.printLog(maps.length);
//
return List.generate(maps.length, (i) {
//
List<Answer> robotQaList = [];
// FIXME: 下面解析报错
// if (maps[i]['type'] == BytedeskConstants.MESSAGE_TYPE_ROBOT) {
// robotQaList = maps[i][columnAnswers] == null
// ? []
// : (json.decode(maps[i][columnAnswers]) as List<dynamic>)
// .map((item) => Answer.fromJson(item))
// .toList();
// }
List<Category> categoriesList = [];
// FIXME: 下面解析报错
// if (maps[i]['type'] == BytedeskConstants.MESSAGE_TYPE_ROBOT_V2) {
// categoriesList = maps[i][columnCategories] == null
// ? []
// : (json.decode(maps[i][columnCategories]) as List<dynamic>)
// .map((item) => Category.fromJson(item))
// .toList();
// }
// debugPrint('4');
return Message(
mid: maps[i]['mid'],
content: maps[i]['content'],
imageUrl: maps[i]['imageUrl'],
voiceUrl: maps[i]['voiceUrl'],
videoUrl: maps[i]['videoUrl'],
fileUrl: maps[i]['fileUrl'],
type: maps[i]['type'],
topic: maps[i]['topic'],
status: maps[i]['status'],
timestamp: maps[i]['timestamp'],
nickname: maps[i]['nickname'],
avatar: maps[i]['avatar'],
isSend: maps[i]['isSend'],
client: maps[i]['client'],
answers: robotQaList,
categories: categoriesList);
});
}