mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 04:29:45 +01:00
Update various things
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
ca4998614c
commit
88647c82bf
@ -46,7 +46,7 @@ android {
|
||||
targetSdkVersion 29
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
versionCode 120
|
||||
versionCode 130
|
||||
versionName "8.0.0alpha1"
|
||||
|
||||
flavorDimensions "default"
|
||||
|
@ -21,6 +21,7 @@
|
||||
package com.nextcloud.talk.newarch.data.repository.offline
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import androidx.lifecycle.map
|
||||
import com.nextcloud.talk.models.json.conversations.Conversation
|
||||
import com.nextcloud.talk.newarch.domain.repository.offline.ConversationsRepository
|
||||
@ -57,13 +58,14 @@ class ConversationsRepositoryImpl(val conversationsDao: ConversationsDao) :
|
||||
}
|
||||
|
||||
override fun getConversationsForUser(userId: Long): LiveData<List<Conversation>> {
|
||||
return conversationsDao
|
||||
return Transformations.distinctUntilChanged(conversationsDao
|
||||
.getConversationsForUser(userId)
|
||||
.map { data ->
|
||||
data.map {
|
||||
it.toConversation()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun clearConversationsForUser(userId: Long) {
|
||||
@ -75,12 +77,14 @@ class ConversationsRepositoryImpl(val conversationsDao: ConversationsDao) :
|
||||
userId: Long,
|
||||
conversations: List<Conversation>
|
||||
) {
|
||||
val map = conversations.map {
|
||||
it.toConversationEntity()
|
||||
}
|
||||
|
||||
conversationsDao
|
||||
.updateConversationsForUser(
|
||||
userId,
|
||||
conversations.map {
|
||||
it.toConversationEntity()
|
||||
}.toTypedArray()
|
||||
map.toTypedArray()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ import com.nextcloud.talk.newarch.local.dao.MessagesDao
|
||||
|
||||
class MessagesRepositoryImpl(val messagesDao: MessagesDao): MessagesRepository {
|
||||
override fun getMessagesWithUserForConversation(
|
||||
userId: Int,
|
||||
conversationId: String
|
||||
): LiveData<List<ChatMessage>> {
|
||||
TODO(
|
||||
|
@ -24,6 +24,6 @@ import androidx.lifecycle.LiveData
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage
|
||||
|
||||
interface MessagesRepository {
|
||||
fun getMessagesWithUserForConversation(userId: Int, conversationId: String): LiveData<List<ChatMessage>>
|
||||
fun getMessagesWithUserForConversation(conversationId: String): LiveData<List<ChatMessage>>
|
||||
|
||||
}
|
@ -81,7 +81,6 @@ import kotlinx.android.synthetic.main.view_states.view.errorStateImageView
|
||||
import kotlinx.android.synthetic.main.view_states.view.errorStateTextView
|
||||
import kotlinx.android.synthetic.main.view_states.view.loadingStateView
|
||||
import kotlinx.android.synthetic.main.view_states.view.stateWithMessageView
|
||||
import org.apache.commons.lang3.builder.CompareToBuilder
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.parceler.Parcels
|
||||
import java.util.ArrayList
|
||||
@ -281,17 +280,9 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
} else {
|
||||
viewState.value = LOADED
|
||||
}
|
||||
val sortedConversationsList = it.toMutableList()
|
||||
|
||||
sortedConversationsList.sortWith(Comparator { conversation1, conversation2 ->
|
||||
CompareToBuilder()
|
||||
.append(conversation2.favorite, conversation1.favorite)
|
||||
.append(conversation2.lastActivity, conversation1.lastActivity)
|
||||
.toComparison()
|
||||
})
|
||||
|
||||
val newConversations = mutableListOf<ConversationItem>()
|
||||
for (conversation in sortedConversationsList) {
|
||||
for (conversation in it) {
|
||||
newConversations.add(
|
||||
ConversationItem(
|
||||
conversation, viewModel.currentUserLiveData.value!!,
|
||||
@ -447,12 +438,12 @@ class ConversationsListView : BaseView(), OnQueryTextListener,
|
||||
val conversation = (clickedItem as ConversationItem).model
|
||||
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(viewModel.currentUserLiveData.value))
|
||||
bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, viewModel.currentUserLiveData.value)
|
||||
bundle.putString(BundleKeys.KEY_ROOM_TOKEN, conversation.token)
|
||||
bundle.putString(BundleKeys.KEY_ROOM_ID, conversation.conversationId)
|
||||
bundle.putParcelable(BundleKeys.KEY_ACTIVE_CONVERSATION, Parcels.wrap(conversation))
|
||||
ConductorRemapping.remapChatController(
|
||||
router, viewModel.currentUserLiveData.value!!.id!!, conversation.token!!,
|
||||
router, viewModel.currentUserLiveData.value!!.id, conversation.token!!,
|
||||
bundle, false
|
||||
)
|
||||
}
|
||||
|
@ -62,8 +62,11 @@ class ConversationsListViewModel constructor(
|
||||
val viewState = MutableLiveData(LOADING)
|
||||
var messageData: String? = null
|
||||
val searchQuery = MutableLiveData<String>()
|
||||
val currentUserLiveData = usersRepository.getActiveUserLiveData()
|
||||
val currentUserLiveData: LiveData<UserNgEntity> = usersRepository.getActiveUserLiveData()
|
||||
val conversationsLiveData = Transformations.switchMap(currentUserLiveData) {
|
||||
if (!LOADING.equals(viewState.value)) {
|
||||
viewState.value = LOADING
|
||||
}
|
||||
conversationsRepository.getConversationsForUser(it.id)
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,11 @@ import com.nextcloud.talk.newarch.local.models.ConversationEntity
|
||||
|
||||
@Dao
|
||||
abstract class ConversationsDao {
|
||||
@Query("SELECT * FROM conversations WHERE id = :userId")
|
||||
|
||||
@Query("SELECT * FROM conversations WHERE user = :userId ORDER BY favorite DESC, last_activity DESC")
|
||||
abstract fun getConversationsForUser(userId: Long): LiveData<List<ConversationEntity>>
|
||||
|
||||
@Query("DELETE FROM conversations WHERE id = :userId")
|
||||
@Query("DELETE FROM conversations WHERE user = :userId")
|
||||
abstract suspend fun clearConversationsForUser(userId: Long)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
@ -50,7 +51,7 @@ abstract class ConversationsDao {
|
||||
abstract suspend fun saveConversations(vararg conversations: ConversationEntity)
|
||||
|
||||
@Query(
|
||||
"UPDATE conversations SET changing = :changing WHERE id = :userId AND conversation_id = :conversationId"
|
||||
"UPDATE conversations SET changing = :changing WHERE user = :userId AND conversation_id = :conversationId"
|
||||
)
|
||||
abstract suspend fun updateChangingValueForConversation(
|
||||
userId: Long,
|
||||
@ -59,7 +60,7 @@ abstract class ConversationsDao {
|
||||
)
|
||||
|
||||
@Query(
|
||||
"UPDATE conversations SET favorite = :favorite, changing = 0 WHERE id = :userId AND conversation_id = :conversationId"
|
||||
"UPDATE conversations SET favorite = :favorite, changing = 0 WHERE user = :userId AND conversation_id = :conversationId"
|
||||
)
|
||||
abstract suspend fun updateFavoriteValueForConversation(
|
||||
userId: Long,
|
||||
@ -67,7 +68,7 @@ abstract class ConversationsDao {
|
||||
favorite: Boolean
|
||||
)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE id = :userId AND conversation_id = :conversationId")
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND conversation_id = :conversationId")
|
||||
abstract suspend fun deleteConversation(
|
||||
userId: Long,
|
||||
conversationId: String
|
||||
@ -76,7 +77,7 @@ abstract class ConversationsDao {
|
||||
@Delete
|
||||
abstract suspend fun deleteConversations(vararg conversation: ConversationEntity)
|
||||
|
||||
@Query("DELETE FROM conversations WHERE id = :userId AND modified_at < :timestamp")
|
||||
@Query("DELETE FROM conversations WHERE user = :userId AND modified_at < :timestamp")
|
||||
abstract suspend fun deleteConversationsForUserWithTimestamp(
|
||||
userId: Long,
|
||||
timestamp: Long
|
||||
@ -94,9 +95,8 @@ abstract class ConversationsDao {
|
||||
it.modifiedAt = System.currentTimeMillis()
|
||||
it
|
||||
}
|
||||
.toTypedArray()
|
||||
|
||||
saveConversations(*conversationsWithTimestampApplied)
|
||||
saveConversations(*conversationsWithTimestampApplied.toTypedArray())
|
||||
deleteConversationsForUserWithTimestamp(userId, timestamp)
|
||||
}
|
||||
}
|
@ -29,8 +29,9 @@ import com.nextcloud.talk.newarch.local.models.MessageEntity
|
||||
|
||||
@Dao
|
||||
abstract class MessagesDao {
|
||||
@Query("SELECT * FROM messages WHERE id = :userId AND conversation = :conversationId")
|
||||
abstract fun getMessagesWithUserForConversation(userId: Long, conversationId: String): LiveData<List<MessageEntity>>
|
||||
@Query("SELECT * FROM messages WHERE conversation = :conversationId")
|
||||
abstract fun getMessagesWithUserForConversation(conversationId: String):
|
||||
LiveData<List<MessageEntity>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract suspend fun saveMessages(vararg messages: MessageEntity)
|
||||
|
@ -48,9 +48,9 @@ import java.util.HashMap
|
||||
)]
|
||||
)
|
||||
data class ConversationEntity(
|
||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") var id: Long? = 0,
|
||||
@ColumnInfo(name = "user") var user: Long?,
|
||||
@ColumnInfo(name = "conversation_id") var conversationId: String?,
|
||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") var id: Long? = null,
|
||||
@ColumnInfo(name = "user") var user: Long? = null,
|
||||
@ColumnInfo(name = "conversation_id") var conversationId: String? = null,
|
||||
@ColumnInfo(name = "token") var token: String? = null,
|
||||
@ColumnInfo(name = "name") var name: String? = null,
|
||||
@ColumnInfo(name = "display_name") var displayName: String? = null,
|
||||
@ -117,7 +117,9 @@ fun ConversationEntity.toConversation(): Conversation {
|
||||
}
|
||||
|
||||
fun Conversation.toConversationEntity(): ConversationEntity {
|
||||
val conversationEntity = ConversationEntity(null, this.internalUserId, this.conversationId)
|
||||
val conversationEntity = ConversationEntity()
|
||||
conversationEntity.user = this.internalUserId
|
||||
conversationEntity.conversationId = this.conversationId
|
||||
conversationEntity.token = this.token
|
||||
conversationEntity.name = this.name
|
||||
conversationEntity.displayName = this.displayName
|
||||
|
Loading…
Reference in New Issue
Block a user