[Store] Fix RoomStates table
This commit is contained in:
parent
d661fb4289
commit
471f9f8c49
|
@ -58,7 +58,7 @@ class Store {
|
||||||
_init() async {
|
_init() async {
|
||||||
var databasePath = await getDatabasesPath();
|
var databasePath = await getDatabasesPath();
|
||||||
String path = p.join(databasePath, "FluffyMatrix.db");
|
String path = p.join(databasePath, "FluffyMatrix.db");
|
||||||
_db = await openDatabase(path, version: 13,
|
_db = await openDatabase(path, version: 14,
|
||||||
onCreate: (Database db, int version) async {
|
onCreate: (Database db, int version) async {
|
||||||
await createTables(db);
|
await createTables(db);
|
||||||
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
}, onUpgrade: (Database db, int oldVersion, int newVersion) async {
|
||||||
|
@ -276,17 +276,18 @@ class Store {
|
||||||
|
|
||||||
if (eventUpdate.content["event_id"] != null) {
|
if (eventUpdate.content["event_id"] != null) {
|
||||||
txn.rawInsert(
|
txn.rawInsert(
|
||||||
"INSERT OR REPLACE INTO State VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
"INSERT OR REPLACE INTO RoomStates VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
eventContent["event_id"],
|
[
|
||||||
chat_id,
|
eventContent["event_id"],
|
||||||
eventContent["origin_server_ts"],
|
chat_id,
|
||||||
eventContent["sender"],
|
eventContent["origin_server_ts"],
|
||||||
state_key,
|
eventContent["sender"],
|
||||||
json.encode(eventContent["unsigned"] ?? ""),
|
state_key,
|
||||||
json.encode(eventContent["prev_content"] ?? ""),
|
json.encode(eventContent["unsigned"] ?? ""),
|
||||||
eventContent["type"],
|
json.encode(eventContent["prev_content"] ?? ""),
|
||||||
json.encode(eventContent["content"]),
|
eventContent["type"],
|
||||||
]);
|
json.encode(eventContent["content"]),
|
||||||
|
]);
|
||||||
} else
|
} else
|
||||||
txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [
|
txn.rawInsert("INSERT OR REPLACE INTO RoomAccountData VALUES(?, ?, ?)", [
|
||||||
eventContent["type"],
|
eventContent["type"],
|
||||||
|
@ -300,7 +301,7 @@ class Store {
|
||||||
/// Returns a User object by a given Matrix ID and a Room.
|
/// Returns a User object by a given Matrix ID and a Room.
|
||||||
Future<User> getUser({String matrixID, Room room}) async {
|
Future<User> getUser({String matrixID, Room room}) async {
|
||||||
List<Map<String, dynamic>> res = await db.rawQuery(
|
List<Map<String, dynamic>> res = await db.rawQuery(
|
||||||
"SELECT * FROM States WHERE state_key=? AND room_id=?",
|
"SELECT * FROM RoomStates WHERE state_key=? AND room_id=?",
|
||||||
[matrixID, room.id]);
|
[matrixID, room.id]);
|
||||||
if (res.length != 1) return null;
|
if (res.length != 1) return null;
|
||||||
return RoomState.fromJson(res[0], room).asUser;
|
return RoomState.fromJson(res[0], room).asUser;
|
||||||
|
@ -310,7 +311,7 @@ class Store {
|
||||||
/// except users who are in the Room with the ID [exceptRoomID].
|
/// except users who are in the Room with the ID [exceptRoomID].
|
||||||
Future<List<User>> loadContacts({String exceptRoomID = ""}) async {
|
Future<List<User>> loadContacts({String exceptRoomID = ""}) async {
|
||||||
List<Map<String, dynamic>> res = await db.rawQuery(
|
List<Map<String, dynamic>> res = await db.rawQuery(
|
||||||
"SELECT * FROM States WHERE state_key!=? AND room_id!=? GROUP BY state_key ORDER BY state_key",
|
"SELECT * FROM RoomStates WHERE state_key!=? AND room_id!=? GROUP BY state_key ORDER BY state_key",
|
||||||
[client.userID, exceptRoomID]);
|
[client.userID, exceptRoomID]);
|
||||||
List<User> userList = [];
|
List<User> userList = [];
|
||||||
for (int i = 0; i < res.length; i++)
|
for (int i = 0; i < res.length; i++)
|
||||||
|
@ -323,7 +324,7 @@ class Store {
|
||||||
Future<List<User>> loadParticipants(Room room) async {
|
Future<List<User>> loadParticipants(Room room) async {
|
||||||
List<Map<String, dynamic>> res = await db.rawQuery(
|
List<Map<String, dynamic>> res = await db.rawQuery(
|
||||||
"SELECT * " +
|
"SELECT * " +
|
||||||
" FROM States " +
|
" FROM RoomStates " +
|
||||||
" WHERE room_id=? " +
|
" WHERE room_id=? " +
|
||||||
" AND type='m.room.member'",
|
" AND type='m.room.member'",
|
||||||
[room.id]);
|
[room.id]);
|
||||||
|
@ -386,7 +387,7 @@ class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Map<String, dynamic>>> getStatesFromRoomId(String id) async {
|
Future<List<Map<String, dynamic>>> getStatesFromRoomId(String id) async {
|
||||||
return db.rawQuery("SELECT * FROM States WHERE room_id=?", [id]);
|
return db.rawQuery("SELECT * FROM RoomStates WHERE room_id=?", [id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> forgetRoom(String roomID) async {
|
Future<void> forgetRoom(String roomID) async {
|
||||||
|
@ -483,7 +484,7 @@ class Store {
|
||||||
'UNIQUE(event_id))',
|
'UNIQUE(event_id))',
|
||||||
|
|
||||||
/// The database scheme for room states.
|
/// The database scheme for room states.
|
||||||
'State': 'CREATE TABLE IF NOT EXISTS State(' +
|
'RoomStates': 'CREATE TABLE IF NOT EXISTS RoomStates(' +
|
||||||
'event_id TEXT PRIMARY KEY, ' +
|
'event_id TEXT PRIMARY KEY, ' +
|
||||||
'room_id TEXT, ' +
|
'room_id TEXT, ' +
|
||||||
'origin_server_ts INTEGER, ' +
|
'origin_server_ts INTEGER, ' +
|
||||||
|
|
Loading…
Reference in New Issue