Skip to content

Commit 2fd54cc

Browse files
committed
fix(social): Resolve compilation errors, fix device verification, profile loading, thread-safety, and timeline subscription GC
1 parent f54967d commit 2fd54cc

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

app/src/main/kotlin/urstark/solstice/ui/screens/social/ChatScreen.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fun ChatScreen(
117117
}
118118

119119
DisposableEffect(roomId) {
120-
var taskHandle: org.matrix.rustcomponents.sdk.TaskHandle? = null
120+
var timelineListenerResult: Any? = null
121121
val client = viewModel.matrixManager.client
122122
if (client != null) {
123123
scope.launch {
@@ -134,7 +134,7 @@ fun ChatScreen(
134134
val t = r.timeline()
135135
timeline = t
136136

137-
t.addListener(object : TimelineListener {
137+
val listenerResult = t.addListener(object : TimelineListener {
138138
override fun onUpdate(diffs: List<TimelineDiff>) {
139139
for (diff in diffs) {
140140
when (diff.change()) {
@@ -165,14 +165,25 @@ fun ChatScreen(
165165
}
166166
}
167167
})
168+
timelineListenerResult = listenerResult
168169
}
169170
} catch (e: Exception) {
170171
e.printStackTrace()
171172
}
172173
}
173174
}
174175
onDispose {
175-
taskHandle?.cancel()
176+
try {
177+
val methods = timelineListenerResult?.javaClass?.methods ?: emptyArray()
178+
val getStreamMethod = methods.find {
179+
it.name == "getItemsStream" || it.name == "getTaskHandle" ||
180+
it.name == "itemsStream" || it.name == "taskHandle"
181+
}
182+
val handle = getStreamMethod?.invoke(timelineListenerResult) as? org.matrix.rustcomponents.sdk.TaskHandle
183+
handle?.cancel()
184+
} catch (e: Exception) {
185+
e.printStackTrace()
186+
}
176187
scope.launch {
177188
try {
178189
room?.typingNotice(false)

app/src/main/kotlin/urstark/solstice/ui/screens/social/NewChatScreen.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import androidx.compose.ui.unit.sp
2121
import androidx.hilt.navigation.compose.hiltViewModel
2222
import androidx.navigation.NavController
2323
import kotlinx.coroutines.launch
24+
import kotlinx.coroutines.withContext
25+
import kotlinx.coroutines.Dispatchers
2426
import org.matrix.rustcomponents.sdk.CreateRoomParameters
2527
import org.matrix.rustcomponents.sdk.RoomPreset
2628
import org.matrix.rustcomponents.sdk.RoomVisibility
@@ -220,7 +222,9 @@ fun NewChatScreen(
220222
avatar = null,
221223
powerLevelContentOverride = null
222224
)
223-
val roomId = client.createRoom(params)
225+
val roomId = withContext(Dispatchers.IO) {
226+
client.createRoom(params)
227+
}
224228
navController.navigate("chat/$roomId") {
225229
popUpTo("social")
226230
}

app/src/main/kotlin/urstark/solstice/ui/screens/social/SocialViewModel.kt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,26 @@ class SocialViewModel @Inject constructor(
200200
viewModelScope.launch {
201201
_isLoadingSettings.value = true
202202
try {
203-
_devices.value = matrixRestApiClient.getDevices(client)
204-
_pushRules.value = matrixRestApiClient.getPushRules(client)
205-
_threePids.value = matrixRestApiClient.get3PIDs(client)
206-
207-
loadIgnoredUsers(client)
203+
try {
204+
_devices.value = matrixRestApiClient.getDevices(client)
205+
} catch (e: Exception) {
206+
e.printStackTrace()
207+
}
208+
try {
209+
_pushRules.value = matrixRestApiClient.getPushRules(client)
210+
} catch (e: Exception) {
211+
e.printStackTrace()
212+
}
213+
try {
214+
_threePids.value = matrixRestApiClient.get3PIDs(client)
215+
} catch (e: Exception) {
216+
e.printStackTrace()
217+
}
218+
try {
219+
loadIgnoredUsers(client)
220+
} catch (e: Exception) {
221+
e.printStackTrace()
222+
}
208223

209224
try {
210225
val notifSettings = client.getNotificationSettings()

0 commit comments

Comments
 (0)