-
Notifications
You must be signed in to change notification settings - Fork 68
DROID-3634 Notifications | Handle pushKeyUpdates and store #2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
konstantiniiv
merged 7 commits into
main
from
droid-3634-handle-push-encryption-key-updates-and-store-securely
May 6, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c98e659
DROID-3634 event channel + tests
konstantiniiv 8f523c8
DROID-3634 model
konstantiniiv 1ab15f6
DROID-3634 data layer
konstantiniiv e19b782
DROID-3634 di
konstantiniiv 414c614
DROID-3634 tests _ logic
konstantiniiv 131e4c4
DROID-3634 fix
konstantiniiv 81f9bcd
DROID-3634 rename
konstantiniiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
core-models/src/main/java/com/anytypeio/anytype/core_models/chats/PushKeyUpdate.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.anytypeio.anytype.core_models.chats | ||
|
|
||
| data class PushKeyUpdate( | ||
| val encryptionKeyId: String, | ||
| val encryptionKey: String | ||
| ) { | ||
| companion object { | ||
| val EMPTY = PushKeyUpdate( | ||
| encryptionKeyId = "", | ||
| encryptionKey = "" | ||
| ) | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
data/src/main/java/com/anytypeio/anytype/data/auth/event/PushKeyRemoteChannel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.anytypeio.anytype.data.auth.event | ||
|
|
||
| import com.anytypeio.anytype.core_models.chats.PushKeyUpdate | ||
| import com.anytypeio.anytype.domain.chats.PushKeyChannel | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface PushKeyRemoteChannel { | ||
| fun start() | ||
| fun stop() | ||
| fun observe(): Flow<PushKeyUpdate> | ||
| } | ||
|
|
||
| class PushKeyDataChannel( | ||
| private val channel: PushKeyRemoteChannel | ||
| ) : PushKeyChannel { | ||
|
|
||
| override fun observe(): Flow<PushKeyUpdate> { | ||
| return channel.observe() | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/com/anytypeio/anytype/domain/chats/PushKeyChannel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.anytypeio.anytype.domain.chats | ||
|
|
||
| import com.anytypeio.anytype.core_models.chats.PushKeyUpdate | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface PushKeyChannel { | ||
| fun observe(): Flow<PushKeyUpdate> | ||
| } |
58 changes: 58 additions & 0 deletions
58
.../main/java/com/anytypeio/anytype/middleware/interactor/events/PushKeyMiddlewareChannel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.anytypeio.anytype.middleware.interactor.events | ||
|
|
||
| import com.anytypeio.anytype.core_models.chats.PushKeyUpdate | ||
| import com.anytypeio.anytype.core_utils.ext.cancel | ||
| import com.anytypeio.anytype.data.auth.event.PushKeyRemoteChannel | ||
| import com.anytypeio.anytype.middleware.interactor.EventHandlerChannel | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.asStateFlow | ||
| import kotlinx.coroutines.flow.catch | ||
| import kotlinx.coroutines.launch | ||
| import timber.log.Timber | ||
|
|
||
| class PushKeyMiddlewareChannel( | ||
| private val scope: CoroutineScope, | ||
| private val channel: EventHandlerChannel, | ||
| private val dispatcher: CoroutineDispatcher | ||
| ) : PushKeyRemoteChannel { | ||
|
|
||
| private val jobs = mutableListOf<Job>() | ||
|
|
||
| private val _pushKeyStatus = MutableStateFlow<PushKeyUpdate>(PushKeyUpdate.EMPTY) | ||
| val pushKeyStatus: Flow<PushKeyUpdate> = _pushKeyStatus.asStateFlow() | ||
|
|
||
| override fun start() { | ||
| Timber.i("PushKeyMiddlewareChannel start") | ||
| jobs.cancel() | ||
konstantiniiv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| jobs += scope.launch(dispatcher) { | ||
| channel.flow() | ||
| .catch { | ||
| Timber.w(it, "Error collecting push key updates") | ||
| } | ||
| .collect { emission -> | ||
| emission.messages.forEach { message -> | ||
| message.pushEncryptionKeyUpdate?.let { | ||
| val pushKeyUpdate = PushKeyUpdate( | ||
| encryptionKeyId = it.encryptionKeyId, | ||
| encryptionKey = it.encryptionKey | ||
| ) | ||
| _pushKeyStatus.value = pushKeyUpdate | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun stop() { | ||
| Timber.i("PushKeyMiddlewareChannel stop") | ||
| jobs.cancel() | ||
| } | ||
|
|
||
| override fun observe(): Flow<PushKeyUpdate> { | ||
| return pushKeyStatus | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.