@@ -89,6 +89,7 @@ import org.matrix.android.sdk.internal.crypto.model.SessionInfo
89
89
import org.matrix.android.sdk.internal.crypto.model.toRest
90
90
import org.matrix.android.sdk.internal.crypto.repository.WarnOnUnknownDeviceRepository
91
91
import org.matrix.android.sdk.internal.crypto.store.IMXCryptoStore
92
+ import org.matrix.android.sdk.internal.crypto.store.db.CryptoStoreAggregator
92
93
import org.matrix.android.sdk.internal.crypto.tasks.DeleteDeviceTask
93
94
import org.matrix.android.sdk.internal.crypto.tasks.GetDeviceInfoTask
94
95
import org.matrix.android.sdk.internal.crypto.tasks.GetDevicesTask
@@ -192,21 +193,21 @@ internal class DefaultCryptoService @Inject constructor(
192
193
private val isStarting = AtomicBoolean (false )
193
194
private val isStarted = AtomicBoolean (false )
194
195
195
- fun onStateEvent (roomId : String , event : Event ) {
196
+ fun onStateEvent (roomId : String , event : Event , cryptoStoreAggregator : CryptoStoreAggregator ? ) {
196
197
when (event.type) {
197
198
EventType .STATE_ROOM_ENCRYPTION -> onRoomEncryptionEvent(roomId, event)
198
199
EventType .STATE_ROOM_MEMBER -> onRoomMembershipEvent(roomId, event)
199
- EventType .STATE_ROOM_HISTORY_VISIBILITY -> onRoomHistoryVisibilityEvent(roomId, event)
200
+ EventType .STATE_ROOM_HISTORY_VISIBILITY -> onRoomHistoryVisibilityEvent(roomId, event, cryptoStoreAggregator )
200
201
}
201
202
}
202
203
203
- fun onLiveEvent (roomId : String , event : Event , isInitialSync : Boolean ) {
204
+ fun onLiveEvent (roomId : String , event : Event , isInitialSync : Boolean , cryptoStoreAggregator : CryptoStoreAggregator ? ) {
204
205
// handle state events
205
206
if (event.isStateEvent()) {
206
207
when (event.type) {
207
208
EventType .STATE_ROOM_ENCRYPTION -> onRoomEncryptionEvent(roomId, event)
208
209
EventType .STATE_ROOM_MEMBER -> onRoomMembershipEvent(roomId, event)
209
- EventType .STATE_ROOM_HISTORY_VISIBILITY -> onRoomHistoryVisibilityEvent(roomId, event)
210
+ EventType .STATE_ROOM_HISTORY_VISIBILITY -> onRoomHistoryVisibilityEvent(roomId, event, cryptoStoreAggregator )
210
211
}
211
212
}
212
213
@@ -430,8 +431,10 @@ internal class DefaultCryptoService @Inject constructor(
430
431
* A sync response has been received.
431
432
*
432
433
* @param syncResponse the syncResponse
434
+ * @param cryptoStoreAggregator data aggregated during the sync response treatment to store
433
435
*/
434
- fun onSyncCompleted (syncResponse : SyncResponse ) {
436
+ fun onSyncCompleted (syncResponse : SyncResponse , cryptoStoreAggregator : CryptoStoreAggregator ) {
437
+ cryptoStore.storeData(cryptoStoreAggregator)
435
438
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
436
439
runCatching {
437
440
if (syncResponse.deviceLists != null ) {
@@ -998,15 +1001,26 @@ internal class DefaultCryptoService @Inject constructor(
998
1001
}
999
1002
}
1000
1003
1001
- private fun onRoomHistoryVisibilityEvent (roomId : String , event : Event ) {
1004
+ private fun onRoomHistoryVisibilityEvent (roomId : String , event : Event , cryptoStoreAggregator : CryptoStoreAggregator ? ) {
1002
1005
if (! event.isStateEvent()) return
1003
1006
val eventContent = event.content.toModel<RoomHistoryVisibilityContent >()
1004
1007
val historyVisibility = eventContent?.historyVisibility
1005
1008
if (historyVisibility == null ) {
1006
- cryptoStore.setShouldShareHistory(roomId, false )
1009
+ if (cryptoStoreAggregator != null ) {
1010
+ cryptoStoreAggregator.setShouldShareHistoryData[roomId] = false
1011
+ } else {
1012
+ // Store immediately
1013
+ cryptoStore.setShouldShareHistory(roomId, false )
1014
+ }
1007
1015
} else {
1008
- cryptoStore.setShouldEncryptForInvitedMembers(roomId, historyVisibility != RoomHistoryVisibility .JOINED )
1009
- cryptoStore.setShouldShareHistory(roomId, historyVisibility.shouldShareHistory())
1016
+ if (cryptoStoreAggregator != null ) {
1017
+ cryptoStoreAggregator.setShouldEncryptForInvitedMembersData[roomId] = historyVisibility != RoomHistoryVisibility .JOINED
1018
+ cryptoStoreAggregator.setShouldShareHistoryData[roomId] = historyVisibility.shouldShareHistory()
1019
+ } else {
1020
+ // Store immediately
1021
+ cryptoStore.setShouldEncryptForInvitedMembers(roomId, historyVisibility != RoomHistoryVisibility .JOINED )
1022
+ cryptoStore.setShouldShareHistory(roomId, historyVisibility.shouldShareHistory())
1023
+ }
1010
1024
}
1011
1025
}
1012
1026
0 commit comments