Skip to content

Commit 232736d

Browse files
refactor(conversations): collapse updateConversationLocallyAndEmit into updateConversation
Since roomListFlow observes the database, updateConversationLocallyAndEmit no longer emits anything itself - it became identical to updateConversation apart from an unused user parameter and a name promising a manual emission that no longer exists. Remove it, point all call sites at updateConversation, and refresh the interface docs that still described the manual-emission contract of getRooms and roomListFlow. Assisted-by: Claude Code:claude-fable-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 353c6e9 commit 232736d

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

app/src/main/java/com/nextcloud/talk/conversationlist/data/OfflineConversationsRepository.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import kotlinx.coroutines.flow.Flow
1616
interface OfflineConversationsRepository {
1717

1818
/**
19-
* Stream of a list of rooms, for use in the conversation list.
19+
* Live stream of the observed account's conversations, for use in the conversation list.
20+
* Backed by the local database: it re-emits whenever conversation rows change (room list
21+
* sync, background catch-up, optimistic updates), with unchanged lists deduplicated.
2022
*/
2123
val roomListFlow: Flow<List<ConversationModel>>
2224

@@ -27,10 +29,9 @@ interface OfflineConversationsRepository {
2729
val conversationFlow: Flow<ConversationModel>
2830

2931
/**
30-
* Loads rooms from local storage. If the rooms are not found, then it
31-
* synchronizes the database with the server, before retrying exactly once. Only
32-
* emits to [roomListFlow] if the rooms list is not empty.
33-
*
32+
* Selects the account observed by [roomListFlow] and synchronizes its conversations with
33+
* the server (when online). The synced changes surface through [roomListFlow], which
34+
* observes the database.
3435
*/
3536
@Deprecated("use observeConversation")
3637
fun getRooms(user: User): Job
@@ -42,10 +43,12 @@ interface OfflineConversationsRepository {
4243
@Deprecated("use observeConversation")
4344
fun getRoom(user: User, roomToken: String): Job
4445

46+
/**
47+
* Updates a single conversation in the local database. [roomListFlow] observes the database
48+
* and re-emits the updated list on its own.
49+
*/
4550
suspend fun updateConversation(conversationModel: ConversationModel)
4651

47-
suspend fun updateConversationLocallyAndEmit(user: User, conversation: ConversationModel)
48-
4952
@Deprecated("use observeConversation")
5053
suspend fun getLocallyStoredConversation(user: User, roomToken: String): ConversationModel?
5154

app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ class OfflineFirstConversationsRepository @Inject constructor(
154154
dao.updateConversation(entity)
155155
}
156156

157-
override suspend fun updateConversationLocallyAndEmit(user: User, conversation: ConversationModel) {
158-
dao.updateConversation(conversation.asEntity())
159-
}
160-
161157
override suspend fun getLocallyStoredConversation(user: User, roomToken: String): ConversationModel? {
162158
val id = user.id!!
163159
return getConversation(id, roomToken)

app/src/main/java/com/nextcloud/talk/conversationlist/viewmodels/ConversationsListViewModel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ class ConversationsListViewModel @Inject constructor(
715715
val url = ApiUtils.getUrlForChatReadMarker(apiVersion, currentUser.baseUrl, conversation.token)
716716
viewModelScope.launch {
717717
withContext(Dispatchers.IO) {
718-
repository.updateConversationLocallyAndEmit(currentUser, optimistic)
718+
repository.updateConversation(optimistic)
719719
}
720720
try {
721721
withContext(Dispatchers.IO) {
@@ -724,7 +724,7 @@ class ConversationsListViewModel @Inject constructor(
724724
_readUnreadState.value = ConversationReadUnreadUiState.Success
725725
} catch (e: Exception) {
726726
withContext(Dispatchers.IO) {
727-
repository.updateConversationLocallyAndEmit(currentUser, original)
727+
repository.updateConversation(original)
728728
}
729729
_readUnreadState.value = ConversationReadUnreadUiState.Error
730730
}
@@ -742,7 +742,7 @@ class ConversationsListViewModel @Inject constructor(
742742
val url = ApiUtils.getUrlForChatReadMarker(apiVersion, currentUser.baseUrl, conversation.token)
743743
viewModelScope.launch {
744744
withContext(Dispatchers.IO) {
745-
repository.updateConversationLocallyAndEmit(currentUser, optimistic)
745+
repository.updateConversation(optimistic)
746746
}
747747
try {
748748
withContext(Dispatchers.IO) {
@@ -751,7 +751,7 @@ class ConversationsListViewModel @Inject constructor(
751751
_readUnreadState.value = ConversationReadUnreadUiState.Success
752752
} catch (e: Exception) {
753753
withContext(Dispatchers.IO) {
754-
repository.updateConversationLocallyAndEmit(currentUser, original)
754+
repository.updateConversation(original)
755755
}
756756
_readUnreadState.value = ConversationReadUnreadUiState.Error
757757
}
@@ -770,7 +770,7 @@ class ConversationsListViewModel @Inject constructor(
770770
val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl, conversation.token)
771771
viewModelScope.launch {
772772
withContext(Dispatchers.IO) {
773-
repository.updateConversationLocallyAndEmit(currentUser, optimistic)
773+
repository.updateConversation(optimistic)
774774
}
775775
try {
776776
withContext(Dispatchers.IO) {
@@ -779,7 +779,7 @@ class ConversationsListViewModel @Inject constructor(
779779
_favoriteState.value = FavoriteUiState.Success
780780
} catch (e: Exception) {
781781
withContext(Dispatchers.IO) {
782-
repository.updateConversationLocallyAndEmit(currentUser, original)
782+
repository.updateConversation(original)
783783
}
784784
_favoriteState.value = FavoriteUiState.Error
785785
}
@@ -794,7 +794,7 @@ class ConversationsListViewModel @Inject constructor(
794794
val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser.baseUrl, conversation.token)
795795
viewModelScope.launch {
796796
withContext(Dispatchers.IO) {
797-
repository.updateConversationLocallyAndEmit(currentUser, optimistic)
797+
repository.updateConversation(optimistic)
798798
}
799799
try {
800800
withContext(Dispatchers.IO) {
@@ -803,7 +803,7 @@ class ConversationsListViewModel @Inject constructor(
803803
_favoriteState.value = FavoriteUiState.Success
804804
} catch (e: Exception) {
805805
withContext(Dispatchers.IO) {
806-
repository.updateConversationLocallyAndEmit(currentUser, original)
806+
repository.updateConversation(original)
807807
}
808808
_favoriteState.value = FavoriteUiState.Error
809809
}

app/src/main/java/com/nextcloud/talk/conversationtags/viewmodels/ConversationTagsViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class ConversationTagsViewModel @Inject constructor(
165165
replaceConversationForTagAssignment(conversation.token, optimistic)
166166
viewModelScope.launch {
167167
withContext(Dispatchers.IO) {
168-
repository.updateConversationLocallyAndEmit(currentUser, optimistic)
168+
repository.updateConversation(optimistic)
169169
}
170170
try {
171171
withContext(Dispatchers.IO) {
@@ -179,7 +179,7 @@ class ConversationTagsViewModel @Inject constructor(
179179
} catch (e: Exception) {
180180
replaceConversationForTagAssignment(conversation.token, original)
181181
withContext(Dispatchers.IO) {
182-
repository.updateConversationLocallyAndEmit(currentUser, original)
182+
repository.updateConversation(original)
183183
}
184184
Log.e(TAG, "Failed to assign conversation tags", e)
185185
}

0 commit comments

Comments
 (0)