WIP Abstracting away ChatMessage to ChatMessageJson and ChatMessageEntity, need to iron out some quirks

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2024-05-22 10:14:55 -05:00
parent 68681b50de
commit 881552357e
No known key found for this signature in database
GPG Key ID: 3AA5FDFED7944099
12 changed files with 113 additions and 78 deletions

View File

@ -137,6 +137,7 @@ import com.nextcloud.talk.adapters.messages.VoiceMessageInterface
import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.callbacks.MentionAutocompleteCallback import com.nextcloud.talk.callbacks.MentionAutocompleteCallback
import com.nextcloud.talk.chat.data.utils.ChatMessageDataMapper
import com.nextcloud.talk.chat.viewmodels.ChatViewModel import com.nextcloud.talk.chat.viewmodels.ChatViewModel
import com.nextcloud.talk.conversationinfo.ConversationInfoActivity import com.nextcloud.talk.conversationinfo.ConversationInfoActivity
import com.nextcloud.talk.conversationlist.ConversationsListActivity import com.nextcloud.talk.conversationlist.ConversationsListActivity
@ -610,10 +611,10 @@ class ChatActivity :
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
if (currentlyPlayedVoiceMessage != null) { if (currentlyPlayedVoiceMessage != null) {
outState.putString(CURRENT_AUDIO_MESSAGE_KEY, currentlyPlayedVoiceMessage!!.getId()) outState.putString(CURRENT_AUDIO_MESSAGE_KEY, currentlyPlayedVoiceMessage!!.id)
outState.putInt(CURRENT_AUDIO_POSITION_KEY, currentlyPlayedVoiceMessage!!.voiceMessagePlayedSeconds) outState.putInt(CURRENT_AUDIO_POSITION_KEY, currentlyPlayedVoiceMessage!!.voiceMessagePlayedSeconds)
outState.putBoolean(CURRENT_AUDIO_WAS_PLAYING_KEY, currentlyPlayedVoiceMessage!!.isPlayingVoiceMessage) outState.putBoolean(CURRENT_AUDIO_WAS_PLAYING_KEY, currentlyPlayedVoiceMessage!!.isPlayingVoiceMessage)
Log.d(RESUME_AUDIO_TAG, "Stored current audio message ID: " + currentlyPlayedVoiceMessage!!.getId()) Log.d(RESUME_AUDIO_TAG, "Stored current audio message ID: " + currentlyPlayedVoiceMessage!!.id)
Log.d( Log.d(
RESUME_AUDIO_TAG, RESUME_AUDIO_TAG,
"Audio Position: " + currentlyPlayedVoiceMessage!!.voiceMessagePlayedSeconds "Audio Position: " + currentlyPlayedVoiceMessage!!.voiceMessagePlayedSeconds
@ -898,7 +899,11 @@ class ChatActivity :
HTTP_CODE_OK -> { HTTP_CODE_OK -> {
Log.d(TAG, "lookIntoFuture: ${state.lookIntoFuture}") Log.d(TAG, "lookIntoFuture: ${state.lookIntoFuture}")
val chatOverall = state.response.body() as ChatOverall? val chatOverall = state.response.body() as ChatOverall?
var chatMessageList = chatOverall?.ocs!!.data!! var chatMessageList = chatOverall?.ocs!!.data!!.map {
ChatMessageDataMapper.mapToMessage(
it
)
}
processHeaderChatLastGiven(state.response, state.lookIntoFuture) processHeaderChatLastGiven(state.response, state.lookIntoFuture)
@ -3946,7 +3951,7 @@ class ChatActivity :
} else { } else {
Log.d( Log.d(
RESUME_AUDIO_TAG, RESUME_AUDIO_TAG,
"voiceMessagePosition is -1, adapter # of items: " + adapter!!.getItemCount() "voiceMessagePosition is -1, adapter # of items: " + adapter!!.itemCount
) )
} }
} else { } else {
@ -4608,7 +4613,8 @@ class ChatActivity :
private fun showMicrophoneButton(show: Boolean) { private fun showMicrophoneButton(show: Boolean) {
if (show && CapabilitiesUtil.hasSpreedFeatureCapability( if (show && CapabilitiesUtil.hasSpreedFeatureCapability(
spreedCapabilities, SpreedFeatures.VOICE_MESSAGE_SHARING spreedCapabilities,
SpreedFeatures.VOICE_MESSAGE_SHARING
) )
) { ) {
Log.d(TAG, "Microphone shown") Log.d(TAG, "Microphone shown")

View File

@ -16,5 +16,5 @@ abstract class ChatDao {
@Query( @Query(
"SELECT * FROM Messages WHERE token = :roomToken" "SELECT * FROM Messages WHERE token = :roomToken"
) )
abstract fun pullChatMessages(roomToken: String): List<ChatMessageEntity> abstract fun getAllMessagesWhere(roomToken: String): List<ChatMessageEntity>
} }

View File

@ -54,7 +54,7 @@ data class ChatMessageEntity(
var replyable: Boolean = false, var replyable: Boolean = false,
@ColumnInfo(name = "parent") @ColumnInfo(name = "parent")
var parentMessage: ChatMessage? = null, var parentMessage: ChatMessage? = null, // FIXME figure this out, might replace w/ parent id
@ColumnInfo(name = "messageType") @ColumnInfo(name = "messageType")
var messageType: String? = null, var messageType: String? = null,

View File

@ -14,7 +14,6 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
// TODO map it to ChatMessage
@Parcelize @Parcelize
@JsonObject @JsonObject
data class ChatMessageJson( data class ChatMessageJson(
@ -52,7 +51,7 @@ data class ChatMessageJson(
var replyable: Boolean = false, var replyable: Boolean = false,
@JsonField(name = ["parent"]) @JsonField(name = ["parent"])
var parentMessage: ChatMessage? = null, var parentMessage: ChatMessageJson? = null,
@JsonField(name = ["messageType"]) @JsonField(name = ["messageType"])
var messageType: String? = null, var messageType: String? = null,

View File

@ -0,0 +1,92 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2024 Julius Linus <juliuslinus1@gmail.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.chat.data.utils
import com.nextcloud.talk.chat.data.model.ChatMessageEntity
import com.nextcloud.talk.chat.data.model.ChatMessageJson
import com.nextcloud.talk.models.json.chat.ChatMessage
object ChatMessageDataMapper {
fun mapToMessage(msg: ChatMessageJson?): ChatMessage {
return msg?.let {
ChatMessage().apply {
jsonMessageId = msg.jsonMessageId
token = msg.token
actorType = msg.actorType
actorId = msg.actorId
actorDisplayName = msg.actorDisplayName
timestamp = msg.timestamp
message = msg.message
messageParameters = msg.messageParameters
systemMessageType = msg.systemMessageType
replyable = msg.replyable
parentMessage = mapToMessage(msg.parentMessage)
messageType = msg.messageType
reactions = msg.reactions
reactionsSelf = msg.reactionsSelf
expirationTimestamp = msg.expirationTimestamp
renderMarkdown = msg.renderMarkdown
lastEditActorDisplayName = msg.lastEditActorDisplayName
lastEditActorId = msg.lastEditActorId
lastEditActorType = msg.lastEditActorType
lastEditTimestamp = msg.lastEditTimestamp
}
} ?: ChatMessage()
}
fun mapToMessage(msg: ChatMessageEntity): ChatMessage {
return ChatMessage().apply {
jsonMessageId = msg.jsonMessageId
token = msg.token
actorType = msg.actorType
actorId = msg.actorId
actorDisplayName = msg.actorDisplayName
timestamp = msg.timestamp
message = msg.message
messageParameters = msg.messageParameters
systemMessageType = msg.systemMessageType
replyable = msg.replyable
parentMessage = msg.parentMessage
messageType = msg.messageType
reactions = msg.reactions
reactionsSelf = msg.reactionsSelf
expirationTimestamp = msg.expirationTimestamp
renderMarkdown = msg.renderMarkdown
lastEditActorDisplayName = msg.lastEditActorDisplayName
lastEditActorId = msg.lastEditActorId
lastEditActorType = msg.lastEditActorType
lastEditTimestamp = msg.lastEditTimestamp
}
}
fun mapToEntity(msg: ChatMessage): ChatMessageEntity {
return ChatMessageEntity().apply {
jsonMessageId = msg.jsonMessageId
token = msg.token
actorType = msg.actorType
actorId = msg.actorId
actorDisplayName = msg.actorDisplayName
timestamp = msg.timestamp
message = msg.message
messageParameters = msg.messageParameters
systemMessageType = msg.systemMessageType
replyable = msg.replyable
parentMessage = msg.parentMessage
messageType = msg.messageType
reactions = msg.reactions
reactionsSelf = msg.reactionsSelf
expirationTimestamp = msg.expirationTimestamp
renderMarkdown = msg.renderMarkdown
lastEditActorDisplayName = msg.lastEditActorDisplayName
lastEditActorId = msg.lastEditActorId
lastEditActorType = msg.lastEditActorType
lastEditTimestamp = msg.lastEditTimestamp
}
}
}

View File

@ -1,13 +0,0 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.chat.data.utils
class ChatMessageEntityMapper {
// TODO
}

View File

@ -1,13 +0,0 @@
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2024 Your Name <your@email.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.chat.data.utils
class ChatMessageJsonMapper {
// TODO
}

View File

@ -9,12 +9,8 @@
*/ */
package com.nextcloud.talk.models.json.chat package com.nextcloud.talk.models.json.chat
import android.os.Parcelable
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonIgnore
import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
@ -24,99 +20,67 @@ import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.CapabilitiesUtil import com.nextcloud.talk.utils.CapabilitiesUtil
import com.stfalcon.chatkit.commons.models.IUser import com.stfalcon.chatkit.commons.models.IUser
import com.stfalcon.chatkit.commons.models.MessageContentType import com.stfalcon.chatkit.commons.models.MessageContentType
import kotlinx.parcelize.Parcelize
import java.security.MessageDigest import java.security.MessageDigest
import java.util.Date import java.util.Date
// TODO remove all Json tags, map ChatMessageJson to this
@Parcelize
@JsonObject
data class ChatMessage( data class ChatMessage(
@JsonIgnore
var isGrouped: Boolean = false, var isGrouped: Boolean = false,
@JsonIgnore
var isOneToOneConversation: Boolean = false, var isOneToOneConversation: Boolean = false,
@JsonIgnore
var isFormerOneToOneConversation: Boolean = false, var isFormerOneToOneConversation: Boolean = false,
@JsonIgnore
var activeUser: User? = null, var activeUser: User? = null,
@JsonIgnore
var selectedIndividualHashMap: Map<String?, String?>? = null, var selectedIndividualHashMap: Map<String?, String?>? = null,
@JsonIgnore
var isDeleted: Boolean = false, var isDeleted: Boolean = false,
@JsonField(name = ["id"])
var jsonMessageId: Int = 0, var jsonMessageId: Int = 0,
@JsonIgnore
var previousMessageId: Int = -1, var previousMessageId: Int = -1,
@JsonField(name = ["token"])
var token: String? = null, var token: String? = null,
// guests or users // guests or users
@JsonField(name = ["actorType"])
var actorType: String? = null, var actorType: String? = null,
@JsonField(name = ["actorId"])
var actorId: String? = null, var actorId: String? = null,
// send when crafting a message // send when crafting a message
@JsonField(name = ["actorDisplayName"])
var actorDisplayName: String? = null, var actorDisplayName: String? = null,
@JsonField(name = ["timestamp"])
var timestamp: Long = 0, var timestamp: Long = 0,
// send when crafting a message, max 1000 lines // send when crafting a message, max 1000 lines
@JsonField(name = ["message"])
var message: String? = null, var message: String? = null,
@JsonField(name = ["messageParameters"])
var messageParameters: HashMap<String?, HashMap<String?, String?>>? = null, var messageParameters: HashMap<String?, HashMap<String?, String?>>? = null,
@JsonField(name = ["systemMessage"], typeConverter = EnumSystemMessageTypeConverter::class)
var systemMessageType: SystemMessageType? = null, var systemMessageType: SystemMessageType? = null,
@JsonField(name = ["isReplyable"])
var replyable: Boolean = false, var replyable: Boolean = false,
@JsonField(name = ["parent"])
var parentMessage: ChatMessage? = null, var parentMessage: ChatMessage? = null,
var readStatus: Enum<ReadStatus> = ReadStatus.NONE, var readStatus: Enum<ReadStatus> = ReadStatus.NONE,
@JsonField(name = ["messageType"])
var messageType: String? = null, var messageType: String? = null,
@JsonField(name = ["reactions"])
var reactions: LinkedHashMap<String, Int>? = null, var reactions: LinkedHashMap<String, Int>? = null,
@JsonField(name = ["reactionsSelf"])
var reactionsSelf: ArrayList<String>? = null, var reactionsSelf: ArrayList<String>? = null,
@JsonField(name = ["expirationTimestamp"])
var expirationTimestamp: Int = 0, var expirationTimestamp: Int = 0,
@JsonField(name = ["markdown"])
var renderMarkdown: Boolean? = null, var renderMarkdown: Boolean? = null,
@JsonField(name = ["lastEditActorDisplayName"])
var lastEditActorDisplayName: String? = null, var lastEditActorDisplayName: String? = null,
@JsonField(name = ["lastEditActorId"])
var lastEditActorId: String? = null, var lastEditActorId: String? = null,
@JsonField(name = ["lastEditActorType"])
var lastEditActorType: String? = null, var lastEditActorType: String? = null,
@JsonField(name = ["lastEditTimestamp"])
var lastEditTimestamp: Long = 0, var lastEditTimestamp: Long = 0,
var isDownloadingVoiceMessage: Boolean = false, var isDownloadingVoiceMessage: Boolean = false,
@ -147,12 +111,11 @@ data class ChatMessage(
var openWhenDownloaded: Boolean = true var openWhenDownloaded: Boolean = true
) : Parcelable, MessageContentType, MessageContentType.Image { ) : MessageContentType, MessageContentType.Image {
var extractedUrlToPreview: String? = null var extractedUrlToPreview: String? = null
// messageTypesToIgnore is weird. must be deleted by refactoring!!! // messageTypesToIgnore is weird. must be deleted by refactoring!!!
@JsonIgnore
var messageTypesToIgnore = listOf( var messageTypesToIgnore = listOf(
MessageType.REGULAR_TEXT_MESSAGE, MessageType.REGULAR_TEXT_MESSAGE,
MessageType.SYSTEM_MESSAGE, MessageType.SYSTEM_MESSAGE,

View File

@ -10,6 +10,7 @@ package com.nextcloud.talk.models.json.chat
import android.os.Parcelable import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.chat.data.model.ChatMessageJson
import com.nextcloud.talk.models.json.generic.GenericMeta import com.nextcloud.talk.models.json.generic.GenericMeta
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@ -19,7 +20,7 @@ data class ChatOCS(
@JsonField(name = ["meta"]) @JsonField(name = ["meta"])
var meta: GenericMeta?, var meta: GenericMeta?,
@JsonField(name = ["data"]) @JsonField(name = ["data"])
var data: List<ChatMessage>? = null var data: List<ChatMessageJson>? = null
) : Parcelable { ) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null, null) constructor() : this(null, null)

View File

@ -10,6 +10,7 @@ package com.nextcloud.talk.models.json.chat
import android.os.Parcelable import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.chat.data.model.ChatMessageJson
import com.nextcloud.talk.models.json.generic.GenericMeta import com.nextcloud.talk.models.json.generic.GenericMeta
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@ -19,7 +20,7 @@ data class ChatOCSSingleMessage(
@JsonField(name = ["meta"]) @JsonField(name = ["meta"])
var meta: GenericMeta?, var meta: GenericMeta?,
@JsonField(name = ["data"]) @JsonField(name = ["data"])
var data: ChatMessage? = null var data: ChatMessageJson? = null
) : Parcelable { ) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null, null) constructor() : this(null, null)

View File

@ -10,14 +10,13 @@ package com.nextcloud.talk.models.json.chat
import android.os.Parcelable import android.os.Parcelable
import com.bluelinelabs.logansquare.annotation.JsonField import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject import com.bluelinelabs.logansquare.annotation.JsonObject
import java.util.HashMap
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@Parcelize @Parcelize
@JsonObject @JsonObject
data class ChatShareOCS( data class ChatShareOCS(
@JsonField(name = ["data"]) @JsonField(name = ["data"])
var data: HashMap<String, ChatMessage>? = null var data: HashMap<String, ChatMessage>? = null // FIXME figure out where to map this from json to message
) : Parcelable { ) : Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null) constructor() : this(null)

View File

@ -68,7 +68,7 @@ data class Conversation(
var unreadMention: Boolean = false, var unreadMention: Boolean = false,
@JsonField(name = ["lastMessage"]) @JsonField(name = ["lastMessage"])
var lastMessage: ChatMessage? = null, var lastMessage: ChatMessage? = null, // FIXME here figure out where to map this from JSON to chatmessage
@JsonField(name = ["objectType"], typeConverter = ConversationObjectTypeConverter::class) @JsonField(name = ["objectType"], typeConverter = ConversationObjectTypeConverter::class)
var objectType: ObjectType? = null, var objectType: ObjectType? = null,