mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-12-18 14:42:16 +03:00
WIP add temporary message
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
de405d57c3
commit
f108dd146c
3 changed files with 92 additions and 0 deletions
|
@ -87,5 +87,12 @@ interface ChatMessageRepository : LifecycleAwareManager {
|
|||
referenceId: String
|
||||
): Flow<Result<ChatOverallSingleMessage>>
|
||||
|
||||
suspend fun addTemporaryMessage(
|
||||
message: CharSequence,
|
||||
displayName: String,
|
||||
replyTo: Int,
|
||||
referenceId: String
|
||||
): Flow<Result<ChatOverallSingleMessage>>
|
||||
|
||||
suspend fun editChatMessage(credentials: String, url: String, text: String): Flow<Result<ChatOverallSingleMessage>>
|
||||
}
|
||||
|
|
|
@ -785,6 +785,75 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun addTemporaryMessage(
|
||||
message: CharSequence,
|
||||
displayName: String,
|
||||
replyTo: Int,
|
||||
referenceId: String
|
||||
): Flow<Result<ChatOverallSingleMessage>> =
|
||||
flow {
|
||||
try {
|
||||
val tempChatMessageEntity = createChatMessageEntity(internalConversationId, message.toString())
|
||||
// accessing internalConversationId creates UninitializedPropertyException because ChatViewModel and
|
||||
// MessageInputViewModel use different instances of ChatRepository for now
|
||||
|
||||
|
||||
chatDao.upsertChatMessage(tempChatMessageEntity)
|
||||
|
||||
val tempChatMessageModel = tempChatMessageEntity.asModel()
|
||||
|
||||
// emit(Result.success(response))
|
||||
|
||||
val triple = Triple(false, false, listOf(tempChatMessageModel))
|
||||
_messageFlow.emit(triple)
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Something went wrong when adding temporary message", e)
|
||||
emit(Result.failure(e))
|
||||
}
|
||||
}
|
||||
|
||||
private fun createChatMessageEntity(internalConversationId: String, message: String): ChatMessageEntity {
|
||||
// val id = chatMessageCounter++
|
||||
|
||||
val emoji1 = "\uD83D\uDE00" // 😀
|
||||
val emoji2 = "\uD83D\uDE1C" // 😜
|
||||
val reactions = LinkedHashMap<String, Int>()
|
||||
reactions[emoji1] = 3
|
||||
reactions[emoji2] = 4
|
||||
|
||||
val reactionsSelf = ArrayList<String>()
|
||||
reactionsSelf.add(emoji1)
|
||||
|
||||
val entity = ChatMessageEntity(
|
||||
internalId = internalConversationId + "_temp1",
|
||||
internalConversationId = internalConversationId,
|
||||
id = 111111111,
|
||||
message = message,
|
||||
reactions = reactions,
|
||||
reactionsSelf = reactionsSelf,
|
||||
deleted = false,
|
||||
token = "",
|
||||
actorId = "",
|
||||
actorType = "",
|
||||
accountId = 1,
|
||||
messageParameters = null,
|
||||
messageType = "",
|
||||
parentMessageId = null,
|
||||
systemMessageType = ChatMessage.SystemMessageType.DUMMY,
|
||||
replyable = false,
|
||||
timestamp = 0,
|
||||
expirationTimestamp = 0,
|
||||
actorDisplayName = "",
|
||||
lastEditActorType = null,
|
||||
lastEditTimestamp = null,
|
||||
renderMarkdown = true,
|
||||
lastEditActorId = "",
|
||||
lastEditActorDisplayName = ""
|
||||
)
|
||||
return entity
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG = OfflineFirstChatRepository::class.simpleName
|
||||
private const val HTTP_CODE_OK: Int = 200
|
||||
|
|
|
@ -150,6 +150,22 @@ class MessageInputViewModel @Inject constructor(
|
|||
val referenceId = SendMessageUtils().generateReferenceId()
|
||||
Log.d(TAG, "Random SHA-256 Hash: $referenceId")
|
||||
|
||||
viewModelScope.launch {
|
||||
chatRepository.addTemporaryMessage(
|
||||
message,
|
||||
displayName,
|
||||
replyTo,
|
||||
referenceId
|
||||
).collect { result ->
|
||||
if (result.isSuccess) {
|
||||
Log.d(TAG, "bbbb")
|
||||
} else {
|
||||
Log.d(TAG, "xxxx")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isQueueing) {
|
||||
val tempID = System.currentTimeMillis().toInt()
|
||||
val qMsg = QueuedMessage(tempID, message, displayName, replyTo, sendWithoutNotification)
|
||||
|
|
Loading…
Reference in a new issue