Skip to content

Commit 00deff4

Browse files
committed
Improvements to self hosting
1 parent 967657d commit 00deff4

13 files changed

Lines changed: 52 additions & 12 deletions

File tree

composeApp/src/androidMain/kotlin/com/github/familyvault/backend/client/PrivMxClient.android.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class PrivMxClient : IPrivMxClient, AutoCloseable {
8383

8484
override fun disconnect() {
8585
connection?.unregisterAll()
86-
container.disconnectAll()
86+
connection?.close()
8787
}
8888

8989
override fun createThread(

composeApp/src/commonMain/composeResources/values-en/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,5 @@
230230
<string name="connection_checking">Checking connection</string>
231231
<string name="connection_ok">Valid FamilyVault server</string>
232232
<string name="connection_failed">Connection test failed</string>
233-
233+
<string name="self_hosting_infobox_content">Click here to learn more about your own FamilyVault server.</string>
234234
</resources>

composeApp/src/commonMain/composeResources/values-pl/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,5 @@
230230
<string name="connection_checking">Sprawdzam połączenie</string>
231231
<string name="connection_ok">Poprawny serwer FamilyVault</string>
232232
<string name="connection_failed">Nieudany test połączenia</string>
233+
<string name="self_hosting_infobox_content">Kliknij tutaj, aby dowiedzieć się więcej o własnym serwerze FamilyVault.</string>
233234
</resources>

composeApp/src/commonMain/kotlin/com/github/familyvault/DI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ val sharedModules = module {
7979
get(),
8080
)
8181
}.bind<IFamilyGroupService>()
82-
single { JoinStatusService() }.bind<IJoinStatusService>()
82+
single { JoinStatusService(get()) }.bind<IJoinStatusService>()
8383
single {
8484
ChatService(
8585
get(),

composeApp/src/commonMain/kotlin/com/github/familyvault/models/FamilyGroupSession.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.familyvault.models
22

33
data class FamilyGroupSession(
44
var bridgeUrl: String,
5+
var backendUrl: String?,
56
val familyGroupName: String,
67
var solutionId: String,
78
var contextId: String,

composeApp/src/commonMain/kotlin/com/github/familyvault/services/FamilyGroupService.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.familyvault.services
22

3-
import com.github.familyvault.AppConfig
43
import com.github.familyvault.backend.client.IFamilyVaultBackendClient
54
import com.github.familyvault.backend.client.IPrivMxClient
65
import com.github.familyvault.backend.exceptions.FamilyVaultBackendNoConnectionException
@@ -61,6 +60,7 @@ class FamilyGroupService(
6160

6261
familyGroupSessionService.assignSession(
6362
familyVaultBackendClient.getBridgeUrl().bridgeUrl,
63+
selfHostedAddressState.get(),
6464
familyGroupName,
6565
solutionId,
6666
contextId,
@@ -96,6 +96,7 @@ class FamilyGroupService(
9696

9797
familyGroupSessionService.assignSession(
9898
familyVaultBackendClient.getBridgeUrl().bridgeUrl,
99+
selfHostedAddressState.get(),
99100
familyGroupInformation.familyGroupName,
100101
solutionId,
101102
contextId,
@@ -118,8 +119,15 @@ class FamilyGroupService(
118119
val credential = familyGroupCredentialsRepository.getDefaultCredential()
119120
?: return ConnectionStatus.NoCredentials
120121

122+
if (credential.backendUrl != null) {
123+
familyVaultBackendClient.setCustomBackendUrl(credential.backendUrl)
124+
} else {
125+
familyVaultBackendClient.removeCustomBackendUrl()
126+
}
127+
121128
val familyGroupInformation: GetFamilyGroupNameResponse
122129

130+
123131
try {
124132
familyGroupInformation =
125133
familyVaultBackendClient.getFamilyGroupName(GetFamilyGroupNameRequest(credential.contextId))
@@ -129,6 +137,7 @@ class FamilyGroupService(
129137

130138
familyGroupSessionService.assignSession(
131139
familyVaultBackendClient.getBridgeUrl().bridgeUrl,
140+
credential.backendUrl,
132141
familyGroupInformation.familyGroupName,
133142
credential.solutionId,
134143
credential.contextId,

composeApp/src/commonMain/kotlin/com/github/familyvault/services/FamilyGroupSessionService.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class FamilyGroupSessionService(
2222
override suspend fun assignSession(familyGroupCredential: FamilyGroupCredential) {
2323
assignSession(
2424
familyVaultBackendClient.getBridgeUrl().bridgeUrl,
25+
familyGroupCredential.backendUrl,
2526
familyGroupCredential.familyGroupName,
2627
familyGroupCredential.solutionId,
2728
familyGroupCredential.contextId,
@@ -34,13 +35,14 @@ class FamilyGroupSessionService(
3435

3536
override fun assignSession(
3637
bridgeUrl: String,
38+
backendUrl: String?,
3739
familyGroupName: String,
3840
solutionId: String,
3941
contextId: String,
4042
keyPair: PublicEncryptedPrivateKeyPair
4143
) {
4244
session = FamilyGroupSession(
43-
bridgeUrl, familyGroupName, solutionId, contextId, PublicPrivateKeyPair(
45+
bridgeUrl, backendUrl, familyGroupName, solutionId, contextId, PublicPrivateKeyPair(
4446
keyPair.publicKey,
4547
privMxClient.decryptPrivateKeyPassword(keyPair.encryptedPrivateKey)
4648
)
@@ -50,8 +52,13 @@ class FamilyGroupSessionService(
5052
override suspend fun connect(): ConnectionStatus {
5153
requireNotNull(session)
5254
try {
55+
if (session?.backendUrl != null) {
56+
familyVaultBackendClient.setCustomBackendUrl(requireNotNull(session?.backendUrl))
57+
} else {
58+
familyVaultBackendClient.removeCustomBackendUrl()
59+
}
5360
privMxClient.establishConnection(
54-
getBridgeUrl(), getSolutionId(), getPrivateKey()
61+
familyVaultBackendClient.getBridgeUrl().bridgeUrl, getSolutionId(), getPrivateKey()
5562
)
5663
currentUser = familyVaultBackendClient.getMemberFromFamilyGroup(
5764
GetMemberFromFamilyGroupRequest(

composeApp/src/commonMain/kotlin/com/github/familyvault/services/IFamilyGroupSessionService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface IFamilyGroupSessionService {
1111
)
1212
fun assignSession(
1313
bridgeUrl: String,
14+
backendUrl: String?,
1415
familyGroupName: String,
1516
solutionId: String,
1617
contextId: String,

composeApp/src/commonMain/kotlin/com/github/familyvault/services/JoinStatusService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.github.familyvault.models.JoinStatusInfo
99
import com.github.familyvault.models.enums.JoinStatusState
1010
import kotlinx.coroutines.delay
1111

12-
class JoinStatusService : IJoinStatusService {
13-
private val familyVaultBackendProxy = FamilyVaultBackendClient()
12+
class JoinStatusService(private val familyVaultBackendProxy: FamilyVaultBackendClient) :
13+
IJoinStatusService {
1414

1515
override suspend fun generateJoinStatus(): JoinStatus {
1616
return familyVaultBackendProxy.generateJoinStatus().joinStatus

composeApp/src/commonMain/kotlin/com/github/familyvault/ui/screens/main/ChangeFamilyGroupScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ChangeFamilyGroupScreen : Screen {
9696
Column {
9797
familyGroups.map {
9898
val isCurrentFamilyGroup =
99-
it.contextId == currentContextId && it.memberPublicKey == currentMemberPublicKey
99+
it.contextId == currentContextId && it.memberPublicKey == currentMemberPublicKey
100100

101101
FamilyGroupEntry(
102102
it,

0 commit comments

Comments
 (0)