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

import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
Future<Database> getDatabaseConnection() async {
WidgetsFlutterBinding.ensureInitialized();
final path = join(await getDatabasesPath(), 'envelope.db');
final database = openDatabase(
path,
// TODO: remove friend_id_decrypted and symmetric_key_decrypted
onCreate: (db, version) async {
await db.execute(
'''
CREATE TABLE IF NOT EXISTS friends(
id TEXT PRIMARY KEY,
user_id TEXT,
username TEXT,
friend_id TEXT,
friend_id_decrypted TEXT,
symmetric_key TEXT,
symmetric_key_decrypted TEXT,
accepted_at TEXT
);
''');
// TODO: Change users to use its own table, as it is a json blob
await db.execute(
'''
CREATE TABLE IF NOT EXISTS conversations(
id TEXT PRIMARY KEY,
user_id TEXT,
conversation_detail_id TEXT,
message_thread_key TEXT,
symmetric_key TEXT,
admin INTEGER,
name TEXT,
users TEXT
);
''');
},
// Set the version. This executes the onCreate function and provides a
// path to perform database upgrades and downgrades.
version: 1,
);
return database;
}