Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/4378/add temporary messages while sending #4422

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
731 changes: 731 additions & 0 deletions app/schemas/com.nextcloud.talk.data.source.local.TalkDatabase/13.json

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions app/src/main/java/com/nextcloud/talk/api/NcApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,14 @@ Observable<Response<ChatOverall>> pullChatMessages(@Header("Authorization") Stri

@FormUrlEncoded
@POST
Observable<GenericOverall> sendChatMessage(@Header("Authorization") String authorization,
Observable<ChatOverallSingleMessage> sendChatMessage(@Header("Authorization") String authorization,
@Url String url,
@Field("message") CharSequence message,
@Field("actorDisplayName") String actorDisplayName,
@Field("replyTo") Integer replyTo,
@Field("silent") Boolean sendWithoutNotification);

@FormUrlEncoded
@PUT
Observable<ChatOverallSingleMessage> editChatMessage(@Header("Authorization") String authorization,
@Url String url,
@Field("message") String message);
@Field("silent") Boolean sendWithoutNotification,
@Field("referenceId") String referenceId
);

@GET
Observable<Response<ChatShareOverall>> getSharedItems(
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/nextcloud/talk/api/NcApiCoroutines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.nextcloud.talk.api

import com.nextcloud.talk.models.json.autocomplete.AutocompleteOverall
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
import com.nextcloud.talk.models.json.conversations.RoomOverall
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.participants.AddParticipantOverall
Expand Down Expand Up @@ -121,6 +122,26 @@ interface NcApiCoroutines {
@DELETE
suspend fun unarchiveConversation(@Header("Authorization") authorization: String, @Url url: String): GenericOverall

@FormUrlEncoded
@POST
suspend fun sendChatMessage(
@Header("Authorization") authorization: String,
@Url url: String,
@Field("message") message: CharSequence,
@Field("actorDisplayName") actorDisplayName: String,
@Field("replyTo") replyTo: Int,
@Field("silent") sendWithoutNotification: Boolean,
@Field("referenceId") referenceId: String
): ChatOverallSingleMessage

@FormUrlEncoded
@PUT
suspend fun editChatMessage(
@Header("Authorization") authorization: String,
@Url url: String,
@Field("message") message: String
): ChatOverallSingleMessage

@FormUrlEncoded
@POST
suspend fun banActor(
Expand Down
25 changes: 12 additions & 13 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import retrofit2.HttpException
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
Expand Down Expand Up @@ -769,18 +768,18 @@ class ChatActivity :
}

is MessageInputViewModel.SendChatMessageErrorState -> {
if (state.e is HttpException) {
val code = state.e.code()
if (code.toString().startsWith("2")) {
myFirstMessage = state.message

if (binding.unreadMessagesPopup.isShown) {
binding.unreadMessagesPopup.visibility = View.GONE
}

binding.messagesListView.smoothScrollToPosition(0)
}
}
// if (state.e is HttpException) {
// val code = state.e.code()
// if (code.toString().startsWith("2")) {
// myFirstMessage = state.message
//
// if (binding.unreadMessagesPopup.isShown) {
// binding.unreadMessagesPopup.visibility = View.GONE
// }
//
// binding.messagesListView.smoothScrollToPosition(0)
// }
// }
}

else -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.os.Bundle
import com.nextcloud.talk.chat.data.io.LifecycleAwareManager
import com.nextcloud.talk.chat.data.model.ChatMessage
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow

Expand Down Expand Up @@ -69,4 +70,23 @@ interface ChatMessageRepository : LifecycleAwareManager {
* Destroys unused resources.
*/
fun handleChatOnBackPress()

suspend fun sendChatMessage(
credentials: String,
url: String,
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean,
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>>
}
57 changes: 22 additions & 35 deletions app/src/main/java/com/nextcloud/talk/chat/data/model/ChatMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ data class ChatMessage(

var isTempMessage: Boolean = false,

var tempMessageId: Int = -1
var tempMessageId: Int = -1,

) : MessageContentType, MessageContentType.Image {
var referenceId: String? = null

) : MessageContentType,
MessageContentType.Image {

var extractedUrlToPreview: String? = null

Expand Down Expand Up @@ -238,8 +241,8 @@ data class ChatMessage(
}
}

fun getCalculateMessageType(): MessageType {
return if (!TextUtils.isEmpty(systemMessage)) {
fun getCalculateMessageType(): MessageType =
if (!TextUtils.isEmpty(systemMessage)) {
MessageType.SYSTEM_MESSAGE
} else if (isVoiceMessage) {
MessageType.VOICE_MESSAGE
Expand All @@ -254,19 +257,15 @@ data class ChatMessage(
} else {
MessageType.REGULAR_TEXT_MESSAGE
}
}

override fun getId(): String {
return jsonMessageId.toString()
}
override fun getId(): String = jsonMessageId.toString()

override fun getText(): String {
return if (message != null) {
override fun getText(): String =
if (message != null) {
getParsedMessage(message, messageParameters)!!
} else {
""
}
}

fun getNullsafeActorDisplayName() =
if (!TextUtils.isEmpty(actorDisplayName)) {
Expand All @@ -275,22 +274,19 @@ data class ChatMessage(
sharedApplication!!.getString(R.string.nc_guest)
}

override fun getUser(): IUser {
return object : IUser {
override fun getId(): String {
return "$actorType/$actorId"
}
override fun getUser(): IUser =
object : IUser {
override fun getId(): String = "$actorType/$actorId"

override fun getName(): String {
return if (!TextUtils.isEmpty(actorDisplayName)) {
override fun getName(): String =
if (!TextUtils.isEmpty(actorDisplayName)) {
actorDisplayName!!
} else {
sharedApplication!!.getString(R.string.nc_guest)
}
}

override fun getAvatar(): String? {
return when {
override fun getAvatar(): String? =
when {
activeUser == null -> {
null
}
Expand All @@ -312,21 +308,14 @@ data class ChatMessage(
ApiUtils.getUrlForGuestAvatar(activeUser!!.baseUrl!!, apiId, true)
}
}
}
}
}

override fun getCreatedAt(): Date {
return Date(timestamp * MILLIES)
}
override fun getCreatedAt(): Date = Date(timestamp * MILLIES)

override fun getSystemMessage(): String {
return EnumSystemMessageTypeConverter().convertToString(systemMessageType)
}
override fun getSystemMessage(): String = EnumSystemMessageTypeConverter().convertToString(systemMessageType)

private fun isHashMapEntryEqualTo(map: HashMap<String?, String?>, key: String, searchTerm: String): Boolean {
return map != null && MessageDigest.isEqual(map[key]!!.toByteArray(), searchTerm.toByteArray())
}
private fun isHashMapEntryEqualTo(map: HashMap<String?, String?>, key: String, searchTerm: String): Boolean =
map != null && MessageDigest.isEqual(map[key]!!.toByteArray(), searchTerm.toByteArray())

// needed a equals and hashcode function to fix detekt errors
override fun equals(other: Any?): Boolean {
Expand All @@ -335,9 +324,7 @@ data class ChatMessage(
return false
}

override fun hashCode(): Int {
return 0
}
override fun hashCode(): Int = 0

val isVoiceMessage: Boolean
get() = "voice-message" == messageType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ChatNetworkDataSource {
url: String,
message: String,
displayName: String
): Observable<GenericOverall> // last two fields are false
): Observable<ChatOverallSingleMessage>

fun checkForNoteToSelf(credentials: String, url: String, includeStatus: Boolean): Observable<RoomsOverall>
fun shareLocationToNotes(
Expand All @@ -49,18 +49,19 @@ interface ChatNetworkDataSource {
): Observable<GenericOverall>

fun leaveRoom(credentials: String, url: String): Observable<GenericOverall>
fun sendChatMessage(
suspend fun sendChatMessage(
credentials: String,
url: String,
message: CharSequence,
displayName: String,
replyTo: Int,
sendWithoutNotification: Boolean
): Observable<GenericOverall>
sendWithoutNotification: Boolean,
referenceId: String
): ChatOverallSingleMessage

fun pullChatMessages(credentials: String, url: String, fieldMap: HashMap<String, Int>): Observable<Response<*>>
fun deleteChatMessage(credentials: String, url: String): Observable<ChatOverallSingleMessage>
fun createRoom(credentials: String, url: String, map: Map<String, String>): Observable<RoomOverall>
fun setChatReadMarker(credentials: String, url: String, previousMessageId: Int): Observable<GenericOverall>
fun editChatMessage(credentials: String, url: String, text: String): Observable<ChatOverallSingleMessage>
suspend fun editChatMessage(credentials: String, url: String, text: String): ChatOverallSingleMessage
}
Loading
Loading