insert method

Future<int> insert(
  1. Message message
)

Implementation

Future<int> insert(Message message) async {
  // FIXME: 暂不支持web
  if (BytedeskUtils.isWeb) {
    return 0;
  }

  String currentUid = SpUtil.getString(BytedeskConstants.VISITOR_UID)!;

  // Check if a message with the same uid already exists
  List<Map> maps = await database!.query("$tableMessage",
      columns: [columnId!],
      where: "$columnUid = ?",
      whereArgs: [message.uid]);

  if (maps.isNotEmpty) {
    // A message with the same uid already exists, so we can update it
    // await update(message.uid, message.status);
    return 0; // or return the id of the updated message
  }
  // debugPrint('insert avatar:' + message.avatar + ' conten:' + message.content + ' timestamp:' + message.timestamp);
  return await database!.insert(tableMessage!, message.toMap(currentUid));
}