mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-21 13:18:52 +01:00
Provide method to ensure non-empty message text preview for notifications and conversation list
This commit is contained in:
@@ -98,7 +98,7 @@ class NotificationManager @Inject constructor(
|
|||||||
val style = NotificationCompat.MessagingStyle("Me")
|
val style = NotificationCompat.MessagingStyle("Me")
|
||||||
messages.forEach { message ->
|
messages.forEach { message ->
|
||||||
val name = if (message.isMe()) null else conversation.getTitle()
|
val name = if (message.isMe()) null else conversation.getTitle()
|
||||||
style.addMessage(message.body, message.date, name)
|
style.addMessage(message.getSummary(), message.date, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import io.realm.annotations.PrimaryKey
|
|||||||
|
|
||||||
open class Message : RealmObject() {
|
open class Message : RealmObject() {
|
||||||
|
|
||||||
enum class DeliveryStatus { NONE, INFO, FAILED, PENDING, RECEIVED }
|
|
||||||
enum class AttachmentType { TEXT, IMAGE, VIDEO, AUDIO, SLIDESHOW, NOT_LOADED }
|
enum class AttachmentType { TEXT, IMAGE, VIDEO, AUDIO, SLIDESHOW, NOT_LOADED }
|
||||||
|
|
||||||
@PrimaryKey var id: Long = 0
|
@PrimaryKey var id: Long = 0
|
||||||
@@ -95,10 +94,37 @@ open class Message : RealmObject() {
|
|||||||
return isOutgoingMms || isOutgoingSms
|
return isOutgoingMms || isOutgoingSms
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getText() : String {
|
/**
|
||||||
|
* Returns the text that should be displayed in the messagelist view
|
||||||
|
* The returned text may be an empty string
|
||||||
|
*/
|
||||||
|
fun getText(): String {
|
||||||
return when {
|
return when {
|
||||||
isSms() -> body
|
isSms() -> body
|
||||||
else -> parts.filter { it.isText() }.joinToString("") { it.text ?: "" }
|
|
||||||
|
else -> parts
|
||||||
|
.mapNotNull { it.text }
|
||||||
|
.joinToString("\n") { text -> text }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the text that should be displayed when a preview of the message
|
||||||
|
* needs to be displayed, such as in the conversation view or in a notification
|
||||||
|
*
|
||||||
|
* TODO: Don't return a hardcoded string
|
||||||
|
*/
|
||||||
|
fun getSummary(): String {
|
||||||
|
return when {
|
||||||
|
isSms() -> body
|
||||||
|
|
||||||
|
else -> parts
|
||||||
|
.mapNotNull { it.text }
|
||||||
|
.joinToString("\n") { text -> text }
|
||||||
|
.takeIf { it.isNotEmpty() }
|
||||||
|
?: subject
|
||||||
|
.takeIf { it.isNotEmpty() }
|
||||||
|
?: "An MMS message"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class ConversationsAdapter @Inject constructor(
|
|||||||
}
|
}
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
view.date.text = dateFormatter.getConversationTimestamp(message.date)
|
view.date.text = dateFormatter.getConversationTimestamp(message.date)
|
||||||
view.snippet.text = if (message.isMe()) "You: ${message.getText()}" else message.getText()
|
view.snippet.text = if (message.isMe()) "You: ${message.getSummary()}" else message.getSummary()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemViewType(position: Int): Int {
|
override fun getItemViewType(position: Int): Int {
|
||||||
|
|||||||
Reference in New Issue
Block a user