Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.9 KiB

  1. import 'dart:async';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:path/path.dart';
  4. import 'package:sqflite/sqflite.dart';
  5. Future<Database> getDatabaseConnection() async {
  6. WidgetsFlutterBinding.ensureInitialized();
  7. final path = join(await getDatabasesPath(), 'envelope.db');
  8. final database = openDatabase(
  9. path,
  10. // TODO: remove friend_id_decrypted and symmetric_key_decrypted
  11. onCreate: (db, version) async {
  12. await db.execute(
  13. '''
  14. CREATE TABLE IF NOT EXISTS friends(
  15. id TEXT PRIMARY KEY,
  16. user_id TEXT,
  17. username TEXT,
  18. friend_id TEXT,
  19. friend_id_decrypted TEXT,
  20. symmetric_key TEXT,
  21. symmetric_key_decrypted TEXT,
  22. accepted_at TEXT
  23. );
  24. ''');
  25. // TODO: Change users to use its own table, as it is a json blob
  26. await db.execute(
  27. '''
  28. CREATE TABLE IF NOT EXISTS conversations(
  29. id TEXT PRIMARY KEY,
  30. user_id TEXT,
  31. conversation_detail_id TEXT,
  32. message_thread_key TEXT,
  33. symmetric_key TEXT,
  34. admin INTEGER,
  35. name TEXT,
  36. users TEXT
  37. );
  38. ''');
  39. },
  40. // Set the version. This executes the onCreate function and provides a
  41. // path to perform database upgrades and downgrades.
  42. version: 1,
  43. );
  44. return database;
  45. }