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