fix: room account data key/type returned encoded

We uri encode all hive keys. But in some cases we never decode them.
This leads to fun issues like SSSS being unreadable after restart.

fixes https://gitlab.com/famedly/company/frontend/famedlysdk/-/issues/179
This commit is contained in:
Nicolas Werner 2021-09-01 17:27:36 +02:00 committed by Krille Fear
parent 33d31cecd1
commit 8b46fa3fc2
2 changed files with 11 additions and 3 deletions

View File

@ -282,8 +282,8 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
final accountData = <String, BasicEvent>{};
for (final key in _accountDataBox.keys) {
final raw = await _accountDataBox.get(key);
accountData[key] = BasicEvent(
type: key,
accountData[key.toString().fromHiveKey] = BasicEvent(
type: key.toString().fromHiveKey,
content: convertToJson(raw),
);
}
@ -1159,7 +1159,7 @@ class MultiKey {
const MultiKey.byParts(this.parts);
MultiKey.fromString(String multiKeyString)
: parts = multiKeyString.split('|');
: parts = multiKeyString.split('|').map((s) => s.fromHiveKey).toList();
@override
String toString() => parts.map((s) => s.toHiveKey).join('|');
@ -1173,3 +1173,7 @@ extension HiveKeyExtension on String {
? '$sigil${Uri.encodeComponent(localpart)}:${Uri.encodeComponent(domain)}'
: Uri.encodeComponent(this);
}
extension FromHiveKeyExtension on String {
String get fromHiveKey => Uri.decodeComponent(this);
}

View File

@ -155,6 +155,10 @@ void testDatabase(Future<DatabaseApi> futureDatabase, int clientId) {
await database.storeAccountData(clientId, 'm.test', '{"foo":"bar"}');
final events = await database.getAccountData(clientId);
expect(events.values.single.type, 'm.test');
await database.storeAccountData(clientId, 'm.abc+de', '{"foo":"bar"}');
final events2 = await database.getAccountData(clientId);
expect(events2.values.any((element) => element.type == 'm.abc+de'), true);
});
test('storeEventUpdate', () async {
await database.storeEventUpdate(