Commit 017f4015 authored by Wilko Manger's avatar Wilko Manger

Handle whitespaces consistent with other apps

Closes #30.
parent 65c883d8
Pipeline #252 passed with stage
in 3 minutes and 8 seconds
......@@ -45,9 +45,15 @@ class ChatEventRemoteSource(private val matrix: Matrix,
: ChatEventSource {
fun send(chatId: String, message: Message) {
val room = matrix.dataHandler.getRoom(chatId)
room.sendTextMessage(message.text, "", "", null)
// Only send non-empty message
if(!message.text.isBlank()) {
val room = matrix.dataHandler.getRoom(chatId)
// Remove leading and trailing whitespace
val text = message.text.trim()
room.sendTextMessage(text, "", "", null)
}
}
@Suppress("UNCHECKED_CAST")
......@@ -107,7 +113,6 @@ class ChatEventRemoteSource(private val matrix: Matrix,
}
EVENT_TYPE_STATE_ROOM_MEMBER -> {
val membership = json?.get("membership")?.asString
Log.d("membership", membership)
val type = when (membership) {
"invite" -> MemberChangeType.INVITE
......@@ -121,8 +126,6 @@ class ChatEventRemoteSource(private val matrix: Matrix,
val subject = User(event.stateKey,
json?.get("displayname")?.asString ?: "")
Log.d("subject", subject.toString())
MemberChangeEvent(
id = id,
sentAt = sentAt,
......
......@@ -183,6 +183,7 @@ class ChatEventAdapter(private val isDirect: Boolean,
holder as EventHolder
holder.layout.content.text = item.text.fromHtml()
// Set the time in the message
holder.layout.time.text = item.sentAt.formatAsTime()
......
......@@ -5,9 +5,10 @@ import android.text.Html
import android.text.Spanned
fun String.fromHtml(): Spanned {
val str = this.replace(" ", " ")
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(this, Html.FROM_HTML_MODE_COMPACT)
Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT)
} else {
Html.fromHtml(this)
Html.fromHtml(str)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment