-
Notifications
You must be signed in to change notification settings - Fork 226
Ensure that we have only one single instance of SeenInviteStore per session #4577
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.invite.api | ||
|
||
import io.element.android.libraries.matrix.api.core.SessionId | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
fun interface SeenInvitesStoreFactory { | ||
fun getOrCreate( | ||
sessionId: SessionId, | ||
sessionCoroutineScope: CoroutineScope, | ||
): SeenInvitesStore | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.features.invite.impl | ||
|
||
import android.content.Context | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import io.element.android.features.invite.api.SeenInvitesStore | ||
import io.element.android.features.invite.api.SeenInvitesStoreFactory | ||
import io.element.android.libraries.di.AppScope | ||
import io.element.android.libraries.di.ApplicationContext | ||
import io.element.android.libraries.di.SingleIn | ||
import io.element.android.libraries.matrix.api.core.SessionId | ||
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver | ||
import kotlinx.coroutines.CoroutineScope | ||
import java.util.concurrent.ConcurrentHashMap | ||
import javax.inject.Inject | ||
|
||
@SingleIn(AppScope::class) | ||
@ContributesBinding(AppScope::class) | ||
class DefaultSeenInvitesStoreFactory @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
private val sessionObserver: SessionObserver, | ||
Check warning on line 27 in features/invite/impl/src/main/kotlin/io/element/android/features/invite/impl/DefaultSeenInvitesStoreFactory.kt
|
||
) : SeenInvitesStoreFactory { | ||
// We can have only one class accessing a single data store, so keep a cache of them. | ||
private val cache = ConcurrentHashMap<SessionId, SeenInvitesStore>() | ||
Check warning on line 30 in features/invite/impl/src/main/kotlin/io/element/android/features/invite/impl/DefaultSeenInvitesStoreFactory.kt
|
||
|
||
override fun getOrCreate( | ||
sessionId: SessionId, | ||
sessionCoroutineScope: CoroutineScope, | ||
): SeenInvitesStore { | ||
return cache.getOrPut(sessionId) { | ||
DefaultSeenInvitesStore( | ||
context = context, | ||
sessionId = sessionId, | ||
sessionCoroutineScope = sessionCoroutineScope, | ||
sessionObserver = sessionObserver, | ||
) | ||
Check warning on line 42 in features/invite/impl/src/main/kotlin/io/element/android/features/invite/impl/DefaultSeenInvitesStoreFactory.kt
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind using this, but I think you could also create a
@Provides
method forSessionScope
that would return the cached store if needed:And then you can just inject the result in the session scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's a bit cleaner, will give it a try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8015668