mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Adding support for notifications and message preview
This commit is contained in:
parent
78a9bdeb4c
commit
d78ed3215b
@ -423,4 +423,5 @@ fun Event.getPollContent(): MessagePollContent? {
|
||||
return content.toModel<MessagePollContent>()
|
||||
}
|
||||
|
||||
fun Event.supportsNotification() = this.getClearType() in EventType.MESSAGE + EventType.POLL_START
|
||||
fun Event.supportsNotification() =
|
||||
this.getClearType() in EventType.MESSAGE + EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO
|
||||
|
@ -33,5 +33,5 @@ object RoomSummaryConstants {
|
||||
EventType.ENCRYPTED,
|
||||
EventType.STICKER,
|
||||
EventType.REACTION
|
||||
) + EventType.POLL_START
|
||||
) + EventType.POLL_START + EventType.STATE_ROOM_BEACON_INFO
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
|
||||
val allEvents = (newJoinEvents + inviteEvents).filter { event ->
|
||||
when (event.type) {
|
||||
in EventType.POLL_START,
|
||||
in EventType.STATE_ROOM_BEACON_INFO,
|
||||
EventType.MESSAGE,
|
||||
EventType.REDACTION,
|
||||
EventType.ENCRYPTED,
|
||||
|
@ -59,7 +59,7 @@ class DisplayableEventFormatter @Inject constructor(
|
||||
val senderName = timelineEvent.senderInfo.disambiguatedDisplayName
|
||||
|
||||
return when (timelineEvent.root.getClearType()) {
|
||||
EventType.MESSAGE -> {
|
||||
EventType.MESSAGE -> {
|
||||
timelineEvent.getLastMessageContent()?.let { messageContent ->
|
||||
when (messageContent.msgType) {
|
||||
MessageType.MSGTYPE_TEXT -> {
|
||||
@ -100,17 +100,17 @@ class DisplayableEventFormatter @Inject constructor(
|
||||
}
|
||||
} ?: span { }
|
||||
}
|
||||
EventType.STICKER -> {
|
||||
EventType.STICKER -> {
|
||||
simpleFormat(senderName, stringProvider.getString(R.string.send_a_sticker), appendAuthor)
|
||||
}
|
||||
EventType.REACTION -> {
|
||||
EventType.REACTION -> {
|
||||
timelineEvent.root.getClearContent().toModel<ReactionContent>()?.relatesTo?.let {
|
||||
val emojiSpanned = emojiSpanify.spanify(stringProvider.getString(R.string.sent_a_reaction, it.key))
|
||||
simpleFormat(senderName, emojiSpanned, appendAuthor)
|
||||
} ?: span { }
|
||||
}
|
||||
EventType.KEY_VERIFICATION_CANCEL,
|
||||
EventType.KEY_VERIFICATION_DONE -> {
|
||||
EventType.KEY_VERIFICATION_DONE -> {
|
||||
// cancel and done can appear in timeline, so should have representation
|
||||
simpleFormat(senderName, stringProvider.getString(R.string.sent_verification_conclusion), appendAuthor)
|
||||
}
|
||||
@ -119,20 +119,23 @@ class DisplayableEventFormatter @Inject constructor(
|
||||
EventType.KEY_VERIFICATION_MAC,
|
||||
EventType.KEY_VERIFICATION_KEY,
|
||||
EventType.KEY_VERIFICATION_READY,
|
||||
EventType.CALL_CANDIDATES -> {
|
||||
EventType.CALL_CANDIDATES -> {
|
||||
span { }
|
||||
}
|
||||
in EventType.POLL_START -> {
|
||||
in EventType.POLL_START -> {
|
||||
timelineEvent.root.getClearContent().toModel<MessagePollContent>(catchError = true)?.getBestPollCreationInfo()?.question?.getBestQuestion()
|
||||
?: stringProvider.getString(R.string.sent_a_poll)
|
||||
}
|
||||
in EventType.POLL_RESPONSE -> {
|
||||
in EventType.POLL_RESPONSE -> {
|
||||
stringProvider.getString(R.string.poll_response_room_list_preview)
|
||||
}
|
||||
in EventType.POLL_END -> {
|
||||
in EventType.POLL_END -> {
|
||||
stringProvider.getString(R.string.poll_end_room_list_preview)
|
||||
}
|
||||
else -> {
|
||||
in EventType.STATE_ROOM_BEACON_INFO -> {
|
||||
simpleFormat(senderName, stringProvider.getString(R.string.sent_live_location), appendAuthor)
|
||||
}
|
||||
else -> {
|
||||
span {
|
||||
text = noticeEventFormatter.format(timelineEvent, isDm) ?: ""
|
||||
textStyle = "italic"
|
||||
@ -167,7 +170,7 @@ class DisplayableEventFormatter @Inject constructor(
|
||||
}
|
||||
|
||||
return when (event.getClearType()) {
|
||||
EventType.MESSAGE -> {
|
||||
EventType.MESSAGE -> {
|
||||
(event.getClearContent().toModel() as? MessageContent)?.let { messageContent ->
|
||||
when (messageContent.msgType) {
|
||||
MessageType.MSGTYPE_TEXT -> {
|
||||
@ -208,25 +211,28 @@ class DisplayableEventFormatter @Inject constructor(
|
||||
}
|
||||
} ?: span { }
|
||||
}
|
||||
EventType.STICKER -> {
|
||||
EventType.STICKER -> {
|
||||
stringProvider.getString(R.string.send_a_sticker)
|
||||
}
|
||||
EventType.REACTION -> {
|
||||
EventType.REACTION -> {
|
||||
event.getClearContent().toModel<ReactionContent>()?.relatesTo?.let {
|
||||
emojiSpanify.spanify(stringProvider.getString(R.string.sent_a_reaction, it.key))
|
||||
} ?: span { }
|
||||
}
|
||||
in EventType.POLL_START -> {
|
||||
in EventType.POLL_START -> {
|
||||
event.getClearContent().toModel<MessagePollContent>(catchError = true)?.pollCreationInfo?.question?.question
|
||||
?: stringProvider.getString(R.string.sent_a_poll)
|
||||
}
|
||||
in EventType.POLL_RESPONSE -> {
|
||||
in EventType.POLL_RESPONSE -> {
|
||||
stringProvider.getString(R.string.poll_response_room_list_preview)
|
||||
}
|
||||
in EventType.POLL_END -> {
|
||||
in EventType.POLL_END -> {
|
||||
stringProvider.getString(R.string.poll_end_room_list_preview)
|
||||
}
|
||||
else -> {
|
||||
in EventType.STATE_ROOM_BEACON_INFO -> {
|
||||
stringProvider.getString(R.string.sent_live_location)
|
||||
}
|
||||
else -> {
|
||||
span {
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,8 @@ class NotifiableEventResolver @Inject constructor(
|
||||
// only convert encrypted messages to NotifiableMessageEvents
|
||||
when (event.root.getClearType()) {
|
||||
EventType.MESSAGE,
|
||||
in EventType.POLL_START -> {
|
||||
in EventType.POLL_START,
|
||||
in EventType.STATE_ROOM_BEACON_INFO -> {
|
||||
val body = displayableEventFormatter.format(event, isDm = room.roomSummary()?.isDirect.orFalse(), appendAuthor = false).toString()
|
||||
val roomName = room.roomSummary()?.displayName ?: ""
|
||||
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
|
||||
@ -187,7 +188,7 @@ class NotifiableEventResolver @Inject constructor(
|
||||
soundName = null
|
||||
)
|
||||
}
|
||||
else -> null
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2121,6 +2121,7 @@
|
||||
<string name="sent_a_reaction">Reacted with: %s</string>
|
||||
<string name="sent_verification_conclusion">Verification Conclusion</string>
|
||||
<string name="sent_location">Shared their location</string>
|
||||
<string name="sent_live_location">Shared their live location</string>
|
||||
|
||||
<string name="verification_request_waiting">Waiting…</string>
|
||||
<string name="verification_request_other_cancelled">%s cancelled</string>
|
||||
|
Loading…
Reference in New Issue
Block a user