Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,6 @@ class ConversationsListActivity : BaseActivity() {
conversationsListViewModel.readUnreadState.collect { state ->
when (state) {
is ConversationsListViewModel.ConversationReadUnreadUiState.Success -> {
fetchRooms()
val resId = if (state.isMarkedRead) R.string.marked_as_read else R.string.marked_as_unread
showSnackbar(String.format(resources.getString(resId), state.conversationDisplayName))
conversationsListViewModel.resetReadUnreadState()
}
is ConversationsListViewModel.ConversationReadUnreadUiState.Error -> {
Expand All @@ -475,6 +472,21 @@ class ConversationsListActivity : BaseActivity() {
}
}
}

lifecycleScope.launch {
conversationsListViewModel.favoriteState.collect { state ->
when (state) {
is ConversationsListViewModel.FavoriteUiState.Success -> {
conversationsListViewModel.resetFavoriteState()
}
is ConversationsListViewModel.FavoriteUiState.Error -> {
showSnackbar(resources.getString(R.string.nc_common_error_sorry))
conversationsListViewModel.resetFavoriteState()
}
ConversationsListViewModel.FavoriteUiState.None -> { /* no-op */ }
}
}
}
}

private fun handleNoteToSelfShortcut(noteToSelfAvailable: Boolean, noteToSelfToken: String) {
Expand Down Expand Up @@ -1096,38 +1108,12 @@ class ConversationsListActivity : BaseActivity() {
}
}

@Suppress("Detekt.TooGenericExceptionCaught", "TooGenericExceptionCaught")
private fun addConversationToFavorites(conversation: ConversationModel) {
val apiVersion = ApiUtils.getConversationApiVersion(currentUser!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser?.baseUrl!!, conversation.token)
lifecycleScope.launch {
try {
withContext(Dispatchers.IO) { ncApiCoroutines.addConversationToFavorites(credentials!!, url) }
fetchRooms()
showSnackbar(
String.format(resources.getString(R.string.added_to_favorites), conversation.displayName)
)
} catch (e: Exception) {
showSnackbar(resources.getString(R.string.nc_common_error_sorry))
}
}
conversationsListViewModel.addConversationToFavorites(conversation)
}

@Suppress("Detekt.TooGenericExceptionCaught", "TooGenericExceptionCaught")
private fun removeConversationFromFavorites(conversation: ConversationModel) {
val apiVersion = ApiUtils.getConversationApiVersion(currentUser!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V1))
val url = ApiUtils.getUrlForRoomFavorite(apiVersion, currentUser?.baseUrl!!, conversation.token)
lifecycleScope.launch {
try {
withContext(Dispatchers.IO) { ncApiCoroutines.removeConversationFromFavorites(credentials!!, url) }
fetchRooms()
showSnackbar(
String.format(resources.getString(R.string.removed_from_favorites), conversation.displayName)
)
} catch (e: Exception) {
showSnackbar(resources.getString(R.string.nc_common_error_sorry))
}
}
conversationsListViewModel.removeConversationFromFavorites(conversation)
}

private fun markConversationAsUnread(conversation: ConversationModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface OfflineConversationsRepository {

suspend fun updateConversation(conversationModel: ConversationModel)

suspend fun updateConversationLocallyAndEmit(user: User, conversation: ConversationModel)

@Deprecated("use observeConversation")
suspend fun getLocallyStoredConversation(user: User, roomToken: String): ConversationModel?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class OfflineFirstConversationsRepository @Inject constructor(
dao.updateConversation(entity)
}

override suspend fun updateConversationLocallyAndEmit(user: User, conversation: ConversationModel) {
dao.updateConversation(conversation.asEntity())
val updatedList = getListOfConversations(user.id!!)
_roomListFlow.emit(updatedList)
}

override suspend fun getLocallyStoredConversation(user: User, roomToken: String): ConversationModel? {
val id = user.id!!
return getConversation(id, roomToken)
Expand Down
Loading
Loading