Вторая часть по кэшу
This commit is contained in:
@@ -26,7 +26,8 @@ class ChatSyncWorker @AssistedInject constructor(
|
||||
@Assisted params: WorkerParameters,
|
||||
private val chatDao: ChatDao,
|
||||
private val messageDao: MessageDao,
|
||||
private val chatApi: chats.data.remote.api.ChatApi
|
||||
private val chatApi: chats.data.remote.api.ChatApi,
|
||||
private val tokenManager: TokenManager
|
||||
) : CoroutineWorker(context, params) {
|
||||
|
||||
companion object {
|
||||
@@ -106,6 +107,11 @@ class ChatSyncWorker @AssistedInject constructor(
|
||||
|
||||
remoteChats.forEach { dto ->
|
||||
val existingChat = chatDao.getChatByRemoteId(dto.id)
|
||||
val lastMessage = dto.messages.firstOrNull()
|
||||
val timestamp = lastMessage?.createdAt?.let {
|
||||
try { java.time.ZonedDateTime.parse(it).toInstant().toEpochMilli() }
|
||||
catch (e: Exception) { null }
|
||||
}
|
||||
val chatEntity = chats.data.local.database.ChatEntity(
|
||||
localId = existingChat?.localId ?: java.util.UUID.randomUUID().toString(),
|
||||
remoteId = dto.id,
|
||||
@@ -113,8 +119,8 @@ class ChatSyncWorker @AssistedInject constructor(
|
||||
name = dto.name ?: "",
|
||||
avatar = dto.avatar,
|
||||
unreadCount = dto.unreadCount,
|
||||
lastMessageText = dto.messages.firstOrNull()?.content,
|
||||
lastMessageTimestamp = dto.messages.firstOrNull()?.createdAt
|
||||
lastMessageText = lastMessage?.content,
|
||||
lastMessageTimestamp = timestamp
|
||||
)
|
||||
localChats.add(chatEntity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user