refactor: Create StrippedStateEvents for invite rooms when loading from db

This commit is contained in:
Krille 2024-05-06 09:42:05 +02:00
parent 587ce378c7
commit a1a542d98e
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
3 changed files with 15 additions and 5 deletions

View File

@ -589,7 +589,9 @@ class HiveCollectionsDatabase extends DatabaseApi {
for (final states in statesList) { for (final states in statesList) {
if (states == null) continue; if (states == null) continue;
final stateEvents = states.values final stateEvents = states.values
.map((raw) => Event.fromJson(copyMap(raw), room)) .map((raw) => room.membership == Membership.invite
? StrippedStateEvent.fromJson(copyMap(raw))
: Event.fromJson(copyMap(raw), room))
.toList(); .toList();
for (final state in stateEvents) { for (final state in stateEvents) {
room.setState(state); room.setState(state);
@ -635,7 +637,9 @@ class HiveCollectionsDatabase extends DatabaseApi {
if (members != null) { if (members != null) {
for (final member in members) { for (final member in members) {
if (member == null) continue; if (member == null) continue;
room.setState(Event.fromJson(copyMap(member), room)); room.setState(room.membership == Membership.invite
? StrippedStateEvent.fromJson(copyMap(member))
: Event.fromJson(copyMap(member), room));
} }
} }
} }

View File

@ -618,7 +618,9 @@ class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin {
Logs().w('Unable to post load member $userId'); Logs().w('Unable to post load member $userId');
continue; continue;
} }
room.setState(Event.fromJson(convertToJson(state), room)); room.setState(room.membership == Membership.invite
? StrippedStateEvent.fromJson(copyMap(raw))
: Event.fromJson(convertToJson(state), room));
} }
// Get the "important" room states. All other states will be loaded once // Get the "important" room states. All other states will be loaded once
@ -628,7 +630,9 @@ class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin {
.get(MultiKey(room.id, type).toString()) as Map?; .get(MultiKey(room.id, type).toString()) as Map?;
if (states == null) continue; if (states == null) continue;
final stateEvents = states.values final stateEvents = states.values
.map((raw) => Event.fromJson(convertToJson(raw), room)) .map((raw) => room.membership == Membership.invite
? StrippedStateEvent.fromJson(copyMap(raw))
: Event.fromJson(convertToJson(raw), room))
.toList(); .toList();
for (final state in stateEvents) { for (final state in stateEvents) {
room.setState(state); room.setState(state);

View File

@ -572,7 +572,9 @@ class MatrixSdkDatabase extends DatabaseApi with DatabaseFileStorage {
} }
final states = entry.value; final states = entry.value;
final stateEvents = states.values final stateEvents = states.values
.map((raw) => Event.fromJson(copyMap(raw), room)) .map((raw) => room.membership == Membership.invite
? StrippedStateEvent.fromJson(copyMap(raw))
: Event.fromJson(copyMap(raw), room))
.toList(); .toList();
for (final state in stateEvents) { for (final state in stateEvents) {
room.setState(state); room.setState(state);